ext/xml/ruby_xml_node.c in libxml-ruby-0.5.0.1 vs ext/xml/ruby_xml_node.c in libxml-ruby-0.5.1.0
- old
+ new
@@ -1,6 +1,6 @@
-/* $Id: ruby_xml_node.c 164 2007-08-31 15:37:35Z danj $ */
+/* $Id: ruby_xml_node.c 167 2007-09-05 12:47:54Z danj $ */
/* Please see the LICENSE file for copyright and distribution information */
#include "libxml.h"
#include "ruby_xml_node.h"
@@ -319,47 +319,35 @@
*/
VALUE
ruby_xml_node_child_set(VALUE self, VALUE rnode) {
ruby_xml_node *cnode, *pnode;
xmlNodePtr chld, ret;
- ruby_xml_document_t *pdoc, *cdoc;
- int ptr;
+ int copied=0;
if (rb_obj_is_kind_of(rnode, cXMLNode) == Qfalse)
rb_raise(rb_eTypeError, "Must pass an XML::Node object");
Data_Get_Struct(self, ruby_xml_node, pnode);
Data_Get_Struct(rnode, ruby_xml_node, cnode);
chld = cnode->node;
-#ifdef IGNORE
- // Only copy if both nodes are in documents, which are different.
- if (pnode->xd && pnode->xd != Qnil) {
- Data_Get_Struct(pnode->xd, ruby_xml_document_t, pdoc);
- if (cnode->xd && cnode->xd != Qnil) {
- Data_Get_Struct(cnode->xd, ruby_xml_document_t, cdoc);
- if (cdoc->doc != pdoc->doc) {
- chld = xmlDocCopyNode(chld, pdoc->doc, 1);
- chld->_private = 0;
- ptr = 1;
- }
- } else {
- chld = xmlDocCopyNode(chld, pdoc->doc, 1);
- chld->_private = 0;
- ptr = 1;
- }
- } else {
- chld->doc = NULL;
+ if ( chld->parent != NULL || chld->doc != NULL ) {
+ chld=xmlCopyNode(chld,1);
+ copied=1;
+ rb_warning("implicit copy of %s",chld->name);
}
-#endif
-
+
ret = xmlAddChild(pnode->node, chld);
- if (ret == NULL)
+ if (ret == NULL) {
+ if ( copied == 1 )
+ xmlFreeNode(chld);
rb_raise(eXMLNodeFailedModify, "unable to add a child to the document");
+ }
- return ruby_xml_node2_wrap(cXMLNode,ret);
+ // wish I could return a new wrapped chld, but ruby only returns the rhs
+ return ruby_xml_node2_wrap(cXMLNode,chld);
}
/*
* call-seq:
* node.doc => document
@@ -2273,9 +2261,10 @@
rb_define_method(cXMLNode, "comment?", ruby_xml_node_comment_q, 0);
rb_define_method(cXMLNode, "copy", ruby_xml_node_copy, 1);
rb_define_method(cXMLNode, "child", ruby_xml_node_child_get, 0);
rb_define_method(cXMLNode, "child?", ruby_xml_node_child_q, 0);
rb_define_method(cXMLNode, "child=", ruby_xml_node_child_set, 1);
+ rb_define_method(cXMLNode, "child_add", ruby_xml_node_child_set, 1);
rb_define_method(cXMLNode, "children", ruby_xml_node_child_get, 0);
rb_define_method(cXMLNode, "children?", ruby_xml_node_child_q, 0);
rb_define_method(cXMLNode, "content", ruby_xml_node_content_get, 0);
rb_define_method(cXMLNode, "content=", ruby_xml_node_content_set, 1);
rb_define_method(cXMLNode, "content_stripped", ruby_xml_node_content_stripped_get, 0);