diff options
| author | Julian Taylor <jtaylor.debian@googlemail.com> | 2017-04-14 21:00:29 +0200 |
|---|---|---|
| committer | Julian Taylor <jtaylor.debian@googlemail.com> | 2017-05-02 22:03:29 +0200 |
| commit | a618b4e10dde4b41acceac3d8f7c042fb88af1a7 (patch) | |
| tree | e439e34fab885df68305affa43602ddbe4284155 /numpy/f2py | |
| parent | b8d0498eb1463e900a6c07311c0c1f80f5611bad (diff) | |
| download | numpy-a618b4e10dde4b41acceac3d8f7c042fb88af1a7.tar.gz | |
MAINT: remove usage of NPY_CHAR from f2py
Diffstat (limited to 'numpy/f2py')
| -rw-r--r-- | numpy/f2py/capi_maps.py | 9 | ||||
| -rw-r--r-- | numpy/f2py/cfuncs.py | 3 | ||||
| -rw-r--r-- | numpy/f2py/src/fortranobject.c | 28 |
3 files changed, 29 insertions, 11 deletions
diff --git a/numpy/f2py/capi_maps.py b/numpy/f2py/capi_maps.py index 441629faa..5b2e6a9b9 100644 --- a/numpy/f2py/capi_maps.py +++ b/numpy/f2py/capi_maps.py @@ -65,7 +65,7 @@ c2py_map = {'double': 'float', c2capi_map = {'double': 'NPY_DOUBLE', 'float': 'NPY_FLOAT', 'long_double': 'NPY_DOUBLE', # forced casting - 'char': 'NPY_CHAR', + 'char': 'NPY_STRING', 'unsigned_char': 'NPY_UBYTE', 'signed_char': 'NPY_BYTE', 'short': 'NPY_SHORT', @@ -77,7 +77,7 @@ c2capi_map = {'double': 'NPY_DOUBLE', 'complex_float': 'NPY_CFLOAT', 'complex_double': 'NPY_CDOUBLE', 'complex_long_double': 'NPY_CDOUBLE', # forced casting - 'string': 'NPY_CHAR'} + 'string': 'NPY_STRING'} # These new maps aren't used anyhere yet, but should be by default # unless building numeric or numarray extensions. @@ -99,10 +99,7 @@ if using_newcore: 'complex_float': 'NPY_CFLOAT', 'complex_double': 'NPY_CDOUBLE', 'complex_long_double': 'NPY_CDOUBLE', - # f2py 2e is not ready for NPY_STRING (must set itemisize - # etc) - 'string': 'NPY_CHAR', - #'string':'NPY_STRING' + 'string':'NPY_STRING' } c2pycode_map = {'double': 'd', diff --git a/numpy/f2py/cfuncs.py b/numpy/f2py/cfuncs.py index 0d0a52764..1632a0d47 100644 --- a/numpy/f2py/cfuncs.py +++ b/numpy/f2py/cfuncs.py @@ -1153,8 +1153,9 @@ def buildcfuncs(): m] = '#define %s(v) (PyArray_SimpleNewFromData(0,NULL,%s,(char *)v))' % (m, c2capi_map[k]) k = 'string' m = 'pyarr_from_p_%s1' % k + # NPY_CHAR compatibility, NPY_STRING with itemsize 1 cppmacros[ - m] = '#define %s(v,dims) (PyArray_SimpleNewFromData(1,dims,NPY_CHAR,(char *)v))' % (m) + m] = '#define %s(v,dims) (PyArray_New(&PyArray_Type, 1, dims, NPY_STRING, NULL, v, 1, NPY_ARRAY_CARRAY, NULL))' % (m) ############ Auxiliary functions for sorting needs ################### diff --git a/numpy/f2py/src/fortranobject.c b/numpy/f2py/src/fortranobject.c index 9024dd5b3..0209cb1be 100644 --- a/numpy/f2py/src/fortranobject.c +++ b/numpy/f2py/src/fortranobject.c @@ -691,7 +691,7 @@ PyArrayObject* array_from_pyobj(const int type_num, } arr = (PyArrayObject *) PyArray_New(&PyArray_Type, rank, dims, type_num, - NULL,NULL,0, + NULL,NULL,1, !(intent&F2PY_INTENT_C), NULL); if (arr==NULL) return NULL; @@ -701,6 +701,15 @@ PyArrayObject* array_from_pyobj(const int type_num, } descr = PyArray_DescrFromType(type_num); + /* compatibility with NPY_CHAR */ + if (type_num == NPY_STRING) { + PyArray_DESCR_REPLACE(descr); + if (descr == NULL) { + return NULL; + } + descr->elsize = 1; + descr->type = NPY_CHARLTR; + } elsize = descr->elsize; typechar = descr->type; Py_DECREF(descr); @@ -781,9 +790,10 @@ PyArrayObject* array_from_pyobj(const int type_num, /* here we have always intent(in) or intent(inplace) */ { - PyArrayObject *retarr = (PyArrayObject *) \ + PyArrayObject * retarr; + retarr = (PyArrayObject *) \ PyArray_New(&PyArray_Type, PyArray_NDIM(arr), PyArray_DIMS(arr), type_num, - NULL,NULL,0, + NULL,NULL,1, !(intent&F2PY_INTENT_C), NULL); if (retarr==NULL) @@ -816,9 +826,19 @@ PyArrayObject* array_from_pyobj(const int type_num, } { + PyArray_Descr * descr = PyArray_DescrFromType(type_num); + /* compatibility with NPY_CHAR */ + if (type_num == NPY_STRING) { + PyArray_DESCR_REPLACE(descr); + if (descr == NULL) { + return NULL; + } + descr->elsize = 1; + descr->type = NPY_CHARLTR; + } F2PY_REPORT_ON_ARRAY_COPY_FROMANY; arr = (PyArrayObject *) \ - PyArray_FromAny(obj,PyArray_DescrFromType(type_num), 0,0, + PyArray_FromAny(obj, descr, 0,0, ((intent & F2PY_INTENT_C)?NPY_ARRAY_CARRAY:NPY_ARRAY_FARRAY) \ | NPY_ARRAY_FORCECAST, NULL); if (arr==NULL) |
