bindings-common 0.1.3 → 0.1.4
raw patch · 9 files changed
+208/−55 lines, 9 filesdep ~basePVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependency ranges changed: base
API changes (from Hackage documentation)
- Bindings.C: instance Storable Timeval
+ Bindings.C: _CLOCKS_PER_SEC :: CClock
+ Bindings.C: asctime :: Ptr Tm -> IO CString
+ Bindings.C: clock :: IO CClock
+ Bindings.C: ctime :: Ptr CTime -> IO CString
+ Bindings.C: data Tm
+ Bindings.C: difftime :: CTime -> CTime -> IO CDouble
+ Bindings.C: gmtime :: Ptr CTime -> IO (Ptr Tm)
+ Bindings.C: localtime :: Ptr CTime -> IO (Ptr Tm)
+ Bindings.C: mktime :: Ptr Tm -> IO CTime
+ Bindings.C: strftime :: CString -> CSize -> CString -> Ptr Tm -> IO CSize
+ Bindings.C: time :: Ptr CTime -> IO CTime
Files
- bindings-common.cabal +9/−3
- src/Bindings/C.hs +19/−33
- src/Bindings/c.c +0/−19
- src/CConstants.hs +7/−0
- src/CFunctions.hs +32/−0
- src/CTypes.hs +75/−0
- src/cconstants.c +7/−0
- src/cfunctions.c +2/−0
- src/ctypes.c +57/−0
bindings-common.cabal view
@@ -9,7 +9,7 @@ level modules that can use it as foundation. They all mimic the exact names and functionality of the original libraries. For a specific library, look for package @bindings-library_name@.-version: 0.1.3+version: 0.1.4 license: BSD3 license-file: LICENSE maintainer: Maurício C. Antunes@@ -19,15 +19,21 @@ library hs-source-dirs: src c-sources:- src/Bindings/c.c+ src/ctypes.c+ src/cfunctions.c+ src/cconstants.c extensions: ForeignFunctionInterface TypeSynonymInstances ScopedTypeVariables MultiParamTypeClasses TypeFamilies- build-depends: base+ build-depends: base >=3 && <5 exposed-modules: Bindings Bindings.Utilities Bindings.C+ other-modules:+ CFunctions+ CConstants+ CTypes
src/Bindings/C.hs view
@@ -1,40 +1,26 @@- module Bindings.C ( - Timeval-- ) where--import Foreign.C-import Foreign-import Data.Int--data Timeval = Timeval {timeval'tv_sec, timeval'tv_usec :: CLong}--instance Storable Timeval where-- sizeOf _ = fromIntegral size_of_timeval-- alignment = sizeOf-- peek p =- with 0 $ \p1 ->- with 0 $ \p2 ->-- c2hs_timeval p p1 p2 >>-- peek p1 >>= \v1 ->- peek p2 >>= \v2 ->+ -- * @time.h@ - return $ Timeval {timeval'tv_sec = v1, timeval'tv_usec = v2}+ -- | <http://www.cplusplus.com/reference/clibrary/ctime> - poke p v = hs2c_timeval p (timeval'tv_sec v) (timeval'tv_usec v)+ clock,+ difftime,+ mktime,+ time,+ asctime,+ ctime,+ gmtime,+ localtime,+ strftime,+ _CLOCKS_PER_SEC,+ Tm, -foreign import ccall "size_of_timeval" size_of_timeval- :: CInt+ -- * @sys/time.h@ -foreign import ccall "hs2c_timeval" hs2c_timeval- :: Ptr Timeval -> CLong -> CLong -> IO ()+ Timeval, -foreign import ccall "c2hs_timeval" c2hs_timeval- :: Ptr Timeval -> Ptr CLong -> Ptr CLong -> IO ()+ ) where+import CFunctions+import CTypes+import CConstants
− src/Bindings/c.c
@@ -1,19 +0,0 @@-#include <sys/time.h>-#include <time.h>--int size_of_timeval (void)-{- return sizeof (struct timeval);-}--void hs2c_timeval (struct timeval *p, long p1, long p2)-{- p->tv_sec = p1;- p->tv_usec = p2;-}--void c2hs_timeval (struct timeval *p, long *p1, long *p2)-{- *p1 = p->tv_sec;- *p2 = p->tv_usec;-}
+ src/CConstants.hs view
@@ -0,0 +1,7 @@+module CConstants where+import Foreign+import Foreign.C+import CTypes++foreign import ccall _CLOCKS_PER_SEC :: CClock+
+ src/CFunctions.hs view
@@ -0,0 +1,32 @@+module CFunctions where +import Foreign+import Foreign.C+import CTypes++foreign import ccall clock+ :: IO CClock++foreign import ccall difftime+ :: CTime -> CTime -> IO CDouble++foreign import ccall mktime+ :: Ptr Tm -> IO CTime++foreign import ccall time+ :: Ptr CTime -> IO CTime++foreign import ccall asctime+ :: Ptr Tm -> IO CString++foreign import ccall ctime+ :: Ptr CTime -> IO CString++foreign import ccall gmtime+ :: Ptr CTime -> IO (Ptr Tm)++foreign import ccall localtime+ :: Ptr CTime -> IO (Ptr Tm)++foreign import ccall strftime+ :: CString -> CSize -> CString -> Ptr Tm -> IO CSize+
+ src/CTypes.hs view
@@ -0,0 +1,75 @@+module CTypes where+import Foreign+import Foreign.C++-- time.h++data Tm = Tm {+ tm'sec,+ tm'min,+ tm'hour,+ tm'mday,+ tm'mon,+ tm'year,+ tm'wday,+ tm'yday,+ tm'isdst :: CInt+ }++instance Storable Tm where+ sizeOf _ = fromIntegral size_of_tm+ alignment = sizeOf+ peek p =+ with 0 $ \p1 -> with 0 $ \p2 -> with 0 $ \p3 ->+ with 0 $ \p4 -> with 0 $ \p5 -> with 0 $ \p6 ->+ with 0 $ \p7 -> with 0 $ \p8 -> with 0 $ \p9 ->+ c2hs_tm p p1 p2 p3 p4 p5 p6 p7 p8 p9 >>+ peek p1 >>= \v1 -> peek p2 >>= \v2 -> peek p3 >>= \v3 ->+ peek p4 >>= \v4 -> peek p5 >>= \v5 -> peek p6 >>= \v6 ->+ peek p7 >>= \v7 -> peek p8 >>= \v8 -> peek p9 >>= \v9 ->+ return $ Tm v1 v2 v3 v4 v5 v6 v7 v8 v9+ poke p (Tm v1 v2 v3 v4 v5 v6 v7 v8 v9) =+ hs2c_tm p v1 v2 v3 v4 v5 v6 v7 v8 v9++foreign import ccall size_of_tm :: CInt++foreign import ccall hs2c_tm+ :: Ptr Tm -> CInt -> CInt -> CInt -> CInt ->+ CInt -> CInt -> CInt -> CInt -> CInt -> IO ()++foreign import ccall c2hs_tm+ :: Ptr Tm -> Ptr CInt -> Ptr CInt -> Ptr CInt -> Ptr CInt ->+ Ptr CInt -> Ptr CInt -> Ptr CInt -> Ptr CInt ->+ Ptr CInt -> IO ()++-- sys/time.h++data Timeval = Timeval {timeval'tv_sec, timeval'tv_usec :: CLong}++instance Storable Timeval where++ sizeOf _ = fromIntegral size_of_timeval++ alignment = sizeOf++ peek p =+ with 0 $ \p1 ->+ with 0 $ \p2 ->++ c2hs_timeval p p1 p2 >>++ peek p1 >>= \v1 ->+ peek p2 >>= \v2 ->++ return $ Timeval {timeval'tv_sec = v1, timeval'tv_usec = v2}++ poke p v = hs2c_timeval p (timeval'tv_sec v) (timeval'tv_usec v)++foreign import ccall "size_of_timeval" size_of_timeval+ :: CInt++foreign import ccall "hs2c_timeval" hs2c_timeval+ :: Ptr Timeval -> CLong -> CLong -> IO ()++foreign import ccall "c2hs_timeval" c2hs_timeval+ :: Ptr Timeval -> Ptr CLong -> Ptr CLong -> IO ()
+ src/cconstants.c view
@@ -0,0 +1,7 @@+#include <time.h>++clock_t _CLOCKS_PER_SEC (void)+{+ return CLOCKS_PER_SEC;+}+
+ src/cfunctions.c view
@@ -0,0 +1,2 @@+#include <time.h>+
+ src/ctypes.c view
@@ -0,0 +1,57 @@+#include <time.h>++int size_of_tm (void)+{+ return sizeof (struct tm);+}++void hs2c_tm (struct tm *p,+ int p1, int p2, int p3,+ int p4, int p5, int p6,+ int p7, int p8, int p9)+{+ p->tm_sec = p1;+ p->tm_min = p2;+ p->tm_hour = p3;+ p->tm_mday = p4;+ p->tm_mon = p5;+ p->tm_year = p6;+ p->tm_wday = p7;+ p->tm_yday = p8;+ p->tm_isdst = p9;+}++void c2hs_tm (struct tm *p,+ int *p1, int *p2, int *p3,+ int *p4, int *p5, int *p6,+ int *p7, int *p8, int *p9)+{+ *p1 = p->tm_sec;+ *p2 = p->tm_min;+ *p3 = p->tm_hour;+ *p4 = p->tm_mday;+ *p5 = p->tm_mon;+ *p6 = p->tm_year;+ *p7 = p->tm_wday;+ *p8 = p->tm_yday;+ *p9 = p->tm_isdst;+}++#include <sys/time.h>++int size_of_timeval (void)+{+ return sizeof (struct timeval);+}++void hs2c_timeval (struct timeval *p, long p1, long p2)+{+ p->tv_sec = p1;+ p->tv_usec = p2;+}++void c2hs_timeval (struct timeval *p, long *p1, long *p2)+{+ *p1 = p->tv_sec;+ *p2 = p->tv_usec;+}