File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 312312needs ['pyobj_from_string1' ]= ['string' ]
313313cppmacros ['pyobj_from_string1' ]= '#define pyobj_from_string1(v) (PyString_FromString((char *)v))'
314314needs ['pyobj_from_string1size' ]= ['string' ]
315- cppmacros ['pyobj_from_string1size' ]= '#define pyobj_from_string1size(v,len) (PyString_FromStringAndSize ((char *)v, len))'
315+ cppmacros ['pyobj_from_string1size' ]= '#define pyobj_from_string1size(v,len) (PyUString_FromStringAndSize ((char *)v, len))'
316316needs ['TRYPYARRAYTEMPLATE' ]= ['PRINTPYOBJERR' ]
317317cppmacros ['TRYPYARRAYTEMPLATE' ]= """\
318318 /* New SciPy */
Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ extern "C" {
2020#define PyString_GET_SIZE PyBytes_GET_SIZE
2121#define PyString_AS_STRING PyBytes_AS_STRING
2222#define PyString_FromString PyBytes_FromString
23+ #define PyUString_FromStringAndSize PyUnicode_FromStringAndSize
2324#define PyString_ConcatAndDel PyBytes_ConcatAndDel
2425#define PyString_AsString PyBytes_AsString
2526
@@ -29,6 +30,10 @@ extern "C" {
2930#define PyInt_AsLong PyLong_AsLong
3031
3132#define PyNumber_Int PyNumber_Long
33+
34+ #else
35+
36+ #define PyUString_FromStringAndSize PyString_FromStringAndSize
3237#endif
3338
3439
Original file line number Diff line number Diff line change @@ -34,6 +34,17 @@ class TestF77Callback(util.F2PyTest):
3434 external fun
3535 call fun(a)
3636 end
37+
38+ subroutine string_callback(callback, a)
39+ external callback
40+ double precision callback
41+ double precision a
42+ character*1 r
43+ cf2py intent(out) a
44+ r = 'r'
45+ a = callback(r)
46+ end
47+
3748 """
3849
3950 @dec .slow
@@ -103,6 +114,19 @@ def mth(self):
103114 r = t (a .mth )
104115 assert_ ( r == 9 , repr (r ))
105116
117+ def test_string_callback (self ):
118+
119+ def callback (code ):
120+ if code == 'r' :
121+ return 0
122+ else :
123+ return 1
124+
125+ f = getattr (self .module , 'string_callback' )
126+ r = f (callback )
127+ assert_ (r == 0 , repr (r ))
128+
129+
106130if __name__ == "__main__" :
107131 import nose
108132 nose .runmodule ()
You can’t perform that action at this time.
0 commit comments