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 all 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 -Wcast-qual -Wwrite-strings -Wextra -Wmissing-noreturn -Winline"
end

case
Expand Down
28 changes: 14 additions & 14 deletions ext/nokogiri/html_element_description.c
Expand Up @@ -8,7 +8,7 @@
*/
static VALUE required_attributes(VALUE self)
{
htmlElemDesc * description;
const htmlElemDesc * description;
VALUE list;
int i;

Expand All @@ -33,7 +33,7 @@ static VALUE required_attributes(VALUE self)
*/
static VALUE deprecated_attributes(VALUE self)
{
htmlElemDesc * description;
const htmlElemDesc * description;
VALUE list;
int i;

Expand All @@ -58,7 +58,7 @@ static VALUE deprecated_attributes(VALUE self)
*/
static VALUE optional_attributes(VALUE self)
{
htmlElemDesc * description;
const htmlElemDesc * description;
VALUE list;
int i;

Expand All @@ -83,7 +83,7 @@ static VALUE optional_attributes(VALUE self)
*/
static VALUE default_sub_element(VALUE self)
{
htmlElemDesc * description;
const htmlElemDesc * description;
Data_Get_Struct(self, htmlElemDesc, description);

if (description->defaultsubelt)
Expand All @@ -100,7 +100,7 @@ static VALUE default_sub_element(VALUE self)
*/
static VALUE sub_elements(VALUE self)
{
htmlElemDesc * description;
const htmlElemDesc * description;
VALUE list;
int i;

Expand All @@ -125,7 +125,7 @@ static VALUE sub_elements(VALUE self)
*/
static VALUE description(VALUE self)
{
htmlElemDesc * description;
const htmlElemDesc * description;
Data_Get_Struct(self, htmlElemDesc, description);

return NOKOGIRI_STR_NEW2(description->desc);
Expand All @@ -139,7 +139,7 @@ static VALUE description(VALUE self)
*/
static VALUE inline_eh(VALUE self)
{
htmlElemDesc * description;
const htmlElemDesc * description;
Data_Get_Struct(self, htmlElemDesc, description);

if(description->isinline) return Qtrue;
Expand All @@ -154,7 +154,7 @@ static VALUE inline_eh(VALUE self)
*/
static VALUE deprecated_eh(VALUE self)
{
htmlElemDesc * description;
const htmlElemDesc * description;
Data_Get_Struct(self, htmlElemDesc, description);

if(description->depr) return Qtrue;
Expand All @@ -169,7 +169,7 @@ static VALUE deprecated_eh(VALUE self)
*/
static VALUE empty_eh(VALUE self)
{
htmlElemDesc * description;
const htmlElemDesc * description;
Data_Get_Struct(self, htmlElemDesc, description);

if(description->empty) return Qtrue;
Expand All @@ -184,7 +184,7 @@ static VALUE empty_eh(VALUE self)
*/
static VALUE save_end_tag_eh(VALUE self)
{
htmlElemDesc * description;
const htmlElemDesc * description;
Data_Get_Struct(self, htmlElemDesc, description);

if(description->saveEndTag) return Qtrue;
Expand All @@ -199,7 +199,7 @@ static VALUE save_end_tag_eh(VALUE self)
*/
static VALUE implied_end_tag_eh(VALUE self)
{
htmlElemDesc * description;
const htmlElemDesc * description;
Data_Get_Struct(self, htmlElemDesc, description);

if(description->endTag) return Qtrue;
Expand All @@ -214,7 +214,7 @@ static VALUE implied_end_tag_eh(VALUE self)
*/
static VALUE implied_start_tag_eh(VALUE self)
{
htmlElemDesc * description;
const htmlElemDesc * description;
Data_Get_Struct(self, htmlElemDesc, description);

if(description->startTag) return Qtrue;
Expand All @@ -229,7 +229,7 @@ static VALUE implied_start_tag_eh(VALUE self)
*/
static VALUE name(VALUE self)
{
htmlElemDesc * description;
const htmlElemDesc * description;
Data_Get_Struct(self, htmlElemDesc, description);

if(NULL == description->name) return Qnil;
Expand All @@ -249,7 +249,7 @@ static VALUE get_description(VALUE klass, VALUE tag_name)
);

if(NULL == description) return Qnil;
return Data_Wrap_Struct(klass, 0, 0, (void *)description);
return Data_Wrap_Struct(klass, 0, 0, (void *)(uintptr_t)description);
}

VALUE cNokogiriHtmlElementDescription ;
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;
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 = (xmlChar *)StringValuePtr(content);
content_str_len = RSTRING_LEN(content);
}

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

Expand Down
5 changes: 2 additions & 3 deletions ext/nokogiri/xml_document.c
Expand Up @@ -179,7 +179,7 @@ static VALUE set_encoding(VALUE self, VALUE encoding)
Data_Get_Struct(self, xmlDoc, doc);

if (doc->encoding)
free((char *) doc->encoding); /* this may produce a gcc cast warning */
free((char *)(uintptr_t) doc->encoding); /* avoid gcc cast warning */

doc->encoding = xmlStrdup((xmlChar *)StringValueCStr(encoding));

Expand Down Expand Up @@ -531,8 +531,7 @@ static VALUE canonicalize(int argc, VALUE* argv, VALUE self)
ns = calloc((size_t)ns_len+1, sizeof(xmlChar *));
for (i = 0 ; i < ns_len ; i++) {
VALUE entry = rb_ary_entry(incl_ns, i);
const char * ptr = StringValueCStr(entry);
ns[i] = (xmlChar*) ptr;
ns[i] = (xmlChar*)StringValueCStr(entry);
}
}

Expand Down
12 changes: 3 additions & 9 deletions ext/nokogiri/xml_namespace.c
Expand Up @@ -14,22 +14,16 @@ static void dealloc_namespace(xmlNsPtr ns)
*/
NOKOGIRI_DEBUG_START(ns) ;
if (ns->href) {
xmlFree((xmlChar *)ns->href);
xmlFree((xmlChar *)(uintptr_t)ns->href);
}
if (ns->prefix) {
xmlFree((xmlChar *)ns->prefix);
xmlFree((xmlChar *)(uintptr_t)ns->prefix);
}
xmlFree(ns);
NOKOGIRI_DEBUG_END(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
38 changes: 23 additions & 15 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 Expand Up @@ -833,18 +841,18 @@ static VALUE set(VALUE self, VALUE property, VALUE value)
static VALUE get(VALUE self, VALUE rattribute)
{
xmlNodePtr node;
const xmlChar *value = 0;
xmlChar *value = 0;
VALUE rvalue;
xmlChar *colon;
const xmlChar *attribute, *attr_name, *prefix;
xmlChar *attribute, *attr_name, *prefix;
xmlNsPtr ns;

if (NIL_P(rattribute)) return Qnil;

Data_Get_Struct(self, xmlNode, node);
attribute = xmlCharStrdup(StringValueCStr(rattribute));

colon = (xmlChar *)xmlStrchr(attribute, (const xmlChar)':');
colon = (xmlChar *)(uintptr_t)xmlStrchr(attribute, (const xmlChar)':');
if (colon) {
/* split the attribute string into separate prefix and name by
* null-terminating the prefix at the colon */
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