Commit 71eda45f authored by Kai Zhang's avatar Kai Zhang

safety

parent a58ec40a
{-# LANGUAGE ForeignFunctionInterface #-} {-# LANGUAGE ForeignFunctionInterface #-}
module IGraph.Internal.Attribute where module IGraph.Internal.Attribute where
import qualified Data.ByteString.Char8 as B import Data.ByteString (packCStringLen)
import Data.ByteString.Unsafe import Data.ByteString.Unsafe (unsafeUseAsCStringLen)
import Control.Monad import Control.Monad
import Control.Applicative import Control.Applicative
import Data.Serialize (Serialize, decode, encode) import Data.Serialize (Serialize, decode, encode)
...@@ -32,7 +32,7 @@ unsafeToBS x = unsafeUseAsCStringLen bs $ \(ptr, n) -> do ...@@ -32,7 +32,7 @@ unsafeToBS x = unsafeUseAsCStringLen bs $ \(ptr, n) -> do
fromBS :: Serialize a => Ptr BSLen -> IO a fromBS :: Serialize a => Ptr BSLen -> IO a
fromBS ptr = do fromBS ptr = do
BSLen x <- peek ptr BSLen x <- peek ptr
result <- decode <$> unsafePackCStringLen x result <- decode <$> packCStringLen x
case result of case result of
Left msg -> error msg Left msg -> error msg
Right r -> return r Right r -> return r
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment