RCArray is unsafe

Andrei Alexandrescu via Digitalmars-d digitalmars-d at puremagic.com
Mon Mar 2 13:00:53 PST 2015


On 3/2/15 12:37 PM, Walter Bright wrote:
> On 3/1/2015 12:51 PM, Michel Fortin wrote:
>> That's actually not enough. You'll have to block access to global
>> variables too:
>>
>>      S s;
>>
>>      void main() {
>>          s.array = RCArray!T([T()]);   // s.array's refcount is now 1
>>          foo(s.array[0]);           // pass by ref
>>      }
>>      void foo(ref T t) {
>>          s.array = RCArray!T([]);      // drop the old s.array
>>          t.doSomething();              // oops, t is gone
>>      }
>
> Thinking about it, there are many other ways this can happen. At the
> moment, I'm stuck thinking of a solution other than requiring foo() to
> be pure. Anyone have ideas?

I have a solution (as in working implementation), but also a deadline 
that's staring me in the face so this will have to wait a couple more days.

I also have a bit of an attack to const/immutable support but that's 
less good (allows too much freedom).


Andrei



More information about the Digitalmars-d mailing list