Skip to content

Commit

Permalink
Merge pull request #2866 from sparklemotion/flavorjones-upgrade-libxm…
Browse files Browse the repository at this point in the history
…l2-2.11.0

dep: update libxml2 to v2.11.3, libxslt to v1.1.38
  • Loading branch information
flavorjones authored May 11, 2023
2 parents 1987d80 + cd79753 commit 32c7543
Show file tree
Hide file tree
Showing 9 changed files with 194 additions and 5,171 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ Benchmarks show that this setting will significantly improve performance, but be
You can read more about this in the decision record at `adr/2023-04-libxml-memory-management.md`.


### Dependencies

[CRuby] Vendored libxml2 is updated to v2.11.3 from v2.10.4. Please see the multiple release notes:

- https://gitlab.gnome.org/GNOME/libxml2/-/releases/v2.11.0
- https://gitlab.gnome.org/GNOME/libxml2/-/releases/v2.11.1
- https://gitlab.gnome.org/GNOME/libxml2/-/releases/v2.11.2
- https://gitlab.gnome.org/GNOME/libxml2/-/releases/v2.11.3


### Added

* `Encoding` objects may now be passed to serialization methods like `#to_xml`, `#to_html`, `#serialize`, and `#write_to` to specify the output encoding. Previously only encoding names (strings) were accepted. [[#2774](https://github.com/sparklemotion/nokogiri/issues/2774), [#2798](https://github.com/sparklemotion/nokogiri/issues/2798)] (Thanks, [@ellaklara](https://github.com/ellaklara)!)
Expand Down
12 changes: 6 additions & 6 deletions dependencies.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
libxml2:
version: "2.10.4"
sha256: "ed0c91c5845008f1936739e4eee2035531c1c94742c6541f44ee66d885948d45"
# sha-256 hash provided in https://download.gnome.org/sources/libxml2/2.10/libxml2-2.10.4.sha256sum
version: "2.11.3"
sha256: "f1acae1664bda006cd81bfc238238217043d586d06659d5c0e3d1bcebe040870"
# sha-256 hash provided in https://download.gnome.org/sources/libxml2/2.11/libxml2-2.11.3.sha256sum

libxslt:
version: "1.1.37"
sha256: "3a4b27dc8027ccd6146725950336f1ec520928f320f144eb5fa7990ae6123ab4"
# sha-256 hash provided in https://download.gnome.org/sources/libxslt/1.1/libxslt-1.1.37.sha256sum
version: "1.1.38"
sha256: "1f32450425819a09acaff2ab7a5a7f8a2ec7956e505d7beeb45e843d0e1ecab1"
# sha-256 hash provided in https://download.gnome.org/sources/libxslt/1.1/libxslt-1.1.38.sha256sum

zlib:
version: "1.2.13"
Expand Down
8 changes: 7 additions & 1 deletion ext/nokogiri/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ def gnome_source
if ENV["NOKOGIRI_USE_CANONICAL_GNOME_SOURCE"]
"https://download.gnome.org"
else
"https://mirror.csclub.uwaterloo.ca/gnome" # old reliable
"https://muug.ca/mirror/gnome" # old reliable
end
end

Expand Down Expand Up @@ -882,8 +882,13 @@ def configure
recipe.patch_files = Dir[File.join(PACKAGE_ROOT_DIR, "patches", "libxml2", "*.patch")].sort
end

cppflags = concat_flags(ENV["CPPFLAGS"])
cflags = concat_flags(ENV["CFLAGS"], "-O2", "-U_FORTIFY_SOURCE", "-g")

if cross_build_p
cppflags = concat_flags(cppflags, "-DNOKOGIRI_PRECOMPILED_LIBRARIES")
end

if zlib_recipe
recipe.configure_options << "--with-zlib=#{zlib_recipe.path}"
end
Expand Down Expand Up @@ -914,6 +919,7 @@ def configure
"--with-c14n",
"--with-debug",
"--with-threads",
"CPPFLAGS=#{cppflags}",
"CFLAGS=#{cflags}",
]
end
Expand Down
11 changes: 6 additions & 5 deletions ext/nokogiri/html4_sax_parser_context.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ parse_file(VALUE klass, VALUE filename, VALUE encoding)
StringValueCStr(filename),
StringValueCStr(encoding)
);

if (ctxt->sax) {
xmlFree(ctxt->sax);
ctxt->sax = NULL;
}

return noko_xml_sax_parser_context_wrap(klass, ctxt);
}

Expand Down Expand Up @@ -78,11 +84,6 @@ parse_with(VALUE self, VALUE sax_handler)
ctxt = noko_xml_sax_parser_context_unwrap(self);
sax = noko_sax_handler_unwrap(sax_handler);

/* Free the sax handler since we'll assign our own */
if (ctxt->sax && ctxt->sax != (xmlSAXHandlerPtr)&xmlDefaultSAXHandler) {
xmlFree(ctxt->sax);
}

ctxt->sax = sax;
ctxt->userData = (void *)NOKOGIRI_SAX_TUPLE_NEW(ctxt, sax_handler);

Expand Down
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
11 changes: 6 additions & 5 deletions ext/nokogiri/xml_sax_parser_context.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ static VALUE
parse_file(VALUE klass, VALUE filename)
{
xmlParserCtxtPtr ctxt = xmlCreateFileParserCtxt(StringValueCStr(filename));

if (ctxt->sax) {
xmlFree(ctxt->sax);
ctxt->sax = NULL;
}

return noko_xml_sax_parser_context_wrap(klass, ctxt);
}

Expand Down Expand Up @@ -147,11 +153,6 @@ parse_with(VALUE self, VALUE sax_handler)
ctxt = noko_xml_sax_parser_context_unwrap(self);
sax = noko_sax_handler_unwrap(sax_handler);

/* Free the sax handler since we'll assign our own */
if (ctxt->sax && ctxt->sax != (xmlSAXHandlerPtr)&xmlDefaultSAXHandler) {
xmlFree(ctxt->sax);
}

ctxt->sax = sax;
ctxt->userData = (void *)NOKOGIRI_SAX_TUPLE_NEW(ctxt, sax_handler);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
From fb618bd27ac7a9fd32973320016c7ff28dd2f60e Mon Sep 17 00:00:00 2001
From: Mike Dalessio <mike.dalessio@gmail.com>
Date: Fri, 5 May 2023 10:10:43 -0400
Subject: [PATCH] rip out libxml2's libc_single_threaded support

This is a preventative measure because this feature relies on a glibc
version we can't realistically require of users today. We're not yet
precompiling on a system with a modern-enough glibc to make this an
actual problem, but I'm doing it while all of this context is fresh.
---
threads.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/threads.c b/threads.c
index 60dbce4c..eb1c12e5 100644
--- a/threads.c
+++ b/threads.c
@@ -27,7 +27,8 @@

#if defined(HAVE_POSIX_THREADS) && \
defined(__GLIBC__) && \
- __GLIBC__ * 100 + __GLIBC_MINOR__ >= 234
+ __GLIBC__ * 100 + __GLIBC_MINOR__ >= 234 && \
+ !defined(NOKOGIRI_PRECOMPILED_LIBRARIES)

/*
* The modern way available since glibc 2.32.
--
2.40.1

Loading

0 comments on commit 32c7543

Please # to comment.