Skip to content

Commit

Permalink
BUG: Fix missing signed_char dependency. Closes #18335.
Browse files Browse the repository at this point in the history
  • Loading branch information
pearu authored and charris committed Feb 7, 2021
1 parent b66f57a commit f673971
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
1 change: 1 addition & 0 deletions numpy/f2py/cb_rules.py
Expand Up @@ -342,6 +342,7 @@
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
Expand Down
40 changes: 40 additions & 0 deletions numpy/f2py/tests/test_callback.py
Expand Up @@ -236,3 +236,43 @@ def incr(x):
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

0 comments on commit f673971

Please sign in to comment.