[Numpy-tickets] [NumPy] #1032: Crash on fastputmask on win32
NumPy
numpy-tickets@scipy....
Mon Mar 2 12:33:24 CST 2009
#1032: Crash on fastputmask on win32
--------------------+-------------------------------------------------------
Reporter: cdavid | Owner: somebody
Type: defect | Status: new
Priority: normal | Milestone: 1.3.0
Component: Other | Version: none
Severity: normal | Resolution:
Keywords: |
--------------------+-------------------------------------------------------
Comment (by cdavid):
Interestingly, by forcing the offending codepath, I get a memory leak on
linux for the exact same test code:
{{{
#!c
static PyObject *
PyArray_PutMask(PyArrayObject *self, PyObject* values0, PyObject* mask0)
{
PyArray_FastPutmaskFunc *func;
PyArrayObject *mask, *values;
int i, chunk, ni, max_item, nv, tmp;
char *src, *dest;
int copied = 0;
mask = NULL;
values = NULL;
if (!PyArray_Check(self)) {
PyErr_SetString(PyExc_TypeError,
"putmask: first argument must "\
"be an array");
return NULL;
}
//if (!PyArray_ISCONTIGUOUS(self) || !(self->flags & ALIGNED))
{
PyArrayObject *obj;
int flags = NPY_CARRAY | NPY_UPDATEIFCOPY;
Py_INCREF(self->descr);
obj = (PyArrayObject *)PyArray_FromArray(self,
self->descr, flags);
if (obj != self) {
copied = 1;
}
self = obj;
}
max_item = PyArray_SIZE(self);
dest = self->data;
chunk = self->descr->elsize;
mask = (PyArrayObject *)\
PyArray_FROM_OTF(mask0, PyArray_BOOL, CARRAY | FORCECAST);
if (mask == NULL) {
goto fail;
}
ni = PyArray_SIZE(mask);
if (ni != max_item) {
PyErr_SetString(PyExc_ValueError,
"putmask: mask and data must be "\
"the same size");
goto fail;
}
Py_INCREF(self->descr);
values = (PyArrayObject *)\
PyArray_FromAny(values0, self->descr, 0, 0, NPY_CARRAY, NULL);
if (values == NULL) {
goto fail;
}
nv = PyArray_SIZE(values); /* zero if null array */
if (nv <= 0) {
Py_XDECREF(values);
Py_XDECREF(mask);
Py_INCREF(Py_None);
return Py_None;
}
if (PyDataType_REFCHK(self->descr)) {
for (i = 0; i < ni; i++) {
tmp = ((Bool *)(mask->data))[i];
if (tmp) {
src = values->data + chunk * (i % nv);
PyArray_Item_INCREF(src, self->descr);
PyArray_Item_XDECREF(dest+i*chunk, self->descr);
memmove(dest + i * chunk, src, chunk);
}
}
}
else {
func = self->descr->f->fastputmask;
if (func == NULL) {
for (i = 0; i < ni; i++) {
tmp = ((Bool *)(mask->data))[i];
if (tmp) {
src = values->data + chunk*(i % nv);
memmove(dest + i*chunk, src, chunk);
}
}
}
else {
func(dest, mask->data, ni, values->data, nv);
}
}
Py_XDECREF(values);
Py_XDECREF(mask);
if (copied) {
Py_DECREF(self);
}
Py_INCREF(Py_None);
return Py_None;
fail:
Py_XDECREF(mask);
Py_XDECREF(values);
if (copied) {
PyArray_XDECREF_ERR(self);
}
return NULL;
}
}}}
--
Ticket URL: <http://scipy.org/scipy/numpy/ticket/1032#comment:2>
NumPy <http://projects.scipy.org/scipy/numpy>
The fundamental package needed for scientific computing with Python.
More information about the Numpy-tickets
mailing list