summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPearu Peterson <pearu.peterson@gmail.com>2021-02-07 00:13:39 +0200
committerPearu Peterson <pearu.peterson@gmail.com>2021-02-07 00:13:39 +0200
commit29f0e8fa1ff5ccda3d92c949eb9d09c5d8327aa3 (patch)
tree7155108e75872b3bf52c7f3eba6295449e3ce0c4
parent2f466b31820b6af40c3bc1ca3957682b6f20365a (diff)
downloadnumpy-29f0e8fa1ff5ccda3d92c949eb9d09c5d8327aa3.tar.gz
BUG: Fix missing signed_char dependency. Closes #18335.
-rw-r--r--numpy/f2py/cb_rules.py1
-rw-r--r--numpy/f2py/tests/test_callback.py40
2 files changed, 41 insertions, 0 deletions
diff --git a/numpy/f2py/cb_rules.py b/numpy/f2py/cb_rules.py
index 3068dc897..60bc1ad11 100644
--- a/numpy/f2py/cb_rules.py
+++ b/numpy/f2py/cb_rules.py
@@ -342,6 +342,7 @@ cb_arg_rules = [
isarray: '#ctype# *',
isstring: '#ctype#'
},
+ 'need': {l_or(isscalar, isarray, isstring): '#ctype#'},
# untested with multiple args
'strarglens': {isstring: ',int #varname_i#_cb_len'},
'strarglens_td': {isstring: ',int'}, # untested with multiple args
diff --git a/numpy/f2py/tests/test_callback.py b/numpy/f2py/tests/test_callback.py
index 37736af21..4d4f2b443 100644
--- a/numpy/f2py/tests/test_callback.py
+++ b/numpy/f2py/tests/test_callback.py
@@ -236,3 +236,43 @@ class TestF90Callback(util.F2PyTest):
y = np.array([1, 2, 3], dtype=np.int64)
r = self.module.gh17797(incr, y)
assert r == 123 + 1 + 2 + 3
+
+
+class TestGH18335(util.F2PyTest):
+ """The reproduction of the reported issue requires specific input that
+ extensions may break the issue conditions, so the reproducer is
+ implemented as a separate test class. Do not extend this test with
+ other tests!
+ """
+
+ suffix = '.f90'
+
+ code = textwrap.dedent(
+ """
+ ! When gh18335_workaround is defined as an extension,
+ ! the issue cannot be reproduced.
+ !subroutine gh18335_workaround(f, y)
+ ! implicit none
+ ! external f
+ ! integer(kind=1) :: y(1)
+ ! call f(y)
+ !end subroutine gh18335_workaround
+
+ function gh18335(f) result (r)
+ implicit none
+ external f
+ integer(kind=1) :: y(1), r
+ y(1) = 123
+ call f(y)
+ r = y(1)
+ end function gh18335
+ """)
+
+ def test_gh18335(self):
+
+ def foo(x):
+ x[0] += 1
+
+ y = np.array([1, 2, 3], dtype=np.int8)
+ r = self.module.gh18335(foo)
+ assert r == 123 + 1