bindings-common 1.3.1 → 1.3.2
raw patch · 7 files changed
+144/−28 lines, 7 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
- Bindings.C.Time: c'TIMER_ABSTIME :: (Num a) => a
+ Bindings.C.Ctype: c'isalnum :: CInt -> IO CInt
+ Bindings.C.Ctype: c'isalpha :: CInt -> IO CInt
+ Bindings.C.Ctype: c'isblank :: CInt -> IO CInt
+ Bindings.C.Ctype: c'iscntrl :: CInt -> IO CInt
+ Bindings.C.Ctype: c'isdigit :: CInt -> IO CInt
+ Bindings.C.Ctype: c'isgraph :: CInt -> IO CInt
+ Bindings.C.Ctype: c'islower :: CInt -> IO CInt
+ Bindings.C.Ctype: c'isprint :: CInt -> IO CInt
+ Bindings.C.Ctype: c'ispunct :: CInt -> IO CInt
+ Bindings.C.Ctype: c'isspace :: CInt -> IO CInt
+ Bindings.C.Ctype: c'isupper :: CInt -> IO CInt
+ Bindings.C.Ctype: c'isxdigit :: CInt -> IO CInt
+ Bindings.C.Ctype: c'tolower :: CInt -> IO CInt
+ Bindings.C.Ctype: c'toupper :: CInt -> IO CInt
+ Bindings.C.Ctype: p'isalnum :: FunPtr (CInt -> IO CInt)
+ Bindings.C.Ctype: p'isalpha :: FunPtr (CInt -> IO CInt)
+ Bindings.C.Ctype: p'isblank :: FunPtr (CInt -> IO CInt)
+ Bindings.C.Ctype: p'iscntrl :: FunPtr (CInt -> IO CInt)
+ Bindings.C.Ctype: p'isdigit :: FunPtr (CInt -> IO CInt)
+ Bindings.C.Ctype: p'isgraph :: FunPtr (CInt -> IO CInt)
+ Bindings.C.Ctype: p'islower :: FunPtr (CInt -> IO CInt)
+ Bindings.C.Ctype: p'isprint :: FunPtr (CInt -> IO CInt)
+ Bindings.C.Ctype: p'ispunct :: FunPtr (CInt -> IO CInt)
+ Bindings.C.Ctype: p'isspace :: FunPtr (CInt -> IO CInt)
+ Bindings.C.Ctype: p'isupper :: FunPtr (CInt -> IO CInt)
+ Bindings.C.Ctype: p'isxdigit :: FunPtr (CInt -> IO CInt)
+ Bindings.C.Ctype: p'tolower :: FunPtr (CInt -> IO CInt)
+ Bindings.C.Ctype: p'toupper :: FunPtr (CInt -> IO CInt)
+ Bindings.C.Locale: C'lconv :: CString -> CString -> CChar -> CString -> CString -> CChar -> CChar -> CChar -> CChar -> CChar -> CChar -> CChar -> CString -> CString -> CString -> CString -> CChar -> CChar -> CChar -> CString -> CChar -> CChar -> CChar -> CString -> C'lconv
+ Bindings.C.Locale: c'LC_ALL :: (Num a) => a
+ Bindings.C.Locale: c'LC_COLLATE :: (Num a) => a
+ Bindings.C.Locale: c'LC_CTYPE :: (Num a) => a
+ Bindings.C.Locale: c'LC_MONETARY :: (Num a) => a
+ Bindings.C.Locale: c'LC_NUMERIC :: (Num a) => a
+ Bindings.C.Locale: c'LC_TIME :: (Num a) => a
+ Bindings.C.Locale: c'lconv'currency_symbol :: C'lconv -> CString
+ Bindings.C.Locale: c'lconv'decimal_point :: C'lconv -> CString
+ Bindings.C.Locale: c'lconv'frac_digits :: C'lconv -> CChar
+ Bindings.C.Locale: c'lconv'grouping :: C'lconv -> CString
+ Bindings.C.Locale: c'lconv'int_curr_symbol :: C'lconv -> CString
+ Bindings.C.Locale: c'lconv'int_frac_digits :: C'lconv -> CChar
+ Bindings.C.Locale: c'lconv'int_n_cs_precedes :: C'lconv -> CChar
+ Bindings.C.Locale: c'lconv'int_n_sep_by_space :: C'lconv -> CChar
+ Bindings.C.Locale: c'lconv'int_n_sign_posn :: C'lconv -> CChar
+ Bindings.C.Locale: c'lconv'int_p_cs_precedes :: C'lconv -> CChar
+ Bindings.C.Locale: c'lconv'int_p_sep_by_space :: C'lconv -> CChar
+ Bindings.C.Locale: c'lconv'int_p_sign_posn :: C'lconv -> CChar
+ Bindings.C.Locale: c'lconv'mon_decimal_point :: C'lconv -> CString
+ Bindings.C.Locale: c'lconv'mon_grouping :: C'lconv -> CString
+ Bindings.C.Locale: c'lconv'mon_thousands_sep :: C'lconv -> CString
+ Bindings.C.Locale: c'lconv'n_cs_precedes :: C'lconv -> CChar
+ Bindings.C.Locale: c'lconv'n_sep_by_space :: C'lconv -> CChar
+ Bindings.C.Locale: c'lconv'n_sign_posn :: C'lconv -> CChar
+ Bindings.C.Locale: c'lconv'negative_sign :: C'lconv -> CString
+ Bindings.C.Locale: c'lconv'p_cs_precedes :: C'lconv -> CChar
+ Bindings.C.Locale: c'lconv'p_sep_by_space :: C'lconv -> CChar
+ Bindings.C.Locale: c'lconv'p_sign_posn :: C'lconv -> CChar
+ Bindings.C.Locale: c'lconv'positive_sign :: C'lconv -> CString
+ Bindings.C.Locale: c'lconv'thousands_sep :: C'lconv -> CString
+ Bindings.C.Locale: c'localeconv :: IO (Ptr C'lconv)
+ Bindings.C.Locale: c'setlocale :: CInt -> CString -> IO CString
+ Bindings.C.Locale: data C'lconv
+ Bindings.C.Locale: instance Eq C'lconv
+ Bindings.C.Locale: instance Show C'lconv
+ Bindings.C.Locale: instance Storable C'lconv
+ Bindings.C.Locale: p'localeconv :: FunPtr (IO (Ptr C'lconv))
+ Bindings.C.Locale: p'setlocale :: FunPtr (CInt -> CString -> IO CString)
+ Bindings.Utils: cast666 :: (Storable a, Storable b) => a -> b
Files
- bindings-common.cabal +13/−10
- src/Bindings/C.hs +1/−15
- src/Bindings/C/Ctype.hsc +23/−0
- src/Bindings/C/Locale.hsc +45/−0
- src/Bindings/C/Time.hsc +0/−1
- src/Bindings/Utils.hs +27/−0
- src/bindings.macros.h +35/−2
bindings-common.cabal view
@@ -2,21 +2,21 @@ name: bindings-common homepage: http://bitbucket.org/mauricio/bindings-common synopsis:- Preprocessor combinator library for low level FFI.+ Preprocessor DSL for low level FFI. description: Packages named @bindings-*@ contain low level bindings to well known libraries, as a resource to be used by developers of higher level modules. This @bindings-common@ package provides @hsc2hs@ macros that allows writing code for such low level- bindings that is easy to read and maintain, while keeping names- and functionality as close as possible to the base library.- These macros can be used as a simple alternative to, say,- @c2hs@, or to @hsc2hs@ original macros. At this moment, there's- no good documentation on how to use them, so please- read the code for "Bindings.C" to understand how they work, or- just fill question\/sugestion reports in the bug tracking web- site.-version: 1.3.1+ bindings that is easy to write, read and maintain, while+ keeping names and functionality as close as possible to the+ base library. These macros can be used as a simple alternative+ to, say, @c2hs@, or to @hsc2hs@ original macros. Bindings+ for the standard C library are also provided, and its source+ code shows how most macros are supposed to be used. More+ examples and reference documentation can be found at project+ homepage.+version: 1.3.2 license: BSD3 license-file: LICENSE maintainer: Maurício C. Antunes <mauricio.antunes@gmail.com>@@ -35,12 +35,15 @@ build-depends: base >=3 && <5 exposed-modules: Bindings.C+ Bindings.C.Ctype Bindings.C.Errno+ Bindings.C.Locale Bindings.C.Math Bindings.C.Signal Bindings.C.Stddef Bindings.C.Stdio Bindings.C.String Bindings.C.Time+ Bindings.Utils cc-options: "-D_ISOC99_SOURCE"
src/Bindings/C.hs view
@@ -1,15 +1,1 @@-module Bindings.C (- module Bindings.C.Errno,- module Bindings.C.Math,- module Bindings.C.Stddef,- module Bindings.C.Stdio,- module Bindings.C.String,- module Bindings.C.Time,- ) where-import Prelude ()-import Bindings.C.Errno-import Bindings.C.Math-import Bindings.C.Stddef-import Bindings.C.Stdio-import Bindings.C.String-import Bindings.C.Time+module Bindings.C (module Bindings.C.Ctype,module Bindings.C.Errno,module Bindings.C.Locale,module Bindings.C.Math,module Bindings.C.Signal,module Bindings.C.Stddef,module Bindings.C.Stdio,module Bindings.C.String,module Bindings.C.Time) where {import Bindings.C.Ctype;import Bindings.C.Errno;import Bindings.C.Locale;import Bindings.C.Math;import Bindings.C.Signal;import Bindings.C.Stddef;import Bindings.C.Stdio;import Bindings.C.String;import Bindings.C.Time}
+ src/Bindings/C/Ctype.hsc view
@@ -0,0 +1,23 @@+#include <bindings.macros.h>+#include <ctype.h>++-- | <http://www.opengroup.org/onlinepubs/9699919799/basedefs/ctype.h.html>++module Bindings.C.Ctype where+#strict_import++#ccall isalnum , CInt -> IO CInt+#ccall isalpha , CInt -> IO CInt+#ccall isblank , CInt -> IO CInt+#ccall iscntrl , CInt -> IO CInt+#ccall isdigit , CInt -> IO CInt+#ccall isgraph , CInt -> IO CInt+#ccall islower , CInt -> IO CInt+#ccall isprint , CInt -> IO CInt+#ccall ispunct , CInt -> IO CInt+#ccall isspace , CInt -> IO CInt+#ccall isupper , CInt -> IO CInt+#ccall isxdigit , CInt -> IO CInt+#ccall tolower , CInt -> IO CInt+#ccall toupper , CInt -> IO CInt+
+ src/Bindings/C/Locale.hsc view
@@ -0,0 +1,45 @@+#include <bindings.macros.h>+#include <locale.h>++-- | <http://www.opengroup.org/onlinepubs/9699919799/basedefs/locale.h.html>++module Bindings.C.Locale where+#strict_import++#starttype struct lconv+#field currency_symbol , CString+#field decimal_point , CString+#field frac_digits , CChar+#field grouping , CString+#field int_curr_symbol , CString+#field int_frac_digits , CChar+#field int_n_cs_precedes , CChar+#field int_n_sep_by_space , CChar+#field int_n_sign_posn , CChar+#field int_p_cs_precedes , CChar+#field int_p_sep_by_space , CChar+#field int_p_sign_posn , CChar+#field mon_decimal_point , CString+#field mon_grouping , CString+#field mon_thousands_sep , CString+#field negative_sign , CString+#field n_cs_precedes , CChar+#field n_sep_by_space , CChar+#field n_sign_posn , CChar+#field positive_sign , CString+#field p_cs_precedes , CChar+#field p_sep_by_space , CChar+#field p_sign_posn , CChar+#field thousands_sep , CString+#stoptype++#num LC_ALL+#num LC_COLLATE+#num LC_CTYPE+#num LC_MONETARY+#num LC_NUMERIC+#num LC_TIME++#ccall localeconv , IO (Ptr <lconv>)+#ccall setlocale , CInt -> CString -> IO CString+
src/Bindings/C/Time.hsc view
@@ -19,7 +19,6 @@ #stoptype #num CLOCKS_PER_SEC-#num TIMER_ABSTIME #ccall clock , IO CClock #ccall difftime , CTime -> CTime -> IO CDouble
+ src/Bindings/Utils.hs view
@@ -0,0 +1,27 @@+module Bindings.Utils (+ cast666,+ ) where+import Foreign++-- | This is safe regarding use of memory. Enough space is+-- allocated to store both values, and the difference between+-- sizes, if any, is filled with zeros. The result is what you+-- would expect if you have a C pointer to the first value and+-- cast it to a pointer to the result. Of course, this can have+-- undesired effects if 'peek' implementation for+-- the result type does more than just reading memory.+--+-- This function can be safely used with any datatype generated by+-- this package macro library.++cast666 :: (Storable a, Storable b) => a -> b+cast666 = unsafePerformIO . genericCast+ where+ genericCast :: (Storable a, Storable b) => a -> IO b+ genericCast v = return undefined >>= \r ->+ let size = max (sizeOf v) (sizeOf r) in+ allocaBytes size $ \p ->+ pokeArray p (replicate size (0::Word8)) >>+ poke (castPtr p) v >>+ if False then return r else peek (castPtr p)+
src/bindings.macros.h view
@@ -1,3 +1,6 @@+#ifndef __BINDINGS_MACROS_H__+#define __BINDINGS_MACROS_H__+ #define hsc_strict_import(dummy) printf( \ "import Foreign.Ptr (Ptr,FunPtr,plusPtr)\n" \ "import Foreign.Ptr (wordPtrToPtr,castPtrToFunPtr)\n" \@@ -109,10 +112,23 @@ { \ int sign = (name)(-1)<0; \ size_t size = sizeof(name); \- if (sign && size==sizeof(int)) printf("CInt\n"); \- else printf("%s%zu\n",sign?"Int":"Word",8*size); \+ if (size==sizeof(int)) printf("%s",sign?"CInt":"CUInt"); \+ else if (size==sizeof(char)) printf("%s", \+ (char)(-1)<0?(sign?"CChar":"CUChar"):(sign?"CSChar":"CChar")); \+ else printf("%s%zu",sign?"Int":"Word",8*size); \+ printf("\n"); \ } \ +#define hsc_fractional_t(name) \+ printf("type ");bc_conid(# name);printf(" = "); \+ switch (sizeof(name)) \+ { \+ case sizeof(float): printf("CFloat");break; \+ case sizeof(double): printf("CDouble");break; \+ case sizeof(long double): printf("CLDouble");break; \+ } \+ printf("\n"); \+ #define hsc_opaque_t(name) \ printf("data ");bc_conid(# name); \ printf(" = "); \@@ -209,4 +225,21 @@ } \ printf(" return ()\n"); \ } \++#define BC_INLINE_(name,ret) \+ ret inline_##name () {return name;} \++#define BC_INLINE0(name,ret) \+ ret inline_##name () {return name();} \++#define BC_INLINE1(name,t1,ret) \+ ret inline_##name (t1 v1) {return name(v1);} \++#define BC_INLINE2(name,t1,t2,ret) \+ ret inline_##name (t1 v1,t2 v2) {return name(v1,v2);} \++#define BC_INLINE4(name,t1,t2,t3,t4,ret) \+ ret inline_##name (t1 v1,t2 v2,t3 v3,t4 v4) {return name(v1,v2,v3,v4);} \++#endif /* __BINDINGS_MACROS_H__ */