-
-
Notifications
You must be signed in to change notification settings - Fork 11.1k
BUG: Make f2py work with intent(in out). #5168
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
Conversation
Strictly speaking, this fixes what could be regarded as abuse of Fortran, but as the Fortran compiler doesn't care, there is code in the wild that has this flaw. |
I don't think this simple fix is correct, for the reason you pointed out in #479. Here's an example: inout.f90
When the argument is not contiguous,
When the argument is contiguous, both versions work as expected:
|
I think there is a bug anyway, but from the fortran side |
98010aa
to
aef2f7a
Compare
Sorry, I'm not proposing an action. I'm just pointing out that the change in this PR doesn't fix the f2py bug. In the f2py generated wrapper of |
Hold on, I think my previous comment applies to an outdated change (or maybe even a change not in this PR). |
Yes, this PR should produce the same signature for both cases, the update just fixed the 'already present' check. Probably needs at least a test for compilation working... |
OK, this works for me now. When I made the above comment, I had used the fix mentioned in #479, and hadn't pulled the change from this PR. Sorry for the noise. Yeah, a unit test for this would be good. |
vars[n]['intent'].append(c) | ||
# Remove spaces so that 'in out' becomes 'inout' | ||
tmp = c.replace(' ', '') | ||
if not tmp in vars[n]['intent']: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps tmp not in vars[...
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, yes. I'm afraid to run pep8 on these files.
OK, I lied, running pep8 yields over a thousand PEP8 violations ;) I've fixed three.
@WarrenWeckesser I've used your example as a test. |
Looks good and works for me. I don't know about the "Subproject commit" of doc/sphinxext. Is that intentional? |
No, it's a d*mn artifact of the common rebase. I'm embarrassed I missed it, thanks for the catch. |
Note that Fortran ignores spaces in this case, so that 'in out' is treated as 'inout'. Closes numpy#479.
This checks that the compilation works and that the expected error is raised when non-contiguous arrays are passed as intent(in out).
73d7a54
to
e98686d
Compare
BUG: Make f2py work with intent(in out).
@juliantaylor You might want to backport this. |
BUG: Make f2py work with intent(in out).
pushed to the branch, thanks |
@pearu Pearu, what is the status of fparser? |
Sorry, guys, but it seems too me that some comments bark up the wrong tree. First, Fortran 77 and newer Fortran standards in fixed mode completely ignore spaces. In free mode, however, spaces are treated as in any popular programming language. For example, Second, f2py "parser" (crackfortran.py) is not a conventional parser as it uses regular expressions. It was a practical choice at the time of creating f2py when the main aim was to have a robust extension source generator, parsing Fortran had a secondary priority. When f2py fails to parse, one can always relay on writing signature files by hand. Implementing Fortran parser with full standard support is far from trivial, fparser project (it exists within f2py google code project) has been created just for that. Since developing f2py financial support had stopped some time ago, I haven't had resources to finish fparser. So, fparser status is 'in hold'. |
@pearu Lahey seems to use the construction in their documentation. We have already patched I was asking about fparser in the hope that there might be a newer version of f2py that would be easier to maintain, but didn't have much hope for that. Parsing Fortran, with all it's versions and idiosyncrasies is not a trivial problem and f2py works wonders, but it is not easy to maintain. |
Note that Fortran ignores spaces in this case, so that 'in out' is
treated as 'inout'.
Closes #479.
Rebased for backport to 1.9.0.