[Python-Dev] Debug entry points for PyMalloc

Aahz aahz@pythoncraft.com
Sat, 23 Mar 2002 16:05:45 -0500


On Thu, Mar 21, 2002, Tim Peters wrote:
>
> + Define three special bit patterns.  In hex, they all end with B
>   (for deBug <wink>), and begin with a vaguely mnemonic letter.
>   Strings of these are unlikely to be legit memory addresses, ints,
>   7-bit ASCII, or floats:
> 
> #define PYMALLOC_CLEANBYTE      0xCB    /* uninitialized memory */
> #define PYMALLOC_DEADBYTE       0xDB    /* free()ed memory */
> #define PYMALLOC_FORBIDDENBYTE  0xFB    /* unusable memory */
> 
>   The debug malloc/free/realloc use these as follows.  Note that this
>   stuff is done regardless of whether PyMalloc handles the request
>   directly or passes it on to the platform malloc (in fact, the debug
>   entry points won't know and won't care).
> 
> + The Debug malloc asks for 16 extra bytes and fills them with
>   useful stuff:

I'm almost certainly betraying my ignorance here, but it sounds to me
like malloc isn't doing any sanity checking to make sure that the memory
it received isn't already being used.  Should each PyDebugMalloc() walk
through the list of used memory?
-- 
Aahz (aahz@pythoncraft.com)           <*>         http://www.pythoncraft.com/

"We should forget about small efficiencies, about 97% of the time.
Premature optimization is the root of all evil."  --Knuth