Re: [Numpy-discussion] PATCH: reference leaks for 'numpy.core._internal' module object

2010-07-03 Thread Pauli Virtanen
Sat, 03 Jul 2010 01:11:20 -0300, Lisandro Dalcin wrote:
 The simple test below show the issue.
[clip: patch]

Thanks, applied in r8469.

[clip]
 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 ;-)

We'll optimize once someone complains this makes their code slow ;)

-- 
Pauli Virtanen

___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


[Numpy-discussion] PATCH: reference leaks for 'numpy.core._internal' module object

2010-07-02 Thread Lisandro Dalcin
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