Re: [Haskell-cafe] Problem using #define in .hsc files

2009-03-30 Thread John Van Enk
In Scurry, I select the CALLCONV on the CPP command line. This might be
better if it's the only place you need an #ifdef.
http://hackage.haskell.org/packages/archive/Scurry/0.0.3/Scurry.cabal

See the OS selection in the executable section:

executable scurry

[..]

if os(mingw32)
c-sources:  src/C/help-win.c
extra-libraries:Iphlpapi, ws2_32
cc-options: -D MINGW32
cpp-options:-DCALLCONV=stdcall

if os(linux)
build-depends: unix >= 2.3.0.0
c-sources:  src/C/help-linux.c
cc-options: -D LINUX
cpp-options:-DCALLCONV=ccall


/jve


On Mon, Mar 30, 2009 at 4:41 AM, Alistair Bayley wrote:

> 2009/3/29 Johan Tibell :
> >
> > foreign import CALLCONV unsafe "send"
> >c_send :: CInt -> Ptr a -> CSize -> CInt -> IO CInt
> >
> > Compiling results in:
> >
> > parse error on input `CALLCONV'
>
>
> This is what we use in Takusen's Database.ODBC.OdbcFunctions.hsc:
>
> #ifdef mingw32_HOST_OS
> #let CALLCONV = "stdcall"
> #else
> #let CALLCONV = "ccall"
> #endif
>
> foreign import #{CALLCONV} unsafe "sql.h SQLAllocHandle" sqlAllocHandle ::
>  SqlHandleType -> Handle -> Ptr Handle -> IO SqlReturn
>
> Alistair
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Problem using #define in .hsc files

2009-03-30 Thread Alistair Bayley
2009/3/29 Johan Tibell :
>
> foreign import CALLCONV unsafe "send"
>    c_send :: CInt -> Ptr a -> CSize -> CInt -> IO CInt
>
> Compiling results in:
>
> parse error on input `CALLCONV'


This is what we use in Takusen's Database.ODBC.OdbcFunctions.hsc:

#ifdef mingw32_HOST_OS
#let CALLCONV = "stdcall"
#else
#let CALLCONV = "ccall"
#endif

foreign import #{CALLCONV} unsafe "sql.h SQLAllocHandle" sqlAllocHandle ::
  SqlHandleType -> Handle -> Ptr Handle -> IO SqlReturn

Alistair
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Problem using #define in .hsc files

2009-03-29 Thread Johan Tibell
Hi,

I'm trying to have hsc2hs interpret this snippet that picks a calling
convention to use for FFI imports:

#if !defined(CALLCONV)
#ifdef WITH_WINSOCK
#define CALLCONV stdcall
#else
#define CALLCONV ccall
#endif
#endif

foreign import CALLCONV unsafe "send"
c_send :: CInt -> Ptr a -> CSize -> CInt -> IO CInt

Compiling results in:

parse error on input `CALLCONV'

Inspecting the generated .hs file shows that CALLCONV appear in the
source code instead of being replaced with either stdcall or ccall as
expected. What's the correct way to use #define in .hsc files?
Changing the file extension to .cpphs solves the problem, by using
plain CPP instead of hsc2hs I presume.

Cheers,

Johan
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe