Skip to content

Instantly share code, notes, and snippets.

@brixen
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brixen/9138421 to your computer and use it in GitHub Desktop.
Save brixen/9138421 to your computer and use it in GitHub Desktop.
diff --git a/ext/nokogiri/html_document.c b/ext/nokogiri/html_document.c
index 3e8e8ec..1f327c1 100644
--- a/ext/nokogiri/html_document.c
+++ b/ext/nokogiri/html_document.c
@@ -65,6 +65,7 @@ static VALUE read_io( VALUE klass,
if (rb_respond_to(io, id_encoding_found)) {
VALUE encoding_found = rb_funcall(io, id_encoding_found, 0);
if (!NIL_P(encoding_found)) {
+fprintf(stderr, "html_document: read_io: %p\n", doc);
xmlFreeDoc(doc);
rb_exc_raise(encoding_found);
}
@@ -73,6 +74,7 @@ static VALUE read_io( VALUE klass,
if(doc == NULL) {
xmlErrorPtr error;
+fprintf(stderr, "html_document: read_io 1: %p\n", doc);
xmlFreeDoc(doc);
error = xmlGetLastError();
@@ -119,6 +121,7 @@ static VALUE read_memory( VALUE klass,
if(doc == NULL) {
xmlErrorPtr error;
+fprintf(stderr, "html_document: read_memory: %p\n", doc);
xmlFreeDoc(doc);
error = xmlGetLastError();
diff --git a/ext/nokogiri/html_sax_parser_context.c b/ext/nokogiri/html_sax_parser_context.c
index 02172ad..1567924 100644
--- a/ext/nokogiri/html_sax_parser_context.c
+++ b/ext/nokogiri/html_sax_parser_context.c
@@ -26,6 +26,7 @@ parse_memory(VALUE klass, VALUE data, VALUE encoding)
ctxt = htmlCreateMemoryParserCtxt(StringValuePtr(data),
(int)RSTRING_LEN(data));
if (ctxt->sax) {
+fprintf(stderr, "sax_parser_context: parse_memory: %p\n", ctxt->sax);
xmlFree(ctxt->sax);
ctxt->sax = NULL;
}
@@ -66,8 +67,10 @@ parse_doc_finalize(VALUE ctxt_val)
{
htmlParserCtxtPtr ctxt = (htmlParserCtxtPtr)ctxt_val;
- if (ctxt->myDoc)
+ if (ctxt->myDoc) {
+fprintf(stderr, "sax_parser_context: parse_doc_finalize: %p\n", ctxt->myDoc);
xmlFreeDoc(ctxt->myDoc);
+}
NOKOGIRI_SAX_TUPLE_DESTROY(ctxt->userData);
return Qnil;
@@ -86,8 +89,10 @@ parse_with(VALUE self, VALUE sax_handler)
Data_Get_Struct(sax_handler, htmlSAXHandler, sax);
/* Free the sax handler since we'll assign our own */
- if (ctxt->sax && ctxt->sax != (xmlSAXHandlerPtr)&xmlDefaultSAXHandler)
+ if (ctxt->sax && ctxt->sax != (xmlSAXHandlerPtr)&xmlDefaultSAXHandler) {
+fprintf(stderr, "sax_parser_context: parse_with: %p\n", ctxt->sax);
xmlFree(ctxt->sax);
+}
ctxt->sax = sax;
ctxt->userData = (void *)NOKOGIRI_SAX_TUPLE_NEW(ctxt, sax_handler);
diff --git a/ext/nokogiri/nokogiri.c b/ext/nokogiri/nokogiri.c
index c6121ec..5ee2f1d 100644
--- a/ext/nokogiri/nokogiri.c
+++ b/ext/nokogiri/nokogiri.c
@@ -68,17 +68,39 @@ void nokogiri_root_nsdef(xmlNsPtr ns, xmlDocPtr doc)
st_insert(tuple->unlinkedNodes, (st_data_t)ns, (st_data_t)ns);
}
+void nokogiri_debug_free(void* ptr) {
+ fprintf(stderr, "free: %p\n", ptr);
+ ruby_xfree(ptr);
+}
+
+void* nokogiri_debug_alloc(size_t bytes) {
+ void* ptr = ruby_xmalloc(bytes);
+ fprintf(stderr, "alloc: %p\n", ptr);
+ return ptr;
+}
+
+void* nokogiri_debug_realloc(void* ptr, size_t bytes) {
+ void* new_ptr = ruby_xrealloc(ptr, bytes);
+ fprintf(stderr, "realloc: %p, %p\n", ptr, new_ptr);
+ return new_ptr;
+}
+
void Init_nokogiri()
{
#ifndef __MACRUBY__
xmlMemSetup(
- (xmlFreeFunc)ruby_xfree,
- (xmlMallocFunc)ruby_xmalloc,
- (xmlReallocFunc)ruby_xrealloc,
+ (xmlFreeFunc)nokogiri_debug_free,
+ // (xmlFreeFunc)ruby_xfree,
+ (xmlMallocFunc)nokogiri_debug_alloc,
+ // (xmlMallocFunc)ruby_xmalloc,
+ // (xmlReallocFunc)ruby_xrealloc,
+ (xmlReallocFunc)nokogiri_debug_realloc,
ruby_strdup
);
#endif
+fprintf(stderr, "Init_nokogiri\n");
+
mNokogiri = rb_define_module("Nokogiri");
mNokogiriXml = rb_define_module_under(mNokogiri, "XML");
mNokogiriHtml = rb_define_module_under(mNokogiri, "HTML");
diff --git a/ext/nokogiri/xml_attr.c b/ext/nokogiri/xml_attr.c
index 0863f61..8d84fa0 100644
--- a/ext/nokogiri/xml_attr.c
+++ b/ext/nokogiri/xml_attr.c
@@ -11,7 +11,9 @@ static VALUE set_value(VALUE self, VALUE content)
xmlAttrPtr attr;
Data_Get_Struct(self, xmlAttr, attr);
- if(attr->children) xmlFreeNodeList(attr->children);
+ if(attr->children) {xmlFreeNodeList(attr->children);
+fprintf(stderr, "xml_attr: set_value: %p\n", attr->children);
+}
attr->children = attr->last = NULL;
@@ -34,6 +36,7 @@ static VALUE set_value(VALUE self, VALUE content)
}
/* Free up memory */
+fprintf(stderr, "xml_attr: set_value end: %p\n", buffer);
xmlFree(buffer);
}
@@ -67,6 +70,7 @@ static VALUE new(int argc, VALUE *argv, VALUE klass)
nokogiri_root_node((xmlNodePtr)node);
+fprintf(stderr, "xml_attr: new: %p\n", node);
rb_node = Nokogiri_wrap_xml_node(klass, (xmlNodePtr)node);
rb_obj_call_init(rb_node, argc, argv);
diff --git a/ext/nokogiri/xml_cdata.c b/ext/nokogiri/xml_cdata.c
index e509266..23c6489 100644
--- a/ext/nokogiri/xml_cdata.c
+++ b/ext/nokogiri/xml_cdata.c
@@ -27,6 +27,7 @@ static VALUE new(int argc, VALUE *argv, VALUE klass)
nokogiri_root_node(node);
+fprintf(stderr, "xml_cdata: new: %p\n", node);
rb_node = Nokogiri_wrap_xml_node(klass, node);
rb_obj_call_init(rb_node, argc, argv);
diff --git a/ext/nokogiri/xml_comment.c b/ext/nokogiri/xml_comment.c
index 2740978..6f2bd7f 100644
--- a/ext/nokogiri/xml_comment.c
+++ b/ext/nokogiri/xml_comment.c
@@ -24,6 +24,7 @@ static VALUE new(int argc, VALUE *argv, VALUE klass)
(const xmlChar *)StringValuePtr(content)
);
+fprintf(stderr, "xml_comment: new: %p\n", node);
rb_node = Nokogiri_wrap_xml_node(klass, node);
rb_obj_call_init(rb_node, argc, argv);
diff --git a/ext/nokogiri/xml_document.c b/ext/nokogiri/xml_document.c
index 87ecf13..d9c5c14 100644
--- a/ext/nokogiri/xml_document.c
+++ b/ext/nokogiri/xml_document.c
@@ -4,9 +4,11 @@ static int dealloc_node_i(xmlNodePtr key, xmlNodePtr node, xmlDocPtr doc)
{
switch(node->type) {
case XML_ATTRIBUTE_NODE:
+fprintf(stderr, "xml_document: dealloc_node_i: %p\n", node);
xmlFreePropList((xmlAttrPtr)node);
break;
case XML_NAMESPACE_DECL:
+fprintf(stderr, "xml_document: dealloc_node_i 1: %p\n", node);
xmlFree(node);
break;
default:
@@ -32,6 +34,7 @@ static void dealloc(xmlDocPtr doc)
free(doc->_private);
doc->_private = NULL;
+fprintf(stderr, "xml_document: dealloc: %p\n", doc);
xmlFreeDoc(doc);
xmlDeregisterNodeDefault(func);
@@ -52,6 +55,7 @@ static void recursively_remove_namespaces_from_node(xmlNodePtr node)
(node->type == XML_XINCLUDE_START) ||
(node->type == XML_XINCLUDE_END)) &&
node->nsDef) {
+fprintf(stderr, "xml_document: rrnfn: %p\n", node->nsDef);
xmlFreeNsList(node->nsDef);
node->nsDef = NULL;
}
@@ -141,6 +145,7 @@ static VALUE root(VALUE self)
root = xmlDocGetRootElement(doc);
if(!root) return Qnil;
+fprintf(stderr, "xml_document: root: %p\n", root);
return Nokogiri_wrap_xml_node(Qnil, root) ;
}
@@ -227,6 +232,7 @@ static VALUE read_io( VALUE klass,
if(doc == NULL) {
xmlErrorPtr error;
+fprintf(stderr, "xml_document: read_io: %p\n", doc);
xmlFreeDoc(doc);
error = xmlGetLastError();
@@ -271,6 +277,7 @@ static VALUE read_memory( VALUE klass,
if(doc == NULL) {
xmlErrorPtr error;
+fprintf(stderr, "xml_document: read_memory: %p\n", doc);
xmlFreeDoc(doc);
error = xmlGetLastError();
@@ -424,6 +431,7 @@ static VALUE create_entity(int argc, VALUE *argv, VALUE self)
return Qnil;
}
+fprintf(stderr, "xml_document: create_entity: %p\n", ptr);
return Nokogiri_wrap_xml_node(cNokogiriXmlEntityDecl, (xmlNodePtr)ptr);
}
@@ -438,8 +446,10 @@ static int block_caller(void * ctx, xmlNodePtr _node, xmlNodePtr _parent)
node = Nokogiri_wrap_xml_namespace(_parent->doc, (xmlNsPtr) _node);
}
else{
+fprintf(stderr, "xml_document: block_caller: %p\n", _node);
node = Nokogiri_wrap_xml_node(Qnil, _node);
}
+if(parent) fprintf(stderr, "xml_document: block_caller parent: %p\n", _parent);
parent = _parent ? Nokogiri_wrap_xml_node(Qnil, _parent) : Qnil;
block = (VALUE)ctx;
diff --git a/ext/nokogiri/xml_document_fragment.c b/ext/nokogiri/xml_document_fragment.c
index 2d7fb17..e9d3100 100644
--- a/ext/nokogiri/xml_document_fragment.c
+++ b/ext/nokogiri/xml_document_fragment.c
@@ -22,6 +22,7 @@ static VALUE new(int argc, VALUE *argv, VALUE klass)
nokogiri_root_node(node);
+fprintf(stderr, "xml_document_fragment: new: %p\n", node);
rb_node = Nokogiri_wrap_xml_node(klass, node);
rb_obj_call_init(rb_node, argc, argv);
diff --git a/ext/nokogiri/xml_dtd.c b/ext/nokogiri/xml_dtd.c
index f70dcde..d5583a2 100644
--- a/ext/nokogiri/xml_dtd.c
+++ b/ext/nokogiri/xml_dtd.c
@@ -22,6 +22,7 @@ static void element_copier(void *_payload, void *data, xmlChar *name)
VALUE hash = (VALUE)data;
xmlNodePtr payload = (xmlNodePtr)_payload;
+fprintf(stderr, "xml_dtd: element_copier: %p\n", payload);
VALUE element = Nokogiri_wrap_xml_node(Qnil, payload);
rb_hash_aset(hash, NOKOGIRI_STR_NEW2(name), element);
@@ -140,6 +141,7 @@ static VALUE validate(VALUE self, VALUE document)
xmlSetStructuredErrorFunc(NULL, NULL);
+fprintf(stderr, "xml_dtd: validate: %p\n", ctxt);
xmlFreeValidCtxt(ctxt);
return error_list;
diff --git a/ext/nokogiri/xml_entity_reference.c b/ext/nokogiri/xml_entity_reference.c
index 261f787..24f8fd0 100644
--- a/ext/nokogiri/xml_entity_reference.c
+++ b/ext/nokogiri/xml_entity_reference.c
@@ -26,6 +26,7 @@ static VALUE new(int argc, VALUE *argv, VALUE klass)
nokogiri_root_node(node);
+fprintf(stderr, "xml_entity_reference: new: %p\n", node);
rb_node = Nokogiri_wrap_xml_node(klass, node);
rb_obj_call_init(rb_node, argc, argv);
diff --git a/ext/nokogiri/xml_node.c b/ext/nokogiri/xml_node.c
index db80071..b079e99 100644
--- a/ext/nokogiri/xml_node.c
+++ b/ext/nokogiri/xml_node.c
@@ -15,11 +15,19 @@ static void debug_node_dealloc(xmlNodePtr x)
static void mark(xmlNodePtr node)
{
xmlNodePtr doc = node->doc;
+
+ if(!node || !doc) {
+ fprintf(stderr, "mark: invalid object: %p, %d, %p\n", node, node->type, doc);
+ return;
+ }
+
+ fprintf(stderr, "mark: %p\n", node);
+
if(doc->type == XML_DOCUMENT_NODE || doc->type == XML_HTML_DOCUMENT_NODE) {
if(DOC_RUBY_OBJECT_TEST(doc)) {
rb_gc_mark(DOC_RUBY_OBJECT(doc));
}
- } else if(node->doc->_private) {
+ } else if(doc->_private) {
rb_gc_mark((VALUE)doc->_private);
}
}
@@ -219,6 +227,7 @@ static VALUE reparent_node_with(VALUE pivot_obj, VALUE reparentee_obj, pivot_rep
relink_namespace(reparented);
+fprintf(stderr, "xml_node: reparent_node_with: %p\n", reparented);
reparented_obj = Nokogiri_wrap_xml_node(Qnil, reparented);
rb_funcall(reparented_obj, decorate_bang, 0);
@@ -273,6 +282,7 @@ static VALUE encode_special_chars(VALUE self, VALUE string)
);
encoded_str = NOKOGIRI_STR_NEW2(encoded);
+fprintf(stderr, "xml_node: encode_special_chars: %p\n", encoded);
xmlFree(encoded);
return encoded_str;
@@ -312,6 +322,7 @@ static VALUE create_internal_subset(VALUE self, VALUE name, VALUE external_id, V
if(!dtd) return Qnil;
+fprintf(stderr, "xml_node: create_internal_subset: %p\n", dtd);
return Nokogiri_wrap_xml_node(Qnil, (xmlNodePtr)dtd);
}
@@ -343,6 +354,7 @@ static VALUE create_external_subset(VALUE self, VALUE name, VALUE external_id, V
if(!dtd) return Qnil;
+fprintf(stderr, "xml_node: create_external_subset: %p\n", dtd);
return Nokogiri_wrap_xml_node(Qnil, (xmlNodePtr)dtd);
}
@@ -367,6 +379,7 @@ static VALUE external_subset(VALUE self)
if(!dtd) return Qnil;
+fprintf(stderr, "xml_node: external_subset: %p\n", dtd);
return Nokogiri_wrap_xml_node(Qnil, (xmlNodePtr)dtd);
}
@@ -391,6 +404,7 @@ static VALUE internal_subset(VALUE self)
if(!dtd) return Qnil;
+fprintf(stderr, "xml_node: internal_subset: %p\n", dtd);
return Nokogiri_wrap_xml_node(Qnil, (xmlNodePtr)dtd);
}
@@ -416,6 +430,7 @@ static VALUE duplicate_node(int argc, VALUE *argv, VALUE self)
nokogiri_root_node(dup);
+fprintf(stderr, "xml_node: duplicate_node: %p\n", dup);
return Nokogiri_wrap_xml_node(rb_obj_class(self), dup);
}
@@ -461,6 +476,7 @@ static VALUE next_sibling(VALUE self)
sibling = node->next;
if(!sibling) return Qnil;
+fprintf(stderr, "xml_node: next_sibling: %p\n", sibling);
return Nokogiri_wrap_xml_node(Qnil, sibling) ;
}
@@ -478,6 +494,7 @@ static VALUE previous_sibling(VALUE self)
sibling = node->prev;
if(!sibling) return Qnil;
+fprintf(stderr, "xml_node: previous_sibling: %p\n", sibling);
return Nokogiri_wrap_xml_node(Qnil, sibling);
}
@@ -495,6 +512,7 @@ static VALUE next_element(VALUE self)
sibling = xmlNextElementSibling(node);
if(!sibling) return Qnil;
+fprintf(stderr, "xml_node: next_element: %p\n", sibling);
return Nokogiri_wrap_xml_node(Qnil, sibling);
}
@@ -518,6 +536,7 @@ static VALUE previous_element(VALUE self)
while(sibling && sibling->type != XML_ELEMENT_NODE)
sibling = sibling->prev;
+if(sibling) fprintf(stderr, "xml_node: previous_element: %p\n", sibling);
return sibling ? Nokogiri_wrap_xml_node(Qnil, sibling) : Qnil ;
}
@@ -620,6 +639,7 @@ static VALUE child(VALUE self)
child = node->children;
if(!child) return Qnil;
+fprintf(stderr, "xml_node: child: %p\n", child);
return Nokogiri_wrap_xml_node(Qnil, child);
}
@@ -641,6 +661,7 @@ static VALUE first_element_child(VALUE self)
child = xmlFirstElementChild(node);
if(!child) return Qnil;
+fprintf(stderr, "xml_node: first_element_child: %p\n", child);
return Nokogiri_wrap_xml_node(Qnil, child);
}
@@ -662,6 +683,7 @@ static VALUE last_element_child(VALUE self)
child = xmlLastElementChild(node);
if(!child) return Qnil;
+fprintf(stderr, "xml_node: last_element_child: %p\n", child);
return Nokogiri_wrap_xml_node(Qnil, child);
}
@@ -771,6 +793,7 @@ static VALUE get(VALUE self, VALUE rattribute)
if (!value) return Qnil;
rvalue = NOKOGIRI_STR_NEW2(value);
+fprintf(stderr, "xml_node: get: %p\n", value);
xmlFree(value);
return rvalue ;
@@ -829,6 +852,7 @@ static VALUE attribute_with_ns(VALUE self, VALUE name, VALUE namespace)
NIL_P(namespace) ? NULL : (xmlChar *)StringValuePtr(namespace));
if(! prop) return Qnil;
+fprintf(stderr, "xml_node: attribute_with_ns: %p\n", prop);
return Nokogiri_wrap_xml_node(Qnil, (xmlNodePtr)prop);
}
@@ -927,6 +951,7 @@ static VALUE namespace_scopes(VALUE self)
rb_ary_push(list, Nokogiri_wrap_xml_namespace(node->doc, ns_list[j]));
}
+fprintf(stderr, "xml_node: namespace_scopes: %p\n", ns_list);
xmlFree(ns_list);
return list;
}
@@ -983,6 +1008,7 @@ static VALUE get_content(VALUE self)
content = xmlNodeGetContent(node);
if(content) {
VALUE rval = NOKOGIRI_STR_NEW2(content);
+fprintf(stderr, "xml_node: get_content: %p\n", content);
xmlFree(content);
return rval;
}
@@ -1009,6 +1035,7 @@ static VALUE get_parent(VALUE self)
parent = node->parent;
if(!parent) return Qnil;
+fprintf(stderr, "xml_node: get_parent: %p\n", parent);
return Nokogiri_wrap_xml_node(Qnil, parent) ;
}
@@ -1057,6 +1084,7 @@ static VALUE path(VALUE self)
path = xmlGetNodePath(node);
rval = NOKOGIRI_STR_NEW2(path);
+fprintf(stderr, "xml_node: path: %p\n", path);
xmlFree(path);
return rval ;
}
@@ -1193,6 +1221,7 @@ static VALUE new(int argc, VALUE *argv, VALUE klass)
node->doc = doc->doc;
nokogiri_root_node(node);
+fprintf(stderr, "xml_node: new: %p\n", node);
rb_node = Nokogiri_wrap_xml_node(
klass == cNokogiriXmlNode ? (VALUE)NULL : klass,
node
@@ -1445,6 +1474,7 @@ VALUE Nokogiri_wrap_xml_node(VALUE klass, xmlNodePtr node)
mark_method = node_has_a_document ? mark : NULL ;
+ fprintf(stderr, "wrap: %p, %p, %d\n", node, mark_method, node->type);
rb_node = Data_Wrap_Struct(klass, mark_method, debug_node_dealloc, node) ;
node->_private = (void *)rb_node;
@@ -1453,6 +1483,7 @@ VALUE Nokogiri_wrap_xml_node(VALUE klass, xmlNodePtr node)
node_cache = DOC_NODE_CACHE(doc);
rb_ary_push(node_cache, rb_node);
rb_funcall(document, decorate, 1, rb_node);
+fprintf(stderr, "cache: %p\n", node);
}
return rb_node ;
@@ -1464,6 +1495,7 @@ void Nokogiri_xml_node_properties(xmlNodePtr node, VALUE attr_list)
xmlAttrPtr prop;
prop = node->properties ;
while (prop != NULL) {
+fprintf(stderr, "xml_node: xml_node_properties: %p\n", prop);
rb_ary_push(attr_list, Nokogiri_wrap_xml_node(Qnil, (xmlNodePtr)prop));
prop = prop->next ;
}
diff --git a/ext/nokogiri/xml_node_set.c b/ext/nokogiri/xml_node_set.c
index 953982b..0be3ddf 100644
--- a/ext/nokogiri/xml_node_set.c
+++ b/ext/nokogiri/xml_node_set.c
@@ -5,6 +5,7 @@ static ID decorate ;
static int dealloc_namespace(xmlNsPtr ns)
{
+fprintf(stderr, "dealloc_namespace: %p\n", ns);
if (ns->href)
xmlFree((xmlChar *)ns->href);
if (ns->prefix)
@@ -51,6 +52,7 @@ static void deallocate(nokogiriNodeSetTuple *tuple)
NOKOGIRI_DEBUG_START(node_set) ;
st_foreach(tuple->namespaces, dealloc_namespace, 0);
+fprintf(stderr, "deallocate: %p\n", node_set);
if (node_set->nodeTab != NULL)
xmlFree(node_set->nodeTab);
@@ -257,14 +259,17 @@ static VALUE index_at(VALUE self, long offset)
Data_Get_Struct(self, nokogiriNodeSetTuple, tuple);
node_set = tuple->node_set;
- if (offset >= node_set->nodeNr || abs((int)offset) > node_set->nodeNr)
+ if (offset >= node_set->nodeNr || labs((int)offset) > node_set->nodeNr)
return Qnil;
if (offset < 0)
offset += node_set->nodeNr;
+assert(offset < node_set->nodeNr);
+
if (XML_NAMESPACE_DECL == node_set->nodeTab[offset]->type)
return Nokogiri_wrap_xml_namespace2(rb_iv_get(self, "@document"), (xmlNsPtr)(node_set->nodeTab[offset]));
+fprintf(stderr, "xml_node_set: index_at: %p, %p, %d, %d\n", node_set->nodeTab[offset], node_set, offset, node_set->nodeNr);
return Nokogiri_wrap_xml_node(Qnil, node_set->nodeTab[offset]);
}
@@ -369,8 +374,10 @@ static VALUE to_array(VALUE self, VALUE rb_node)
for(i = 0; i < set->nodeNr; i++) {
if (XML_NAMESPACE_DECL == set->nodeTab[i]->type)
elts[i] = Nokogiri_wrap_xml_namespace2(rb_iv_get(self, "@document"), (xmlNsPtr)(set->nodeTab[i]));
- else
+ else {
+fprintf(stderr, "xml_node_set: to_array: %p\n", set->nodeTab[i]);
elts[i] = Nokogiri_wrap_xml_node(Qnil, set->nodeTab[i]);
+}
}
list = rb_ary_new4((long)set->nodeNr, elts);
@@ -399,6 +406,7 @@ static VALUE unlink_nodeset(VALUE self)
if (XML_NAMESPACE_DECL != node_set->nodeTab[j]->type) {
VALUE node ;
xmlNodePtr node_ptr;
+fprintf(stderr, "xml_node_set: unlink_nodeset: %p\n", node_set->nodeTab[j]);
node = Nokogiri_wrap_xml_node(Qnil, node_set->nodeTab[j]);
rb_funcall(node, rb_intern("unlink"), 0); /* modifies the C struct out from under the object */
Data_Get_Struct(node, xmlNode, node_ptr);
diff --git a/ext/nokogiri/xml_processing_instruction.c b/ext/nokogiri/xml_processing_instruction.c
index 71854af..85cf0be 100644
--- a/ext/nokogiri/xml_processing_instruction.c
+++ b/ext/nokogiri/xml_processing_instruction.c
@@ -29,6 +29,7 @@ static VALUE new(int argc, VALUE *argv, VALUE klass)
nokogiri_root_node(node);
+fprintf(stderr, "xml_processing_insn: new: %p\n", node);
rb_node = Nokogiri_wrap_xml_node(klass, node);
rb_obj_call_init(rb_node, argc, argv);
diff --git a/ext/nokogiri/xml_reader.c b/ext/nokogiri/xml_reader.c
index 7fcf3cd..4f33121 100644
--- a/ext/nokogiri/xml_reader.c
+++ b/ext/nokogiri/xml_reader.c
@@ -3,6 +3,7 @@
static void dealloc(xmlTextReaderPtr reader)
{
NOKOGIRI_DEBUG_START(reader);
+fprintf(stderr, "xml_reader: dealloc: %p\n", reader);
xmlFreeTextReader(reader);
NOKOGIRI_DEBUG_END(reader);
}
@@ -197,6 +198,7 @@ static VALUE attribute_at(VALUE self, VALUE index)
if(value == NULL) return Qnil;
rb_value = NOKOGIRI_STR_NEW2(value);
+fprintf(stderr, "xml_reader: attribute_at: %p\n", value);
xmlFree(value);
return rb_value;
}
@@ -226,15 +228,18 @@ static VALUE reader_attribute(VALUE self, VALUE name)
xmlChar *localname = xmlSplitQName2((xmlChar*)StringValuePtr(name), &prefix);
if (localname != NULL) {
value = xmlTextReaderLookupNamespace(reader, localname);
+fprintf(stderr, "xml_reader: reader_attribute: %p\n", localname);
xmlFree(localname) ;
} else {
value = xmlTextReaderLookupNamespace(reader, prefix);
}
+fprintf(stderr, "xml_reader: reader_attribute 1: %p\n", prefix);
xmlFree(prefix);
}
if(value == NULL) return Qnil;
rb_value = NOKOGIRI_STR_NEW2(value);
+fprintf(stderr, "xml_reader: reader_attribute 2: %p\n", value);
xmlFree(value);
return rb_value;
}
@@ -498,6 +503,7 @@ static VALUE inner_xml(VALUE self)
str = Qnil;
if(value) {
str = NOKOGIRI_STR_NEW2((char*)value);
+fprintf(stderr, "xml_reader: inner_xml: %p\n", value);
xmlFree(value);
}
@@ -523,6 +529,7 @@ static VALUE outer_xml(VALUE self)
if(value) {
str = NOKOGIRI_STR_NEW2((char*)value);
+fprintf(stderr, "xml_reader: outer_xml: %p\n", value);
xmlFree(value);
}
return str;
@@ -559,6 +566,7 @@ static VALUE from_memory(int argc, VALUE *argv, VALUE klass)
);
if(reader == NULL) {
+fprintf(stderr, "xml_reader: from_memory: %p\n", reader);
xmlFreeTextReader(reader);
rb_raise(rb_eRuntimeError, "couldn't create a parser");
}
@@ -604,6 +612,7 @@ static VALUE from_io(int argc, VALUE *argv, VALUE klass)
);
if(reader == NULL) {
+fprintf(stderr, "xml_reader: from_io: %p\n", reader);
xmlFreeTextReader(reader);
rb_raise(rb_eRuntimeError, "couldn't create a parser");
}
diff --git a/ext/nokogiri/xml_sax_parser_context.c b/ext/nokogiri/xml_sax_parser_context.c
index 6c88d4a..1b8be8f 100644
--- a/ext/nokogiri/xml_sax_parser_context.c
+++ b/ext/nokogiri/xml_sax_parser_context.c
@@ -8,6 +8,7 @@ static void deallocate(xmlParserCtxtPtr ctxt)
ctxt->sax = NULL;
+fprintf(stderr, "sax_parser: deallocate: %p\n", ctxt);
xmlFreeParserCtxt(ctxt);
NOKOGIRI_DEBUG_END(handler);
@@ -30,6 +31,7 @@ parse_io(VALUE klass, VALUE io, VALUE encoding)
(xmlInputCloseCallback)io_close_callback,
(void *)io, enc);
if (ctxt->sax) {
+fprintf(stderr, "sax_parser: parse_io: %p\n", ctxt->sax);
xmlFree(ctxt->sax);
ctxt->sax = NULL;
}
@@ -68,6 +70,7 @@ parse_memory(VALUE klass, VALUE data)
ctxt = xmlCreateMemoryParserCtxt(StringValuePtr(data),
(int)RSTRING_LEN(data));
if (ctxt->sax) {
+fprintf(stderr, "sax_parser: parse_memory: %p\n", ctxt->sax);
xmlFree(ctxt->sax);
ctxt->sax = NULL;
}
@@ -88,8 +91,10 @@ parse_doc_finalize(VALUE ctxt_val)
{
xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr)ctxt_val;
- if (NULL != ctxt->myDoc)
+ if (NULL != ctxt->myDoc) {
+fprintf(stderr, "sax_parser: parse_doc_finalize: %p\n", ctxt->myDoc);
xmlFreeDoc(ctxt->myDoc);
+}
NOKOGIRI_SAX_TUPLE_DESTROY(ctxt->userData);
return Qnil;
@@ -114,8 +119,10 @@ parse_with(VALUE self, VALUE sax_handler)
Data_Get_Struct(sax_handler, xmlSAXHandler, sax);
/* Free the sax handler since we'll assign our own */
- if (ctxt->sax && ctxt->sax != (xmlSAXHandlerPtr)&xmlDefaultSAXHandler)
+ if (ctxt->sax && ctxt->sax != (xmlSAXHandlerPtr)&xmlDefaultSAXHandler) {
+fprintf(stderr, "sax_parser: parse_with: %p\n", ctxt->myDoc);
xmlFree(ctxt->sax);
+}
ctxt->sax = sax;
ctxt->userData = (void *)NOKOGIRI_SAX_TUPLE_NEW(ctxt, sax_handler);
diff --git a/ext/nokogiri/xml_sax_push_parser.c b/ext/nokogiri/xml_sax_push_parser.c
index 9b69c98..e8e5a94 100644
--- a/ext/nokogiri/xml_sax_push_parser.c
+++ b/ext/nokogiri/xml_sax_push_parser.c
@@ -5,6 +5,7 @@ static void deallocate(xmlParserCtxtPtr ctx)
NOKOGIRI_DEBUG_START(ctx);
if(ctx != NULL) {
NOKOGIRI_SAX_TUPLE_DESTROY(ctx->userData);
+fprintf(stderr, "sax deallocate: %p\n", ctx);
xmlFreeParserCtxt(ctx);
}
NOKOGIRI_DEBUG_END(ctx);
diff --git a/ext/nokogiri/xml_text.c b/ext/nokogiri/xml_text.c
index f824717..a2b5cb8 100644
--- a/ext/nokogiri/xml_text.c
+++ b/ext/nokogiri/xml_text.c
@@ -24,6 +24,7 @@ static VALUE new(int argc, VALUE *argv, VALUE klass)
nokogiri_root_node(node);
+fprintf(stderr, "xml_text: new: %p\n", node);
rb_node = Nokogiri_wrap_xml_node(klass, node) ;
rb_obj_call_init(rb_node, argc, argv);
diff --git a/ext/nokogiri/xml_xpath_context.c b/ext/nokogiri/xml_xpath_context.c
index 25e43aa..629e5dd 100644
--- a/ext/nokogiri/xml_xpath_context.c
+++ b/ext/nokogiri/xml_xpath_context.c
@@ -233,6 +233,7 @@ static VALUE evaluate(int argc, VALUE *argv, VALUE self)
switch(xpath->type) {
case XPATH_STRING:
thing = NOKOGIRI_STR_NEW2(xpath->stringval);
+fprintf(stderr, "xpath_context: evaluate: %p\n", xpath->stringval);
xmlFree(xpath->stringval);
break;
case XPATH_NODESET:
diff --git a/ext/nokogiri/xslt_stylesheet.c b/ext/nokogiri/xslt_stylesheet.c
index e132b83..e998728 100644
--- a/ext/nokogiri/xslt_stylesheet.c
+++ b/ext/nokogiri/xslt_stylesheet.c
@@ -78,6 +78,7 @@ static VALUE parse_stylesheet_doc(VALUE klass, VALUE xmldocobj)
xsltSetGenericErrorFunc(NULL, NULL);
if (!ss) {
+fprintf(stderr, "xslt_stylesheet: parse_stylesheet_doc: %p\n", xml_cpy);
xmlFreeDoc(xml_cpy);
exception = rb_exc_new3(rb_eRuntimeError, errstr);
rb_exc_raise(exception);
@@ -105,6 +106,7 @@ static VALUE serialize(VALUE self, VALUE xmlobj)
Data_Get_Struct(self, nokogiriXsltStylesheetTuple, wrapper);
xsltSaveResultToString(&doc_ptr, &doc_len, xml, wrapper->ss);
rval = NOKOGIRI_STR_NEW(doc_ptr, doc_len);
+fprintf(stderr, "xslt_stylesheet: serialize: %p\n", doc_ptr);
xmlFree(doc_ptr);
return rval ;
}
diff --git a/vm/builtin/data.cpp b/vm/builtin/data.cpp
index dc3948d..efce496 100644
--- a/vm/builtin/data.cpp
+++ b/vm/builtin/data.cpp
@@ -121,14 +121,17 @@ namespace rubinius {
// MRI only calls free if the data_ptr is not NULL.
if(void* data_ptr = data->data()) {
+fprintf(stderr, "data: finalize: %p\n", data_ptr);
Data::FreeFunctor f = data->free();
if(f) {
// If the user specifies -1, then we call free. We check here rather
// than when Data_Make_Struct is called because the user is allowed to
// change dfree.
if(reinterpret_cast<intptr_t>(f) == -1) {
+fprintf(stderr, "data: ::free: %p\n", data_ptr);
::free(data_ptr);
} else {
+fprintf(stderr, "data: f: %p\n", data_ptr);
f(data_ptr);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment