Skip to content

Commit

Permalink
Merge pull request #2579 from sparklemotion/fix-compaction-on-nodes
Browse files Browse the repository at this point in the history
Fix compaction on nodes
  • Loading branch information
flavorjones committed Jul 12, 2022
2 parents 3f8b5a2 + a036080 commit 82ff9e9
Show file tree
Hide file tree
Showing 17 changed files with 189 additions and 96 deletions.
1 change: 1 addition & 0 deletions ext/nokogiri/extconf.rb
Expand Up @@ -972,6 +972,7 @@ def compile
have_func("xmlRelaxNGSetValidStructuredErrors") # introduced in libxml 2.6.21
have_func("xmlSchemaSetValidStructuredErrors") # introduced in libxml 2.6.23
have_func("xmlSchemaSetParserStructuredErrors") # introduced in libxml 2.6.23
have_func("rb_gc_location") # introduced in Ruby 2.7

other_library_versions_string = OTHER_LIBRARY_VERSIONS.map { |k, v| [k, v].join(":") }.join(",")
append_cppflags(%[-DNOKOGIRI_OTHER_LIBRARY_VERSIONS="\\\"#{other_library_versions_string}\\\""])
Expand Down
2 changes: 1 addition & 1 deletion ext/nokogiri/gumbo.c
Expand Up @@ -404,7 +404,7 @@ static xmlNodePtr
extract_xml_node(VALUE node)
{
xmlNodePtr xml_node;
Data_Get_Struct(node, xmlNode, xml_node);
Noko_Node_Get_Struct(node, xmlNode, xml_node);
return xml_node;
}

Expand Down
2 changes: 2 additions & 0 deletions ext/nokogiri/nokogiri.h
Expand Up @@ -177,6 +177,8 @@ int noko_io_read(void *ctx, char *buffer, int len);
int noko_io_write(void *ctx, char *buffer, int len);
int noko_io_close(void *ctx);

#define Noko_Node_Get_Struct(obj,type,sval) ((sval) = (type*)DATA_PTR(obj))

VALUE noko_xml_node_wrap(VALUE klass, xmlNodePtr node) ;
VALUE noko_xml_node_wrap_node_set_result(xmlNodePtr node, VALUE node_set) ;
VALUE noko_xml_node_attrs(xmlNodePtr node) ;
Expand Down
4 changes: 2 additions & 2 deletions ext/nokogiri/xml_attr.c
Expand Up @@ -16,7 +16,7 @@ set_value(VALUE self, VALUE content)
xmlChar *value;
xmlNode *cur;

Data_Get_Struct(self, xmlAttr, attr);
Noko_Node_Get_Struct(self, xmlAttr, attr);

if (attr->children) {
xmlFreeNodeList(attr->children);
Expand Down Expand Up @@ -68,7 +68,7 @@ new (int argc, VALUE *argv, VALUE klass)
rb_raise(rb_eArgError, "parameter must be a Nokogiri::XML::Document");
}

Data_Get_Struct(document, xmlDoc, xml_doc);
Noko_Node_Get_Struct(document, xmlDoc, xml_doc);

node = xmlNewDocProp(
xml_doc,
Expand Down
6 changes: 3 additions & 3 deletions ext/nokogiri/xml_attribute_decl.c
Expand Up @@ -12,7 +12,7 @@ static VALUE
attribute_type(VALUE self)
{
xmlAttributePtr node;
Data_Get_Struct(self, xmlAttribute, node);
Noko_Node_Get_Struct(self, xmlAttribute, node);
return INT2NUM((long)node->atype);
}

Expand All @@ -26,7 +26,7 @@ static VALUE
default_value(VALUE self)
{
xmlAttributePtr node;
Data_Get_Struct(self, xmlAttribute, node);
Noko_Node_Get_Struct(self, xmlAttribute, node);

if (node->defaultValue) { return NOKOGIRI_STR_NEW2(node->defaultValue); }
return Qnil;
Expand All @@ -45,7 +45,7 @@ enumeration(VALUE self)
xmlEnumerationPtr enm;
VALUE list;

Data_Get_Struct(self, xmlAttribute, node);
Noko_Node_Get_Struct(self, xmlAttribute, node);

list = rb_ary_new();
enm = node->tree;
Expand Down
2 changes: 1 addition & 1 deletion ext/nokogiri/xml_cdata.c
Expand Up @@ -25,7 +25,7 @@ new (int argc, VALUE *argv, VALUE klass)

rb_scan_args(argc, argv, "2*", &doc, &content, &rest);

Data_Get_Struct(doc, xmlDoc, xml_doc);
Noko_Node_Get_Struct(doc, xmlDoc, xml_doc);

if (!NIL_P(content)) {
content_str = (xmlChar *)StringValuePtr(content);
Expand Down
2 changes: 1 addition & 1 deletion ext/nokogiri/xml_document.c
Expand Up @@ -161,7 +161,7 @@ rb_xml_document_root_set(VALUE self, VALUE rb_new_root)
rb_obj_class(rb_new_root));
}

Data_Get_Struct(rb_new_root, xmlNode, c_new_root);
Noko_Node_Get_Struct(rb_new_root, xmlNode, c_new_root);

/* If the new root's document is not the same as the current document,
* then we need to dup the node in to this document. */
Expand Down
16 changes: 8 additions & 8 deletions ext/nokogiri/xml_dtd.c
Expand Up @@ -44,7 +44,7 @@ entities(VALUE self)
xmlDtdPtr dtd;
VALUE hash;

Data_Get_Struct(self, xmlDtd, dtd);
Noko_Node_Get_Struct(self, xmlDtd, dtd);

if (!dtd->entities) { return Qnil; }

Expand All @@ -67,7 +67,7 @@ notations(VALUE self)
xmlDtdPtr dtd;
VALUE hash;

Data_Get_Struct(self, xmlDtd, dtd);
Noko_Node_Get_Struct(self, xmlDtd, dtd);

if (!dtd->notations) { return Qnil; }

Expand All @@ -90,7 +90,7 @@ attributes(VALUE self)
xmlDtdPtr dtd;
VALUE hash;

Data_Get_Struct(self, xmlDtd, dtd);
Noko_Node_Get_Struct(self, xmlDtd, dtd);

hash = rb_hash_new();

Expand All @@ -113,7 +113,7 @@ elements(VALUE self)
xmlDtdPtr dtd;
VALUE hash;

Data_Get_Struct(self, xmlDtd, dtd);
Noko_Node_Get_Struct(self, xmlDtd, dtd);

if (!dtd->elements) { return Qnil; }

Expand All @@ -138,8 +138,8 @@ validate(VALUE self, VALUE document)
xmlValidCtxtPtr ctxt;
VALUE error_list;

Data_Get_Struct(self, xmlDtd, dtd);
Data_Get_Struct(document, xmlDoc, doc);
Noko_Node_Get_Struct(self, xmlDtd, dtd);
Noko_Node_Get_Struct(document, xmlDoc, doc);
error_list = rb_ary_new();

ctxt = xmlNewValidCtxt();
Expand All @@ -165,7 +165,7 @@ static VALUE
system_id(VALUE self)
{
xmlDtdPtr dtd;
Data_Get_Struct(self, xmlDtd, dtd);
Noko_Node_Get_Struct(self, xmlDtd, dtd);

if (!dtd->SystemID) { return Qnil; }

Expand All @@ -182,7 +182,7 @@ static VALUE
external_id(VALUE self)
{
xmlDtdPtr dtd;
Data_Get_Struct(self, xmlDtd, dtd);
Noko_Node_Get_Struct(self, xmlDtd, dtd);

if (!dtd->ExternalID) { return Qnil; }

Expand Down
6 changes: 3 additions & 3 deletions ext/nokogiri/xml_element_decl.c
Expand Up @@ -14,7 +14,7 @@ static VALUE
element_type(VALUE self)
{
xmlElementPtr node;
Data_Get_Struct(self, xmlElement, node);
Noko_Node_Get_Struct(self, xmlElement, node);
return INT2NUM((long)node->etype);
}

Expand All @@ -28,7 +28,7 @@ static VALUE
content(VALUE self)
{
xmlElementPtr node;
Data_Get_Struct(self, xmlElement, node);
Noko_Node_Get_Struct(self, xmlElement, node);

if (!node->content) { return Qnil; }

Expand All @@ -48,7 +48,7 @@ static VALUE
prefix(VALUE self)
{
xmlElementPtr node;
Data_Get_Struct(self, xmlElement, node);
Noko_Node_Get_Struct(self, xmlElement, node);

if (!node->prefix) { return Qnil; }

Expand Down
10 changes: 5 additions & 5 deletions ext/nokogiri/xml_entity_decl.c
Expand Up @@ -12,7 +12,7 @@ static VALUE
original_content(VALUE self)
{
xmlEntityPtr node;
Data_Get_Struct(self, xmlEntity, node);
Noko_Node_Get_Struct(self, xmlEntity, node);

if (!node->orig) { return Qnil; }

Expand All @@ -29,7 +29,7 @@ static VALUE
get_content(VALUE self)
{
xmlEntityPtr node;
Data_Get_Struct(self, xmlEntity, node);
Noko_Node_Get_Struct(self, xmlEntity, node);

if (!node->content) { return Qnil; }

Expand All @@ -46,7 +46,7 @@ static VALUE
entity_type(VALUE self)
{
xmlEntityPtr node;
Data_Get_Struct(self, xmlEntity, node);
Noko_Node_Get_Struct(self, xmlEntity, node);

return INT2NUM((int)node->etype);
}
Expand All @@ -61,7 +61,7 @@ static VALUE
external_id(VALUE self)
{
xmlEntityPtr node;
Data_Get_Struct(self, xmlEntity, node);
Noko_Node_Get_Struct(self, xmlEntity, node);

if (!node->ExternalID) { return Qnil; }

Expand All @@ -78,7 +78,7 @@ static VALUE
system_id(VALUE self)
{
xmlEntityPtr node;
Data_Get_Struct(self, xmlEntity, node);
Noko_Node_Get_Struct(self, xmlEntity, node);

if (!node->SystemID) { return Qnil; }

Expand Down

0 comments on commit 82ff9e9

Please sign in to comment.