cvs: php4 /ext/domxml php_domxml.c
| From: | Christian Stocker | Date: | Thu, 10 Apr 2003 12:45:38 +0000 |
| Subject: | cvs: php4 /ext/domxml php_domxml.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-20216@lists.php.net to get a copy of this message | ||
chregu Thu Apr 10 08:45:38 2003 EDT
Modified files:
/php4/ext/domxml php_domxml.c
Log:
- More TSRMLS stuff.
- Fixed memleaks in domxml_doc_add_root, domxml_xslt_stylesheet
and domxml_xslt_stylesheet_doc
- Completed implementation of domxml_doc_imported_node.
Index: php4/ext/domxml/php_domxml.c
diff -u php4/ext/domxml/php_domxml.c:1.250 php4/ext/domxml/php_domxml.c:1.251
--- php4/ext/domxml/php_domxml.c:1.250 Wed Apr 9 15:14:44 2003
+++ php4/ext/domxml/php_domxml.c Thu Apr 10 08:45:38 2003
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_domxml.c,v 1.250 2003/04/09 19:14:44 helly Exp $ */
+/* $Id: php_domxml.c,v 1.251 2003/04/10 12:45:38 chregu Exp $ */
/* TODO
* - Support Notation Nodes
@@ -602,11 +602,10 @@
/* This function should only be used when freeing nodes
as dependant objects are destroyed */
-static inline void node_wrapper_free(xmlNodePtr node)
+static inline void node_wrapper_free(xmlNodePtr node TSRMLS_DC)
{
zval *wrapper, **handle;
int type, refcount = 0;
- TSRMLS_FETCH();
if (!node) {
return;
@@ -616,7 +615,6 @@
if (wrapper != NULL ) {
/* All references need to be destroyed */
if (zend_hash_index_find(Z_OBJPROP_P(wrapper), 0, (void **) &handle) == SUCCESS) {
- TSRMLS_FETCH();
if (zend_list_find(Z_LVAL_PP(handle), &type)) {
zend_list_delete(Z_LVAL_PP(handle));
}
@@ -644,10 +642,10 @@
/* destroyref is a bool indicating if all registered objects for nodes
within the tree should be destroyed */
-static inline void node_list_wrapper_dtor(xmlNodePtr node, int destroyref)
+static inline void node_list_wrapper_dtor(xmlNodePtr node, int destroyref TSRMLS_DC)
{
while (node != NULL) {
- node_list_wrapper_dtor(node->children, destroyref);
+ node_list_wrapper_dtor(node->children, destroyref TSRMLS_CC);
switch (node->type) {
/* Skip property freeing for the following types */
case XML_ATTRIBUTE_DECL:
@@ -659,11 +657,11 @@
/* Attribute Nodes contain accessible children
Call this function with the propert list
attr_list_wrapper_dtor(node->properties); */
- node_list_wrapper_dtor((xmlNodePtr) node->properties, destroyref);
+ node_list_wrapper_dtor((xmlNodePtr) node->properties, destroyref TSRMLS_CC);
}
if (destroyref == 1) {
- node_wrapper_free(node);
+ node_wrapper_free(node TSRMLS_CC);
} else {
node_wrapper_dtor(node);
}
@@ -731,7 +729,7 @@
xmlDoc *doc = (xmlDoc *) rsrc->ptr;
if (doc) {
- node_list_wrapper_dtor(doc->children, 0);
+ node_list_wrapper_dtor(doc->children, 0 TSRMLS_CC);
node_wrapper_dtor((xmlNodePtr) doc);
xmlFreeDoc(doc);
}
@@ -746,8 +744,8 @@
if (node->parent == NULL) {
/* Attribute Nodes ccontain accessible children
attr_list_wrapper_dtor(node->properties); */
- node_list_wrapper_dtor((xmlNodePtr) node->properties, 0);
- node_list_wrapper_dtor(node->children, 0);
+ node_list_wrapper_dtor((xmlNodePtr) node->properties, 0 TSRMLS_CC);
+ node_list_wrapper_dtor(node->children, 0 TSRMLS_CC);
node_wrapper_dtor(node);
xmlFreeNode(node);
} else {
@@ -760,7 +758,7 @@
xmlNodePtr node = (xmlNodePtr) rsrc->ptr;
if (node->parent == NULL) {
/* Attribute Nodes contain accessible children */
- node_list_wrapper_dtor(node->children, 0);
+ node_list_wrapper_dtor(node->children, 0 TSRMLS_CC);
node_wrapper_dtor(node);
xmlFreeProp((xmlAttrPtr) node);
} else {
@@ -3862,11 +3860,14 @@
DOMXML_GET_OBJ(srcnode, arg1, le_domxmlnodep);
- node = xmlCopyNode(srcnode, recursive);
+ /* node = xmlCopyNode(srcnode, recursive); */
+ node = xmlDocCopyNode(srcnode, docp, recursive);
if (!node) {
RETURN_FALSE;
}
- node->doc = docp; /* Not enough because other nodes in the tree are not set */
+ /* No longer need handled by xmlDocCopyNode
+ node->doc = docp;
+ */
DOMXML_RET_OBJ(rv, node, &ret);
}
@@ -4358,7 +4359,7 @@
{
zval *id, *rv = NULL;
xmlDoc *docp;
- xmlNode *nodep;
+ xmlNode *nodep, *root;
int ret, name_len;
char *name;
@@ -4369,7 +4370,14 @@
RETURN_FALSE;
}
- xmlDocSetRootElement(docp, nodep);
+ if ((root = xmlDocSetRootElement(docp, nodep)) != NULL) {
+ /* Root node already unlinked from xmlDocSetRootElement */
+ if (dom_object_get_data(root) == NULL) {
+ node_list_unlink(root->children);
+ node_list_unlink((xmlNodePtr) root->properties);
+ xmlFreeNode(root);
+ }
+ }
DOMXML_RET_OBJ(rv, nodep, &ret);
}
@@ -4473,11 +4481,11 @@
RETURN_FALSE;
}
- node_list_wrapper_dtor(docp->children, 1);
- node_list_wrapper_dtor((xmlNodePtr) docp->properties, 1);
+ node_list_wrapper_dtor(docp->children, 1 TSRMLS_CC);
+ node_list_wrapper_dtor((xmlNodePtr) docp->properties, 1 TSRMLS_CC);
/* Attribute Nodes ccontain accessible children
attr_list_wrapper_dtor(docp->properties); */
- node_wrapper_free(docp);
+ node_wrapper_free(docp TSRMLS_CC);
RETURN_TRUE;
}
@@ -5342,6 +5350,7 @@
sheetp = xsltParseStylesheetDoc(docp);
if (!sheetp) {
+ xmlFreeDoc(docp);
RETURN_FALSE;
}
@@ -5375,6 +5384,7 @@
sheetp = xsltParseStylesheetDoc(newdocp);
if (!sheetp) {
+ xmlFreeDoc(newdocp);
RETURN_FALSE;
}