[Python-Dev] Pymalloc and backward compatibility

Neil Schemenauer nas@python.ca
Thu, 4 Apr 2002 07:20:50 -0800


Moore, Paul wrote:
> I've been watching the pymalloc discussions going on recently, and I'm
> concerned that there may be some fairly major compatibility changes
> coming.

We are trying to avoid that.

> The code has survived essentially unchanged through [Python 1.4] to
> Python 2.2, and still works fine.

This is a great test case.  Can you provide a URL to the code?

> It seems to me that there are two options open for me:
> 
> 1. The Python API from 1.4 is still guaranteed to work unchanged (even given
> the liberties mentioned above). In that case, do nothing.
> 2. There are changes required. In that case, make them, protected by python
> API checks (annoying ifdef fun).

As long as you don't use free() to deallocate objects then you are safe.
Python 1.4 has PyMem_DEL.  You can use a macro like this:

    #if PY_VERSION_HEX < 0x01060000
    #define PyObject_New PyObject_NEW
    #define PyObject_Del PyMem_DEL
    #endif

and use PyObject_New and PyObject_Del to manage object memory.

  Neil