on master help sign in
tidying things up a bit
a5b3ab1aslatter
Data/UUID.hs+21−21
@@ -20,7 +20,7 @@ module Data.UUID(UUID
20 ,toString
20 ,toString
21 ,toStringUpper
21 ,toStringUpper
22 ,toStringLower
22 ,toStringLower
23− ,generate
23+ ,generate
24 ,generateRandom
24 ,generateRandom
25 ,generateTime
25 ,generateTime
26 ,null
26 ,null
@@ -124,20 +124,20 @@ instance Storable UUID where
124
124
125 peek p = do
125 peek p = do
126 tl <- peek $ castPtr p
126 tl <- peek $ castPtr p
127− tm <- peekByteOff (castPtr p) 4
127+ tm <- peekByteOff p 4
128− th <- peekByteOff (castPtr p) 6
128+ th <- peekByteOff p 6
129− ch <- peekByteOff (castPtr p) 8
129+ ch <- peekByteOff p 8
130− cl <- peekByteOff (castPtr p) 9
130+ cl <- peekByteOff p 9
131− node <- peekByteOff (castPtr p) 10
131+ node <- peekByteOff p 10
132 return $ UUID tl tm th ch cl node
132 return $ UUID tl tm th ch cl node
133
133
134 poke p (UUID tl tm th ch cl node) = do
134 poke p (UUID tl tm th ch cl node) = do
135 poke (castPtr p) tl
135 poke (castPtr p) tl
136− pokeByteOff (castPtr p) 4 tm
136+ pokeByteOff p 4 tm
137− pokeByteOff (castPtr p) 6 th
137+ pokeByteOff p 6 th
138− pokeByteOff (castPtr p) 8 ch
138+ pokeByteOff p 8 ch
139− pokeByteOff (castPtr p) 9 cl
139+ pokeByteOff p 9 cl
140− pokeByteOff (castPtr p) 10 node
140+ pokeByteOff p 10 node
141
141
142instance Storable Node where
142instance Storable Node where
143 sizeOf _ = 6
143 sizeOf _ = 6
@@ -145,20 +145,20 @@ instance Storable Node where
145
145
146 peek p = do
146 peek p = do
147 w1 <- peek $ castPtr p
147 w1 <- peek $ castPtr p
148− w2 <- peekByteOff (castPtr p) 1
148+ w2 <- peekByteOff p 1
149− w3 <- peekByteOff (castPtr p) 2
149+ w3 <- peekByteOff p 2
150− w4 <- peekByteOff (castPtr p) 3
150+ w4 <- peekByteOff p 3
151− w5 <- peekByteOff (castPtr p) 4
151+ w5 <- peekByteOff p 4
152− w6 <- peekByteOff (castPtr p) 5
152+ w6 <- peekByteOff p 5
153 return $ Node w1 w2 w3 w4 w5 w6
153 return $ Node w1 w2 w3 w4 w5 w6
154
154
155 poke p (Node w1 w2 w3 w4 w5 w6) = do
155 poke p (Node w1 w2 w3 w4 w5 w6) = do
156 poke (castPtr p) w1
156 poke (castPtr p) w1
157− pokeByteOff (castPtr p) 1 w2
157+ pokeByteOff p 1 w2
158− pokeByteOff (castPtr p) 2 w3
158+ pokeByteOff p 2 w3
159− pokeByteOff (castPtr p) 3 w4
159+ pokeByteOff p 3 w4
160− pokeByteOff (castPtr p) 4 w5
160+ pokeByteOff p 4 w5
161− pokeByteOff (castPtr p) 5 w6
161+ pokeByteOff p 5 w6
162
162
163-- My goal with this instance was to make it work just enough to do what
163-- My goal with this instance was to make it work just enough to do what
164-- I want when used with the HStringTemplate library.
164-- I want when used with the HStringTemplate library.
Data/UUID/Internal.hsdeleted−63
@@ -1,63 +0,0 @@
1−-- |
2−-- Module : Data.UUID.Internal
3−-- Copyright : (c) 2008 Antoine Latter
4−--
5−-- License : BSD-style
6−--
7−-- Maintainer : aslatter@gmail.com
8−-- Stability : experimental
9−-- Portability : portable
10−--
11−-- If the public interface in "Data.UUID" doesn't give you
12−-- the flexibility you need, you should be able to find
13−-- something here.
14−
15−module Data.UUID.Internal(UUID(..)
16− ,toBytes
17− ,fromBytes
18− ,unsafeFromBytes
19− ,toForeignPtr
20− ,fromForeignPtr
21− ) where
22−
23−import Foreign.ForeignPtr
24−import Foreign.C
25−import Foreign
26−
27−-- |The UUID type. Represents 128-bits of identification.
28−newtype UUID = U (ForeignPtr CChar)
29−
30−-- |Returns the passed in UUID as a list of 16 bytes.
31−toBytes :: UUID -> [Word8]
32−toBytes (U fp) = unsafePerformIO $ withForeignPtr fp $ \p ->
33− peekArray 16 (castPtr p)
34−
35−-- |Creates a UUID out of a list of bytes.
36−-- Will throw an error if the list is not of length 16.
37−fromBytes :: [Word8] -> UUID
38−fromBytes xs = if length xs == 16
39− then unsafeFromBytes xs
40− else error "Data.UUID.Internal.fromBytes: passed in list of bytes must be of length 16."
41−
42−-- |Creates a UUID out of a list of bytes.
43−-- Does not perform a length check on the passed in list.
44−-- Behavior is undefined for lists not of length 16.
45−unsafeFromBytes :: [Word8] -> UUID
46−unsafeFromBytes xs = U $ castForeignPtr $ unsafePerformIO $ do
47− p <- mallocForeignPtrBytes 16
48− withForeignPtr p $ flip pokeArray xs
49− return p
50−
51−-- |Unsafe.
52−--
53−-- Given a UUID, returns a pointer to the 16 bytes
54−-- of memory that make up the UUID.
55−toForeignPtr :: UUID -> ForeignPtr CChar
56−toForeignPtr (U p) = p
57−
58−-- |Unsafe.
59−--
60−-- The passed in pointer is treated as if it were a pointer
61−-- to 16 bytes of memory, which is then returned as a UUID.
62−fromForeignPtr :: ForeignPtr CChar -> UUID
63−fromForeignPtr = U