f90wrap
f90wrap copied to clipboard
Fix issue 157
it seems that the C code generator in f2py converts everything to lowercase when creating the C functions; this PR brings in some small tweaks to allow reserved words to pass through as the same fortran variables (and all function names are retained in C, converted to lowercase); handles to f90wrap_ subroutines are also renamed to lowercase.
Finally, the pywrapgen.py file is changed to use orig_names and the .lower() method is invoked to ensure that renaming of reserved words is lowercase.
Background:
My understanding is that f2py will rename keywords (like size) to something else when generating the C code; these definitions are provided in numpy.f2py.crackfortran.badnames. To make f90wrap-generated Python classes compatible, I've removed the renaming (where I can see it) for reserved words in the unwrapping of derived type elements using .orig_name where applicable, and only renamed the python classes in f90wrap/pywrapgen.py.
Other minor change: change python to python3 in the Makefile under examples
All tests pass. Added new test with a derived type called "Size".
Final point: the preprocessing step (gfortran -E?) is the one that generates the modules in .fpp format that ultimately get built; if the intent is to have all reserved words renamed at the source level, then it may be required to add in-place replacement for all source code (including parts of the code that get compiled into a library/shared object, i.e., Fortran source that is "invisible" to python). Because there is presently no general provision to do so (other than to use preprocessor directives), I'm opting to use the present solution.
Right off the bat, there will be some edge cases like having arrays of a derived type called "size" that fail immediately, because of the size() check in f90wrap-generated files. Ultimately, my take away from this exercise is that it should be verboten to use any reserved words in Fortran source; I'm tweaking f90wrap to accommodate some limited cases where singleton instances of a derived type with a reserved name is allowed.
Thanks for this contribution. The new examples seems very extensive; would it be possible to cut it down to something minimal which still demonstrates the problems with the previous implementation?
@jameskermode removed the math library I had included by mistake. Hopefully that trims it down to a cmake/ folder (which builds the Makefiles) and a src/ folder
Still seems much larger than needed to test the changes you're proposing: please make a minimal example if at all possible, to speed up the evaluation of the test-set, e.g. a single Fortran subroutine, or at most a single source file.
@jameskermode reduced to single fortran source file (highest.F90).
Thanks. I'll try it out locally as the CI isn't running on this branch for some reason. There might be a problem relying on cmake since the rest of the examples use a standard Makefile.
As suspected your new test does not run when I do make test from the f90wrap/examples directory. It needs to be added to the Makefile there, and then also to work with plain make rather than cmake on a unix-like system so that the GitHub CI tests work. If you like I can convert it, if you give me (@jameskermode) push access to your fork of f90wrap.
Got a basic makefile working, and removed CMake = it should work now; I renamed python to python3.
On Thu, Oct 21, 2021 at 5:31 AM James Kermode @.***> wrote:
As suspected your new test does not run when I do make test from the f90wrap/examples directory. It needs to be added to the Makefile there, and then also to work with plain make rather than cmake on a unix-like system so that the GitHub CI tests work. If you like I can convert it, if you give me @.*** https://github.com/jameskermode) push access to your fork of f90wrap.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/jameskermode/f90wrap/pull/158#issuecomment-948567963, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADX46YQ7P3F45SPIIWDEPM3UIAB2RANCNFSM5GAT2ZHA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.
-- Talent hits a target no one else can hit; Genius hits a target no one else can see. --Arthur Schopenhauer
I added you as a collaborator; if you don't have an invite for access, please let me know and I'll figure out what's going on.
On Thu, Oct 21, 2021 at 2:51 PM Ananth Sridharan @.***> wrote:
Got a basic makefile working, and removed CMake = it should work now; I renamed python to python3.
On Thu, Oct 21, 2021 at 5:31 AM James Kermode @.***> wrote:
As suspected your new test does not run when I do make test from the f90wrap/examples directory. It needs to be added to the Makefile there, and then also to work with plain make rather than cmake on a unix-like system so that the GitHub CI tests work. If you like I can convert it, if you give me @.*** https://github.com/jameskermode) push access to your fork of f90wrap.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/jameskermode/f90wrap/pull/158#issuecomment-948567963, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADX46YQ7P3F45SPIIWDEPM3UIAB2RANCNFSM5GAT2ZHA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.
-- Talent hits a target no one else can hit; Genius hits a target no one else can see. --Arthur Schopenhauer
-- Talent hits a target no one else can hit; Genius hits a target no one else can see. --Arthur Schopenhauer