From 2f43a2fcedd049de347a4cef4fc3456ce2cb0499 Mon Sep 17 00:00:00 2001 From: Travis Oliphant Date: Mon, 30 Oct 2006 22:45:31 +0000 Subject: Fix some reference-count problems in f2py with data-type objects. --- numpy/f2py/src/fortranobject.c | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) (limited to 'numpy/f2py/src') diff --git a/numpy/f2py/src/fortranobject.c b/numpy/f2py/src/fortranobject.c index 48f8b3247..27488d24d 100644 --- a/numpy/f2py/src/fortranobject.c +++ b/numpy/f2py/src/fortranobject.c @@ -116,7 +116,8 @@ fortran_doc (FortranDataDef def) { } } else { PyArray_Descr *d = PyArray_DescrFromType(def.type); - if (sprintf(p,"%s'%c'-",p,d->type)==0) goto fail; + if (sprintf(p,"%s'%c'-",p,d->type)==0) {Py_DECREF(d); goto fail;} + Py_DECREF(d); if (def.data==NULL) { if (sprintf(p,"%sarray(%" NPY_INTP_FMT,p,def.dims.d[0])==0) goto fail; for(i=1;ielsize; + typechar = descr->type; + Py_DECREF(descr); if (PyArray_Check(obj)) { arr = (PyArrayObject *)obj; - + if (intent & F2PY_INTENT_CACHE) { /* intent(cache) */ if (PyArray_ISONESEGMENT(obj) - && PyArray_ITEMSIZE((PyArrayObject *)obj)>=descr->elsize) { - if (check_and_fix_dimensions((PyArrayObject *)obj,rank,dims)) + && PyArray_ITEMSIZE((PyArrayObject *)obj)>=elsize) { + if (check_and_fix_dimensions((PyArrayObject *)obj,rank,dims)) { return NULL; /*XXX: set exception */ + } if (intent & F2PY_INTENT_OUT) Py_INCREF(obj); return (PyArrayObject *)obj; @@ -565,9 +573,9 @@ PyArrayObject* array_from_pyobj(const int type_num, sprintf(mess,"failed to initialize intent(cache) array"); if (!PyArray_ISONESEGMENT(obj)) sprintf(mess+strlen(mess)," -- input must be in one segment"); - if (PyArray_ITEMSIZE(arr)elsize) + if (PyArray_ITEMSIZE(arr)elsize,PyArray_ITEMSIZE(arr) + elsize,PyArray_ITEMSIZE(arr) ); PyErr_SetString(PyExc_ValueError,mess); return NULL; @@ -575,11 +583,12 @@ PyArrayObject* array_from_pyobj(const int type_num, /* here we have always intent(in) or intent(inout) or intent(inplace) */ - if (check_and_fix_dimensions(arr,rank,dims)) + if (check_and_fix_dimensions(arr,rank,dims)) { return NULL; /*XXX: set exception */ + } if ((! (intent & F2PY_INTENT_COPY)) - && PyArray_ITEMSIZE(arr)==descr->elsize + && PyArray_ITEMSIZE(arr)==elsize && ARRAY_ISCOMPATIBLE(arr,type_num) ) { if ((intent & F2PY_INTENT_C)?PyArray_ISCARRAY(arr):PyArray_ISFARRAY(arr)) { @@ -597,14 +606,14 @@ PyArrayObject* array_from_pyobj(const int type_num, sprintf(mess+strlen(mess)," -- input not contiguous"); if (!(intent & F2PY_INTENT_C) && !PyArray_ISFARRAY(arr)) sprintf(mess+strlen(mess)," -- input not fortran contiguous"); - if (PyArray_ITEMSIZE(arr)!=descr->elsize) + if (PyArray_ITEMSIZE(arr)!=elsize) sprintf(mess+strlen(mess)," -- expected elsize=%d but got %d", - descr->elsize, + elsize, PyArray_ITEMSIZE(arr) ); if (!(ARRAY_ISCOMPATIBLE(arr,type_num))) sprintf(mess+strlen(mess)," -- input '%c' not compatible to '%c'", - arr->descr->type,descr->type); + arr->descr->type,typechar); PyErr_SetString(PyExc_ValueError,mess); return NULL; } -- cgit v1.2.1