Lisandro Dalcin, 27.08.2010 18:08:
> On 27 August 2010 09:40, Stefan Behnel wrote:
>>
>> BTW, now that you mention it - does anyone know what became of the idea to
>> allow a
>>
>>      cdef __dict__
>>
>> attribute notation (as for __weakref__) to add a dict to an extension type?
>> AFAIR, that was already proposed more than once on this list.
>>
>
> Here you have a tentative patch (use "hg import --no-commit ...")
>
> There is a small gotcha, tough... CPython makes an optimization and
> the instance dict in created on-demand. My patch unconditionally
> creates the dict at tp_new. If not, the dict slot in the object
> structure has to be set to NULL, but any usage of __dict__ in cdef
> methods will assume non-NULL and segfault.

Why is that? Does the external lookup code pass through the slot directly? 
I can't see that from your patch. Also, I don't see why this would be 
necessary. I don't think access to TheType.__dict__ or obj.__dict__ is 
commonly performance critical enough to require direct slot access. From my 
point of view, descriptor based access would be perfectly ok, and on-demand 
instantiation would work just fine with that.

I think the right way to implement this is with custom decriptors for both 
the type and its instance.

Stefan
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to