[Python-Dev] Activating pymalloc (original) (raw)

Jack Jansen Jack.Jansen@oratrix.com
Fri, 15 Mar 2002 10:54:44 +0100


On Friday, March 15, 2002, at 08:20 , Tim Peters wrote:

[Andrew MacIntyre]

My OS/2 build definitely uses threads (don't remember what FreeBSD ./configures to), and survives all the threading tests - which may not highlight the problems you're referring to. Switching to pymalloc shouldn't be a correctness issue for code playing strictly by the rules. The historical problem is that the Python C API exposes more different spellings for "get memory" and "free memory" than you may believe possible, "the rules" for navigating this maze aren't documented, and so far all the spellings have reduced to plain "malloc" and "free".

This may be overkill, but we could check correct usage of allocator/free pairs in a DEBUG build. At the end of pymem.h conditionally include pymemdebug.h which painstakingly replaces all the *alloc and *free defines with versions that go to a set of routines that check that something freed with PyFooBAR_FREE() has actually been allocated with PyFooBAR_ALLOC(). The accompanying pymemdebug.c would have magic to disable the inclusion of pymemdebug.h when it includes pymem.h, so the debugging routines actually get to use what was defined in pymem.h.