Skip to content

Commit e6709aa

Browse files
committed
windows: work around libxml2 xmlCleanupParser
Closes #2241
1 parent 8f54c0f commit e6709aa

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

ext/nokogiri/nokogiri.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,26 @@ Init_nokogiri()
191191
rb_const_set(mNokogiri, rb_intern("OTHER_LIBRARY_VERSIONS"), NOKOGIRI_STR_NEW2(NOKOGIRI_OTHER_LIBRARY_VERSIONS));
192192
#endif
193193

194+
#if defined(_WIN32) && !defined(NOKOGIRI_PACKAGED_LIBRARIES)
195+
/*
196+
* We choose *not* to do use Ruby's memory management functions with windows DLLs because of this
197+
* issue in libxml 2.9.12:
198+
*
199+
* https://github.com/sparklemotion/nokogiri/issues/2241
200+
*
201+
* If the atexit() issue gets fixed in a future version of libxml2, then we may be able to skip
202+
* this config only for the specific libxml2 versions 2.9.12.
203+
*
204+
* Alternatively, now that Ruby has a generational GC, it might be OK to let libxml2 use its
205+
* default memory management functions (recall that this config was introduced to reduce memory
206+
* bloat and allow Ruby to GC more often); but we should *really* test with production workloads
207+
* before making that kind of a potentially-invasive change.
208+
*/
209+
rb_const_set(mNokogiri, rb_intern("LIBXML_MEMORY_MANAGEMENT"), NOKOGIRI_STR_NEW2("default"));
210+
#else
211+
rb_const_set(mNokogiri, rb_intern("LIBXML_MEMORY_MANAGEMENT"), NOKOGIRI_STR_NEW2("ruby"));
194212
xmlMemSetup((xmlFreeFunc)ruby_xfree, (xmlMallocFunc)ruby_xmalloc, (xmlReallocFunc)ruby_xrealloc, ruby_strdup);
213+
#endif
195214

196215
xmlInitParser();
197216

lib/nokogiri/version/info.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ def to_hash
137137
else
138138
libxml["source"] = "system"
139139
end
140+
libxml["memory_management"] = Nokogiri::LIBXML_MEMORY_MANAGEMENT
140141
libxml["iconv_enabled"] = libxml2_has_iconv?
141142
libxml["compiled"] = compiled_libxml_version.to_s
142143
libxml["loaded"] = loaded_libxml_version.to_s

0 commit comments

Comments
 (0)