Skip to content

Commit

Permalink
dev: ignore deprecations on xmlDeregisterNodeDefault
Browse files Browse the repository at this point in the history
This is deprecated in libxml2 2.11.0, but we need to check this to
make sure we're compatible with libxml-ruby < 3.0.0.
  • Loading branch information
flavorjones committed May 2, 2023
1 parent fc66535 commit cfb6b99
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions ext/nokogiri/xml_document.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,23 @@ dealloc(void *data)

ruby_xfree(doc->_private);

/* When both Nokogiri and libxml-ruby are loaded, make sure that all nodes
* have their _private pointers cleared. This is to avoid libxml-ruby's
* xmlDeregisterNode callback from accessing VALUE pointers from ruby's GC
* free context, which can result in segfaults.
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations" // xmlDeregisterNodeDefault is deprecated as of libxml2 2.11.0
/*
* libxml-ruby < 3.0.0 uses xmlDeregisterNodeDefault. If the user is using one of those older
* versions, the registered callback from libxml-ruby will access the _private pointers set by
* nokogiri, which will result in segfaults.
*
* To avoid this, we need to clear the _private pointers from all nodes in this document tree
* before that callback gets invoked.
*
* libxml-ruby 3.0.0 was released in 2017-02, so at some point we can probably safely remove this
* safeguard (though probably pairing with a runtime check on the libxml-ruby version).
*/
if (xmlDeregisterNodeDefaultValue) {
remove_private((xmlNodePtr)doc);
}
#pragma GCC diagnostic pop

xmlFreeDoc(doc);
}
Expand Down

0 comments on commit cfb6b99

Please sign in to comment.