Extension objects in Python 1.5 and 2.2
Martin v. Löwis
loewis at informatik.hu-berlin.de
Thu Jun 13 09:48:35 CEST 2002
Martin Sjögren <martin at strakt.com> writes:
> How do I write extension objects so that they work in both Python 1.5 and
> the 2.x series?
This can work only on the source level. Binary compatibility of
modules is, in general, not possible between 1.5 and 2.x (even though
it will work fine in certain cases).
> Until now, I've used PyObject_New and PyObject_Del for 2.x, are
> there an equivalent set for 1.5 and if so, can they be used in 2.x
> too, or do I have to #ifdef?
In 1.5, you need to use PyObject_NEW and PyMem_DEL. You can get the
1.5 documentation from
> What's the correct way to do this? And gee, it would be nice if the
> objects were classes in 2.2 too, but I suppose that'd be a LOT of
You would normally use #ifdefs, indeed.
To make extension types classes, the biggest problem is that you need
to fill additional slots in the type objects, slots that were not
available in 1.5. So you #ifdef part of the type object (potentially
also the functions in the slots, although that is not strictly
More information about the Python-list