提交 051a6b95 authored 作者: Gabe Schwartz's avatar Gabe Schwartz

Fixed #defines to work with npy_3kcompat and bytes.

npy_3kcompat redefines old PyString_X to use bytes, but this breaks compatibility with python code expecting new strings. The solution is to use PyUnicode wherever possible instead of PyBytes.
上级 c6398151
...@@ -3,25 +3,21 @@ ...@@ -3,25 +3,21 @@
// Defines for Python 2/3 compatibility. // Defines for Python 2/3 compatibility.
#if PY_MAJOR_VERSION >= 3 #if PY_MAJOR_VERSION >= 3
// Py3k treats all ints as longs. // Py3k treats all ints as longs. This one is not caught by npy_3kcompat.h.
#define PyInt_Check PyLong_Check
#define PyInt_CheckExact PyLong_CheckExact
#define PyInt_AsLong PyLong_AsLong
#define PyInt_FromLong PyLong_FromLong
#define PyNumber_Int PyNumber_Long #define PyNumber_Int PyNumber_Long
#include "numpy/npy_3kcompat.h"
// Py3k strings are unicode, these mimic old functionality. // Py3k strings are unicode, these mimic old functionality.
//
// NOTE: npy_3kcompat.h replaces PyString_X with PyBytes_X, which breaks
// compatibility with some functions returning text.
#define PyString_Check PyUnicode_Check #define PyString_Check PyUnicode_Check
#define PyString_FromString PyUnicode_FromString #define PyString_FromString PyUnicode_FromString
#define PyString_AsString PyUnicode_AsUTF8 #define PyString_AsString PyUnicode_AsUTF8
#define PyString_FromStringAndSize PyUnicode_FromStringAndSize #define PyString_FromStringAndSize PyUnicode_FromStringAndSize
#define PyString_Size PyUnicode_GET_SIZE #define PyString_Size PyUnicode_GET_SIZE
#include "numpy/npy_3kcompat.h"
#define PyCObject_AsVoidPtr NpyCapsule_AsVoidPtr
#define PyCObject_GetDesc NpyCapsule_GetDesc
#define PyCObject_Check NpyCapsule_Check
// Python 3 expects a PyObject* as the first argument to PySlice_GetIndicesEx(). // Python 3 expects a PyObject* as the first argument to PySlice_GetIndicesEx().
#define SLICE_CAST(x) (x) #define SLICE_CAST(x) (x)
#else #else
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论