8000 Merge pull request #18350 from pearu/pearu/18335 · numpy/numpy@8742209 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8742209

Browse files
authored
Merge pull request #18350 from pearu/pearu/18335
BUG: Fix missing signed_char dependency.
2 parents b666225 + 29f0e8f commit 8742209

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

numpy/f2py/cb_rules.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,7 @@
342342
isarray: '#ctype# *',
343343
isstring: '#ctype#'
344344
},
345+
'need': {l_or(isscalar, isarray, isstring): '#ctype#'},
345346
# untested with multiple args
346347
'strarglens': {isstring: ',int #varname_i#_cb_len'},
347348
'strarglens_td': {isstring: ',int'}, # untested with multiple args

numpy/f2py/tests/test_callback.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,3 +236,43 @@ def incr(x):
236236
y = np.array([1, 2, 3], dtype=np.int64)
237237
r = self.module.gh17797(incr, y)
238238
assert r == 123 + 1 + 2 + 3
239+
240+
241+
class TestGH18335(util.F2PyTest):
242+
"""The reproduction of the reported issue requires specific input that
243+
extensions may break the issue conditions, so the reproducer is
244+
implemented as a separate test class. Do not extend this test with
245+
other tests!
246+
"""
247+
248+
suffix = '.f90'
249+
250+
code = textwrap.dedent(
251+
"""
252+
! When gh18335_workaround is defined as an extension,
253+
! the issue cannot be reproduced.
254+
!subroutine gh18335_workaround(f, y)
255+
! implicit none
256+
! external f
257+
! integer(kind=1) :: y(1)
258+
! call f(y)
259+
!end subroutine gh18335_workaround
260+
261+
function gh18335(f) result (r)
262+
implicit none
263+
external f
264+
integer(kind=1) :: y(1), r
265+
y(1) = 123
266+
call f(y)
267+
r = y(1)
268+
end function gh18335
269+
""")
270+
271+
def test_gh18335(self):
272+
273+
def foo(x):
274+
x[0] += 1
275+
276+
y = np.array([1, 2, 3], dtype=np.int8)
277+
r = self.module.gh18335(foo)
278+
assert r == 123 + 1

0 commit comments

Comments
 (0)
0