DIP77 - Fix unsafe RC pass by 'ref'

Walter Bright via Digitalmars-d digitalmars-d at puremagic.com
Fri Apr 10 02:14:32 PDT 2015


On 4/10/2015 2:14 AM, "Ola Fosheim =?UTF-8?B?R3LDuHN0YWQi?= 
<ola.fosheim.grostad+dlang at gmail.com>" wrote:
> On Friday, 10 April 2015 at 08:47:09 UTC, Walter Bright wrote:
>> On 4/10/2015 12:10 AM, "Ola Fosheim =?UTF-8?B?R3LDuHN0YWQi?=
>>> ref1 -> Node->RCRef->Edge(RCO)->Node->RCRef->Edge(RCO)->Node"X"
>>> ref2 -> Node"X"
>>
>> Because with two parameters, if one is a ref coming from an RCO rc1, and the
>> other is a ref to a type that is the root of a graph that contains an RCO
>> type, then the rc1 is copied.
>
> ref1 -> RCO1 -> N1 -> RCRef1 -> RCO2 -> N2 -> RCRef3 -> RCO3 -> N3
> ref2 -> N3
>
> N1..N3 represent resources (like a file).
>
> process(ref1,ref2){
>      ref1.stuff.stuff.stuff.release(); // Node2 and Node3 is released.
>      ref2.read(); // fails/garbage
> }


ref2 is copied.


More information about the Digitalmars-d mailing list