Skip to content

Commit

Permalink
squash into 47e2ef2
Browse files Browse the repository at this point in the history
  • Loading branch information
flavorjones committed Jul 10, 2022
1 parent 47e2ef2 commit 1c74ba1
Show file tree
Hide file tree
Showing 14 changed files with 89 additions and 94 deletions.
4 changes: 3 additions & 1 deletion ext/nokogiri/gumbo.c
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,9 @@ lookup_namespace(VALUE node, bool require_known_ns)
static xmlNodePtr
extract_xml_node(VALUE node)
{
return noko_xml_node_unwrap(node);
xmlNodePtr xml_node;
Noko_Node_Get_Struct(node, xmlNode, xml_node);
return xml_node;
}

static VALUE fragment_continue(VALUE parse_args);
Expand Down
3 changes: 2 additions & 1 deletion ext/nokogiri/nokogiri.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,9 @@ 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) = RBIMPL_CAST((type*)DATA_PTR(obj)))

VALUE noko_xml_node_wrap(VALUE klass, xmlNodePtr node) ;
xmlNodePtr noko_xml_node_unwrap(VALUE obj) ;
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
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ set_value(VALUE self, VALUE content)
xmlChar *value;
xmlNode *cur;

attr = (xmlAttrPtr)noko_xml_node_unwrap(self);
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");
}

xml_doc = (xmlDocPtr)noko_xml_node_unwrap(document);
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
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ static VALUE
attribute_type(VALUE self)
{
xmlAttributePtr node;
node = (xmlAttributePtr)noko_xml_node_unwrap(self);
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;
node = (xmlAttributePtr)noko_xml_node_unwrap(self);
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;

node = (xmlAttributePtr)noko_xml_node_unwrap(self);
Noko_Node_Get_Struct(self, xmlAttribute, node);

list = rb_ary_new();
enm = node->tree;
Expand Down
3 changes: 1 addition & 2 deletions ext/nokogiri/xml_cdata.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ new (int argc, VALUE *argv, VALUE klass)

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

xml_doc = (xmlDocPtr)noko_xml_node_unwrap(doc);

Noko_Node_Get_Struct(doc, xmlDoc, xml_doc);
if (!NIL_P(content)) {
content_str = (xmlChar *)StringValuePtr(content);
content_str_len = RSTRING_LEN(content);
Expand Down
2 changes: 1 addition & 1 deletion ext/nokogiri/xml_document.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ rb_xml_document_root_set(VALUE self, VALUE rb_new_root)
rb_obj_class(rb_new_root));
}

c_new_root = noko_xml_node_unwrap(rb_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
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ entities(VALUE self)
xmlDtdPtr dtd;
VALUE hash;

dtd = (xmlDtdPtr)noko_xml_node_unwrap(self);
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;

dtd = (xmlDtdPtr)noko_xml_node_unwrap(self);
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;

dtd = (xmlDtdPtr)noko_xml_node_unwrap(self);
Noko_Node_Get_Struct(self, xmlDtd, dtd);

hash = rb_hash_new();

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

dtd = (xmlDtdPtr)noko_xml_node_unwrap(self);
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;

dtd = (xmlDtdPtr)noko_xml_node_unwrap(self);
doc = (xmlDocPtr)noko_xml_node_unwrap(document);
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;
dtd = (xmlDtdPtr)noko_xml_node_unwrap(self);
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;
dtd = (xmlDtdPtr)noko_xml_node_unwrap(self);
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ static VALUE
element_type(VALUE self)
{
xmlElementPtr node;
node = (xmlElementPtr)noko_xml_node_unwrap(self);
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;
node = (xmlElementPtr)noko_xml_node_unwrap(self);
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;
node = (xmlElementPtr)noko_xml_node_unwrap(self);
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
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ static VALUE
original_content(VALUE self)
{
xmlEntityPtr node;
node = (xmlEntityPtr)noko_xml_node_unwrap(self);
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;
node = (xmlEntityPtr)noko_xml_node_unwrap(self);
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;
node = (xmlEntityPtr)noko_xml_node_unwrap(self);
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;
node = (xmlEntityPtr)noko_xml_node_unwrap(self);
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;
node = (xmlEntityPtr)noko_xml_node_unwrap(self);
Noko_Node_Get_Struct(self, xmlEntity, node);

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

Expand Down
Loading

0 comments on commit 1c74ba1

Please sign in to comment.