Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can segfault #5

Open
ndmitchell opened this issue Nov 27, 2016 · 4 comments
Open

Can segfault #5

ndmitchell opened this issue Nov 27, 2016 · 4 comments

Comments

@ndmitchell
Copy link
Collaborator

The library can segfault. Pugi requires the document to be kept alive while any nodes are being used, but the Haskell binding doesn't ensure that.

@ndmitchell
Copy link
Collaborator Author

Example code:

segfault :: IO ()
segfault = forever $ do
    bs <- BS.readFile "example.xml"
    let Right root = parse def bs
    let unattend = fromJust $ child "unattend" root
    print $ show unattend
    E.evaluate bs

@dbeacham
Copy link

Are there any workarounds to this?

I'd prefer a more permanent fix but couldn't determine at first glance what might need to be done. Are there any hints on what such a fix would look like?

@dbeacham
Copy link

dbeacham commented Apr 11, 2017

Being a bit dense above - easy to work around by keeping the doc node in scope until I've finished with it! Annoying but it works for now...

I'll also have a read through of the pugixml docs to see where / how I can set up the FFI finalizers to keep the doc around until after all the nodes have been used. Is anyone aware of any other FFI bindings that do a similar thing?

@ndmitchell
Copy link
Collaborator Author

Pugixml deliberately doesn't require the nodes to be kept alive - they a single pointers that reference inside the original doc. The real solution is not to keep alive the memory that Pugixml-hs allocated, but to skip the memory allocation in the first place. As for an example of a library that follows that pattern, Hexml is the perfect example. see here, where each node points at the central document.

I was working on a patch to do the above, but then discovered even with those changes the underlying Pugixml was too slow, so went off and developed Hexml.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants