
Hi, when embedding python 3.1, I have my own free-method in tp_dealloc. The allocated memory is in host-memory, not in python (dll). Now, the problem is, Python appears to read-access the deallocated memory still after tp_dealloc. After tp_dealloc, I get an access violation if the pyobject-header fields have been modified inside tp_dealloc. If I leave the header unmodified, then no access violation occurs. Accessing deallocated memory sounds like a bug, or is this intended design? Thank you Marvin -- GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT! Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01

smarv@gmx.net wrote:
Now, the problem is, Python appears to read-access the deallocated memory still after tp_dealloc.
It's not clear exactly what you mean by "after tp_dealloc". The usual pattern is for a type's tp_dealloc method to call the base type's tp_dealloc, which can make further references to the object's memory. At the end of the tp_dealloc chain, tp_free gets called, which is what actually deallocates the memory. I would say your tp_dealloc shouldn't be modifying anything in the object struct that your corresponding tp_alloc method didn't set up, because code further along the tp_dealloc chain may rely on it. That includes fields in the object header. -- Greg

smarv@gmx.net wrote:
Now, the problem is, Python appears to read-access the deallocated memory still after tp_dealloc.
It's not clear exactly what you mean by "after tp_dealloc". The usual pattern is for a type's tp_dealloc method to call the base type's tp_dealloc, which can make further references to the object's memory. At the end of the tp_dealloc chain, tp_free gets called, which is what actually deallocates the memory. I would say your tp_dealloc shouldn't be modifying anything in the object struct that your corresponding tp_alloc method didn't set up, because code further along the tp_dealloc chain may rely on it. That includes fields in the object header. -- Greg
participants (2)
-
Greg Ewing
-
smarv@gmx.net