Skip to content
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

pure-gen compilation troubles #30

Closed
agraef opened this issue Aug 21, 2019 · 4 comments
Closed

pure-gen compilation troubles #30

agraef opened this issue Aug 21, 2019 · 4 comments
Assignees
Labels

Comments

@agraef
Copy link
Owner

agraef commented Aug 21, 2019

As discussed on the mailing list, this example from the pure-gen manual has stopped working:

rm -f mygsl.pure mygsl.c
DEFS=-DGSL_DISABLE_DEPRECATED
for x in /usr/include/gsl/gsl_*.h; do
  pure-gen $DEFS -N -fc-auto -s "$x::" $x -o mygsl.pure -c mygsl.c
done
gcc $DEFS -shared -o mygsl.so mygsl.c -lgsl

dump-ast generates a bunch of empty output warnings, and errors like:

dump-ast: /usr/include/bits/mathcalls-helper-functions.h:21: (column 40) [ERROR]  >>> Syntax Error !
  Syntax error !
  The symbol `__value' does not fit here.

CallStack (from HasCallStack):
  error, called at dump-ast.hs:27:17 in main:Main

It's always the same kind of error message, followed by a Haskell exception. Having the parser crash with a Haskell exception is not a good thing. ;-) That might also explain why so many empty output files are created.

The resulting code is also partially broken, apparently pure-gen mistakes long double* for double *:

$ gcc $DEFS -shared -o mygsl.so mygsl.c -lgsl
mygsl.c: In function ‘Pure_gsl_matrix_complex_long_double_const_view_array’:
mygsl.c:1181:57: warning: passing argument 1 of ‘gsl_matrix_complex_long_double_const_view_array’ from incompatible pointer type [-Wincompatible-pointer-types]
 1181 |   ret = gsl_matrix_complex_long_double_const_view_array(arg0, arg1, arg2); return &ret;
      |                                                         ^~~~
      |                                                         |
      |                                                         const double *

Always the same error again.

@agraef
Copy link
Owner Author

agraef commented Aug 21, 2019

I should add that this is using the headers from gsl-2.5 on Arch.

@agraef
Copy link
Owner Author

agraef commented Aug 7, 2022

The empty output warnings seem harmless, and can be made to go away by adding -w0 to the pure-gen command. They are apparently generated by headers containing nothing but type definitions and other stuff which isn't wrapped in Pure.

The "symbol `__value' does not fit here" errors are caused by 128 bit floating point types (__float128 and __Float128) which the language-c version 0.5.0 that we use doesn't support. Support for those was added in later language-c versions, though, and I already backported those changes to our language-c version. This is already in the AUR (haskell-language-c5 package), and will be committed here along with the corresponding changes in pure-gen shortly. This makes all these errors go away. (In gsl-2.7.1, there are still a few other unrelated syntax errors due to the gsl_spmatrix_pool type being undefined, but I think that these are due to some mistakes in the corresponding header files, i.e., the header files not being truly self-contained. In any case they can be worked around with a -Dgsl_spmatrix_pool=void.)

The long double* being mapped to double * in the C module seems to be a genuine bug. This won't have any real consequences, as the Pure module actually accepts a void * for any of these, and the user will have to figure out a way to produce these pointers in Pure anyway. But it would still be nice to have the proper type generated on the C side, to avoid those warnings when compiling the C module. This still needs to be addressed for now.

@agraef
Copy link
Owner Author

agraef commented Aug 7, 2022

Yes, some of the headers clearly aren't self-contained, so a better procedure is to collect all the headers in a big header file and run pure-gen on that:

DEFS=-DGSL_DISABLE_DEPRECATED
(for x in /usr/include/gsl/*.h; do echo "#include \"$x\""; done) > mygsl.h
pure-gen $DEFS -w0 -fc-auto -s '/usr/include/gsl/*::' mygsl.h

This eliminates the issue with the undefined types. I also found that I had to add a couple of libraries in compilation to make the module load properly:

# Compile the resulting C module.
gcc $DEFS -shared -o mygsl.so mygsl.c -lgsl -lgslcblas -lcblas

The resulting module now loads fine and seems to work (running a few basic examples). There still are a few symbols which seem to be in the GSL headers but aren't actually in the library, but these can just be deleted from mygsl.pure.

Just pushed the necessary changes to pure-gen and language-c. Next I'll be looking into the long double issue.

@agraef agraef self-assigned this Aug 7, 2022
@agraef agraef added the bug label Aug 7, 2022
@agraef agraef closed this as completed in a5d0ffd Aug 7, 2022
@agraef
Copy link
Owner Author

agraef commented Aug 7, 2022

Actually, only the const long double* pointers were being messed up. Just fixed in git, generated C code compiles cleanly now. This resolves this bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant