468,306 Members | 1,264 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,306 developers. It's quick & easy.

IMPORTANT 2.5 API changes for C Extension Modules and Embedders

If you don't write or otherwise maintain Python Extension Modules
written in C (or C++) or embed Python in your application,
you can stop reading.

Python 2.5 alpha 1 was released April 5, 2006. The second alpha
should be released in a few weeks. There are several changes
which can cause C extension modules or embedded applications
to crash the interpreter if not fixed. Periodically, I will send out
these reminders with updated information until 2.5 is released.

* support for 64-bit sequences (eg, > 2GB strings)
* memory allocation modifications

64-bit changes
There are important changes that are in 2.5 to support 64-bit systems.
The 64-bit changes can cause Python to crash if your module is not upgraded
to support the changes. Python was changed internally to use 64-bit
values on 64-bit machines for indices. If you've got a machine with
more than 16 GB of RAM, it would be great if you can test Python with
large (> 2GB) strings and other sequences.

For more details about the Python 2.5 schedule:
For more details about the 64-bit change:
How to fix your module:

The effbot wrote a program to check your code and find potential
problems with the 64-bit APIs.

Memory Allocation Modifications
In previous versions of Python, it was possible to use different
families of APIs (PyMem_* vs. PyObject_*) to allocate and free
the same block of memory. APIs in these families include:

PyMem_*: PyMem_Malloc, PyMem_Realloc, PyMem_Free,
PyObject_*: PyObject_Malloc, PyObject_Realloc, PyObject_Free

There are a few other APIs with similar names and also the macro variants.

In 2.5, if allocate a block of memory with one family, you must reallocate
or free with the same family. That means:

If you allocate with PyMem_Malloc (or MALLOC), you must reallocate
with PyMem_Realloc (or REALLOC) and free with PyMem_Free (or FREE).
If you allocate with PyObject_Malloc (or MALLOC), you must reallocate
with PyObject_Realloc (or REALLOC) and free with PyObject_Free (or FREE).

Using inconsistent APIs can cause double frees or otherwise crash
the interpreter. It is fine to mix and match functions or macros
within the same family.

Please test and upgrade your extension modules!

Apr 12 '06 #1
0 746

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Simon Burton | last post: by
3 posts views Thread by nnorwitz | last post: by
1 post views Thread by zpinhead | last post: by
reply views Thread by shamirza | last post: by
1 post views Thread by Stefan Braumeister | last post: by
15 posts views Thread by kyosohma | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.