April 13, 2008
"Jarrett Billingsley" <kb3ctd2@yahoo.com> wrote in message news:fttdej$1nfs$1@digitalmars.com...
> "Sean Kelly" <sean@invisibleduck.org> wrote in message news:fttd02$1mp1$1@digitalmars.com...
>>
>> Are these tables AAs?  And how do the weak references store their
>> reference?
>> The type information provided to AAs is a bit weak, and so some
>> non-pointer
>> data is currently still scanned by the GC.  I'm going to improve this a
>> bit in the
>> next Tango release, but it still won't be perfect (because the compiler
>> doesn't
>> provide enough info for it to be).
>
> In my tests I've just been doing
>
> auto weakref = new WeakRef!(A)(new A);
>
> and then checking that after doing god-knows-what to try to get it to collect that instance of A, so it's not even that I'm doing anything that crazy.
>

Testing my code in Linux causes a crash in glibc's free() after the program exits.  (And the assertion still fails.)

Something really weird is happening.


April 13, 2008
"Bill Baxter" <dnewsgroup@billbaxter.com> wrote in message news:fttn2m$2emt$1@digitalmars.com...
> Michel Fortin wrote:
>> On 2008-04-12 17:24:44 -0400, "Jarrett Billingsley" <kb3ctd2@yahoo.com> said:
>>
>>> Is this possible at all?  Am I just not using Bill's weakref properly?
>>
>> I've been using an alternate strategy in the D/Objective-C bridge for the bridged object lookup table. Basically, I'm casting object references to size_t (so they're no longer pointers)
>
> Yes, that's what the weak ref class does.
>
>> and mangling the pointers (so the garbage collector can't see them as pointers, I think this is no longer be necessary).
>
> I agree that that's not necessary.
>
>> When the bridged object gets deleted on the D side, it removes its mangled pointer from the table.
>>
>> So if your referenced object knows about its weak reference in the table, you could implement it as such and don't have to worry about null pointers polluting your table.
>
> Good idea.  I was thinking to suggest something like that too.  A WeakRef class is not really an optimal way to keep track of a collection of weak refs.  In addition to null pointers polluting the table, there's also just the basic overhead of needing to create an extra object for each entry. Ideally there would be WeakArray, WeakSet, WeakHeap... etc. I think I've seen such things in some language.  Python maybe?

Lua's tables can have weak keys, weak values, or both.


April 13, 2008
Jarrett Billingsley wrote:
> Lua's tables can have weak keys, weak values, or both. 

And MiniD's...? ;-P
April 13, 2008
"Robert Fraser" <fraserofthenight@gmail.com> wrote in message news:fttt4r$2oic$2@digitalmars.com...
> Jarrett Billingsley wrote:
>> Lua's tables can have weak keys, weak values, or both.
>
> And MiniD's...? ;-P

If I had a weak reference lib for D it could X(


April 14, 2008
Jarrett Billingsley wrote:

> "Jarrett Billingsley" <kb3ctd2@yahoo.com> wrote in message news:fttdej$1nfs$1@digitalmars.com...
>> "Sean Kelly" <sean@invisibleduck.org> wrote in message news:fttd02$1mp1$1@digitalmars.com...
>>>
>>> Are these tables AAs?  And how do the weak references store their
>>> reference?
>>> The type information provided to AAs is a bit weak, and so some
>>> non-pointer
>>> data is currently still scanned by the GC.  I'm going to improve this a
>>> bit in the
>>> next Tango release, but it still won't be perfect (because the compiler
>>> doesn't
>>> provide enough info for it to be).
>>
>> In my tests I've just been doing
>>
>> auto weakref = new WeakRef!(A)(new A);
>>
>> and then checking that after doing god-knows-what to try to get it to collect that instance of A, so it's not even that I'm doing anything that crazy.
>>
> 
> Testing my code in Linux causes a crash in glibc's free() after the
> program
> exits.  (And the assertion still fails.)
> 
> Something really weird is happening.

Ok, my latest testing (and testing by others for configurations I don't have) are collected in the list below.  I don't see any pattern.

tango+linux+dmd = works
tango+linux+gdc = crash in glibc
tango+windows+dmd = does not collect
tango+windows+gdc = ???
phobos+linux+dmd = works
phobos+linux+gdc = does not collect
phobos+windows+dmd = ???
phobos+windows+gdc = ???

These tests are based off the code at http://tango.pastebin.com/m10aa57b6 Note that phobos users must comment out the version=Tango line.  Any additional tests would be appreciated.

April 14, 2008
== Quote from Jarrett Billingsley (kb3ctd2@yahoo.com)'s article
> "Sean Kelly" <sean@invisibleduck.org> wrote in message news:fttd02$1mp1$1@digitalmars.com...
> >
> > Are these tables AAs?  And how do the weak references store their
> > reference?
> > The type information provided to AAs is a bit weak, and so some
> > non-pointer
> > data is currently still scanned by the GC.  I'm going to improve this a
> > bit in the
> > next Tango release, but it still won't be perfect (because the compiler
> > doesn't
> > provide enough info for it to be).
> In my tests I've just been doing
> auto weakref = new WeakRef!(A)(new A);
> and then checking that after doing god-knows-what to try to get it to
> collect that instance of A, so it's not even that I'm doing anything that
> crazy.

Just for kicks, try querying the GC to determine whether the GC thinks weakref contains pointers.


Sean
April 14, 2008
Jason House wrote:
> Jarrett Billingsley wrote:
> 
>> "Jarrett Billingsley" <kb3ctd2@yahoo.com> wrote in message
>> news:fttdej$1nfs$1@digitalmars.com...
>>> "Sean Kelly" <sean@invisibleduck.org> wrote in message
>>> news:fttd02$1mp1$1@digitalmars.com...
>>>> Are these tables AAs?  And how do the weak references store their
>>>> reference?
>>>> The type information provided to AAs is a bit weak, and so some
>>>> non-pointer
>>>> data is currently still scanned by the GC.  I'm going to improve this a
>>>> bit in the
>>>> next Tango release, but it still won't be perfect (because the compiler
>>>> doesn't
>>>> provide enough info for it to be).
>>> In my tests I've just been doing
>>>
>>> auto weakref = new WeakRef!(A)(new A);
>>>
>>> and then checking that after doing god-knows-what to try to get it to
>>> collect that instance of A, so it's not even that I'm doing anything that
>>> crazy.
>>>
>> Testing my code in Linux causes a crash in glibc's free() after the
>> program
>> exits.  (And the assertion still fails.)
>>
>> Something really weird is happening.
> 
> Ok, my latest testing (and testing by others for configurations I don't
> have) are collected in the list below.  I don't see any pattern.
> 
> tango+linux+dmd = works
> tango+linux+gdc = crash in glibc
> tango+windows+dmd = does not collect
> tango+windows+gdc = ???
> phobos+linux+dmd = works
> phobos+linux+gdc = does not collect
> phobos+windows+dmd = ???
> phobos+windows+gdc = ???
> 
> These tests are based off the code at http://tango.pastebin.com/m10aa57b6
> Note that phobos users must comment out the version=Tango line.  Any
> additional tests would be appreciated.
> 

I'd be worried about stack references in the second example.  That inner function makeWa may be getting inlined or something with some compiler combos.

The first unittest there works ok right?  Maybe explicitly overwriting a with null after using it would help.

Anyway, I'm pretty sure Sean said after he added the functions to Tango that he thought they should work but they weren't tested very well.  So I wouldn't be surprised if there were issues.  And really, Phobos's gc functions for weak ref support probably haven't been tested all that well either.

--bb
April 14, 2008
Sean Kelly wrote:

> == Quote from Jarrett Billingsley (kb3ctd2@yahoo.com)'s article
>> "Sean Kelly" <sean@invisibleduck.org> wrote in message news:fttd02$1mp1$1@digitalmars.com...
>> >
>> > Are these tables AAs?  And how do the weak references store their
>> > reference?
>> > The type information provided to AAs is a bit weak, and so some
>> > non-pointer
>> > data is currently still scanned by the GC.  I'm going to improve this a
>> > bit in the
>> > next Tango release, but it still won't be perfect (because the compiler
>> > doesn't
>> > provide enough info for it to be).
>> In my tests I've just been doing
>> auto weakref = new WeakRef!(A)(new A);
>> and then checking that after doing god-knows-what to try to get it to
>> collect that instance of A, so it's not even that I'm doing anything that
>> crazy.
> 
> Just for kicks, try querying the GC to determine whether the GC thinks weakref contains pointers.
> 
> 
> Sean

How would one do that?
April 14, 2008
Bill Baxter wrote:

> Jason House wrote:
>> Jarrett Billingsley wrote:
>> 
>>> "Jarrett Billingsley" <kb3ctd2@yahoo.com> wrote in message news:fttdej$1nfs$1@digitalmars.com...
>>>> "Sean Kelly" <sean@invisibleduck.org> wrote in message news:fttd02$1mp1$1@digitalmars.com...
>>>>> Are these tables AAs?  And how do the weak references store their
>>>>> reference?
>>>>> The type information provided to AAs is a bit weak, and so some
>>>>> non-pointer
>>>>> data is currently still scanned by the GC.  I'm going to improve this
>>>>> a bit in the
>>>>> next Tango release, but it still won't be perfect (because the
>>>>> compiler doesn't
>>>>> provide enough info for it to be).
>>>> In my tests I've just been doing
>>>>
>>>> auto weakref = new WeakRef!(A)(new A);
>>>>
>>>> and then checking that after doing god-knows-what to try to get it to collect that instance of A, so it's not even that I'm doing anything that crazy.
>>>>
>>> Testing my code in Linux causes a crash in glibc's free() after the
>>> program
>>> exits.  (And the assertion still fails.)
>>>
>>> Something really weird is happening.
>> 
>> Ok, my latest testing (and testing by others for configurations I don't have) are collected in the list below.  I don't see any pattern.
>> 
>> tango+linux+dmd = works
>> tango+linux+gdc = crash in glibc
>> tango+windows+dmd = does not collect
>> tango+windows+gdc = ???
>> phobos+linux+dmd = works
>> phobos+linux+gdc = does not collect
>> phobos+windows+dmd = ???
>> phobos+windows+gdc = ???
>> 
>> These tests are based off the code at http://tango.pastebin.com/m10aa57b6 Note that phobos users must comment out the version=Tango line.  Any additional tests would be appreciated.
>> 
> 
> I'd be worried about stack references in the second example.  That inner function makeWa may be getting inlined or something with some compiler combos.
> 
> The first unittest there works ok right?  Maybe explicitly overwriting a with null after using it would help.
> 
> Anyway, I'm pretty sure Sean said after he added the functions to Tango that he thought they should work but they weren't tested very well.  So I wouldn't be surprised if there were issues.  And really, Phobos's gc functions for weak ref support probably haven't been tested all that well either.
> 
> --bb

I'm mostly trying to extract as much info as I can from this example to better help me file a bug report.  The unit test can't differentiate between "never cleans up" and "didn't clean up from register values hanging around"...  Nevertheless, it's a good start for further investigation. Certainly the crash inside glibc is a bug in either gdc, tango, or both.
April 14, 2008
== Quote from Jason House (jason.james.house@gmail.com)'s article
> Sean Kelly wrote:
> > == Quote from Jarrett Billingsley (kb3ctd2@yahoo.com)'s article
> >> "Sean Kelly" <sean@invisibleduck.org> wrote in message news:fttd02$1mp1$1@digitalmars.com...
> >> >
> >> > Are these tables AAs?  And how do the weak references store their
> >> > reference?
> >> > The type information provided to AAs is a bit weak, and so some
> >> > non-pointer
> >> > data is currently still scanned by the GC.  I'm going to improve this a
> >> > bit in the
> >> > next Tango release, but it still won't be perfect (because the compiler
> >> > doesn't
> >> > provide enough info for it to be).
> >> In my tests I've just been doing
> >> auto weakref = new WeakRef!(A)(new A);
> >> and then checking that after doing god-knows-what to try to get it to
> >> collect that instance of A, so it's not even that I'm doing anything that
> >> crazy.
> >
> > Just for kicks, try querying the GC to determine whether the GC thinks weakref contains pointers.
> >
> >
> > Sean
> How would one do that?

(from memory)

    if( GC.getAttr( weakref ) & GC.BlkAttr.NO_SCAN )
        printf( "The GC will not scan weakref\n" );


Sean