Permalink
Browse files

Add some comments to getRandomBytes

  • Loading branch information...
1 parent 4a3b117 commit a3c25f69dd18a92b458c5aac2b09f52b0ff198ee @bos committed Oct 2, 2012
Showing with 8 additions and 1 deletion.
  1. +8 −1 Data/Hashable/RandomSource.hs
@@ -11,6 +11,7 @@ import Data.Word (Word8)
import Foreign.C.Error (throwErrnoIfMinus1_)
import Foreign.C.Types (CInt(..))
import Foreign.Ptr (Ptr)
+import Foreign.Marshal.Alloc
getRandomBytes :: Int -> IO ByteString
getRandomBytes nbytes
@@ -20,5 +21,11 @@ getRandomBytes nbytes
throwErrnoIfMinus1_ "getRandomBytes" .
c_getRandomBytes (fromIntegral nbytes)
+getRandom :: Storable a => IO a
+getRandom = do
+ alloca $ \ptr ->
+ throwErrnoIfMinus1_ "getRandomBytes" $
+ c_getRandomBytes (fromIntegral size) ptr
+
foreign import ccall unsafe "hashable_getRandomBytes" c_getRandomBytes
- :: CInt -> Ptr Word8 -> IO CInt
+ :: CInt -> Ptr a -> IO CInt

0 comments on commit a3c25f6

Please sign in to comment.