question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

f2py (1.20) drops definition`typedef signed char signed_char;` for callbacks in some circumstances

See original GitHub issue

Reproducing code example:

Unfortunately this is part of a larger project. And may be tricky to reproduce. Depending on other definition of callback functions, I get the error message below for the second routine.

this causes the error:

subroutine pyexit(code)

  implicit none
  integer(kind=4), intent(IN):: code

  !f2py    integer intent(in): code
  !f2py    intent(callback, hide) endkepler()
  external endkepler

  call endkepler()

end subroutine pyexit

!=======================================================================

subroutine pygets(ttymsg)

  implicit none
  character*(*), intent(inout) :: ttymsg

  integer, parameter :: n = 132
  integer :: i
  integer(kind=1), dimension(n) :: data

  !f2py    intent(callback, hide) ttykepler(data)
  external ttykepler

  call ttykepler(data)

  do i = 1, min(n, len(ttymsg))
     ttymsg(i:i) = char(data(i))
  end do

end subroutine pygets

but if I change the first routine to

subroutine pyexit(code)

  implicit none
  integer(kind=4), intent(IN):: code

  !f2py    integer intent(in): code
  !f2py    intent(callback, hide) endkepler(code)
  external endkepler

  call endkepler(code)
end subroutine pyexit

then the compilation error in the second routine does not occur.

Error message:

...
/tmp/tmp2skuwcza/src.linux-x86_64-3.9/_kepler_NBURN_8192_JMZ_1983_FULDAT_fuldat1_f_CPU_Intel_R_Xeon_R_W_2145_CPU_3_70GHzmodule.c:29:63: error: unknown type name ‘signed_char’; did you mean ‘signed char’?
   29 | typedef void(*cb_ttykepler_in_pygets__user__routines_typedef)(signed_char *);
...

NumPy/Python version information:

1.20.0 3.9.1 (default, Dec 16 2020, 01:02:01) [GCC 10.2.1 20201125 (Red Hat 10.2.1-9)]

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:21 (21 by maintainers)

github_iconTop GitHub Comments

2reactions
pearucommented, Feb 6, 2021

@2sn could you change your local copy of numpy/f2py according to (it is one line only change)

https://github.com/numpy/numpy/pull/18350/files#diff-b1639eaf518e24317733541ac7fc4f58cf217666e339b0b9604e85460506a85a

to check if it fixes your use case.

1reaction
2sncommented, Feb 6, 2021

I confirm, this fixed that issue for me! Thank you so much.

Read more comments on GitHub >

github_iconTop Results From Across the Web

No results found

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found