on master help sign in
Make sure all the methods that access the str do a touch on the foreign ptr
commitba3a70d4616a0e393b1cc8573d542616af317eb2 authorNeil Mitchell <ndmitchell@gmail.com> dateWed 30 Nov 2016, 19:08 (10 years ago) parentd2cd77e
1 file changed+6−2
src/Text/XML/Hexml.hs+6−2
src/Text/XML/Hexml.hs+6−2
@@ -95,9 +95,11 @@ parse src = do
9595-- | Given a node, rerender it to something with an equivalent parse tree.
9696-- Mostly useful for debugging - if you want the real source document use 'outer' instead.
9797render :: Node -> BS.ByteString
98−render (Node _ doc n) = unsafePerformIO $ withForeignPtr doc $ \d -> do
98+render (Node src doc n) = unsafePerformIO $ withForeignPtr doc $ \d -> do
9999 i <- node_render d n nullPtr 0
100− BS.create (fromIntegral i) $ \ptr -> void $ node_render d n (castPtr ptr) i
100+ res <- BS.create (fromIntegral i) $ \ptr -> void $ node_render d n (castPtr ptr) i
101+ touchForeignPtr $ fst3 $ BS.toForeignPtr src
102+ return res
101103
102104applyStr :: BS.ByteString -> Str -> BS.ByteString
103105applyStr bs Str{..} = BS.take (fromIntegral strLength) $ BS.drop (fromIntegral strStart) bs
@@ -170,6 +172,7 @@ childrenBy (Node src doc n) str = go nullPtr
170172 go old = unsafePerformIO $ withForeignPtr doc $ \d ->
171173 BS.unsafeUseAsCStringLen str $ \(bs, len) -> do
172174 r <- node_childBy d n old bs $ fromIntegral len
175+ touchForeignPtr $ fst3 $ BS.toForeignPtr src
173176 return $ if r == nullPtr then [] else Node src doc r : go r
174177
175178-- | Get the first attribute of this node which has a specific name, if there is one.
@@ -180,6 +183,7 @@ attributeBy :: Node -> BS.ByteString -> Maybe Attribute
180183attributeBy (Node src doc n) str = unsafePerformIO $ withForeignPtr doc $ \d ->
181184 BS.unsafeUseAsCStringLen str $ \(bs, len) -> do
182185 r <- node_attributeBy d n bs $ fromIntegral len
186+ touchForeignPtr $ fst3 $ BS.toForeignPtr src
183187 return $ if r == nullPtr then Nothing else Just $ attrPeek src doc r
184188
185189-- | Find the starting location of a node, the '<' character.