@@ -1,4 +1,5 @@
1{-# INCLUDE <uuid/uuid.h> #-}
1{-# INCLUDE <uuid/uuid.h> #-}
2+{-# INCLUDE <string.h> #-}
2{-# LANGUAGE ForeignFunctionInterface #-}
3{-# LANGUAGE ForeignFunctionInterface #-}
4-- |Haskell bindings to /libuuid/.
5-- |Haskell bindings to /libuuid/.
@@ -26,6 +27,8 @@ import Foreign.C
26import Foreign.ForeignPtr
27import Foreign.ForeignPtr
27import Foreign
28import Foreign
29import Prelude hiding (null)
32import Prelude hiding (null)
31import Data.UUID.Internal
34import Data.UUID.Internal
@@ -50,6 +53,23 @@ instance Read UUID where
50 Nothing -> []
53 Nothing -> []
51 Just u -> [(u,drop 36 str)]
54 Just u -> [(u,drop 36 str)]
56+instance Typeable UUID where
57+ typeOf _ = mkTyConApp (mkTyCon "Data.UUID.UUID") []
59+instance Storable UUID where
60+ sizeOf _ = (16 *) $ alignment (undefined :: CChar)
61+ alignment _ = alignment (undefined :: CChar)
64+ fp <- mallocForeignPtrArray 16
65+ withForeignPtr fp $ \pdest ->
66+ memcpy pdest psource $ fromIntegral $ sizeOf (undefined :: UUID)
69+ poke pdest (U fp) = withForeignPtr fp $ \psource ->
70+ memcpy pdest psource $ fromIntegral $ sizeOf (undefined :: UUID)
53-- |Creates a new 'UUID'. If \/dev\/urandom is available, it will be used.
73-- |Creates a new 'UUID'. If \/dev\/urandom is available, it will be used.
54-- Otherwise a UUID will be generated based on the current time and the
74-- Otherwise a UUID will be generated based on the current time and the
55-- hardware MAC address, if available.
75-- hardware MAC address, if available.
@@ -177,3 +197,8 @@ foreign import ccall unsafe "uuid_type"
178foreign import ccall unsafe "uuid_variant"
198foreign import ccall unsafe "uuid_variant"
179 c_variant :: C_UUID -> CInt
199 c_variant :: C_UUID -> CInt
203+foreign import ccall unsafe "memcpy"
204+ memcpy :: Ptr a -> Ptr b -> CSize -> IO ()