on master help sign in
Make sure all the methods that access the str do a touch on the foreign ptr
ba3a70dNeil Mitchell
src/Text/XML/Hexml.hs+6−2
@@ -95,9 +95,11 @@ parse src = do
95-- | Given a node, rerender it to something with an equivalent parse tree.
95-- | Given a node, rerender it to something with an equivalent parse tree.
96-- Mostly useful for debugging - if you want the real source document use 'outer' instead.
96-- Mostly useful for debugging - if you want the real source document use 'outer' instead.
97render :: Node -> BS.ByteString
97render :: Node -> BS.ByteString
98−render (Node _ doc n) = unsafePerformIO $ withForeignPtr doc $ \d -> do
98+render (Node src doc n) = unsafePerformIO $ withForeignPtr doc $ \d -> do
99 i <- node_render d n nullPtr 0
99 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
101
103
102applyStr :: BS.ByteString -> Str -> BS.ByteString
104applyStr :: BS.ByteString -> Str -> BS.ByteString
103applyStr bs Str{..} = BS.take (fromIntegral strLength) $ BS.drop (fromIntegral strStart) bs
105applyStr bs Str{..} = BS.take (fromIntegral strLength) $ BS.drop (fromIntegral strStart) bs
@@ -170,6 +172,7 @@ childrenBy (Node src doc n) str = go nullPtr
170 go old = unsafePerformIO $ withForeignPtr doc $ \d ->
172 go old = unsafePerformIO $ withForeignPtr doc $ \d ->
171 BS.unsafeUseAsCStringLen str $ \(bs, len) -> do
173 BS.unsafeUseAsCStringLen str $ \(bs, len) -> do
172 r <- node_childBy d n old bs $ fromIntegral len
174 r <- node_childBy d n old bs $ fromIntegral len
175+ touchForeignPtr $ fst3 $ BS.toForeignPtr src
173 return $ if r == nullPtr then [] else Node src doc r : go r
176 return $ if r == nullPtr then [] else Node src doc r : go r
174
177
175-- | Get the first attribute of this node which has a specific name, if there is one.
178-- | 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
180attributeBy (Node src doc n) str = unsafePerformIO $ withForeignPtr doc $ \d ->
183attributeBy (Node src doc n) str = unsafePerformIO $ withForeignPtr doc $ \d ->
181 BS.unsafeUseAsCStringLen str $ \(bs, len) -> do
184 BS.unsafeUseAsCStringLen str $ \(bs, len) -> do
182 r <- node_attributeBy d n bs $ fromIntegral len
185 r <- node_attributeBy d n bs $ fromIntegral len
186+ touchForeignPtr $ fst3 $ BS.toForeignPtr src
183 return $ if r == nullPtr then Nothing else Just $ attrPeek src doc r
187 return $ if r == nullPtr then Nothing else Just $ attrPeek src doc r
184
188
185-- | Find the starting location of a node, the '<' character.
189-- | Find the starting location of a node, the '<' character.