helly           Thu Oct 11 01:03:19 2007 UTC

  Modified files:              (Branch: PHP_5_3)
    /php-src/ext/simplexml      simplexml.c 
  Log:
  - MFH debug object helper
  
http://cvs.php.net/viewvc.cgi/php-src/ext/simplexml/simplexml.c?r1=1.151.2.22.2.35.2.2&r2=1.151.2.22.2.35.2.3&diff_format=u
Index: php-src/ext/simplexml/simplexml.c
diff -u php-src/ext/simplexml/simplexml.c:1.151.2.22.2.35.2.2 
php-src/ext/simplexml/simplexml.c:1.151.2.22.2.35.2.3
--- php-src/ext/simplexml/simplexml.c:1.151.2.22.2.35.2.2       Sun Oct  7 
05:22:06 2007
+++ php-src/ext/simplexml/simplexml.c   Thu Oct 11 01:03:19 2007
@@ -18,7 +18,7 @@
   +----------------------------------------------------------------------+
 */
 
-/* $Id: simplexml.c,v 1.151.2.22.2.35.2.2 2007/10/07 05:22:06 davidw Exp $ */
+/* $Id: simplexml.c,v 1.151.2.22.2.35.2.3 2007/10/11 01:03:19 helly Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -136,7 +136,7 @@
 static xmlNodePtr sxe_get_element_by_offset(php_sxe_object *sxe, long offset, 
xmlNodePtr node, long *cnt) /* {{{ */
 {
        long nodendx = 0;
-       
+
        if (sxe->iter.type == SXE_ITER_NONE) {
                if (offset == 0) {
                        if (cnt) {
@@ -161,7 +161,7 @@
 next_iter:
                node = node->next;
        }
-       
+
        if (cnt) {
                *cnt = nodendx;
        }
@@ -275,7 +275,7 @@
 
        if (sxe->iter.type == SXE_ITER_ATTRLIST) {
                attribs = 1;
-               elements = 0;           
+               elements = 0;
                node = php_sxe_get_first_node(sxe, node TSRMLS_CC);
                attr = (xmlAttrPtr)node;
                test = sxe->iter.name != NULL;
@@ -337,7 +337,7 @@
                                        }
                                } else if (member) {
                                        node = sxe_get_element_by_offset(sxe, 
Z_LVAL_P(member), node, &cnt);
-                               } else {                                        
+                               } else {
                                        node = NULL;
                                }
                                if (node) {
@@ -502,7 +502,7 @@
 
        if (sxe->iter.type == SXE_ITER_ATTRLIST) {
                attribs = 1;
-               elements = 0;           
+               elements = 0;
                node = php_sxe_get_first_node(sxe, node TSRMLS_CC);
                attr = (xmlAttrPtr)node;
                test = sxe->iter.name != NULL;
@@ -639,7 +639,7 @@
                        if (!node) {
                                if (!member || Z_TYPE_P(member) == IS_LONG) {
                                        newnode = 
xmlNewTextChild(mynode->parent, mynode->ns, mynode->name, value ? (xmlChar 
*)Z_STRVAL_P(value) : NULL);
-                               } else {                                
+                               } else {
                                        newnode = xmlNewTextChild(mynode, 
mynode->ns, (xmlChar *)Z_STRVAL_P(member), value ? (xmlChar *)Z_STRVAL_P(value) 
: NULL);
                                }
                        } else if (!member || Z_TYPE_P(member) == IS_LONG) {
@@ -711,6 +711,9 @@
        _node_as_zval(sxe, node, return_value, type, name, sxe->iter.nsprefix, 
sxe->iter.isprefix TSRMLS_CC);
 
        sxe = php_sxe_fetch_object(return_value TSRMLS_CC);
+       if (sxe->tmp) {
+               zval_ptr_dtor(&sxe->tmp);
+       }
        sxe->tmp = return_value;
        Z_SET_ISREF_P(return_value);
 
@@ -752,7 +755,7 @@
 
        if (sxe->iter.type == SXE_ITER_ATTRLIST) {
                attribs = 1;
-               elements = 0;           
+               elements = 0;
                node = php_sxe_get_first_node(sxe, node TSRMLS_CC);
                attr = (xmlAttrPtr)node;
                test = sxe->iter.name != NULL;
@@ -814,7 +817,7 @@
                        }
                        if (node) {
                                exists = 1;
-                                if (check_empty == 1 && 
+                                if (check_empty == 1 &&
                                        (!node->children || 
(node->children->type == XML_TEXT_NODE && !node->children->next &&
                                                (!node->children->content || 
!node->children->content[0] || !xmlStrcmp(node->children->content, "0")))) ) {
                                        exists = 0;
@@ -882,7 +885,7 @@
 
        if (sxe->iter.type == SXE_ITER_ATTRLIST) {
                attribs = 1;
-               elements = 0;           
+               elements = 0;
                node = php_sxe_get_first_node(sxe, node TSRMLS_CC);
                attr = (xmlAttrPtr)node;
                test = sxe->iter.name != NULL;
@@ -978,7 +981,7 @@
        char    *res = estrdup((char*)tmp);
 
        xmlFree(tmp);
-       
+
        return res;
 }
 
@@ -1038,9 +1041,9 @@
        }
 }
 
-/* {{{ sxe_properties_get()
+/* {{{ sxe_get_prop_hash()
  */
-static HashTable * sxe_properties_get(zval *object TSRMLS_DC)
+static HashTable * sxe_get_prop_hash(zval *object, int is_debug TSRMLS_DC) /* 
{{{ */
 {
        zval            *value;
        zval            *zattr;
@@ -1054,7 +1057,11 @@
 
        sxe = php_sxe_fetch_object(object TSRMLS_CC);
 
-       if (sxe->properties) {
+       if (is_debug) {
+               ALLOC_HASHTABLE(rv);
+               zend_hash_init(rv, 0, NULL, ZVAL_PTR_DTOR, 0);
+       }
+       else if (sxe->properties) {
                zend_hash_clean(sxe->properties);
                rv = sxe->properties;
        } else {
@@ -1067,7 +1074,7 @@
        if (!node) {
                return rv;
        }
-       if (1||sxe->iter.type != SXE_ITER_CHILD) {
+       if (is_debug) {
                if (sxe->iter.type == SXE_ITER_ELEMENT) {
                        node = php_sxe_get_first_node(sxe, node TSRMLS_CC);
                }
@@ -1137,6 +1144,19 @@
 }
 /* }}} */
 
+static HashTable * sxe_get_properties(zval *object TSRMLS_DC) /* {{{ */
+{
+       return sxe_get_prop_hash(object, 0 TSRMLS_CC);
+}
+/* }}} */
+
+static HashTable * sxe_get_debug_info(zval *object, int *is_temp TSRMLS_DC) /* 
{{{ */
+{
+       *is_temp = 1;
+       return sxe_get_prop_hash(object, 1 TSRMLS_CC);
+}
+/* }}} */
+
 static int sxe_objects_compare(zval *object1, zval *object2 TSRMLS_DC) /* {{{ 
*/
 {
        php_sxe_object *sxe1;
@@ -1365,13 +1385,13 @@
 {
        xmlAttrPtr  attr;
 
-       if (node->ns) { 
+       if (node->ns) {
                sxe_add_namespace_name(return_value, node->ns);
        }
 
        attr = node->properties;
        while (attr) {
-               if (attr->ns) { 
+               if (attr->ns) {
                        sxe_add_namespace_name(return_value, attr->ns);
                }
                attr = attr->next;
@@ -1521,7 +1541,7 @@
 
        sxe = php_sxe_fetch_object(getThis() TSRMLS_CC);
        GET_NODE(sxe, node);
-       
+
        if (sxe->iter.type == SXE_ITER_ATTRLIST) {
                return; /* attributes don't have attributes */
        }
@@ -1565,7 +1585,7 @@
 
        if (node == NULL) {
                php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot add child. 
Parent is not a permanent member of the XML tree");
-               return; 
+               return;
        }
 
        localname = xmlSplitQName2((xmlChar *)qname, &prefix);
@@ -1704,13 +1724,17 @@
        xmlChar           *contents = NULL;
        xmlNodePtr          node;
        int rv;
+       HashTable      *prop_hash;
 
        sxe = php_sxe_fetch_object(readobj TSRMLS_CC);
-       
+
        if (type == IS_BOOL) {
                node = php_sxe_get_first_node(sxe, NULL TSRMLS_CC);
+               prop_hash = sxe_get_prop_hash(readobj, 1 TSRMLS_CC);
                INIT_PZVAL(writeobj);
-               ZVAL_BOOL(writeobj, node != NULL || 
zend_hash_num_elements(sxe_properties_get(readobj TSRMLS_CC)) > 0);
+               ZVAL_BOOL(writeobj, node != NULL || 
zend_hash_num_elements(prop_hash) > 0);
+               zend_hash_destroy(prop_hash);
+               efree(prop_hash);
                return SUCCESS;
        }
 
@@ -1755,7 +1779,7 @@
        sxe->iter.data = NULL;
 
        node = php_sxe_reset_iterator(sxe, 0 TSRMLS_CC);
-       
+
        while (node)
        {
                (*count)++;
@@ -1800,7 +1824,7 @@
        sxe_property_delete,
        sxe_dimension_exists,
        sxe_dimension_delete,
-       sxe_properties_get,
+       sxe_get_properties,
        NULL, /* zend_get_std_object_handlers()->get_method,*/
        NULL, /* zend_get_std_object_handlers()->call_method,*/
        NULL, /* zend_get_std_object_handlers()->get_constructor, */
@@ -1808,7 +1832,8 @@
        NULL, /* zend_get_std_object_handlers()->get_class_name,*/
        sxe_objects_compare,
        sxe_object_cast,
-       sxe_count_elements
+       sxe_count_elements,
+       sxe_get_debug_info
 };
 
 static zend_object_handlers sxe_ze1_object_handlers = {
@@ -1824,7 +1849,7 @@
        sxe_property_delete,
        sxe_dimension_exists,
        sxe_dimension_delete,
-       sxe_properties_get,
+       sxe_get_properties,
        NULL, /* zend_get_std_object_handlers()->get_method,*/
        NULL, /* zend_get_std_object_handlers()->call_method,*/
        NULL, /* zend_get_std_object_handlers()->get_constructor, */
@@ -1832,7 +1857,8 @@
        NULL, /* zend_get_std_object_handlers()->get_class_name,*/
        sxe_objects_compare,
        sxe_object_cast,
-       sxe_count_elements
+       sxe_count_elements,
+       sxe_get_debug_info
 };
 
 static zend_object_value sxe_object_ze1_clone(zval *zobject TSRMLS_DC)
@@ -2294,7 +2320,7 @@
 
        sxe = php_sxe_fetch_object(object TSRMLS_CC);
        GET_NODE(sxe, node);
-       return php_sxe_get_first_node(sxe, node TSRMLS_CC);     
+       return php_sxe_get_first_node(sxe, node TSRMLS_CC);
 }
 
 /* {{{ proto simplemxml_element simplexml_import_dom(domNode node [, string 
class_name])
@@ -2440,7 +2466,7 @@
 {
        php_info_print_table_start();
        php_info_print_table_header(2, "Simplexml support", "enabled");
-       php_info_print_table_row(2, "Revision", "$Revision: 1.151.2.22.2.35.2.2 
$");
+       php_info_print_table_row(2, "Revision", "$Revision: 1.151.2.22.2.35.2.3 
$");
        php_info_print_table_row(2, "Schema support",
 #ifdef LIBXML_SCHEMAS_ENABLED
                "enabled");

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to