Skip to content

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

Closed

Description

@dhermes

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

Activity

  1. changed the title [-]f2py parser fails when a Fortran function with C binding[/-] [+]f2py parser fails on a Fortran function with C binding[/+] on Sep 15, 2017
  2. kprussing commented on Dec 17, 2017

    @kprussing

    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.

  3. self-assigned this
    on Aug 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions