-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
BUG: f2py: Exception when trying to parse private/public subroutine declaration in combination with only:
option
#26920
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
Comments
only:
optiononly:
option
Thanks for the detailed bug report and the suggested fix, would you be able to open a PR? If not I can incorporate this (with credit) and a test later this week. |
Yes, I can prepare a PR, just wanted to make sure the fix is acceptable. |
Awesome, yes I think this is a pragmatic solution and in keeping with the rest of the F2PY design, please feel free to ping me as a reviewer for the PR :) |
Don't mistake public/private declarations of subroutines for variables. Also, handle modules with no public variables or subroutines, caused by the filtering. Closes numpygh-26920.
Don't mistake public/private declarations of subroutines for variables when the corresponding subroutines are filtered by use of only:. Also, handle modules with no public variables or subroutines, caused by the filtering. Closes numpygh-26920.
Don't mistake public/private declarations of F90 subroutines for variables when the corresponding subroutines are filtered by use of only:. Also, handle modules with no public variables or subroutines, caused by the filtering. Closes numpygh-26920.
Don't mistake public/private declarations of F90 subroutines for variables when the corresponding subroutines are filtered by use of only:. Also, handle modules with no public variables or subroutines, caused by the filtering. Closes numpygh-26920.
Don't mistake public/private declarations of F90 subroutines for variables when the corresponding subroutines are filtered by use of only:. Also, handle modules with no public variables or subroutines, caused by the filtering. Closes numpygh-26920.
Don't mistake public/private declarations of F90 subroutines for variables when the corresponding subroutines are filtered by use of only:. Also, handle modules with no public variables or subroutines, caused by the filtering. Closes numpygh-26920.
Don't mistake public/private declarations of F90 subroutines for variables when the corresponding subroutines are filtered by use of only:. Also, handle modules with no public variables or subroutines, caused by the filtering. Closes numpygh-26920.
Describe the issue:
When trying to build a Python module for a legacy Fortran 90 code base, I think I came across a small bug in f2py.
When f2py is used with the
only:
directive to only selectively map routines, then private/public statements for subroutines in f90 modules will be mistaken as variables (the subroutines themselves will be filtered out at an earlier step). This leads to an exception in f2py because no type for those 'variables' can be inferred. In the example below, the modulemod2
has two public subroutines, which will be filtered by a correspondingonly:
option for f2py. yet, the definitionswill remain, leading to the problems described here.
My interpretation of this is: f2py will remove the body of subroutines that are not listed in the
onlyfuncs
variable (in crackfortran.py), which then leads to the remaining artifacts in the declaration of the module being mistaken as variables (f90mod_rules.py).I was able to work around this issue by adding a check into the corresponding function, which I believe filters out those remaining public/private declarations (while I'm not deeply familiar with Fortran 90 syntax, I believe that anything in the form
PUBLIC :: [NAME]
orPRIVATE :: [NAME]:
must always refer to subroutines. Variables should always require a type?).This, however, lead to another issue: It is now possible that a module has no attributes or subroutines to export (either because everything is private, or filtered out due to
only:
). This leads to the generation of boilerplate C code for the empty module that crashes Python when the generated module is loaded. To solve this, I added another check that skips a given module if neither variables or anything else is to be exported.The second issue can be prevented by either USEin the module, or by adding public dummy variables.
The work-around patch for current numpy HEAD (abeca76):
Reproduce the code example:
Error message:
Python and NumPy Versions:
Runtime Environment:
Context for the issue:
For legacy code bases, sometimes only a small subset of functionality needs to be exported to python. Potentially, the described behavior prevents the successful generation of Python interfaces for those packages.
The text was updated successfully, but these errors were encountered: