summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2012-04-11 07:51:53 -0600
committerCharles Harris <charlesr.harris@gmail.com>2012-04-11 08:44:56 -0600
commit0a3a954c3750419552c076aa444563ac20def14a (patch)
tree0fd2fe188bb11154ef690e9e6e02c51f996eda8a /numpy
parent0dac136795ba7d6f2b371fe5a7c34c34fe0a9a5f (diff)
downloadnumpy-0a3a954c3750419552c076aa444563ac20def14a.tar.gz
BUG: ticket #1578, Fix python-debug warning for python >= 2.7.
In Python >= 2.7 the memory management of unicode objects changed from PyMem_* to PyObject_*. Numpy had its own modified copy of some of the Python code for handling unicode objects and it needed to be updated to deal with the change. Thanks to Joseph Miessner for tracking this down and finding the fix.
Diffstat (limited to 'numpy')
-rw-r--r--numpy/core/src/multiarray/scalarapi.c6
-rw-r--r--numpy/core/src/multiarray/ucsnarrow.c16
2 files changed, 18 insertions, 4 deletions
diff --git a/numpy/core/src/multiarray/scalarapi.c b/numpy/core/src/multiarray/scalarapi.c
index e43e0dbe8..5afa61a1c 100644
--- a/numpy/core/src/multiarray/scalarapi.c
+++ b/numpy/core/src/multiarray/scalarapi.c
@@ -707,7 +707,11 @@ PyArray_Scalar(void *data, PyArray_Descr *descr, PyObject *base)
#endif
/* Need an extra slot and need to use Python memory manager */
uni->str = NULL;
- destptr = PyMem_NEW(Py_UNICODE,length+1);
+#if PY_VERSION_HEX >= 0x02070000
+ destptr = PyObject_MALLOC(sizeof(Py_UNICODE) * (length + 1));
+#else
+ destptr = PyMem_NEW(Py_UNICODE, length + 1);
+#endif
if (destptr == NULL) {
Py_DECREF(obj);
return PyErr_NoMemory();
diff --git a/numpy/core/src/multiarray/ucsnarrow.c b/numpy/core/src/multiarray/ucsnarrow.c
index 607ed834f..c192bbd1c 100644
--- a/numpy/core/src/multiarray/ucsnarrow.c
+++ b/numpy/core/src/multiarray/ucsnarrow.c
@@ -90,8 +90,14 @@ MyPyUnicode_New(int length)
{
PyUnicodeObject *unicode;
unicode = PyObject_New(PyUnicodeObject, &PyUnicode_Type);
- if (unicode == NULL) return NULL;
- unicode->str = PyMem_NEW(Py_UNICODE, length+1);
+ if (unicode == NULL) {
+ return NULL;
+ }
+#if PY_VERSION_HEX >= 0x02070000
+ unicode->str = PyObject_MALLOC(sizeof(Py_UNICODE) * (length + 1));
+#else
+ unicode->str = PyMem_NEW(Py_UNICODE, length + 1);
+#endif
if (!unicode->str) {
_Py_ForgetReference((PyObject *)unicode);
PyObject_Del(unicode);
@@ -114,7 +120,11 @@ MyPyUnicode_Resize(PyUnicodeObject *uni, int length)
void *oldstr;
oldstr = uni->str;
- PyMem_RESIZE(uni->str, Py_UNICODE, length+1);
+#if PY_VERSION_HEX >= 0x02070000
+ PyObject_REALLOC(uni->str, sizeof(Py_UNICODE) * (length + 1));
+#else
+ PyMem_RESIZE(uni->str, Py_UNICODE, length + 1);
+#endif
if (!uni->str) {
uni->str = oldstr;
PyErr_NoMemory();