mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-03-24 20:14:13 +03:00
This commit: * Adds Python 3 module initialization functions. I split out the main init of each module into a static setup_module function. * Adds a py3.h which unifies int/long in Python 3 and unicode/bytes in Python 2. _imagingft.c unfortunately looks a little kludgy after this because it was already using PyUnicode functions, and I had to mix and match there manually. With this commit, the modules all build successfully under Python 3. What this commit does NOT do is patch all of the uses of PyArg_ParseTuple and Py_BuildValue, which all need to be checked for proper use of bytes and unicode codes. It also does not let selftest.py run yet, because there are probably hundreds of issues to fix in the Python code itself.
49 lines
1.6 KiB
C
49 lines
1.6 KiB
C
/*
|
|
Python3 definition file to consistently map the code to Python 2.6 or
|
|
Python 3.
|
|
|
|
PyInt and PyLong were merged into PyLong in Python 3, so all PyInt functions
|
|
are mapped to PyLong.
|
|
|
|
PyString, on the other hand, was split into PyBytes and PyUnicode. We map
|
|
both back onto PyString, so use PyBytes or PyUnicode where appropriate. The
|
|
only exception to this is _imagingft.c, where PyUnicode is left alone.
|
|
*/
|
|
|
|
#if PY_VERSION_HEX >= 0x03000000
|
|
/* Map PyInt -> PyLong */
|
|
#define PyInt_AsLong PyLong_AsLong
|
|
#define PyInt_Check PyLong_Check
|
|
#define PyInt_FromLong PyLong_FromLong
|
|
#define PyInt_AS_LONG PyLong_AS_LONG
|
|
|
|
#else
|
|
|
|
#if !defined(KEEP_PY_UNICODE)
|
|
/* Map PyUnicode -> PyString */
|
|
#undef PyUnicode_AsString
|
|
#undef PyUnicode_AS_STRING
|
|
#undef PyUnicode_Check
|
|
#undef PyUnicode_FromStringAndSize
|
|
#undef PyUnicode_FromString
|
|
#undef PyUnicode_FromFormat
|
|
|
|
#define PyUnicode_AsString PyString_AsString
|
|
#define PyUnicode_AS_STRING PyString_AS_STRING
|
|
#define PyUnicode_Check PyString_Check
|
|
#define PyUnicode_FromStringAndSize PyString_FromStringAndSize
|
|
#define PyUnicode_FromString PyString_FromString
|
|
#define PyUnicode_FromFormat PyString_FromFormat
|
|
#endif
|
|
|
|
/* Map PyBytes -> PyString */
|
|
#define PyBytes_AsString PyString_AsString
|
|
#define PyBytes_AS_STRING PyString_AS_STRING
|
|
#define PyBytes_Check PyString_Check
|
|
#define PyBytes_FromStringAndSize PyString_FromStringAndSize
|
|
#define PyBytes_FromString PyString_FromString
|
|
#define _PyBytes_Resize _PyString_Resize
|
|
|
|
#endif /* PY_VERSION_HEX < 0x03000000 */
|
|
|