[Python-3000] cleaning up different ways to free an object

Neal Norwitz nnorwitz at gmail.com
Sun Aug 19 20:50:47 CEST 2007


I just fixed a bug in the new memoryview that used PyObject_DEL which
caused a problem in debug mode.  I had to change it to a Py_DECREF.
It seems we have a lot of spellings of ways to free an object and I
wonder if there are more problems lurking in there.

$ cat */*.c | grep -c PyObject_Del
103
$ cat */*.c | grep -c PyObject_DEL
16
$ cat */*.c | grep -c PyObject_Free
16
$ cat */*.c | grep -c PyObject_FREE
19

I don't know how many of these are correct or incorrect.

Note in Include/objimpl, the Del and Free variants are the same.  I
plan to get rid of one of them.

#define PyObject_Del            PyObject_Free
#define PyObject_DEL            PyObject_FREE

PyObject_{MALLOC,REALLOC,FREE} depend upon whether python is compiled
with debug mode, pymalloc, or not.

What are the rules for when a particular API should be used (or not
used) to free an object?

n


More information about the Python-3000 mailing list