Skip to content

Commit 8d0c4ea

Browse files
committed
dev: introduce NOKO_WARN_DEPRECATION macro
which will use rb_category_warning if it's available, and rb_warning if it's not
1 parent 12874a7 commit 8d0c4ea

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

ext/nokogiri/extconf.rb

+1
Original file line numberDiff line numberDiff line change
@@ -974,6 +974,7 @@ def compile
974974
have_func("xmlSchemaSetValidStructuredErrors") # introduced in libxml 2.6.23
975975
have_func("xmlSchemaSetParserStructuredErrors") # introduced in libxml 2.6.23
976976
have_func("rb_gc_location") # introduced in Ruby 2.7
977+
have_func("rb_category_warning") # introduced in Ruby 3.0
977978

978979
have_func("vasprintf")
979980

ext/nokogiri/nokogiri.h

+6
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,12 @@ NOKOPUBFUN VALUE Nokogiri_wrap_xml_document(VALUE klass,
202202
#define DISCARD_CONST_QUAL(t, v) ((t)(uintptr_t)(v))
203203
#define DISCARD_CONST_QUAL_XMLCHAR(v) DISCARD_CONST_QUAL(xmlChar *, v)
204204

205+
#if HAVE_RB_CATEGORY_WARNING
206+
# define NOKO_WARN_DEPRECATION(message) rb_category_warning(RB_WARN_CATEGORY_DEPRECATED, message)
207+
#else
208+
# define NOKO_WARN_DEPRECATION(message) rb_warning(message)
209+
#endif
210+
205211
void Nokogiri_structured_error_func_save(libxmlStructuredErrorHandlerState *handler_state);
206212
void Nokogiri_structured_error_func_save_and_set(libxmlStructuredErrorHandlerState *handler_state, void *user_data,
207213
xmlStructuredErrorFunc handler);

ext/nokogiri/xml_node.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1806,7 +1806,7 @@ rb_xml_node_new(int argc, VALUE *argv, VALUE klass)
18061806
}
18071807
if (!rb_obj_is_kind_of(rb_document_node, cNokogiriXmlDocument)) {
18081808
// TODO: deprecate allowing Node
1809-
rb_warn("Passing a Node as the second parameter to Node.new is deprecated. Please pass a Document instead, or prefer an alternative constructor like Node#add_child. This will become an error in a future release of Nokogiri.");
1809+
NOKO_WARN_DEPRECATION("Passing a Node as the second parameter to Node.new is deprecated. Please pass a Document instead, or prefer an alternative constructor like Node#add_child. This will become an error in a future release of Nokogiri.");
18101810
}
18111811
Noko_Node_Get_Struct(rb_document_node, xmlNode, c_document_node);
18121812

0 commit comments

Comments
 (0)