[Pyrex] NoneType object is not callable in dealloc
Lenard Lindstrom
len-l at telus.net
Thu Sep 29 21:35:22 CEST 2005
On 29 Sep 2005 at 20:57, AKX wrote:
> Hiya,
>
> I'm making a rather large wrapper for a rather large library, but now
> I've reached an impasse...
>
> When a program exits with an AlFont instance in memory, it crashes
> (Win32), emitting "Exception exceptions.TypeError: "'NoneType' object
> is not callable" in <_pyalleg.AlFont object at 0x009EC060> ignored".
> Through print debugging (arcane art, I say), I've found out it crashes
> in the debug() line. Other classes built similarly do not crash in a
> similar situation.
>
> The responsible code follows (and the generated C is a bit abridged
> and formatted).
>
> Does anyone have any pointers on how to fix this, or is it a Pyrex
> bug? (Always blame the tool developers... just kidding, Pyrex rocks.)
>
> Thanks in advance,
>
> AKX
>
> --------------------------------------------------------------------------------
>
> == _pyalleg.pyx snippet ==
>
> cdef class AlFont:
> cdef ALFONT_FONT *f
> # SNIP
> def __dealloc__(self):
> if self.f!=NULL: # <-- line 825
> debug("Deallocating AlFont "+str(self))
> alfont_destroy_font(self.f) # void ... (ALFONT_FONT *)
> self.f=NULL
> # SNIP
It is possible the debug function is garbage collected before the AlFont instance. Try
this:
cdef class AlFont:
<cdefs>
cdef object debug
def __new__(self, ...): # or __init__
self.debug = debug
<other stuff>
def __dealloc__(self):
if ...
self.debug("Deallocating AlFont" + str(self))
Making debug an attribute keeps it alive until the AlFont instance deallocated.
Lenard Lindstrom
<len-l at telus.net>
More information about the Pyrex
mailing list