[Python-Dev] pdb segfaults in 2.5 trunk?

Tim Peters tim.peters at gmail.com
Tue Apr 11 03:33:08 CEST 2006


[Greg Ewing]
> However, if they're not exclusively for objects,
> having "Object" in the name would seem to be
> highly confusing, perhaps dangerously so. (Person
> A writes PyObject_Alloc(some_chars), Person B
> writing the code to free it thinks "What???
> That can't be right!" and uses PyMem_Free.)

Given that it's been this way since the PyObject_ memory family was
introduced, and a real Person B hasn't posted to complain about being
led into temptation yet, sorry, I don't take this argument seriously. 
The comments in objimpl.h tell the truth, and it's really quite
simple:

   For allocating objects, use PyObject_{New, NewVar} instead whenever
   possible.  The PyObject_{Malloc, Realloc, Free} family is exposed
   so that you can exploit Python's small-block allocator for non-object
   uses.  If you must use these routines to allocate object memory, make sure
   the object gets initialized via PyObject_{Init, InitVar} after obtaining
   the raw memory.


More information about the Python-Dev mailing list