[Python-Dev] Debug entry points for PyMalloc (original) (raw)

Tim Peters tim.one@comcast.net
Thu, 21 Mar 2002 14:45:32 -0500


[Michael Hudson]

... Presuambly it would be possible to do this wrapped around malloc() & free() too?

Provided they were spelled PyMem_Malloc etc, sure. The debug routines as sketched don't make any secret assumptions about the underlying allocators they call.

No real point, I guess.

There may be an excellent point to it: one of the pad bytes could be used to record which "API family" a block of memory came from. Then a mismatching realloc/free could be caught directly at the time it happened.

+ The Debug free first uses the address to find the number of bytes originally asked for, then checks the 8 bytes on each end for sanity (in particular, that the PYMALLOCFORBIDDENBYTEs are still intact). XXX Make this checking a distinct entry point.

Yes. Particularly if you can call it from gdb.

Is something extraordinary required to make that possible? I had in mind nothing fancier than

extern void _PyMalloc_DebugCheckAddress(void* p);

... Is it worth having an option where you don't call Free?

Not if I have to code it.

... What are you waiting for?

For endless silly objections to fade away .