The simple test below show the issue.
import sys
import numpy as np
from numpy.core import _internal
def f(a = np.zeros(4)):
a = np.zeros(4)
b = memoryview(a)
c = np.asarray(b)
print sys.getrefcount(_internal)
while 1:
f()
The patch it trivial (I've added a little extra, unrelated NULL check):
Index: numpy/core/src/multiarray/buffer.c
===
--- numpy/core/src/multiarray/buffer.c (revision 8468)
+++ numpy/core/src/multiarray/buffer.c (working copy)
@@ -747,9 +747,13 @@
}
str = PyUString_FromStringAndSize(buf, strlen(buf));
free(buf);
+if (str == NULL) {
+return NULL;
+}
descr = (PyArray_Descr*)PyObject_CallMethod(
_numpy_internal, _dtype_from_pep3118, O, str);
Py_DECREF(str);
+Py_DECREF(_numpy_internal);
if (descr == NULL) {
PyErr_Format(PyExc_ValueError,
'%s' is not a valid PEP 3118 buffer format string, buf);
PS: I think that such implementation should at least handle the very
simple one/two character format (eg, 'i', 'f', 'd', 'Zf', 'Zd', etc.)
without calling Python code... Of course, complaints without patches
should not be taken too seriously ;-)
--
Lisandro Dalcin
---
CIMEC (INTEC/CONICET-UNL)
Predio CONICET-Santa Fe
Colectora RN 168 Km 472, Paraje El Pozo
Tel: +54-342-4511594 (ext 1011)
Tel/Fax: +54-342-4511169
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion