summaryrefslogtreecommitdiff
path: root/numpy/f2py/src
diff options
context:
space:
mode:
authorTravis Oliphant <oliphant@enthought.com>2006-03-08 22:47:17 +0000
committerTravis Oliphant <oliphant@enthought.com>2006-03-08 22:47:17 +0000
commit704204550661e497888ac879e292cb69a55bbd8c (patch)
tree2f0eb084f0e33475b2713079a63e30242efbb262 /numpy/f2py/src
parent07d036080bcac11ef5ff601b5f6a3215fed230c8 (diff)
downloadnumpy-704204550661e497888ac879e292cb69a55bbd8c.tar.gz
Fix f2py to handle character arrays in common blocks
Diffstat (limited to 'numpy/f2py/src')
-rw-r--r--numpy/f2py/src/fortranobject.c32
-rw-r--r--numpy/f2py/src/fortranobject.h1
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);