RefSerialize 0.3.0.0 → 0.3.0.1
raw patch · 3 files changed
+27/−3 lines, 3 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
- Data.RefSerialize: varName :: a -> [Char]
+ Data.RefSerialize: addrHash :: Context -> a -> IO (Either Int Int)
+ Data.RefSerialize.Serialize: addrHash :: Context -> a -> IO (Either Int Int)
Files
- Data/RefSerialize.hs +9/−1
- Data/RefSerialize/Serialize.hs +17/−1
- RefSerialize.cabal +1/−1
Data/RefSerialize.hs view
@@ -85,8 +85,9 @@ ,rShow ,rRead ,insertVar+ ,addrHash ,readVar- ,varName+ ,takep ,readHexp ,showHexp@@ -243,6 +244,12 @@ (StatW(c',str,_), _) = f (StatW(c,[],vars)) in showExpr str c' +++-- let STW f= insertVar (const $ return ()) x >> return (varName x)+-- (StatW(c',str,_), v) = f (StatW(c,[],""))+-- in v+ -- | serialize the variables. if the Bool flag is true, it prepend the text with the string "where" showContext :: Context -> Bool -> ByteString showContext c False=@@ -332,6 +339,7 @@ case Data.RefSerialize.Serialize.lookup hash c of Nothing -> False Just (x,y,z,n) -> insert hash (x,y,z,n+1) c `seq` True+ -- | inform if the expression iwas already referenced and return @Right varname@ -- otherwise, add the expresion to the context and giive it a name and return @Left varname@
Data/RefSerialize/Serialize.hs view
@@ -65,6 +65,19 @@ fromList = unsafePerformIO . HT.fromList HT.hashInt +-- | return a unique hash identifier for an object+-- the context assures that no StableName used in addrStr is garbage collected,+-- so the hashes are constant and the correspondence address - string+-- remain one to one as long as the context is not garbage collected.+-- Left is returned if it is the first time that @addHash@ is called for that variable+addrHash :: Context -> a -> IO (Either Int Int)+addrHash c x =+ case Data.RefSerialize.Serialize.lookup hash c of+ Nothing -> addc [Var hash] c >> return (Left hash)+ Just (x,y,z,n) -> HT.update c hash (x,y,z,n+1) >> return (Right hash)+ where+ addc str c= HT.update c hash (st,unsafeCoerce x, str,1)+ (hash,st) = hasht x readContext :: ByteString -> ByteString -> (ByteString, ByteString) readContext pattern str= readContext1 (pack "") str where@@ -80,7 +93,10 @@ st <- makeStableName $! x return (hashStableName st,unsafeCoerce st) --- ! two variables that point to the same address will have identical varname (derived from import System.Mem.StableName)varName:: a -> String+-- | two variables that point to the same address will have identical varname (derived from import System.Mem.StableName)varName:: a -> String+-- . The stable names of during the serializing deserializing process are not deleted+-- . This is assured by the pointers in the context,+-- so the hash values remain and the comparison of varNames is correct. varName x= "v"++ (show . hash) x where hash x= let (ht,_)= hasht x in ht
RefSerialize.cabal view
@@ -1,5 +1,5 @@ name: RefSerialize-version: 0.3.0.0+version: 0.3.0.1 synopsis: Write to and read from ByteStrings maintaining internal memory references description: Read, Show and Binary instances do not check for internal data references to the same address.