diff options
Diffstat (limited to 'numpy/f2py/src')
-rw-r--r-- | numpy/f2py/src/fortranobject.c | 32 | ||||
-rw-r--r-- | numpy/f2py/src/fortranobject.h | 1 |
2 files changed, 28 insertions, 5 deletions
diff --git a/numpy/f2py/src/fortranobject.c b/numpy/f2py/src/fortranobject.c index be0251f24..4a1fe0cf4 100644 --- a/numpy/f2py/src/fortranobject.c +++ b/numpy/f2py/src/fortranobject.c @@ -12,6 +12,20 @@ extern "C" { $Date: 2005/07/11 07:44:20 $ */ +int +F2PyDict_SetItemString(PyObject *dict, char *name, PyObject *obj) +{ + if (obj==NULL) { + fprintf(stderr, "Error loading %s\n", name); + if (PyErr_Occurred()) { + PyErr_Print(); + PyErr_Clear(); + } + return -1; + } + return PyDict_SetItemString(dict, name, obj); +} + /************************* FortranObject *******************************/ typedef PyObject *(*fortranfunc)(PyObject *,PyObject *,PyObject *,void *); @@ -36,11 +50,19 @@ PyFortranObject_New(FortranDataDef* defs, f2py_void_func init) { PyDict_SetItemString(fp->dict,fp->defs[i].name,v); } else if ((fp->defs[i].data)!=NULL) { /* Is Fortran variable or array (not allocatable) */ - v = PyArray_New(&PyArray_Type, fp->defs[i].rank, fp->defs[i].dims.d, - fp->defs[i].type, NULL, fp->defs[i].data, 0, FARRAY_FLAGS, - NULL); - if (v==NULL) return NULL; - PyDict_SetItemString(fp->dict,fp->defs[i].name,v); + if (fp->defs[i].type == PyArray_STRING) { + int n = fp->defs[i].rank-1; + v = PyArray_New(&PyArray_Type, n, fp->defs[i].dims.d, + PyArray_STRING, NULL, fp->defs[i].data, fp->defs[i].dims.d[n], + FARRAY_FLAGS, NULL); + } + else { + v = PyArray_New(&PyArray_Type, fp->defs[i].rank, fp->defs[i].dims.d, + fp->defs[i].type, NULL, fp->defs[i].data, 0, FARRAY_FLAGS, + NULL); + } + if (v==NULL) return NULL; + PyDict_SetItemString(fp->dict,fp->defs[i].name,v); } Py_XDECREF(v); return (PyObject *)fp; diff --git a/numpy/f2py/src/fortranobject.h b/numpy/f2py/src/fortranobject.h index 44778822a..353b2a64b 100644 --- a/numpy/f2py/src/fortranobject.h +++ b/numpy/f2py/src/fortranobject.h @@ -92,6 +92,7 @@ typedef struct { #define PyFortran_Check1(op) (0==strcmp((op)->ob_type->tp_name,"fortran")) extern PyTypeObject PyFortran_Type; + extern int F2PyDict_SetItemString(PyObject* dict, char *name, PyObject *obj); extern PyObject * PyFortranObject_New(FortranDataDef* defs, f2py_void_func init); extern PyObject * PyFortranObject_NewAsAttr(FortranDataDef* defs); |