Thanks to visit codestin.com
Credit goes to github.com

Skip to content

f2py parser fails on a Fortran function with C binding #9693

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

Closed
dhermes opened this issue Sep 15, 2017 · 1 comment · Fixed by #24555
Closed

f2py parser fails on a Fortran function with C binding #9693

dhermes opened this issue Sep 15, 2017 · 1 comment · Fixed by #24555
Assignees

Comments

@dhermes
Copy link
Contributor

dhermes commented Sep 15, 2017

Related to #2275 (I opened a new issue per @charris request).

See this gist for a repro. Observed with numpy==1.13.1 in Python 3.6. The source causing a failure is:

function wat(x, y) result(z) bind(c, name='wat')
  integer, intent(in) :: x, y
  integer :: z

  z = x + y
end function wat
@dhermes dhermes changed the title f2py parser fails when a Fortran function with C binding f2py parser fails on a Fortran function with C binding Sep 15, 2017
@kprussing
Copy link

kprussing commented Dec 17, 2017

This is in part due to the fact that the bind(c) attribute is part of the Fortran 2003 standard and the snippet is not valid Fortran 2003. The function must be in a module that uses the iso_c_binding module. A valid minimum failing example would be:

module mfe
    use iso_c_binding
    implicit none
contains
    function wat(x, y) result(z) bind(c, name='wat')
        integer(c_int), intent(in) :: x, y
        integer(c_int) :: z
    
        z = x + 7
    end function wat
end module mfe

This compiles happily with gfortran on macOS 10.12.6 However, this still throw an assertion error with NumPy 1.13.3

AssertionError: (1, "x, y@)@ result@(@z@)@ bind@(@c, name='wat'", "x@,@ y@)@ result@(@z@)@ bind@(@c, name='wat'", ')')

I get the same error in both Python 3.6 and 2.7 installed from MacPorts. I cloned the repo and managed to build tags v1.6.0 and v1.7.0 against the native Python (2.7), but I still get the error.

So, is this a user error trying to parse the source using f2py.crackfortran.crackfortran or a parer error as referenced in the closed issue? Are there any other tags where this was to have been fixed?

Update: Fixed the attributes to properly declare the types of the arguments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

4 participants