summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2014-02-20 10:06:56 -0700
committerCharles Harris <charlesr.harris@gmail.com>2014-02-20 10:06:56 -0700
commitd54b6784501de8aef405794f20cf1f4b3941c68f (patch)
tree1e97b84e3c066c139707a2495449f5af1e5fe58e
parent0178b12f3cd9804df066d0045a75180177962831 (diff)
parentddcb49e5f779a9e42356914b9ec4162b722d4ab0 (diff)
downloadnumpy-d54b6784501de8aef405794f20cf1f4b3941c68f.tar.gz
Merge pull request #4305 from charris/fix-gh-4256
BUG: #4256: f2py, PyString_FromStringAndSize is undefined in Python3.
-rw-r--r--numpy/f2py/cfuncs.py2
-rw-r--r--numpy/f2py/src/fortranobject.h5
-rw-r--r--numpy/f2py/tests/test_callback.py24
3 files changed, 30 insertions, 1 deletions
diff --git a/numpy/f2py/cfuncs.py b/numpy/f2py/cfuncs.py
index 287192db2..7fb630697 100644
--- a/numpy/f2py/cfuncs.py
+++ b/numpy/f2py/cfuncs.py
@@ -312,7 +312,7 @@ cppmacros['pyobj_from_complex_float1']='#define pyobj_from_complex_float1(v) (Py
needs['pyobj_from_string1']=['string']
cppmacros['pyobj_from_string1']='#define pyobj_from_string1(v) (PyString_FromString((char *)v))'
needs['pyobj_from_string1size']=['string']
-cppmacros['pyobj_from_string1size']='#define pyobj_from_string1size(v,len) (PyString_FromStringAndSize((char *)v, len))'
+cppmacros['pyobj_from_string1size']='#define pyobj_from_string1size(v,len) (PyUString_FromStringAndSize((char *)v, len))'
needs['TRYPYARRAYTEMPLATE']=['PRINTPYOBJERR']
cppmacros['TRYPYARRAYTEMPLATE']="""\
/* New SciPy */
diff --git a/numpy/f2py/src/fortranobject.h b/numpy/f2py/src/fortranobject.h
index 76a357b5e..689f78c92 100644
--- a/numpy/f2py/src/fortranobject.h
+++ b/numpy/f2py/src/fortranobject.h
@@ -20,6 +20,7 @@ extern "C" {
#define PyString_GET_SIZE PyBytes_GET_SIZE
#define PyString_AS_STRING PyBytes_AS_STRING
#define PyString_FromString PyBytes_FromString
+#define PyUString_FromStringAndSize PyUnicode_FromStringAndSize
#define PyString_ConcatAndDel PyBytes_ConcatAndDel
#define PyString_AsString PyBytes_AsString
@@ -29,6 +30,10 @@ extern "C" {
#define PyInt_AsLong PyLong_AsLong
#define PyNumber_Int PyNumber_Long
+
+#else
+
+#define PyUString_FromStringAndSize PyString_FromStringAndSize
#endif
diff --git a/numpy/f2py/tests/test_callback.py b/numpy/f2py/tests/test_callback.py
index 98a90a28c..16464140f 100644
--- a/numpy/f2py/tests/test_callback.py
+++ b/numpy/f2py/tests/test_callback.py
@@ -34,6 +34,17 @@ cf2py intent(out) a
external fun
call fun(a)
end
+
+ subroutine string_callback(callback, a)
+ external callback
+ double precision callback
+ double precision a
+ character*1 r
+cf2py intent(out) a
+ r = 'r'
+ a = callback(r)
+ end
+
"""
@dec.slow
@@ -103,6 +114,19 @@ cf2py intent(out) a
r = t(a.mth)
assert_( r==9, repr(r))
+ def test_string_callback(self):
+
+ def callback(code):
+ if code == 'r':
+ return 0
+ else:
+ return 1
+
+ f = getattr(self.module, 'string_callback')
+ r = f(callback)
+ assert_(r == 0, repr(r))
+
+
if __name__ == "__main__":
import nose
nose.runmodule()