Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix compilation warnings #1731

Merged
merged 6 commits into from Mar 14, 2018
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion ext/nokogiri/extconf.rb
Expand Up @@ -434,7 +434,7 @@ def using_system_libraries?

if RbConfig::MAKEFILE_CONFIG['CC'] =~ /gcc/
$CFLAGS << " -O3" unless $CFLAGS[/-O\d/]
$CFLAGS << " -Wall -Wcast-qual -Wwrite-strings -Wconversion -Wmissing-noreturn -Winline"
$CFLAGS << " -Wall -Wextra -Wwrite-strings -Wmissing-noreturn -Winline"
end

case
Expand Down
10 changes: 6 additions & 4 deletions ext/nokogiri/xml_cdata.c
Expand Up @@ -17,15 +17,17 @@ static VALUE new(int argc, VALUE *argv, VALUE klass)
VALUE content;
VALUE rest;
VALUE rb_node;
const xmlChar *content_str;
int content_str_len;
const xmlChar *content_str = NULL;
int content_str_len = 0;

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

Data_Get_Struct(doc, xmlDoc, xml_doc);

content_str = NIL_P(content) ? NULL : (const xmlChar *)StringValueCStr(content);
content_str_len = (content_str == NULL) ? 0 : strlen(content_str);
if (!NIL_P(content)) {
content_str = (const xmlChar *)StringValueCStr(content);
content_str_len = strlen((char *)content_str);
}

node = xmlNewCDataBlock(xml_doc->doc, content_str, content_str_len);

Expand Down
8 changes: 1 addition & 7 deletions ext/nokogiri/xml_namespace.c
Expand Up @@ -24,12 +24,6 @@ static void dealloc_namespace(xmlNsPtr ns)
}


int Nokogiri_namespace_eh(xmlNodePtr node)
{
return (node->type == XML_NAMESPACE_DECL);
}


/*
* call-seq:
* prefix
Expand Down Expand Up @@ -64,7 +58,7 @@ static VALUE href(VALUE self)

static int part_of_an_xpath_node_set_eh(xmlNsPtr node)
{
return (node->next && ! Nokogiri_namespace_eh(node->next));
return (node->next && ! NOKOGIRI_NAMESPACE_EH(node->next));
}

VALUE Nokogiri_wrap_xml_namespace(xmlDocPtr doc, xmlNsPtr node)
Expand Down
2 changes: 2 additions & 0 deletions ext/nokogiri/xml_namespace.h
Expand Up @@ -10,4 +10,6 @@ extern VALUE cNokogiriXmlNamespace ;
VALUE Nokogiri_wrap_xml_namespace(xmlDocPtr doc, xmlNsPtr node) ;
VALUE Nokogiri_wrap_xml_namespace2(VALUE document, xmlNsPtr node) ;

#define NOKOGIRI_NAMESPACE_EH(node) ((node)->type == XML_NAMESPACE_DECL)

#endif
32 changes: 20 additions & 12 deletions ext/nokogiri/xml_node.c
Expand Up @@ -168,18 +168,20 @@ static VALUE reparent_node_with(VALUE pivot_obj, VALUE reparentee_obj, pivot_rep
case XML_DOCUMENT_NODE:
case XML_HTML_DOCUMENT_NODE:
switch (reparentee->type) {
case XML_ELEMENT_NODE:
case XML_PI_NODE:
case XML_COMMENT_NODE:
case XML_DOCUMENT_TYPE_NODE:
/*
* The DOM specification says no to adding text-like nodes
* directly to a document, but we allow it for compatibility.
*/
case XML_TEXT_NODE:
case XML_CDATA_SECTION_NODE:
case XML_ENTITY_REF_NODE:
goto ok;
case XML_ELEMENT_NODE:
case XML_PI_NODE:
case XML_COMMENT_NODE:
case XML_DOCUMENT_TYPE_NODE:
/*
* The DOM specification says no to adding text-like nodes
* directly to a document, but we allow it for compatibility.
*/
case XML_TEXT_NODE:
case XML_CDATA_SECTION_NODE:
case XML_ENTITY_REF_NODE:
goto ok;
default:
break;
}
break;
case XML_DOCUMENT_FRAG_NODE:
Expand All @@ -193,13 +195,17 @@ static VALUE reparent_node_with(VALUE pivot_obj, VALUE reparentee_obj, pivot_rep
case XML_CDATA_SECTION_NODE:
case XML_ENTITY_REF_NODE:
goto ok;
default:
break;
}
break;
case XML_ATTRIBUTE_NODE:
switch (reparentee->type) {
case XML_TEXT_NODE:
case XML_ENTITY_REF_NODE:
goto ok;
default:
break;
}
break;
case XML_TEXT_NODE:
Expand All @@ -210,6 +216,8 @@ static VALUE reparent_node_with(VALUE pivot_obj, VALUE reparentee_obj, pivot_rep
* operation, we should inhibit it.
*/
break;
default:
break;
}

rb_raise(rb_eArgError, "cannot reparent %s there", rb_obj_classname(reparentee_obj));
Expand Down
6 changes: 3 additions & 3 deletions ext/nokogiri/xml_node_set.c
Expand Up @@ -350,7 +350,7 @@ static VALUE unlink_nodeset(VALUE self)

nodeNr = node_set->nodeNr ;
for (j = 0 ; j < nodeNr ; j++) {
if (! Nokogiri_namespace_eh(node_set->nodeTab[j])) {
if (! NOKOGIRI_NAMESPACE_EH(node_set->nodeTab[j])) {
VALUE node ;
xmlNodePtr node_ptr;
node = Nokogiri_wrap_xml_node(Qnil, node_set->nodeTab[j]);
Expand Down Expand Up @@ -388,7 +388,7 @@ static void reify_node_set_namespaces(VALUE self)
namespace_cache = rb_iv_get(self, "@namespace_cache");

for (j = 0 ; j < node_set->nodeNr ; j++) {
if (Nokogiri_namespace_eh(node_set->nodeTab[j])) {
if (NOKOGIRI_NAMESPACE_EH(node_set->nodeTab[j])) {
rb_ary_push(namespace_cache, Nokogiri_wrap_xml_node_set_node(node_set->nodeTab[j], self));
}
}
Expand Down Expand Up @@ -420,7 +420,7 @@ VALUE Nokogiri_wrap_xml_node_set_node(xmlNodePtr node, VALUE node_set)
{
xmlDocPtr document ;

if (Nokogiri_namespace_eh(node)) {
if (NOKOGIRI_NAMESPACE_EH(node)) {
Data_Get_Struct(rb_iv_get(node_set, "@document"), xmlDoc, document);
return Nokogiri_wrap_xml_namespace(document, (xmlNsPtr)node);
} else {
Expand Down
1 change: 0 additions & 1 deletion ext/nokogiri/xml_node_set.h
Expand Up @@ -8,6 +8,5 @@ extern VALUE cNokogiriXmlNodeSet ;
VALUE Nokogiri_wrap_xml_node_set(xmlNodeSetPtr node_set, VALUE document) ;
VALUE Nokogiri_wrap_xml_node_set_node(xmlNodePtr node, VALUE node_set) ;
VALUE Nokogiri_wrap_xml_node_set_namespace(xmlNsPtr node, VALUE node_set) ;
int Nokogiri_namespace_eh(xmlNodePtr node) ;

#endif
4 changes: 2 additions & 2 deletions ext/nokogiri/xslt_stylesheet.c
Expand Up @@ -214,7 +214,7 @@ static void * initFunc(xsltTransformContextPtr ctxt, const xmlChar *uri)
(unsigned char *)StringValueCStr(method_name), uri, method_caller);
}

Data_Get_Struct(ctxt->style->_private, nokogiriXsltStylesheetTuple,
Data_Get_Struct((VALUE)ctxt->style->_private, nokogiriXsltStylesheetTuple,
wrapper);
inst = rb_class_new_instance(0, NULL, obj);
rb_ary_push(wrapper->func_instances, inst);
Expand All @@ -227,7 +227,7 @@ static void shutdownFunc(xsltTransformContextPtr ctxt,
{
nokogiriXsltStylesheetTuple *wrapper;

Data_Get_Struct(ctxt->style->_private, nokogiriXsltStylesheetTuple,
Data_Get_Struct((VALUE)ctxt->style->_private, nokogiriXsltStylesheetTuple,
wrapper);

rb_ary_clear(wrapper->func_instances);
Expand Down