-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
BUG: Fix f2py string variables in callbacks. #10031
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
import textwrap | ||
import sys | ||
|
||
from numpy import array | ||
import numpy as np | ||
from numpy.testing import run_module_suite, assert_, assert_equal, dec | ||
from . import util | ||
|
||
|
@@ -48,6 +48,16 @@ class TestF77Callback(util.F2PyTest): | |
a = callback(r) | ||
end | ||
|
||
subroutine string_callback_array(callback, cu, lencu, a) | ||
external callback | ||
integer callback | ||
integer lencu | ||
character*8 cu(lencu) | ||
integer a | ||
cf2py intent(out) a | ||
|
||
a = callback(cu, lencu) | ||
end | ||
""" | ||
|
||
@dec.slow | ||
|
@@ -120,7 +130,8 @@ def mth(self): | |
r = t(a.mth) | ||
assert_(r == 9, repr(r)) | ||
|
||
@dec.knownfailureif(sys.platform=='win32', msg='Fails with MinGW64 Gfortran (Issue #9673)') | ||
@dec.knownfailureif(sys.platform=='win32', | ||
msg='Fails with MinGW64 Gfortran (Issue #9673)') | ||
def test_string_callback(self): | ||
|
||
def callback(code): | ||
|
@@ -133,6 +144,25 @@ def callback(code): | |
r = f(callback) | ||
assert_(r == 0, repr(r)) | ||
|
||
@dec.knownfailureif(sys.platform=='win32', | ||
msg='Fails with MinGW64 Gfortran (Issue #9673)') | ||
def test_string_callback_array(self): | ||
# See gh-10027 | ||
cu = np.zeros((1, 8), 'S1') | ||
|
||
def callback(cu, lencu): | ||
if cu.shape != (lencu, 8): | ||
return 1 | ||
if cu.dtype != 'S1': | ||
return 2 | ||
if not np.all(cu == b''): | ||
return 3 | ||
return 0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm curious - what happens if you use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't know, I was tempted but figured to play safe ... Yes, that works. The fortran subroutine doesn't catch the error, rather the call wrapper does a |
||
|
||
f = getattr(self.module, 'string_callback_array') | ||
res = f(callback, cu, len(cu)) | ||
assert_(res == 0, repr(res)) | ||
|
||
|
||
if __name__ == "__main__": | ||
run_module_suite() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any way that
VOID
orUNICODE
can end up here? They might need a similar fix, if so.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so. My thought was that we will need to wait and see, the original was always defaulting. Fortran added a UCS-4 type in 2003 (name
ISO_10646
), but I do not see that in the current f2py. If/when we add that functionality we will need to revisit this.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Support for UCS-4 seems rather sporadic, it wasn't required until 2008. I expect utf-8 will eventually show up, but Fortran seems wedded to fixed width strings (like the NumPy
S
andU
types) so I don't expect that to happen anytime soon.