Dag Sverre Seljebotn, 25.03.2010 20:08:
> Stefan Behnel wrote:
>> Lisandro Dalcin, 25.03.2010 19:43:
>>> BTW, I've previously commented on something related to this ... In
>>> CPython, classes defining  __del__() are not GC'ed, because __del__
>>> can invoke arbitrary Python code... However, this is not the case for
>>> Cython's __dealloc__ ...  Am I missing something?
>>
>> Well, yes, there is a difference. Python code can only do Python operations
>> for cleanup, so this can lead to all sorts of complications. On the other
>> hand, C code can run any kind of safe C operations, and this is often
>> required for timely memory cleanup in wrapper code.
>>
>> The special __dealloc__ method serves the latter purpose. Although it
>> certainly is not hard to write crashing code in __dealloc__, it's rather
>> unlikely that someone does so a) on purpose or b) without recognising it
>> somewhat soon due to a crash.
>>
> Would __dealloc__ be implied "nogil" (that is, as in the signature, not
> as in "with nogil") solve anything which isn't already solved? Or is
> that already the case?

No, it's not, and Python operations are not evil per se. From the top of my 
head, I don't even know which Python operations are really dangerous in 
__dealloc__, and even those that are may not lead to an error in a 
particular case due to the way GC works. So I'd prefer allowing them in 
general, and just discourage them in the docs. If we ever find patterns 
that should better be disallowed, we can try to issue a warning, but 
detecting that programmatically may not be trivial.

I think this is one of those parts of the language where we just have to 
accept that people can use it to shoot themselves in the foot.

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

Reply via email to