-
Notifications
You must be signed in to change notification settings - Fork 124
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
Fix C and C++ bindings #125
Conversation
Main problems found in the original version are: I. C vs iso_c_binding: 1. Mismatch between float complex and float parameters in C prototypes and icba*.f90 files 2. Mismatch between passing of some arguments by pointer vs by value II. iso_c_binding vs Fortran: 1. Mismatch between real and complex parameters 2. Wrong intent for 'workev' These problems lead to UB, which, in particular, resulted in test crashes on i686 targets. This patch fixes them.
This no longer includes a tweaked copy of arpack.h. Maintaining both sets of prototypes separately is too much manual labor.
double _Complex* workd, double _Complex* workl, int lworkl, | ||
double _Complex* rwork, int& info); | ||
} | ||
#include "arpack.h" |
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.
Durr my bad - sorry! I should have done this from the start. Thanks!
Sorry for the late reply. Changes in icbazn.f90 and icbacn.f90 looks correct (my mystake, at the time, I had to do all from scratch). The same problem has been probably cut-pasted in icbpzn.f90 and icbpcn.f90. Ideally, tests should use/test all cases/signatures... But there are a lot of them (I did a few). |
There are no tests for PARPACK C bindings, are there? Frankly, I've never dealt with PARPACK, so I'm not even sure how I can make a test for its C bindings. But indeed, the |
OK, I've done the mechanical fixes for PARPACK C and C++ bindings too, but they are completely untested (or all tests pass if there exist any I don't know about). |
@10110111 : thanks ! Your patch looks OK to me : in icb[ap]*.f90, the bug is |
Do you think it fixes all issues? |
Well, all those I found. There might be another mismatches between |
I hope so !... Is it ok on i386 ?
100% agree: arpack users will open issues if they find problems (easy to fix a posteriori and add test - crazy job to check a priori). Ideally, tests should test all signatures (= heavy job for a walking-dead-fortran thing like arpack...). |
These changes should be more correct than my previous attempt. I've fixed complex-related
icba*.f90
files, and regenerated the C prototypes from all theicba*.f90
files. C++ header now simply includes the C one to avoid duplication of maintenance effort.The C prototypes were generated by a quick-and-dirty perl script, which won't work in the fully general case, but should work for the well-behaved
iso_c_binding
code (namely, it relies on the order of parameters described inside the*_c
functions being the same as in their prototypes). Here's the script, in case someone wants to regenerate the prototypes later (NOTE: for PARPACK you'll have to filter the output with something likesed 's@\<int comm,@MPI_Fint comm,@'
):This fixes #123.