2
2
#if __GLASGOW_HASKELL__ >= 702
3
3
{-# LANGUAGE DeriveGeneric #-}
4
4
#endif
5
+ #if __GLASGOW_HASKELL__ >= 706
6
+ {-# LANGUAGE CApiFFI #-}
7
+ #endif
5
8
-----------------------------------------------------------------------------
6
9
-- |
7
10
-- Copyright : (c) 2006-2015 Duncan Coutts
@@ -1008,13 +1011,25 @@ newtype StreamState = StreamState (Ptr StreamState)
1008
1011
--
1009
1012
-- So we define c_inflateInit2 and c_deflateInit2 here as wrappers around
1010
1013
-- their _ counterparts and pass the extra args.
1014
+ --
1015
+ -- As of GHC 7.6, we can import macros directly using the CApiFFI extension.
1016
+ -- This avoids the need for the hsc2hs #{const_str} construct, which means
1017
+ -- hsc2hs can run in cross-compilation mode.
1011
1018
1012
1019
##ifdef NON_BLOCKING_FFI
1013
1020
##define SAFTY safe
1014
1021
##else
1015
1022
##define SAFTY unsafe
1016
1023
##endif
1017
1024
1025
+ #if __GLASGOW_HASKELL__ >= 706
1026
+ foreign import capi unsafe " zlib.h inflateInit2"
1027
+ c_inflateInit2 :: StreamState -> CInt -> IO CInt
1028
+
1029
+ foreign import capi unsafe " zlib.h deflateInit2"
1030
+ c_deflateInit2 :: StreamState
1031
+ -> CInt -> CInt -> CInt -> CInt -> CInt -> IO CInt
1032
+ #else
1018
1033
foreign import ccall unsafe " zlib.h inflateInit2_"
1019
1034
c_inflateInit2_ :: StreamState -> CInt -> Ptr CChar -> CInt -> IO CInt
1020
1035
@@ -1023,15 +1038,6 @@ c_inflateInit2 z n =
1023
1038
withCAString # {const_str ZLIB_VERSION } $ \ versionStr ->
1024
1039
c_inflateInit2_ z n versionStr (# {const sizeof(z_stream)} :: CInt )
1025
1040
1026
- foreign import ccall SAFTY " zlib.h inflate"
1027
- c_inflate :: StreamState -> CInt -> IO CInt
1028
-
1029
- foreign import ccall unsafe " zlib.h &inflateEnd"
1030
- c_inflateEnd :: FinalizerPtr StreamState
1031
-
1032
- foreign import ccall unsafe " zlib.h inflateReset"
1033
- c_inflateReset :: StreamState -> IO CInt
1034
-
1035
1041
foreign import ccall unsafe " zlib.h deflateInit2_"
1036
1042
c_deflateInit2_ :: StreamState
1037
1043
-> CInt -> CInt -> CInt -> CInt -> CInt
@@ -1043,6 +1049,16 @@ c_deflateInit2 :: StreamState
1043
1049
c_deflateInit2 z a b c d e =
1044
1050
withCAString # {const_str ZLIB_VERSION } $ \ versionStr ->
1045
1051
c_deflateInit2_ z a b c d e versionStr (# {const sizeof(z_stream)} :: CInt )
1052
+ #endif
1053
+
1054
+ foreign import ccall SAFTY " zlib.h inflate"
1055
+ c_inflate :: StreamState -> CInt -> IO CInt
1056
+
1057
+ foreign import ccall unsafe " zlib.h &inflateEnd"
1058
+ c_inflateEnd :: FinalizerPtr StreamState
1059
+
1060
+ foreign import ccall unsafe " zlib.h inflateReset"
1061
+ c_inflateReset :: StreamState -> IO CInt
1046
1062
1047
1063
foreign import ccall unsafe " zlib.h deflateSetDictionary"
1048
1064
c_deflateSetDictionary :: StreamState
0 commit comments