[C2hs] problem with sys/sysmacros.h

Manuel M T Chakravarty chak at cse.unsw.edu.au
Mon May 31 22:00:17 EDT 2004


Hi Jens,

On Sun, 2004-05-16 at 11:24, Jens Petersen wrote: 
> Hi,
> 
> I have a problem when processing "vte/vte.h" (from
> vte-0.11.10) with c2hs-0.12.0 and glibc-2.3.3:
> 
> LANG=C c2hs --cppopts="-I/usr/include/gtk-2.0 -I/usr/lib/gtk-2.0/include -I/usr/include/atk-1.0 -I/usr/include/pango-1.0 -I/usr/X11R6/include -I/usr/include/freetype2 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include" vte.h Vte.chs
> c2hs: Generic fatal error.
> 
> /usr/include/sys/sysmacros.h:43: (column 1) [FATAL] 
>   >>> Syntax error!
>   The symbol `{' does not fit here.
> 
> 
> It seems sys/sysmacros.h changed from glibc-2.3.2.  Here is
> the context:
> 
> # if defined __GNUC__ && __GNUC__ >= 2
> __extension__ extern __inline unsigned int
> gnu_dev_major (unsigned long long int __dev) __THROW
> {
>   return ((__dev >> 8) & 0xfff) | ((unsigned int) (__dev >> 32) & ~0xfff);
> }

The problem is the function body.  C->Haskell's parser does not
understand them (as they usually don't occur in header files).  It is
not hard to extend the parser to parse them and for c2hs to ignore them
(after all C's statement syntax is quite simple and c2hs already handles
expressions).  I'll make this the next thing to add to c2hs (unless
somebody beats me to it - it really is straight forward if you have got
a C grammar at hand).

It would be harder to find a way to actually use such functions from
Haskell.  gnu_dev_major is supposed to be inlined, which is hard to do
in Haskell code.

> Jens
> 
> ps glibc-2.3.3 will be in Fedora Core 2, which is being released
> on Tuesday.
> 
> pps I just uploaded c2hs-0.12.0 rpms built with glibc-2.3.3
> to <http://haskell.org/~petersen/rpms/c2hs/>.  

The web server claims I don't have permission to access this directory.

> I applied the
> following patch to build it with ghc-6.2.1:
> 
> --- c2hs-0.12.0/c2hs/c/CAttrs.hs~	2004-05-16 09:46:07.000000000 +0900
> +++ c2hs-0.12.0/c2hs/c/CAttrs.hs	2004-05-16 09:46:07.000000000 +0900
> @@ -144,7 +144,7 @@
>  --
>  leaveObjRangeC    :: AttrC -> AttrC
>  leaveObjRangeC ac  = ac {
> -		       defObjsAC = fst . leaveRange . defObjsAC $ ac,
> +		       defObjsAC = fst . leaveRange . defObjsAC $ ac
>  		     }
>  
>  -- add another definitions to the object name space (EXPORTED)

Thanks, that's been included in the CVS version.

Cheers,
Manuel




More information about the C2hs mailing list