mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Note C API incompatibilities
This commit is contained in:
parent
4e86195a99
commit
f7c6290ca4
1 changed files with 32 additions and 0 deletions
|
@ -1453,6 +1453,23 @@ actually drop when you delete them, and the memory may be returned to
|
||||||
the operating system. (Implemented by Evan Jones, and reworked by Tim
|
the operating system. (Implemented by Evan Jones, and reworked by Tim
|
||||||
Peters.)
|
Peters.)
|
||||||
|
|
||||||
|
Note that this change means extension modules need to be more careful
|
||||||
|
with how they allocate memory. Python's API has a number of different
|
||||||
|
functions for allocating memory that are grouped into families. For
|
||||||
|
example, \cfunction{PyMem_Malloc()}, \cfunction{PyMem_Realloc()}, and
|
||||||
|
\cfunction{PyMem_Free()} are one family that allocates raw memory,
|
||||||
|
while \cfunction{PyObject_Malloc()}, \cfunction{PyObject_Realloc()},
|
||||||
|
and \cfunction{PyObject_Free()} are another family that's supposed to
|
||||||
|
be used for creating Python objects.
|
||||||
|
|
||||||
|
Previously these different families all reduced to the platform's
|
||||||
|
\cfunction{malloc()} and \cfunction{free()} functions. This meant
|
||||||
|
it didn't matter if you got things wrong and allocated memory with the
|
||||||
|
\cfunction{PyMem} function but freed it with the \cfunction{PyObject}
|
||||||
|
function. With the obmalloc change, these families now do different
|
||||||
|
things, and mismatches will probably result in a segfault. You should
|
||||||
|
carefully test your C extension modules with Python 2.5.
|
||||||
|
|
||||||
\item Coverity, a company that markets a source code analysis tool
|
\item Coverity, a company that markets a source code analysis tool
|
||||||
called Prevent, provided the results of their examination of the Python
|
called Prevent, provided the results of their examination of the Python
|
||||||
source code. The analysis found a number of refcounting bugs, often
|
source code. The analysis found a number of refcounting bugs, often
|
||||||
|
@ -1472,6 +1489,21 @@ changes to your code:
|
||||||
|
|
||||||
\item The \module{pickle} module no longer uses the deprecated \var{bin} parameter.
|
\item The \module{pickle} module no longer uses the deprecated \var{bin} parameter.
|
||||||
|
|
||||||
|
\item C API: Many functions now use \ctype{Py_ssize_t}
|
||||||
|
instead of \ctype{int} to allow processing more data
|
||||||
|
on 64-bit machines. Extension code may need to make
|
||||||
|
the same change to avoid warnings and to support 64-bit machines.
|
||||||
|
See the earlier
|
||||||
|
section~ref{section-353} for a discussion of this change.
|
||||||
|
|
||||||
|
\item C API:
|
||||||
|
The obmalloc changes mean that
|
||||||
|
you must be careful to not mix usage
|
||||||
|
of the \cfunction{PyMem_*()} and \cfunction{PyObject_*()}
|
||||||
|
families of functions. Memory allocated with
|
||||||
|
one family's \cfunction{*_Malloc()} must be
|
||||||
|
freed with the corresponding family's \cfunction{*_Free()} function.
|
||||||
|
|
||||||
\end{itemize}
|
\end{itemize}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue