[Pyrex] Weakrefs patch
Peter Johnson
peter at tortall.net
Fri Dec 8 04:48:20 UTC 2006
On Fri, 8 Dec 2006, Greg Ewing wrote:
> Peter Johnson wrote:
>> I recently ran into this problem myself (as the current code causes Python
>> to crash), so I whipped up a quick patch that fixes it for me. I think it
>> follows all of the weakref guidelines now.
>
> Thanks, I'll see about incorporating this into the
> main version.
>
> One thing that bothers me a little is that if the
> __weakref__ slot can now be NULL, things will blow
> up if the user tries to reference it as a normal
> attribute, so I might have to put something in to
> prevent that. Probably a good idea anyway, since
> the user shouldn't be messing with it in the first
> place.
>
> Or should they? Are there any legitimate uses for
> Pyrex code to access the __weakref__ attribute?
I don't believe so, and hiding it is probably a good idea if doing so
would cause blowup.
> And if not, perhaps it shouldn't have a user visible
> name at all? Would some other way of signalling
> weak-referenceability be better?
It looks like normal the normal Python way to do this is by doing:
import weakref
class foo(weakref.ref)
but I think this is ugly for Pyrex to try to handle. Maybe instead derive
the class from it as a keyword? e.g.
cdef class foo(__weakref__)
? But I've not yet looked to see how hard this would be to implement.
-Peter
More information about the Pyrex
mailing list