On Tue, 31 Oct 2006 03:36:59 -0800, Martin Albrecht  
<[EMAIL PROTECTED]> wrote:
> On Tuesday 31 October 2006 08:42, you wrote:
>> Hi David and Martin,
>> and it worked.  Evidently Pyrex doesn't generate code to initialize the
>> __weakref__ PyObject* to 0.  And, unfortunately, to use __weakref__ with
>> Pyrex, you have to use the notation
>>
>>      cdef object __weakref__
>>
>> Once you do that, I think there is no way to write
>>
>>      self.__weakref__ = NULL
>
>> wince NULL is not a Python object, and __weakref__ *has* to be one.
>
> How about a macro doing this? This would bypass Pyrex's restrictions?

I don't know.  Maybe.  But then one has to know to explicitly use that  
macro
every time for every object what defines.  And there could be problems  
because
Pyrex definitely always assigns the None object to __weakref__ and  
increments
its reference count.  Moreover, Pyrex claims to and should treat this
weakref thing transparently.

>> Moreover, according to the Python guide, one must call this code
>> in the destructor:
>>
>>      if (inst->in_weakreflist != NULL)
>>          PyObject_ClearWeakRefs((PyObject *) inst);
>
>> Pyrex doesn't generate any code that has ClearWekRefs in it, so again
>> I think it's messed up regarding its support for weak references.
>
> Can't we just call this (using a macro or "C name specifier")  in the
> destructor? Or is there a destructor after the one which we can control?

We could likely call it explicitly.  However, again Pyrex claims to
(and should) treat all weakref stuff automatically, i.e., Pyrex is
the place where this code goes.

William

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/sage-devel
URLs: http://sage.scipy.org/sage/ and http://modular.math.washington.edu/sage/
-~----------~----~----~----~------~----~------~--~---

Reply via email to