haskell / c2hs

c2hs is a pre-processor for Haskell FFI bindings to C libraries
http://hackage.haskell.org/package/c2hs
Other
198 stars 50 forks source link

c2hs seems to have issue with C11 _Noreturn function specifier. #159

Open mitchty opened 8 years ago

mitchty commented 8 years ago

Noticed this on alpine linux 3.3.1 when compiling the ncurses package.

The error log:

Configuring ncurses-0.2.15...
Building ncurses-0.2.15...
Preprocessing library ncurses-0.2.15...
c2hs: C header contains errors:

/usr/include/stdlib.h:44: (column 11) [ERROR]  >>> Syntax error !
  The symbol `void' does not fit here.

And that section of stdlib.h:

_Noreturn void abort (void);
int atexit (void (*) (void));
_Noreturn void exit (int);
_Noreturn void _Exit (int);
int at_quick_exit (void (*) (void));
_Noreturn void quick_exit (int);

I think it would be ok to just ignore _Noreturn in these cases correct? The function specifier doesn't really change the fact that its a function just specifies that these functions never return to their caller. I couldn't find anything in the source that seems to indicate _Noreturn is parsed at all but if I missed it let me know.

ian-ross commented 8 years ago

@mitchty C2HS uses the language-c library to parse header files: the language-c package claims to deal with "all of C99 and a large set of GNU extensions", i.e. it's not a C11 parser. We're getting more and more problems with C2HS due to the default C compilers supplied with distributions moving beyond C99. I know what to do about it, which is to use one of the other Haskell C parsing libraries, but switching C2HS over to a completely new parsing library isn't something I want to do myself.

mitchty commented 8 years ago

@ian-ross Fair point, I'll open up a bug against language-c. I think having it work with C11 would be preferable as I don't think it will be going away. I notice it just changed ownership as well so we'll see where this goes. For the moment I'm just hacking stdlib.h to work around things.

visq commented 8 years ago

I've started working on C11 support in language.c. _Noreturn has been implemented already: https://github.com/visq/language-c/commit/7a1ab1af9b5df9019931412130056cdc173698bf