FFI breaking with -O?

John Meacham john@repetae.net
Tue, 10 Sep 2002 02:58:32 -0700


okay, I figured out putting the -fasm after the -O and that seems to
cause the problem to go away supporting my theory. 
For an example of something that breaks, the following will create an
error when compiled via-C and not otherwise. 

#include <ncurses.h>
foreign import ccall touchwin :: Window -> IO CInt

for the ncurses included with red hat linux, i think it has something to
do with the fact that touchwin is both #defined in terms of other
routines AND part of the ncurses library as its own function. I imagine
they did this to allow inlining when compiling C as well as external
bindings and function pointers to refer to the function. many other
routines give warnings which are #definied in similar ways.
	John



On Tue, Sep 10, 2002 at 10:34:04AM +0100, Simon Marlow wrote:
> > I have a variety of C interfaces which are generated with hsc2hs, in
> > particular a ncurses and openssl wrapper. they work perfectly when
> > compiling normally, but when i use the -O or -O2 option, I end up with
> > at the least a ton of C warnings on the /tmp/ghc*.hc file and in some
> > cases a fatal error. as far as i can tell they relate to some odd
> > interaction with the C preprocessor and the generated haskell 
> > code. I am
> > not compiling with -fvia-C but it appears to be going via C 
> > anyway. Does
> > anyone have any ideas why this might be the case or a 
> > workaround for the
> > problem?  Perhaps if this is the case, I can force it to not 
> > compile via
> > C even when optimizing?
> > 	John
> > 
> > (the offending code is part of 'ginsu' my gale client implemented in
> > haskell http://repetae.net/john/computer/ginsu/ )
> 
> This "shouldn't" happen, although there are occasionally good reasons
> why it does.  Are you including the right header files using the
> -#include option?  Can you send us some sample code to test, or should I
> try the whole of ginsu?
> 
> You can force non-via-C by saying -fasm.  Put this flag *after* -O,
> because -O implies -fvia-C.
> 
> Cheers,
> 	Simon
> _______________________________________________
> Glasgow-haskell-users mailing list
> Glasgow-haskell-users@haskell.org
> http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
> 

-- 
---------------------------------------------------------------------------
John Meacham - California Institute of Technology, Alum. - john@foo.net
---------------------------------------------------------------------------