]> granicus.if.org Git - php/commitdiff
Refactor simpleXML (compilable, but incompleted)
authorXinchen Hui <laruence@gmail.com>
Mon, 14 Apr 2014 11:27:22 +0000 (19:27 +0800)
committerXinchen Hui <laruence@gmail.com>
Mon, 14 Apr 2014 11:27:22 +0000 (19:27 +0800)
ext/libxml/php_libxml.h
ext/simplexml/php_simplexml.h
ext/simplexml/php_simplexml_exports.h
ext/simplexml/simplexml.c
ext/simplexml/sxe.c

index 64c6bd78741405c71f79b49f7eb5e2e0bd208a0d..246994ddf8cf0666a695528fd365b6a8f2284f6d 100644 (file)
@@ -75,10 +75,10 @@ typedef struct _php_libxml_node_ptr {
 } php_libxml_node_ptr;
 
 typedef struct _php_libxml_node_object {
-       zend_object  std;
        php_libxml_node_ptr *node;
        php_libxml_ref_obj *document;
        HashTable *properties;
+       zend_object  std;
 } php_libxml_node_object;
 
 typedef void * (*php_libxml_export_node) (zval *object TSRMLS_DC);
index 7314d8c825a2750de4476e037fcb647aead8c82e..b908e4c722cf494acaabab00bc0c358833155c51 100644 (file)
@@ -55,7 +55,6 @@ typedef enum {
 } SXE_ITER;
 
 typedef struct {
-       zend_object zo;
        php_libxml_node_ptr *node;
        php_libxml_ref_obj *document;
        HashTable *properties;
@@ -65,10 +64,11 @@ typedef struct {
                xmlChar               *nsprefix;
                int                   isprefix;
                SXE_ITER              type;
-               zval                  *data;
+               zval                  data;
        } iter;
-       zval *tmp;
+       zval tmp;
        zend_function *fptr_count;
+       zend_object zo;
 } php_sxe_object;
 
 #ifdef ZTS
index 2c858566b959c3289fccd2b87590f7f42f7d3eff..6cdda1be4ae6070527b4f72a699fa49b11a15eff 100644 (file)
        } \
 }
 
-PHP_SXE_API zend_object_value sxe_object_new(zend_class_entry *ce TSRMLS_DC);
-/* {{{ php_sxe_fetch_object()
- */
-static inline php_sxe_object *
-php_sxe_fetch_object(zval *object TSRMLS_DC)
-{
-       return (php_sxe_object *) zend_object_store_get_object(object TSRMLS_CC);
+PHP_SXE_API zend_object *sxe_object_new(zend_class_entry *ce TSRMLS_DC);
+
+static inline php_sxe_object *php_sxe_fetch_object(zend_object *obj) /* {{{ */ {
+       return (php_sxe_object *)((char*)(obj) - XtOffsetOf(php_sxe_object, zo));
 }
 /* }}} */
 
+#define Z_SXEOBJ_P(zv) php_sxe_fetch_object(Z_OBJ_P((zv)))
+
 typedef struct {
        zend_object_iterator  intern;
        php_sxe_object        *sxe;
index 363ea1fc44b0b7775e2ec3ce8456530fec6d1660..757a1cd2f011042aeabd8eb4632b7d5c96e7f07e 100644 (file)
@@ -52,13 +52,13 @@ PHP_SXE_API zend_class_entry *sxe_get_element_class_entry() /* {{{ */
 #define SXE_METHOD(func) PHP_METHOD(simplexml_element, func)
 
 static php_sxe_object* php_sxe_object_new(zend_class_entry *ce TSRMLS_DC);
-static zend_object_value php_sxe_register_object(php_sxe_object * TSRMLS_DC);
+static zend_object *php_sxe_register_object(php_sxe_object * TSRMLS_DC);
 static xmlNodePtr php_sxe_reset_iterator(php_sxe_object *sxe, int use_data TSRMLS_DC);
 static xmlNodePtr php_sxe_iterator_fetch(php_sxe_object *sxe, xmlNodePtr node, int use_data TSRMLS_DC);
 static zval *sxe_get_value(zval *z TSRMLS_DC);
 static void php_sxe_iterator_dtor(zend_object_iterator *iter TSRMLS_DC);
 static int php_sxe_iterator_valid(zend_object_iterator *iter TSRMLS_DC);
-static void php_sxe_iterator_current_data(zend_object_iterator *iter, zval ***data TSRMLS_DC);
+static zval *php_sxe_iterator_current_data(zend_object_iterator *iter TSRMLS_DC);
 static void php_sxe_iterator_current_key(zend_object_iterator *iter, zval *key TSRMLS_DC);
 static void php_sxe_iterator_move_forward(zend_object_iterator *iter TSRMLS_DC);
 static void php_sxe_iterator_rewind(zend_object_iterator *iter TSRMLS_DC);
@@ -83,8 +83,7 @@ static void _node_as_zval(php_sxe_object *sxe, xmlNodePtr node, zval *value, SXE
 
        php_libxml_increment_node_ptr((php_libxml_node_object *)subnode, node, NULL TSRMLS_CC);
 
-       value->type = IS_OBJECT;
-       value->value.obj = php_sxe_register_object(subnode TSRMLS_CC);
+       ZVAL_OBJ(value, php_sxe_register_object(subnode TSRMLS_CC));
 }
 /* }}} */
 
@@ -115,8 +114,8 @@ static xmlNodePtr php_sxe_get_first_node(php_sxe_object *sxe, xmlNodePtr node TS
 
        if (sxe && sxe->iter.type != SXE_ITER_NONE) {
                php_sxe_reset_iterator(sxe, 1 TSRMLS_CC);
-               if (sxe->iter.data) {
-                       intern = (php_sxe_object *)zend_object_store_get_object(sxe->iter.data TSRMLS_CC);
+               if (!ZVAL_IS_UNDEF(&sxe->iter.data)) {
+                       intern = Z_SXEOBJ_P(&sxe->iter.data);
                        GET_NODE(intern, retnode)
                }
                return retnode;
@@ -245,9 +244,8 @@ next_iter:
 
 /* {{{ sxe_prop_dim_read()
  */
-static zval * sxe_prop_dim_read(zval *object, zval *member, zend_bool elements, zend_bool attribs, int type TSRMLS_DC)
+static zval *sxe_prop_dim_read(zval *object, zval *member, zend_bool elements, zend_bool attribs, int type, zval *rv TSRMLS_DC)
 {
-       zval           *return_value;
        php_sxe_object *sxe;
        char           *name;
        xmlNodePtr      node;
@@ -256,7 +254,7 @@ static zval * sxe_prop_dim_read(zval *object, zval *member, zend_bool elements,
        int             nodendx = 0;
        int             test = 0;
 
-       sxe = php_sxe_fetch_object(object TSRMLS_CC);
+       sxe = Z_SXEOBJ_P(object);
 
        if (!member || Z_TYPE_P(member) == IS_LONG) {
                if (sxe->iter.type != SXE_ITER_ATTRLIST) {
@@ -298,8 +296,7 @@ static zval * sxe_prop_dim_read(zval *object, zval *member, zend_bool elements,
                }
        }
 
-       MAKE_STD_ZVAL(return_value);
-       ZVAL_NULL(return_value);
+       ZVAL_UNDEF(rv);
 
        if (node) {
                if (attribs) {
@@ -308,7 +305,7 @@ static zval * sxe_prop_dim_read(zval *object, zval *member, zend_bool elements,
                                        while (attr && nodendx <= Z_LVAL_P(member)) {
                                                if ((!test || !xmlStrcmp(attr->name, sxe->iter.name)) && match_ns(sxe, (xmlNodePtr) attr, sxe->iter.nsprefix, sxe->iter.isprefix)) {
                                                        if (nodendx == Z_LVAL_P(member)) {
-                                                               _node_as_zval(sxe, (xmlNodePtr) attr, return_value, SXE_ITER_NONE, NULL, sxe->iter.nsprefix, sxe->iter.isprefix TSRMLS_CC);
+                                                               _node_as_zval(sxe, (xmlNodePtr) attr, rv, SXE_ITER_NONE, NULL, sxe->iter.nsprefix, sxe->iter.isprefix TSRMLS_CC);
                                                                break;
                                                        }
                                                        nodendx++;
@@ -318,7 +315,7 @@ static zval * sxe_prop_dim_read(zval *object, zval *member, zend_bool elements,
                                } else {
                                        while (attr) {
                                                if ((!test || !xmlStrcmp(attr->name, sxe->iter.name)) && !xmlStrcmp(attr->name, (xmlChar *)name) && match_ns(sxe, (xmlNodePtr) attr, sxe->iter.nsprefix, sxe->iter.isprefix)) {
-                                                       _node_as_zval(sxe, (xmlNodePtr) attr, return_value, SXE_ITER_NONE, NULL, sxe->iter.nsprefix, sxe->iter.isprefix TSRMLS_CC);
+                                                       _node_as_zval(sxe, (xmlNodePtr) attr, rv, SXE_ITER_NONE, NULL, sxe->iter.nsprefix, sxe->iter.isprefix TSRMLS_CC);
                                                        break;
                                                }
                                                attr = attr->next;
@@ -348,13 +345,13 @@ static zval * sxe_prop_dim_read(zval *object, zval *member, zend_bool elements,
                                        node = NULL;
                                }
                                if (node) {
-                                       _node_as_zval(sxe, node, return_value, SXE_ITER_NONE, NULL, sxe->iter.nsprefix, sxe->iter.isprefix TSRMLS_CC);
+                                       _node_as_zval(sxe, node, rv, SXE_ITER_NONE, NULL, sxe->iter.nsprefix, sxe->iter.isprefix TSRMLS_CC);
                                } else if (type == BP_VAR_W || type == BP_VAR_RW) {
                                        if (member && cnt < Z_LVAL_P(member)) {
                                                php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot add element %s number %ld when only %ld such elements exist", mynode->name, Z_LVAL_P(member), cnt);
                                        }
                                        node = xmlNewTextChild(mynode->parent, mynode->ns, mynode->name, NULL);
-                                       _node_as_zval(sxe, node, return_value, SXE_ITER_NONE, NULL, sxe->iter.nsprefix, sxe->iter.isprefix TSRMLS_CC);
+                                       _node_as_zval(sxe, node, rv, SXE_ITER_NONE, NULL, sxe->iter.nsprefix, sxe->iter.isprefix TSRMLS_CC);
                                }
                        } else {
 #if SXE_ELEMENT_BY_NAME
@@ -363,43 +360,40 @@ static zval * sxe_prop_dim_read(zval *object, zval *member, zend_bool elements,
                                GET_NODE(sxe, node);
                                node = sxe_get_element_by_name(sxe, node, &name, &newtype TSRMLS_CC);
                                if (node) {
-                                       _node_as_zval(sxe, node, return_value, newtype, name, sxe->iter.nsprefix, sxe->iter.isprefix TSRMLS_CC);
+                                       _node_as_zval(sxe, node, rv, newtype, name, sxe->iter.nsprefix, sxe->iter.isprefix TSRMLS_CC);
                                }
 #else
-                               _node_as_zval(sxe, node, return_value, SXE_ITER_ELEMENT, name, sxe->iter.nsprefix, sxe->iter.isprefix TSRMLS_CC);
+                               _node_as_zval(sxe, node, rv, SXE_ITER_ELEMENT, name, sxe->iter.nsprefix, sxe->iter.isprefix TSRMLS_CC);
 #endif
                        }
                }
        }
 
-       Z_SET_REFCOUNT_P(return_value, 0);
-       Z_UNSET_ISREF_P(return_value);
-
        if (member == &tmp_zv) {
                zval_dtor(&tmp_zv);
        }
-       if (Z_TYPE_P(return_value) == IS_NULL) {
-               FREE_ZVAL(return_value);
-               return_value = &EG(uninitialized_zval);
+
+       if (ZVAL_IS_NULL(rv)) {
+               return &EG(uninitialized_zval);
        }
 
-       return return_value;
+       return rv;
 }
 /* }}} */
 
 /* {{{ sxe_property_read()
  */
-static zval * sxe_property_read(zval *object, zval *member, int type, const zend_literal *key TSRMLS_DC)
+static zval *sxe_property_read(zval *object, zval *member, int type, const zend_literal *key, zval *rv TSRMLS_DC)
 {
-       return sxe_prop_dim_read(object, member, 1, 0, type TSRMLS_CC);
+       return sxe_prop_dim_read(object, member, 1, 0, type, rv TSRMLS_CC);
 }
 /* }}} */
 
 /* {{{ sxe_dimension_read()
  */
-static zval * sxe_dimension_read(zval *object, zval *offset, int type TSRMLS_DC)
+static zval *sxe_dimension_read(zval *object, zval *offset, int type, zval *rv TSRMLS_DC)
 {
-       return sxe_prop_dim_read(object, offset, 0, 1, type TSRMLS_CC);
+       return sxe_prop_dim_read(object, offset, 0, 1, type, rv TSRMLS_CC);
 }
 /* }}} */
 
@@ -466,7 +460,7 @@ static int sxe_prop_dim_write(zval *object, zval *member, zval *value, zend_bool
        int                             retval = SUCCESS;
        zval            tmp_zv, trim_zv, value_copy;
 
-       sxe = php_sxe_fetch_object(object TSRMLS_CC);
+       sxe = Z_SXEOBJ_P(object);
 
        if (!member || Z_TYPE_P(member) == IS_LONG) {
                if (sxe->iter.type != SXE_ITER_ATTRLIST) {
@@ -547,7 +541,8 @@ static int sxe_prop_dim_write(zval *object, zval *member, zval *value, zend_bool
                        case IS_OBJECT:
                                if (Z_OBJCE_P(value) == sxe_class_entry) {
                                        value = sxe_get_value(value TSRMLS_CC);
-                                       INIT_PZVAL(value);
+                                       //???
+                                       //INIT_PZVAL(value);
                                        new_value = 1;
                                        break;
                                }
@@ -669,10 +664,10 @@ next_iter:
                *pnewnode = newnode;
        }
        if (value && value == &value_copy) {
-               zval_dtor(value);
+               zval_ptr_dtor(value);
        }
        if (new_value) {
-               zval_ptr_dtor(&value);
+               zval_ptr_dtor(value);
        }
        return retval;
 }
@@ -694,15 +689,15 @@ static void sxe_dimension_write(zval *object, zval *offset, zval *value TSRMLS_D
 }
 /* }}} */
 
-static zval** sxe_property_get_adr(zval *object, zval *member, int fetch_type, const zend_literal *key TSRMLS_DC) /* {{{ */
+static zval *sxe_property_get_adr(zval *object, zval *member, int fetch_type, const zend_literal *key TSRMLS_DC) /* {{{ */
 {
        php_sxe_object *sxe;
        xmlNodePtr      node;
-       zval           *return_value;
+       zval            ret;
        char           *name;
        SXE_ITER        type;
 
-       sxe = php_sxe_fetch_object(object TSRMLS_CC);
+       sxe = Z_SXEOBJ_P(object);
 
        GET_NODE(sxe, node);
        convert_to_string(member);
@@ -717,15 +712,15 @@ static zval** sxe_property_get_adr(zval *object, zval *member, int fetch_type, c
        type = SXE_ITER_NONE;
        name = NULL;
 
-       MAKE_STD_ZVAL(return_value);
-       _node_as_zval(sxe, node, return_value, type, name, sxe->iter.nsprefix, sxe->iter.isprefix TSRMLS_CC);
+       _node_as_zval(sxe, node, &ret, type, name, sxe->iter.nsprefix, sxe->iter.isprefix TSRMLS_CC);
 
-       sxe = php_sxe_fetch_object(return_value TSRMLS_CC);
-       if (sxe->tmp) {
+       sxe = Z_SXEOBJ_P(&ret);
+       if (!ZVAL_IS_UNDEF(&sxe->tmp)) {
                zval_ptr_dtor(&sxe->tmp);
        }
-       sxe->tmp = return_value;
-       Z_SET_ISREF_P(return_value);
+
+       ZVAL_COPY_VALUE(&sxe->tmp, &ret);
+       //???? Z_SET_ISREF_P(return_value);
 
        return &sxe->tmp;
 }
@@ -749,7 +744,7 @@ static int sxe_prop_dim_exists(zval *object, zval *member, int check_empty, zend
                convert_to_string(member);
        }
 
-       sxe = php_sxe_fetch_object(object TSRMLS_CC);
+       sxe = Z_SXEOBJ_P(object);
 
        GET_NODE(sxe, node);
 
@@ -879,7 +874,7 @@ static void sxe_prop_dim_delete(zval *object, zval *member, zend_bool elements,
                convert_to_string(member);
        }
 
-       sxe = php_sxe_fetch_object(object TSRMLS_CC);
+       sxe = Z_SXEOBJ_P(object);
 
        GET_NODE(sxe, node);
 
@@ -985,13 +980,13 @@ static void sxe_dimension_delete(zval *object, zval *offset TSRMLS_DC)
 }
 /* }}} */
 
-static inline char * sxe_xmlNodeListGetString(xmlDocPtr doc, xmlNodePtr list, int inLine) /* {{{ */
+static inline zend_string * sxe_xmlNodeListGetString(xmlDocPtr doc, xmlNodePtr list, int inLine) /* {{{ */
 {
        xmlChar *tmp = xmlNodeListGetString(doc, list, inLine);
-       char    *res;
+       zend_string *res;
        
        if (tmp) {
-               res = estrdup((char*)tmp);
+               res = STR_INIT((char*)tmp, strlen((char *)tmp), 0);
                xmlFree(tmp);
        } else {
                res = STR_EMPTY_ALLOC();
@@ -1003,17 +998,15 @@ static inline char * sxe_xmlNodeListGetString(xmlDocPtr doc, xmlNodePtr list, in
 
 /* {{{ _get_base_node_value()
  */
-static void _get_base_node_value(php_sxe_object *sxe_ref, xmlNodePtr node, zval **value, xmlChar *nsprefix, int isprefix TSRMLS_DC)
+static void _get_base_node_value(php_sxe_object *sxe_ref, xmlNodePtr node, zval *value, xmlChar *nsprefix, int isprefix TSRMLS_DC)
 {
        php_sxe_object *subnode;
        xmlChar        *contents;
 
-       MAKE_STD_ZVAL(*value);
-
        if (node->children && node->children->type == XML_TEXT_NODE && !xmlIsBlankNode(node->children)) {
                contents = xmlNodeListGetString(node->doc, node->children, 1);
                if (contents) {
-                       ZVAL_STRING(*value, (char *)contents, 1);
+                       ZVAL_STRING(value, (char *)contents);
                        xmlFree(contents);
                }
        } else {
@@ -1026,8 +1019,7 @@ static void _get_base_node_value(php_sxe_object *sxe_ref, xmlNodePtr node, zval
                }
                php_libxml_increment_node_ptr((php_libxml_node_object *)subnode, node, NULL TSRMLS_CC);
 
-               (*value)->type = IS_OBJECT;
-               (*value)->value.obj = php_sxe_register_object(subnode TSRMLS_CC);
+               ZVAL_OBJ(value, php_sxe_register_object(subnode TSRMLS_CC));
                /*zval_add_ref(value);*/
        }
 }
@@ -1035,33 +1027,33 @@ static void _get_base_node_value(php_sxe_object *sxe_ref, xmlNodePtr node, zval
 
 static void sxe_properties_add(HashTable *rv, char *name, int namelen, zval *value TSRMLS_DC) /* {{{ */
 {
-       zval  **data_ptr;
-       zval  *newptr;
-       ulong h = zend_hash_func(name, namelen);
+       zval  *data_ptr;
+       zval  newptr;
 
-       if (zend_hash_quick_find(rv, name, namelen, h, (void **) &data_ptr) == SUCCESS) {
-               if (Z_TYPE_PP(data_ptr) == IS_ARRAY) {
-                       zend_hash_next_index_insert(Z_ARRVAL_PP(data_ptr), &value, sizeof(zval *), NULL);
+       if ((data_ptr = zend_hash_str_find(rv, name, namelen)) != NULL) {
+               if (Z_TYPE_P(data_ptr) == IS_ARRAY) {
+                       zend_hash_next_index_insert(Z_ARRVAL_P(data_ptr), value);
                } else {
-                       MAKE_STD_ZVAL(newptr);
-                       array_init(newptr);
+                       array_init(&newptr);
 
-                       zval_add_ref(data_ptr);
-                       zend_hash_next_index_insert(Z_ARRVAL_P(newptr), data_ptr, sizeof(zval *), NULL);
-                       zend_hash_next_index_insert(Z_ARRVAL_P(newptr), &value, sizeof(zval *), NULL);
+                       if (Z_REFCOUNTED_P(data_ptr)) {
+                               Z_ADDREF_P(data_ptr);
+                       }
+                       zend_hash_next_index_insert(Z_ARRVAL(newptr), data_ptr);
+                       zend_hash_next_index_insert(Z_ARRVAL(newptr), value);
 
-                       zend_hash_quick_update(rv, name, namelen, h, &newptr, sizeof(zval *), NULL);
+                       zend_hash_str_update(rv, name, namelen, &newptr);
                }
        } else {
-               zend_hash_quick_update(rv, name, namelen, h, &value, sizeof(zval *), NULL);
+               zend_hash_str_update(rv, name, namelen, value);
        }
 }
 /* }}} */
 
-static HashTable * sxe_get_prop_hash(zval *object, int is_debug TSRMLS_DC) /* {{{ */
+static HashTable *sxe_get_prop_hash(zval *object, int is_debug TSRMLS_DC) /* {{{ */
 {
-       zval            *value;
-       zval            *zattr;
+       zval            value;
+       zval            zattr;
        HashTable       *rv;
        php_sxe_object  *sxe;
        char            *name;
@@ -1069,18 +1061,17 @@ static HashTable * sxe_get_prop_hash(zval *object, int is_debug TSRMLS_DC) /* {{
        xmlAttrPtr       attr;
        int              namelen;
        int              test;
-       char             use_iter;
-       zval            *iter_data = NULL;
+       char                     use_iter;
+       zval             iter_data;
 
        use_iter = 0;
 
-       sxe = php_sxe_fetch_object(object TSRMLS_CC);
+       sxe = Z_SXEOBJ_P(object);
 
        if (is_debug) {
                ALLOC_HASHTABLE(rv);
                zend_hash_init(rv, 0, NULL, ZVAL_PTR_DTOR, 0);
-       }
-       else if (sxe->properties) {
+       } else if (sxe->properties) {
                zend_hash_clean(sxe->properties);
                rv = sxe->properties;
        } else {
@@ -1099,19 +1090,17 @@ static HashTable * sxe_get_prop_hash(zval *object, int is_debug TSRMLS_DC) /* {{
                }
                if (!node || node->type != XML_ENTITY_DECL) {
                        attr = node ? (xmlAttrPtr)node->properties : NULL;
-                       zattr = NULL;
+                       ZVAL_UNDEF(&zattr);
                        test = sxe->iter.name && sxe->iter.type == SXE_ITER_ATTRLIST;
                        while (attr) {
                                if ((!test || !xmlStrcmp(attr->name, sxe->iter.name)) && match_ns(sxe, (xmlNodePtr)attr, sxe->iter.nsprefix, sxe->iter.isprefix)) {
-                                       MAKE_STD_ZVAL(value);
-                                       ZVAL_STRING(value, sxe_xmlNodeListGetString((xmlDocPtr) sxe->document->ptr, attr->children, 1), 0);
-                                       namelen = xmlStrlen(attr->name) + 1;
-                                       if (!zattr) {
-                                               MAKE_STD_ZVAL(zattr);
-                                               array_init(zattr);
-                                               sxe_properties_add(rv, "@attributes", sizeof("@attributes"), zattr TSRMLS_CC);
+                                       ZVAL_STR(&value, sxe_xmlNodeListGetString((xmlDocPtr) sxe->document->ptr, attr->children, 1));
+                                       namelen = xmlStrlen(attr->name);
+                                       if (ZVAL_IS_UNDEF(&zattr)) {
+                                               array_init(&zattr);
+                                               sxe_properties_add(rv, "@attributes", sizeof("@attributes") - 1, &zattr TSRMLS_CC);
                                        }
-                                       add_assoc_zval_ex(zattr, (char*)attr->name, namelen, value);
+                                       add_assoc_zval_ex(&zattr, (char*)attr->name, namelen, &value);
                                }
                                attr = attr->next;
                        }
@@ -1123,17 +1112,16 @@ static HashTable * sxe_get_prop_hash(zval *object, int is_debug TSRMLS_DC) /* {{
 
        if (node && sxe->iter.type != SXE_ITER_ATTRLIST) {
                if (node->type == XML_ATTRIBUTE_NODE) {
-                       MAKE_STD_ZVAL(value);
-                       ZVAL_STRING(value, sxe_xmlNodeListGetString(node->doc, node->children, 1), 0);
-                       zend_hash_next_index_insert(rv, &value, sizeof(zval *), NULL);
+                       ZVAL_STR(&value, sxe_xmlNodeListGetString(node->doc, node->children, 1));
+                       zend_hash_next_index_insert(rv, &value);
                        node = NULL;
                } else if (sxe->iter.type != SXE_ITER_CHILD) {
 
                        if ( !node->children || !node->parent || node->children->next || node->children->children || node->parent->children == node->parent->last ) {
                                node = node->children;
                        } else {
-                               iter_data = sxe->iter.data;
-                               sxe->iter.data = NULL;
+                               ZVAL_COPY_VALUE(&iter_data, &sxe->iter.data);
+                               ZVAL_UNDEF(&sxe->iter.data);
 
                                node = php_sxe_reset_iterator(sxe, 0 TSRMLS_CC);
 
@@ -1149,9 +1137,8 @@ static HashTable * sxe_get_prop_hash(zval *object, int is_debug TSRMLS_DC) /* {{
                                        const xmlChar *cur = node->content;
                                        
                                        if (*cur != 0) {
-                                               MAKE_STD_ZVAL(value);
-                                               ZVAL_STRING(value, sxe_xmlNodeListGetString(node->doc, node, 1), 0);
-                                               zend_hash_next_index_insert(rv, &value, sizeof(zval *), NULL);
+                                               ZVAL_STR(&value, sxe_xmlNodeListGetString(node->doc, node, 1));
+                                               zend_hash_next_index_insert(rv, &value);
                                        }
                                        goto next_iter;
                                }
@@ -1165,18 +1152,18 @@ static HashTable * sxe_get_prop_hash(zval *object, int is_debug TSRMLS_DC) /* {{
                        if (!name) {
                                goto next_iter;
                        } else {
-                               namelen = xmlStrlen(node->name) + 1;
+                               namelen = xmlStrlen(node->name);
                        }
 
                        _get_base_node_value(sxe, node, &value, sxe->iter.nsprefix, sxe->iter.isprefix TSRMLS_CC);
 
                        if ( use_iter ) {
-                               zend_hash_next_index_insert(rv, &value, sizeof(zval *), NULL);
+                               zend_hash_next_index_insert(rv, &value);
                        } else {
-                               sxe_properties_add(rv, name, namelen, value TSRMLS_CC);
+                               sxe_properties_add(rv, name, namelen, &value TSRMLS_CC);
                        }
 next_iter:
-                       if ( use_iter ) {
+                       if (use_iter) {
                                node = php_sxe_iterator_fetch(sxe, node->next, 0 TSRMLS_CC);
                        } else {
                                node = node->next;
@@ -1184,20 +1171,20 @@ next_iter:
                }
        }
 
-       if ( use_iter ) {
-               if (sxe->iter.data) {
+       if (use_iter) {
+               if (!ZVAL_IS_UNDEF(&sxe->iter.data)) {
                        zval_ptr_dtor(&sxe->iter.data);
                }
-               sxe->iter.data = iter_data;
+               ZVAL_COPY_VALUE(&sxe->iter.data, &iter_data);
        }
 
        return rv;
 }
 /* }}} */
 
-static HashTable * sxe_get_gc(zval *object, zval ***table, int *n TSRMLS_DC) /* {{{ */ {
-       php_sxe_object  *sxe;
-       sxe = php_sxe_fetch_object(object TSRMLS_CC);
+static HashTable *sxe_get_gc(zval *object, zval **table, int *n TSRMLS_DC) /* {{{ */ {
+       php_sxe_object *sxe;
+       sxe = Z_SXEOBJ_P(object);
        
        *table = NULL;
        *n = 0;
@@ -1205,7 +1192,7 @@ static HashTable * sxe_get_gc(zval *object, zval ***table, int *n TSRMLS_DC) /*
 }
 /* }}} */
 
-static HashTable * sxe_get_properties(zval *object TSRMLS_DC) /* {{{ */
+static HashTable *sxe_get_properties(zval *object TSRMLS_DC) /* {{{ */
 {
        return sxe_get_prop_hash(object, 0 TSRMLS_CC);
 }
@@ -1223,8 +1210,8 @@ static int sxe_objects_compare(zval *object1, zval *object2 TSRMLS_DC) /* {{{ */
        php_sxe_object *sxe1;
        php_sxe_object *sxe2;
 
-       sxe1 = php_sxe_fetch_object(object1 TSRMLS_CC);
-       sxe2 = php_sxe_fetch_object(object2 TSRMLS_CC);
+       sxe1 = Z_SXEOBJ_P(object1);
+       sxe2 = Z_SXEOBJ_P(object2);
 
        if (sxe1->node == NULL) {
                if (sxe2->node) {
@@ -1244,7 +1231,7 @@ static int sxe_objects_compare(zval *object1, zval *object2 TSRMLS_DC) /* {{{ */
 SXE_METHOD(xpath)
 {
        php_sxe_object    *sxe;
-       zval              *value;
+       zval               value;
        char              *query;
        int                query_len;
        int                i;
@@ -1258,7 +1245,7 @@ SXE_METHOD(xpath)
                return;
        }
 
-       sxe = php_sxe_fetch_object(getThis() TSRMLS_CC);
+       sxe = Z_SXEOBJ_P(getThis());
 
        if (sxe->iter.type == SXE_ITER_ATTRLIST) {
                return; /* attributes don't have attributes */
@@ -1304,21 +1291,20 @@ SXE_METHOD(xpath)
                for (i = 0; i < result->nodeNr; ++i) {
                        nodeptr = result->nodeTab[i];
                        if (nodeptr->type == XML_TEXT_NODE || nodeptr->type == XML_ELEMENT_NODE || nodeptr->type == XML_ATTRIBUTE_NODE) {
-                               MAKE_STD_ZVAL(value);
                                /**
                                 * Detect the case where the last selector is text(), simplexml
                                 * always accesses the text() child by default, therefore we assign
                                 * to the parent node.
                                 */
                                if (nodeptr->type == XML_TEXT_NODE) {
-                                       _node_as_zval(sxe, nodeptr->parent, value, SXE_ITER_NONE, NULL, NULL, 0 TSRMLS_CC);
+                                       _node_as_zval(sxe, nodeptr->parent, &value, SXE_ITER_NONE, NULL, NULL, 0 TSRMLS_CC);
                                } else if (nodeptr->type == XML_ATTRIBUTE_NODE) {
-                                       _node_as_zval(sxe, nodeptr->parent, value, SXE_ITER_ATTRLIST, (char*)nodeptr->name, nodeptr->ns ? (xmlChar *)nodeptr->ns->href : NULL, 0 TSRMLS_CC);
+                                       _node_as_zval(sxe, nodeptr->parent, &value, SXE_ITER_ATTRLIST, (char*)nodeptr->name, nodeptr->ns ? (xmlChar *)nodeptr->ns->href : NULL, 0 TSRMLS_CC);
                                } else {
-                                       _node_as_zval(sxe, nodeptr, value, SXE_ITER_NONE, NULL, NULL, 0 TSRMLS_CC);
+                                       _node_as_zval(sxe, nodeptr, &value, SXE_ITER_NONE, NULL, NULL, 0 TSRMLS_CC);
                                }
 
-                               add_next_index_zval(return_value, value);
+                               add_next_index_zval(return_value, &value);
                        }
                }
        }
@@ -1339,7 +1325,7 @@ SXE_METHOD(registerXPathNamespace)
                return;
        }
 
-       sxe = php_sxe_fetch_object(getThis() TSRMLS_CC);
+       sxe = Z_SXEOBJ_P(getThis());
        if (!sxe->xpath) {
                sxe->xpath = xmlXPathNewContext((xmlDocPtr) sxe->document->ptr);
        }
@@ -1373,7 +1359,7 @@ SXE_METHOD(asXML)
                        RETURN_FALSE;
                }
 
-               sxe = php_sxe_fetch_object(getThis() TSRMLS_CC);
+               sxe = Z_SXEOBJ_P(getThis());
                GET_NODE(sxe, node);
                node = php_sxe_get_first_node(sxe, node TSRMLS_CC);
 
@@ -1402,14 +1388,14 @@ SXE_METHOD(asXML)
                }
        }
 
-       sxe = php_sxe_fetch_object(getThis() TSRMLS_CC);
+       sxe = Z_SXEOBJ_P(getThis());
        GET_NODE(sxe, node);
        node = php_sxe_get_first_node(sxe, node TSRMLS_CC);
 
        if (node) {
                if (node->parent && (XML_DOCUMENT_NODE == node->parent->type)) {
                        xmlDocDumpMemoryEnc((xmlDocPtr) sxe->document->ptr, &strval, &strval_len, ((xmlDocPtr) sxe->document->ptr)->encoding);
-                       RETVAL_STRINGL((char *)strval, strval_len, 1);
+                       RETVAL_STRINGL((char *)strval, strval_len);
                        xmlFree(strval);
                } else {
                        /* Should we be passing encoding information instead of NULL? */
@@ -1422,9 +1408,9 @@ SXE_METHOD(asXML)
                        xmlNodeDumpOutput(outbuf, (xmlDocPtr) sxe->document->ptr, node, 0, 0, ((xmlDocPtr) sxe->document->ptr)->encoding);
                        xmlOutputBufferFlush(outbuf);
 #ifdef LIBXML2_NEW_BUFFER
-                       RETVAL_STRINGL((char *)xmlOutputBufferGetContent(outbuf), xmlOutputBufferGetSize(outbuf), 1);
+                       RETVAL_STRINGL((char *)xmlOutputBufferGetContent(outbuf), xmlOutputBufferGetSize(outbuf));
 #else
-                       RETVAL_STRINGL((char *)outbuf->buffer->content, outbuf->buffer->use, 1);
+                       RETVAL_STRINGL((char *)outbuf->buffer->content, outbuf->buffer->use);
 #endif
                        xmlOutputBufferClose(outbuf);
                }
@@ -1439,7 +1425,7 @@ SXE_METHOD(asXML)
 static inline void sxe_add_namespace_name(zval *return_value, xmlNsPtr ns) /* {{{ */
 {
        char *prefix = SXE_NS_PREFIX(ns);
-       if (zend_hash_exists(Z_ARRVAL_P(return_value), prefix, strlen(prefix) + 1) == 0) {
+       if (zend_hash_str_exists(Z_ARRVAL_P(return_value), prefix, strlen(prefix)) == 0) {
                add_assoc_string(return_value, prefix, (char*)ns->href, 1);
        }
 }
@@ -1486,7 +1472,7 @@ SXE_METHOD(getNamespaces)
 
        array_init(return_value);
 
-       sxe = php_sxe_fetch_object(getThis() TSRMLS_CC);
+       sxe = Z_SXEOBJ_P(getThis());
        GET_NODE(sxe, node);
        node = php_sxe_get_first_node(sxe, node TSRMLS_CC);
 
@@ -1535,7 +1521,7 @@ SXE_METHOD(getDocNamespaces)
 
        array_init(return_value);
 
-       sxe = php_sxe_fetch_object(getThis() TSRMLS_CC);
+       sxe = Z_SXEOBJ_P(getThis());
        if(from_root){
                node = xmlDocGetRootElement((xmlDocPtr)sxe->document->ptr);
        }else{
@@ -1560,7 +1546,7 @@ SXE_METHOD(children)
                return;
        }
 
-       sxe = php_sxe_fetch_object(getThis() TSRMLS_CC);
+       sxe = Z_SXEOBJ_P(getThis());
 
        if (sxe->iter.type == SXE_ITER_ATTRLIST) {
                return; /* attributes don't have attributes */
@@ -1582,13 +1568,13 @@ SXE_METHOD(getName)
        xmlNodePtr      node;
        int             namelen;
 
-       sxe = php_sxe_fetch_object(getThis() TSRMLS_CC);
+       sxe = Z_SXEOBJ_P(getThis());
 
        GET_NODE(sxe, node);
        node = php_sxe_get_first_node(sxe, node TSRMLS_CC);
        if (node) {
                namelen = xmlStrlen(node->name);
-               RETURN_STRINGL((char*)node->name, namelen, 1);
+               RETURN_STRINGL((char*)node->name, namelen);
        } else {
                RETURN_EMPTY_STRING();
        }
@@ -1609,7 +1595,7 @@ SXE_METHOD(attributes)
                return;
        }
 
-       sxe = php_sxe_fetch_object(getThis() TSRMLS_CC);
+       sxe = Z_SXEOBJ_P(getThis());
        GET_NODE(sxe, node);
 
        if (sxe->iter.type == SXE_ITER_ATTRLIST) {
@@ -1643,7 +1629,7 @@ SXE_METHOD(addChild)
                return;
        }
 
-       sxe = php_sxe_fetch_object(getThis() TSRMLS_CC);
+       sxe = Z_SXEOBJ_P(getThis());
        GET_NODE(sxe, node);
 
        if (sxe->iter.type == SXE_ITER_ATTRLIST) {
@@ -1709,7 +1695,7 @@ SXE_METHOD(addAttribute)
                return;
        }
 
-       sxe = php_sxe_fetch_object(getThis() TSRMLS_CC);
+       sxe = Z_SXEOBJ_P(getThis());
        GET_NODE(sxe, node);
 
        node = php_sxe_get_first_node(sxe, node TSRMLS_CC);
@@ -1766,12 +1752,12 @@ SXE_METHOD(addAttribute)
 static int cast_object(zval *object, int type, char *contents TSRMLS_DC)
 {
        if (contents) {
-               ZVAL_STRINGL(object, contents, strlen(contents), 1);
+               ZVAL_STRINGL(object, contents, strlen(contents));
        } else {
                ZVAL_NULL(object);
        }
-       Z_SET_REFCOUNT_P(object, 1);
-       Z_UNSET_ISREF_P(object);
+       //???? Z_SET_REFCOUNT_P(object, 1);
+       //Z_UNSET_ISREF_P(object);
 
        switch (type) {
                case IS_STRING:
@@ -1798,17 +1784,16 @@ static int cast_object(zval *object, int type, char *contents TSRMLS_DC)
 static int sxe_object_cast(zval *readobj, zval *writeobj, int type TSRMLS_DC)
 {
        php_sxe_object *sxe;
-       xmlChar           *contents = NULL;
+       xmlChar        *contents = NULL;
        xmlNodePtr          node;
        int rv;
        HashTable      *prop_hash;
 
-       sxe = php_sxe_fetch_object(readobj TSRMLS_CC);
+       sxe = Z_SXEOBJ_P(readobj);
 
        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(prop_hash) > 0);
                zend_hash_destroy(prop_hash);
                efree(prop_hash);
@@ -1835,8 +1820,7 @@ static int sxe_object_cast(zval *readobj, zval *writeobj, int type TSRMLS_DC)
        }
 
        if (readobj == writeobj) {
-               INIT_PZVAL(writeobj);
-               zval_dtor(readobj);
+               zval_ptr_dtor(readobj);
        }
 
        rv = cast_object(writeobj, type, (char *)contents TSRMLS_CC);
@@ -1844,6 +1828,7 @@ static int sxe_object_cast(zval *readobj, zval *writeobj, int type TSRMLS_DC)
        if (contents) {
                xmlFree(contents);
        }
+
        return rv;
 }
 /* }}} */
@@ -1852,12 +1837,10 @@ static int sxe_object_cast(zval *readobj, zval *writeobj, int type TSRMLS_DC)
    Returns the string content */
 SXE_METHOD(__toString)
 {
-       zval           *result;
-
-       ALLOC_INIT_ZVAL(result);
+       zval           result;
 
-       if (sxe_object_cast(getThis(), result, IS_STRING TSRMLS_CC) == SUCCESS) {
-               RETURN_ZVAL(result, 1, 1);
+       if (sxe_object_cast(getThis(), &result, IS_STRING TSRMLS_CC) == SUCCESS) {
+               RETURN_ZVAL(&result, 0, 0);
        } else {
                zval_ptr_dtor(&result);
                RETURN_EMPTY_STRING();
@@ -1867,13 +1850,13 @@ SXE_METHOD(__toString)
 
 static int php_sxe_count_elements_helper(php_sxe_object *sxe, long *count TSRMLS_DC) /* {{{ */
 {
-       xmlNodePtr       node;
-       zval            *data;
+       xmlNodePtr      node;
+       zval            data;
 
        *count = 0;
 
-       data = sxe->iter.data;
-       sxe->iter.data = NULL;
+       ZVAL_COPY_VALUE(&data, &sxe->iter.data);
+       ZVAL_UNDEF(&sxe->iter.data);
 
        node = php_sxe_reset_iterator(sxe, 0 TSRMLS_CC);
 
@@ -1883,10 +1866,10 @@ static int php_sxe_count_elements_helper(php_sxe_object *sxe, long *count TSRMLS
                node = php_sxe_iterator_fetch(sxe, node->next, 0 TSRMLS_CC);
        }
 
-       if (sxe->iter.data) {
+       if (!ZVAL_IS_UNDEF(&sxe->iter.data)) {
                zval_ptr_dtor(&sxe->iter.data);
        }
-       sxe->iter.data = data;
+       ZVAL_COPY_VALUE(&sxe->iter.data, &data);
 
        return SUCCESS;
 }
@@ -1895,18 +1878,17 @@ static int php_sxe_count_elements_helper(php_sxe_object *sxe, long *count TSRMLS
 static int sxe_count_elements(zval *object, long *count TSRMLS_DC) /* {{{ */
 {
        php_sxe_object  *intern;
-       intern = php_sxe_fetch_object(object TSRMLS_CC);
+       intern = Z_SXEOBJ_P(object);
        if (intern->fptr_count) {
-               zval *rv;
-               zend_call_method_with_0_params(&object, intern->zo.ce, &intern->fptr_count, "count", &rv);
-               if (rv) {
-                       if (intern->tmp) {
+               zval rv;
+               zend_call_method_with_0_params(object, intern->zo.ce, &intern->fptr_count, "count", &rv);
+               if (!ZVAL_IS_UNDEF(&rv)) {
+                       if (!ZVAL_IS_UNDEF(&intern->tmp)) {
                                zval_ptr_dtor(&intern->tmp);
                        }
-                       MAKE_STD_ZVAL(intern->tmp);
-                       ZVAL_ZVAL(intern->tmp, rv, 1, 1);
-                       convert_to_long(intern->tmp);
-                       *count = (long) Z_LVAL_P(intern->tmp);
+                       ZVAL_ZVAL(&intern->tmp, &rv, 0, 0);
+                       convert_to_long(&intern->tmp);
+                       *count = (long)Z_LVAL(intern->tmp);
                        return SUCCESS;
                }
                return FAILURE;
@@ -1920,7 +1902,7 @@ static int sxe_count_elements(zval *object, long *count TSRMLS_DC) /* {{{ */
 SXE_METHOD(count)
 {
        long count = 0;
-       php_sxe_object *sxe = php_sxe_fetch_object(getThis() TSRMLS_CC);
+       php_sxe_object *sxe = Z_SXEOBJ_P(getThis());
 
        if (zend_parse_parameters_none() == FAILURE) {
                return;
@@ -1934,17 +1916,21 @@ SXE_METHOD(count)
 
 static zval *sxe_get_value(zval *z TSRMLS_DC) /* {{{ */
 {
+#if 0
+       ?????
        zval *retval;
 
        MAKE_STD_ZVAL(retval);
 
-       if (sxe_object_cast(z, retval, IS_STRING TSRMLS_CC)==FAILURE) {
+       if (sxe_object_cast(z, retval, IS_STRING TSRMLS_CC) == FAILURE) {
                zend_error(E_ERROR, "Unable to cast node to string");
                /* FIXME: Should not be fatal */
        }
 
        Z_SET_REFCOUNT_P(retval, 0);
        return retval;
+#endif
+       return NULL;
 }
 /* }}} */
 
@@ -1978,10 +1964,10 @@ static zend_object_handlers sxe_object_handlers = { /* {{{ */
 
 /* {{{ sxe_object_clone()
  */
-static void
-sxe_object_clone(void *object, void **clone_ptr TSRMLS_DC)
+static zend_object *
+sxe_object_clone(zend_object *object TSRMLS_DC)
 {
-       php_sxe_object *sxe = (php_sxe_object *) object;
+       php_sxe_object *sxe = php_sxe_fetch_object(object);
        php_sxe_object *clone;
        xmlNodePtr nodep = NULL;
        xmlDocPtr docp = NULL;
@@ -2008,23 +1994,22 @@ sxe_object_clone(void *object, void **clone_ptr TSRMLS_DC)
 
        php_libxml_increment_node_ptr((php_libxml_node_object *)clone, nodep, NULL TSRMLS_CC);
 
-       *clone_ptr = (void *) clone;
+       return &clone->zo;
 }
 /* }}} */
 
 /* {{{ sxe_object_dtor()
  */
-static void sxe_object_dtor(void *object, zend_object_handle handle TSRMLS_DC)
+static void sxe_object_dtor(void *object TSRMLS_DC)
 {
        /* dtor required to cleanup iterator related data properly */
-
        php_sxe_object *sxe;
 
-       sxe = (php_sxe_object *) object;
+       sxe = php_sxe_fetch_object(object);
 
-       if (sxe->iter.data) {
+       if (!ZVAL_IS_UNDEF(&sxe->iter.data)) {
                zval_ptr_dtor(&sxe->iter.data);
-               sxe->iter.data = NULL;
+               ZVAL_UNDEF(&sxe->iter.data);
        }
 
        if (sxe->iter.name) {
@@ -2035,9 +2020,9 @@ static void sxe_object_dtor(void *object, zend_object_handle handle TSRMLS_DC)
                xmlFree(sxe->iter.nsprefix);
                sxe->iter.nsprefix = NULL;
        }
-       if (sxe->tmp) {
+       if (!ZVAL_IS_UNDEF(&sxe->tmp)) {
                zval_ptr_dtor(&sxe->tmp);
-               sxe->tmp = NULL;
+               ZVAL_UNDEF(&sxe->tmp);
        }
 }
 /* }}} */
@@ -2048,21 +2033,9 @@ static void sxe_object_free_storage(void *object TSRMLS_DC)
 {
        php_sxe_object *sxe;
 
-       sxe = (php_sxe_object *) object;
+       sxe = php_sxe_fetch_object(object);
 
-#if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION == 1 && PHP_RELEASE_VERSION > 2) || (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION > 1) || (PHP_MAJOR_VERSION > 5)
        zend_object_std_dtor(&sxe->zo TSRMLS_CC);
-#else
-       if (sxe->zo.guards) {
-               zend_hash_destroy(sxe->zo.guards);
-               FREE_HASHTABLE(sxe->zo.guards);
-       }
-
-       if (sxe->zo.properties) {
-               zend_hash_destroy(sxe->zo.properties);
-               FREE_HASHTABLE(sxe->zo.properties);
-       }
-#endif
 
        php_libxml_node_decrement_resource((php_libxml_node_object *)sxe TSRMLS_CC);
 
@@ -2075,7 +2048,7 @@ static void sxe_object_free_storage(void *object TSRMLS_DC)
                FREE_HASHTABLE(sxe->properties);
        }
 
-       efree(object);
+       efree(sxe);
 }
 /* }}} */
 
@@ -2084,25 +2057,17 @@ static void sxe_object_free_storage(void *object TSRMLS_DC)
 static php_sxe_object* php_sxe_object_new(zend_class_entry *ce TSRMLS_DC)
 {
        php_sxe_object *intern;
-       zend_class_entry     *parent = ce;
+       zend_class_entry *parent = ce;
        int inherited = 0;
 
-       intern = ecalloc(1, sizeof(php_sxe_object));
+       intern = ecalloc(1, sizeof(php_sxe_object) + sizeof(zval) * (parent->default_properties_count - 1));
 
        intern->iter.type = SXE_ITER_NONE;
        intern->iter.nsprefix = NULL;
        intern->iter.name = NULL;
        intern->fptr_count = NULL;
 
-#if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION == 1 && PHP_RELEASE_VERSION > 2) || (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION > 1) || (PHP_MAJOR_VERSION > 5)
        zend_object_std_init(&intern->zo, ce TSRMLS_CC);
-#else
-       ALLOC_HASHTABLE(intern->zo.properties);
-       zend_hash_init(intern->zo.properties, 0, NULL, ZVAL_PTR_DTOR, 0);
-
-       intern->zo.ce = ce;
-       intern->zo.guards = NULL;
-#endif
 
        while (parent) {
                if (parent == sxe_class_entry) {
@@ -2114,7 +2079,7 @@ static php_sxe_object* php_sxe_object_new(zend_class_entry *ce TSRMLS_DC)
        }
 
        if (inherited) {
-               zend_hash_find(&ce->function_table, "count", sizeof("count"),(void **) &intern->fptr_count);
+               intern->fptr_count = zend_hash_str_find_ptr(&ce->function_table, "count", sizeof("count") - 1);
                if (intern->fptr_count->common.scope == parent) {
                        intern->fptr_count = NULL;
                }
@@ -2126,21 +2091,17 @@ static php_sxe_object* php_sxe_object_new(zend_class_entry *ce TSRMLS_DC)
 
 /* {{{ php_sxe_register_object
  */
-static zend_object_value
+static zend_object *
 php_sxe_register_object(php_sxe_object *intern TSRMLS_DC)
 {
-       zend_object_value rv;
-
-       rv.handle = zend_objects_store_put(intern, sxe_object_dtor, (zend_objects_free_object_storage_t)sxe_object_free_storage, sxe_object_clone TSRMLS_CC);
-       rv.handlers = (zend_object_handlers *) &sxe_object_handlers;
-
-       return rv;
+       zend_objects_store_put(&intern->zo TSRMLS_CC);
+       return &intern->zo;
 }
 /* }}} */
 
 /* {{{ sxe_object_new()
  */
-PHP_SXE_API zend_object_value
+PHP_SXE_API zend_object *
 sxe_object_new(zend_class_entry *ce TSRMLS_DC)
 {
        php_sxe_object    *intern;
@@ -2170,7 +2131,7 @@ PHP_FUNCTION(simplexml_load_file)
 
        docp = xmlReadFile(filename, NULL, options);
 
-       if (! docp) {
+       if (!docp) {
                RETURN_FALSE;
        }
 
@@ -2183,8 +2144,7 @@ PHP_FUNCTION(simplexml_load_file)
        php_libxml_increment_doc_ref((php_libxml_node_object *)sxe, docp TSRMLS_CC);
        php_libxml_increment_node_ptr((php_libxml_node_object *)sxe, xmlDocGetRootElement(docp), NULL TSRMLS_CC);
 
-       return_value->type = IS_OBJECT;
-       return_value->value.obj = php_sxe_register_object(sxe TSRMLS_CC);
+       ZVAL_OBJ(return_value, php_sxe_register_object(sxe TSRMLS_CC));
 }
 /* }}} */
 
@@ -2208,7 +2168,7 @@ PHP_FUNCTION(simplexml_load_string)
 
        docp = xmlReadMemory(data, data_len, NULL, NULL, options);
 
-       if (! docp) {
+       if (!docp) {
                RETURN_FALSE;
        }
 
@@ -2221,8 +2181,7 @@ PHP_FUNCTION(simplexml_load_string)
        php_libxml_increment_doc_ref((php_libxml_node_object *)sxe, docp TSRMLS_CC);
        php_libxml_increment_node_ptr((php_libxml_node_object *)sxe, xmlDocGetRootElement(docp), NULL TSRMLS_CC);
 
-       return_value->type = IS_OBJECT;
-       return_value->value.obj = php_sxe_register_object(sxe TSRMLS_CC);
+       ZVAL_OBJ(return_value, php_sxe_register_object(sxe TSRMLS_CC));
 }
 /* }}} */
 
@@ -2230,7 +2189,7 @@ PHP_FUNCTION(simplexml_load_string)
    SimpleXMLElement constructor */
 SXE_METHOD(__construct)
 {
-       php_sxe_object *sxe = php_sxe_fetch_object(getThis() TSRMLS_CC);
+       php_sxe_object *sxe = Z_SXEOBJ_P(getThis());
        char           *data, *ns = NULL;
        int             data_len, ns_len = 0;
        xmlDocPtr       docp;
@@ -2294,8 +2253,7 @@ next_iter:
        }
 
        if (node && use_data) {
-               ALLOC_INIT_ZVAL(sxe->iter.data);
-               _node_as_zval(sxe, node, sxe->iter.data, SXE_ITER_NONE, NULL, prefix, isprefix TSRMLS_CC);
+               _node_as_zval(sxe, node, &sxe->iter.data, SXE_ITER_NONE, NULL, prefix, isprefix TSRMLS_CC);
        }
 
        return node;
@@ -2306,9 +2264,9 @@ static xmlNodePtr php_sxe_reset_iterator(php_sxe_object *sxe, int use_data TSRML
 {
        xmlNodePtr node;
 
-       if (sxe->iter.data) {
+       if (!ZVAL_IS_UNDEF(&sxe->iter.data)) {
                zval_ptr_dtor(&sxe->iter.data);
-               sxe->iter.data = NULL;
+               ZVAL_UNDEF(&sxe->iter.data);
        }
 
        GET_NODE(sxe, node)
@@ -2338,10 +2296,9 @@ zend_object_iterator *php_sxe_get_iterator(zend_class_entry *ce, zval *object, i
        }
        iterator = emalloc(sizeof(php_sxe_iterator));
 
-       Z_ADDREF_P(object);
-       iterator->intern.data = (void*)object;
+       ZVAL_COPY(&iterator->intern.data, object);
        iterator->intern.funcs = &php_sxe_iterator_funcs;
-       iterator->sxe = php_sxe_fetch_object(object TSRMLS_CC);
+       iterator->sxe = Z_SXEOBJ_P(object);
 
        return (zend_object_iterator*)iterator;
 }
@@ -2352,8 +2309,8 @@ static void php_sxe_iterator_dtor(zend_object_iterator *iter TSRMLS_DC) /* {{{ *
        php_sxe_iterator *iterator = (php_sxe_iterator *)iter;
 
        /* cleanup handled in sxe_object_dtor as we dont always have an iterator wrapper */
-       if (iterator->intern.data) {
-               zval_ptr_dtor((zval**)&iterator->intern.data);
+       if (!ZVAL_IS_UNDEF(&iterator->intern.data)) {
+               zval_ptr_dtor(&iterator->intern.data);
        }
 
        efree(iterator);
@@ -2364,23 +2321,23 @@ static int php_sxe_iterator_valid(zend_object_iterator *iter TSRMLS_DC) /* {{{ *
 {
        php_sxe_iterator *iterator = (php_sxe_iterator *)iter;
 
-       return iterator->sxe->iter.data ? SUCCESS : FAILURE;
+       return ZVAL_IS_UNDEF(&iterator->sxe->iter.data) ? FAILURE : SUCCESS;
 }
 /* }}} */
 
-static void php_sxe_iterator_current_data(zend_object_iterator *iter, zval ***data TSRMLS_DC) /* {{{ */
+static zval *php_sxe_iterator_current_data(zend_object_iterator *iter TSRMLS_DC) /* {{{ */
 {
        php_sxe_iterator *iterator = (php_sxe_iterator *)iter;
 
-       *data = &iterator->sxe->iter.data;
+       return &iterator->sxe->iter.data;
 }
 /* }}} */
 
 static void php_sxe_iterator_current_key(zend_object_iterator *iter, zval *key TSRMLS_DC) /* {{{ */
 {
        php_sxe_iterator *iterator = (php_sxe_iterator *)iter;
-       zval *curobj = iterator->sxe->iter.data;
-       php_sxe_object *intern = (php_sxe_object *)zend_object_store_get_object(curobj TSRMLS_CC);
+       zval *curobj = &iterator->sxe->iter.data;
+       php_sxe_object *intern = Z_SXEOBJ_P(curobj);
 
        xmlNodePtr curnode = NULL;
        if (intern != NULL && intern->node != NULL) {
@@ -2388,7 +2345,7 @@ static void php_sxe_iterator_current_key(zend_object_iterator *iter, zval *key T
        }
 
        if (curnode) {
-               ZVAL_STRINGL(key, (char *) curnode->name, xmlStrlen(curnode->name), 1);
+               ZVAL_STRINGL(key, (char *) curnode->name, xmlStrlen(curnode->name));
        } else {
                ZVAL_NULL(key);
        }
@@ -2400,11 +2357,11 @@ PHP_SXE_API void php_sxe_move_forward_iterator(php_sxe_object *sxe TSRMLS_DC) /*
        xmlNodePtr      node = NULL;
        php_sxe_object  *intern;
 
-       if (sxe->iter.data) {
-               intern = (php_sxe_object *)zend_object_store_get_object(sxe->iter.data TSRMLS_CC);
+       if (!ZVAL_IS_UNDEF(&sxe->iter.data)) {
+               intern = Z_SXEOBJ_P(&sxe->iter.data);
                GET_NODE(intern, node)
                zval_ptr_dtor(&sxe->iter.data);
-               sxe->iter.data = NULL;
+               ZVAL_UNDEF(&sxe->iter.data);
        }
 
        if (node) {
@@ -2436,7 +2393,7 @@ void *simplexml_export_node(zval *object TSRMLS_DC) /* {{{ */
        php_sxe_object *sxe;
        xmlNodePtr node;
 
-       sxe = php_sxe_fetch_object(object TSRMLS_CC);
+       sxe = Z_SXEOBJ_P(object);
        GET_NODE(sxe, node);
        return php_sxe_get_first_node(sxe, node TSRMLS_CC);
 }
@@ -2450,13 +2407,13 @@ PHP_FUNCTION(simplexml_import_dom)
        zval *node;
        php_libxml_node_object *object;
        xmlNodePtr              nodep = NULL;
-       zend_class_entry *ce= sxe_class_entry;
+       zend_class_entry *ce = sxe_class_entry;
 
        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o|C!", &node, &ce) == FAILURE) {
                return;
        }
 
-       object = (php_libxml_node_object *)zend_object_store_get_object(node TSRMLS_CC);
+       object = (php_libxml_node_object *)Z_SXEOBJ_P(node);
 
        nodep = php_libxml_import_node(node TSRMLS_CC);
 
@@ -2479,8 +2436,7 @@ PHP_FUNCTION(simplexml_import_dom)
                php_libxml_increment_doc_ref((php_libxml_node_object *)sxe, nodep->doc TSRMLS_CC);
                php_libxml_increment_node_ptr((php_libxml_node_object *)sxe, nodep, NULL TSRMLS_CC);
 
-               return_value->type = IS_OBJECT;
-               return_value->value.obj = php_sxe_register_object(sxe TSRMLS_CC);
+               ZVAL_OBJ(return_value, php_sxe_register_object(sxe TSRMLS_CC));
        } else {
                php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid Nodetype to import");
                RETVAL_NULL();
@@ -2622,6 +2578,9 @@ PHP_MINIT_FUNCTION(simplexml)
        sxe_class_entry->get_iterator = php_sxe_get_iterator;
        sxe_class_entry->iterator_funcs.funcs = &php_sxe_iterator_funcs;
        zend_class_implements(sxe_class_entry TSRMLS_CC, 1, zend_ce_traversable);
+       sxe_object_handlers.dtor_obj = sxe_object_dtor;
+       sxe_object_handlers.free_obj = sxe_object_free_storage;
+       sxe_object_handlers.clone_obj = sxe_object_clone;
        sxe_object_handlers.get_method = zend_get_std_object_handlers()->get_method;
        sxe_object_handlers.get_constructor = zend_get_std_object_handlers()->get_constructor;
        sxe_object_handlers.get_class_entry = zend_get_std_object_handlers()->get_class_entry;
index 4ecd7539ffa9913124a586375659acf99b7f81ff..c88cbfbe93099abe8df2f2010e9bc6e7427cdf22 100644 (file)
@@ -46,7 +46,7 @@ PHP_METHOD(ce_SimpleXMLIterator, rewind)
                return;
        }
 
-       iter.sxe = php_sxe_fetch_object(getThis() TSRMLS_CC);
+       iter.sxe = Z_SXEOBJ_P(getThis());
        ce_SimpleXMLElement->iterator_funcs.funcs->rewind((zend_object_iterator*)&iter TSRMLS_CC);
 }
 /* }}} */
@@ -55,13 +55,13 @@ PHP_METHOD(ce_SimpleXMLIterator, rewind)
  Check whether iteration is valid */
 PHP_METHOD(ce_SimpleXMLIterator, valid)
 {
-       php_sxe_object *sxe = php_sxe_fetch_object(getThis() TSRMLS_CC);
+       php_sxe_object *sxe = Z_SXEOBJ_P(getThis());
        
        if (zend_parse_parameters_none() == FAILURE) {
                return;
        }
 
-       RETURN_BOOL(sxe->iter.data);
+       RETURN_BOOL(!ZVAL_IS_UNDEF(&sxe->iter.data));
 }
 /* }}} */
 
@@ -69,17 +69,17 @@ PHP_METHOD(ce_SimpleXMLIterator, valid)
  Get current element */
 PHP_METHOD(ce_SimpleXMLIterator, current)
 {
-       php_sxe_object *sxe = php_sxe_fetch_object(getThis() TSRMLS_CC);
+       php_sxe_object *sxe = Z_SXEOBJ_P(getThis());
        
        if (zend_parse_parameters_none() == FAILURE) {
                return;
        }
 
-       if (!sxe->iter.data) {
+       if (ZVAL_IS_UNDEF(&sxe->iter.data)) {
                return; /* return NULL */
        }
 
-       RETURN_ZVAL(sxe->iter.data, 1, 0);
+       RETURN_ZVAL(&sxe->iter.data, 1, 0);
 }
 /* }}} */
 
@@ -89,20 +89,20 @@ PHP_METHOD(ce_SimpleXMLIterator, key)
 {
        xmlNodePtr curnode;
        php_sxe_object *intern;
-       php_sxe_object *sxe = php_sxe_fetch_object(getThis() TSRMLS_CC);
+       php_sxe_object *sxe = Z_SXEOBJ_P(getThis());
        
        if (zend_parse_parameters_none() == FAILURE) {
                return;
        }
 
-       if (!sxe->iter.data) {
+       if (ZVAL_IS_UNDEF(&sxe->iter.data)) {
                RETURN_FALSE;
        }
 
-       intern = (php_sxe_object *)zend_object_store_get_object(sxe->iter.data TSRMLS_CC);
+       intern = Z_SXEOBJ_P(&sxe->iter.data);
        if (intern != NULL && intern->node != NULL) {
                curnode = (xmlNodePtr)((php_libxml_node_ptr *)intern->node)->node;
-               RETURN_STRINGL((char*)curnode->name, xmlStrlen(curnode->name), 1);
+               RETURN_STRINGL((char*)curnode->name, xmlStrlen(curnode->name));
        }
     
        RETURN_FALSE;
@@ -119,7 +119,7 @@ PHP_METHOD(ce_SimpleXMLIterator, next)
                return;
        }
 
-       iter.sxe = php_sxe_fetch_object(getThis() TSRMLS_CC);
+       iter.sxe = Z_SXEOBJ_P(getThis());
        ce_SimpleXMLElement->iterator_funcs.funcs->move_forward((zend_object_iterator*)&iter TSRMLS_CC);
 }
 /* }}} */
@@ -128,7 +128,7 @@ PHP_METHOD(ce_SimpleXMLIterator, next)
  Check whether element has children (elements) */ 
 PHP_METHOD(ce_SimpleXMLIterator, hasChildren)
 {
-       php_sxe_object *sxe = php_sxe_fetch_object(getThis() TSRMLS_CC);
+       php_sxe_object *sxe = Z_SXEOBJ_P(getThis());
        php_sxe_object *child;
        xmlNodePtr      node;
        
@@ -136,10 +136,10 @@ PHP_METHOD(ce_SimpleXMLIterator, hasChildren)
                return;
        }
 
-       if (!sxe->iter.data || sxe->iter.type == SXE_ITER_ATTRLIST) {
+       if (ZVAL_IS_UNDEF(&sxe->iter.data) || sxe->iter.type == SXE_ITER_ATTRLIST) {
                RETURN_FALSE;
        }
-       child = php_sxe_fetch_object(sxe->iter.data TSRMLS_CC);
+       child = Z_SXEOBJ_P(&sxe->iter.data);
 
        GET_NODE(child, node);
        if (node) {
@@ -156,16 +156,16 @@ PHP_METHOD(ce_SimpleXMLIterator, hasChildren)
  Get child element iterator */ 
 PHP_METHOD(ce_SimpleXMLIterator, getChildren)
 {
-       php_sxe_object *sxe = php_sxe_fetch_object(getThis() TSRMLS_CC);
+       php_sxe_object *sxe = Z_SXEOBJ_P(getThis());
        
        if (zend_parse_parameters_none() == FAILURE) {
                return;
        }
 
-       if (!sxe->iter.data || sxe->iter.type == SXE_ITER_ATTRLIST) {
+       if (ZVAL_IS_UNDEF(&sxe->iter.data) || sxe->iter.type == SXE_ITER_ATTRLIST) {
                return; /* return NULL */
        }
-       RETURN_ZVAL(sxe->iter.data, 1, 0);
+       RETURN_ZVAL(&sxe->iter.data, 1, 0);
 }
 
 /* {{{ arginfo */
@@ -187,18 +187,18 @@ static const zend_function_entry funcs_SimpleXMLIterator[] = {
 
 PHP_MINIT_FUNCTION(sxe) /* {{{ */
 {
-       zend_class_entry **pce;
+       zend_class_entry *pce;
        zend_class_entry sxi;
 
-       if (zend_hash_find(CG(class_table), "simplexmlelement", sizeof("SimpleXMLElement"), (void **) &pce) == FAILURE) {
+       if ((pce = zend_hash_str_find_ptr(CG(class_table), "simplexmlelement", sizeof("SimpleXMLElement") - 1)) == NULL) {
                ce_SimpleXMLElement  = NULL;
                ce_SimpleXMLIterator = NULL;
                return SUCCESS; /* SimpleXML must be initialized before */
        }
 
-       ce_SimpleXMLElement = *pce;
+       ce_SimpleXMLElement = pce;
 
-       INIT_CLASS_ENTRY_EX(sxi, "SimpleXMLIterator", strlen("SimpleXMLIterator"), funcs_SimpleXMLIterator);
+       INIT_CLASS_ENTRY_EX(sxi, "SimpleXMLIterator", sizeof("SimpleXMLIterator") - 1, funcs_SimpleXMLIterator);
        ce_SimpleXMLIterator = zend_register_internal_class_ex(&sxi, ce_SimpleXMLElement TSRMLS_CC);
        ce_SimpleXMLIterator->create_object = ce_SimpleXMLElement->create_object;