on master help sign in
Make sure the methods that process the bytestring call touch afterwards
commit9ada065bd39373cd8beee6b955b7f1c4c6eb862e authorNeil Mitchell <ndmitchell@gmail.com> dateWed 30 Nov 2016, 19:08 (10 years ago) parentba3a70d
1 file changed+7−3
src/Text/XML/Hexml.hs+7−3
src/Text/XML/Hexml.hs+7−3
@@ -73,6 +73,10 @@ instance Show Node where
7373 show d = "Node " ++ show (BS.unpack $ outer d)
7474
7575
76+touchBS :: BS.ByteString -> IO ()
77+touchBS = touchForeignPtr . fst3 . BS.toForeignPtr
78+
79+
7680-- | Parse a ByteString as an XML document, returning a 'Left' error message, or a 'Right' document.
7781-- Note that the returned node will have a 'name' of @\"\"@, no attributes, and content as per the document.
7882-- Often the first child will be the @\<?xml ... ?\>@ element. For documents which comprise a single
@@ -98,7 +102,7 @@ render :: Node -> BS.ByteString
98102render (Node src doc n) = unsafePerformIO $ withForeignPtr doc $ \d -> do
99103 i <- node_render d n nullPtr 0
100104 res <- BS.create (fromIntegral i) $ \ptr -> void $ node_render d n (castPtr ptr) i
101− touchForeignPtr $ fst3 $ BS.toForeignPtr src
105+ touchBS src
102106 return res
103107
104108applyStr :: BS.ByteString -> Str -> BS.ByteString
@@ -172,7 +176,7 @@ childrenBy (Node src doc n) str = go nullPtr
172176 go old = unsafePerformIO $ withForeignPtr doc $ \d ->
173177 BS.unsafeUseAsCStringLen str $ \(bs, len) -> do
174178 r <- node_childBy d n old bs $ fromIntegral len
175− touchForeignPtr $ fst3 $ BS.toForeignPtr src
179+ touchBS src
176180 return $ if r == nullPtr then [] else Node src doc r : go r
177181
178182-- | Get the first attribute of this node which has a specific name, if there is one.
@@ -183,7 +187,7 @@ attributeBy :: Node -> BS.ByteString -> Maybe Attribute
183187attributeBy (Node src doc n) str = unsafePerformIO $ withForeignPtr doc $ \d ->
184188 BS.unsafeUseAsCStringLen str $ \(bs, len) -> do
185189 r <- node_attributeBy d n bs $ fromIntegral len
186− touchForeignPtr $ fst3 $ BS.toForeignPtr src
190+ touchBS src
187191 return $ if r == nullPtr then Nothing else Just $ attrPeek src doc r
188192
189193-- | Find the starting location of a node, the '<' character.