-
-
Notifications
You must be signed in to change notification settings - Fork 901
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
Creating a new document by with a root node cloned from another causes segfault #91
Comments
Should have noted that this occurs both on Mac OS X (libxml2 2.7.3) and Gentoo Linux (libxml2 2.7.2). |
This is more of the node dictionary allocation issue, which occurs when nodes have resources owned by another document. In this case, when the node is dup()ed, it still references dictionary strings owned by the original document. At GC time, things blow up. |
Basically, libxml2 does not support moving nodes from one document to another, nor does it support moving dupes of a node to another document. Sigh. |
But this shouldn't be that problem, right? I thought we copied the tree on dups? |
This is that problem! Really. I think if we copy the document, everything works correctly. But copying a node and jamming it into another doc is definitely going to break libxml. |
moving roots around will copy them and gc old roots. closed by 10f5710 |
This involves several fixes: 1. Removing the linker flag that causes the error. 2. Adding scripts to simplify and speed up testing, in particular both the `--with-libxml2` and `--without-libxml2` are tested in each build. 3. Adding a script to create and run a Docker container based on stevecheckoway/gentoo-ruby which is based on the official Gentoo image but with ruby, libxml2, and bundler installed. 4. A somewhat unrelated change to fix an issue when Nokogiri is built with system libraries. In this case, `pkg-config` needs to be available which is easiest to provide via the `pkg-config` gem. Unfortunately, bundler installs dependencies in alphabetical order and this needs to be installed before Nokogiri. To resolve this, `scripts/fix-dep-order.gemspec` (which comes alphabetically before `nokogiri`) declares a dependency on `pkg-config` thus building it first. This is a ridiculous work-around, but I couldn't find an alternative.
When trying to create a new document from part of an existing document via #dup a segfault results:
doc = Nokogiri::XML('<title>test</title>')
doc2 = Nokogiri::XML::Document.new
doc2.root = doc.root.dup(1)
The text was updated successfully, but these errors were encountered: