diff --git a/ext/dom/documenttype.c b/ext/dom/documenttype.c index 895a34cebf65..63da0306649a 100644 --- a/ext/dom/documenttype.c +++ b/ext/dom/documenttype.c @@ -22,6 +22,7 @@ #include "php.h" #if defined(HAVE_LIBXML) && defined(HAVE_DOM) #include "php_dom.h" +#include "obj_map.h" #include "dom_properties.h" #include "internal_helpers.h" @@ -53,7 +54,7 @@ zend_result dom_documenttype_entities_read(dom_object *obj, zval *retval) xmlHashTable *entityht = (xmlHashTable *) dtdptr->entities; dom_object *intern = Z_DOMOBJ_P(retval); - dom_namednode_iter(obj, intern, entityht, NULL, NULL, &php_dom_obj_map_entities); + php_dom_create_obj_map(obj, intern, entityht, NULL, NULL, &php_dom_obj_map_entities); return SUCCESS; } @@ -74,7 +75,7 @@ zend_result dom_documenttype_notations_read(dom_object *obj, zval *retval) xmlHashTable *notationht = (xmlHashTable *) dtdptr->notations; dom_object *intern = Z_DOMOBJ_P(retval); - dom_namednode_iter(obj, intern, notationht, NULL, NULL, &php_dom_obj_map_notations); + php_dom_create_obj_map(obj, intern, notationht, NULL, NULL, &php_dom_obj_map_notations); return SUCCESS; } diff --git a/ext/dom/dom_iterators.c b/ext/dom/dom_iterators.c index 19c4ea41adad..90e973723f6c 100644 --- a/ext/dom/dom_iterators.c +++ b/ext/dom/dom_iterators.c @@ -22,7 +22,7 @@ #include "php.h" #if defined(HAVE_LIBXML) && defined(HAVE_DOM) #include "php_dom.h" -#include "dom_ce.h" +#include "obj_map.h" typedef struct nodeIterator { int cur; diff --git a/ext/dom/element.c b/ext/dom/element.c index d0fc0b4a4d3e..27e2845c9f0c 100644 --- a/ext/dom/element.c +++ b/ext/dom/element.c @@ -23,8 +23,8 @@ #if defined(HAVE_LIBXML) && defined(HAVE_DOM) #include "zend_enum.h" #include "php_dom.h" +#include "obj_map.h" #include "namespace_compat.h" -#include "private_data.h" #include "internal_helpers.h" #include "dom_properties.h" #include "token_list.h" @@ -825,7 +825,7 @@ static void dom_element_get_elements_by_tag_name(INTERNAL_FUNCTION_PARAMETERS, z object_init_ex(return_value, iter_ce); namednode = Z_DOMOBJ_P(return_value); - dom_namednode_iter(intern, namednode, NULL, name, NULL, &php_dom_obj_map_by_tag_name); + php_dom_create_obj_map(intern, namednode, NULL, name, NULL, &php_dom_obj_map_by_tag_name); } PHP_METHOD(DOMElement, getElementsByTagName) @@ -1257,7 +1257,7 @@ static void dom_element_get_elements_by_tag_name_ns(INTERNAL_FUNCTION_PARAMETERS object_init_ex(return_value, iter_ce); namednode = Z_DOMOBJ_P(return_value); - dom_namednode_iter(intern, namednode, NULL, name, uri, &php_dom_obj_map_by_tag_name); + php_dom_create_obj_map(intern, namednode, NULL, name, uri, &php_dom_obj_map_by_tag_name); } PHP_METHOD(DOMElement, getElementsByTagNameNS) diff --git a/ext/dom/html_collection.c b/ext/dom/html_collection.c index e4c044601668..e5dca84de75f 100644 --- a/ext/dom/html_collection.c +++ b/ext/dom/html_collection.c @@ -21,6 +21,7 @@ #include "php.h" #if defined(HAVE_LIBXML) && defined(HAVE_DOM) #include "php_dom.h" +#include "obj_map.h" #include "nodelist.h" #include "html_collection.h" #include "namespace_compat.h" @@ -115,7 +116,7 @@ zval *dom_html_collection_read_dimension(zend_object *object, zval *offset, int dom_html_collection_named_item_into_zval(rv, index.str, object); } else { ZEND_ASSERT(index.type == DOM_NODELIST_DIM_LONG); - php_dom_nodelist_get_item_into_zval(php_dom_obj_from_obj(object)->ptr, index.lval, rv); + php_dom_obj_map_get_item_into_zval(php_dom_obj_from_obj(object)->ptr, index.lval, rv); } return rv; diff --git a/ext/dom/namednodemap.c b/ext/dom/namednodemap.c index 2f8f6d10132c..953731ad8448 100644 --- a/ext/dom/namednodemap.c +++ b/ext/dom/namednodemap.c @@ -22,6 +22,7 @@ #include "php.h" #if defined(HAVE_LIBXML) && defined(HAVE_DOM) #include "php_dom.h" +#include "obj_map.h" #include "zend_interfaces.h" /* @@ -54,16 +55,6 @@ zend_result dom_namednodemap_length_read(dom_object *obj, zval *retval) /* }}} */ -void php_dom_named_node_map_get_named_item_into_zval(dom_nnodemap_object *objmap, const zend_string *named, const char *ns, zval *return_value) -{ - xmlNodePtr itemnode = objmap->handler->get_named_item(objmap, named, ns); - if (itemnode) { - DOM_RET_OBJ(itemnode, objmap->baseobj); - } else { - RETURN_NULL(); - } -} - /* {{{ URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-1074577549 Since: */ @@ -76,7 +67,7 @@ PHP_METHOD(DOMNamedNodeMap, getNamedItem) } dom_nnodemap_object *objmap = Z_DOMOBJ_P(ZEND_THIS)->ptr; - php_dom_named_node_map_get_named_item_into_zval(objmap, named, NULL, return_value); + php_dom_obj_map_get_named_item_into_zval(objmap, named, NULL, return_value); } /* }}} end dom_namednodemap_get_named_item */ @@ -121,7 +112,7 @@ PHP_METHOD(DOMNamedNodeMap, getNamedItemNS) objmap = (dom_nnodemap_object *)intern->ptr; if (objmap != NULL) { - php_dom_named_node_map_get_named_item_into_zval(objmap, named, uri, return_value); + php_dom_obj_map_get_named_item_into_zval(objmap, named, uri, return_value); } } /* }}} end dom_namednodemap_get_named_item_ns */ diff --git a/ext/dom/node.c b/ext/dom/node.c index 99069d778ebf..dba4bb8db87c 100644 --- a/ext/dom/node.c +++ b/ext/dom/node.c @@ -22,6 +22,7 @@ #include "php.h" #if defined(HAVE_LIBXML) && defined(HAVE_DOM) #include "php_dom.h" +#include "obj_map.h" #include "namespace_compat.h" #include "private_data.h" #include "internal_helpers.h" @@ -288,7 +289,7 @@ zend_result dom_node_child_nodes_read(dom_object *obj, zval *retval) object_init_ex(retval, dom_get_nodelist_ce(php_dom_follow_spec_intern(obj))); dom_object *intern = Z_DOMOBJ_P(retval); - dom_namednode_iter(obj, intern, NULL, NULL, NULL, &php_dom_obj_map_child_nodes); + php_dom_create_obj_map(obj, intern, NULL, NULL, NULL, &php_dom_obj_map_child_nodes); return SUCCESS; } @@ -422,7 +423,7 @@ zend_result dom_node_attributes_read(dom_object *obj, zval *retval) if (nodep->type == XML_ELEMENT_NODE) { object_init_ex(retval, dom_get_namednodemap_ce(php_dom_follow_spec_intern(obj))); dom_object *intern = Z_DOMOBJ_P(retval); - dom_namednode_iter(obj, intern, NULL, NULL, NULL, &php_dom_obj_map_attributes); + php_dom_create_obj_map(obj, intern, NULL, NULL, NULL, &php_dom_obj_map_attributes); } else { ZVAL_NULL(retval); } diff --git a/ext/dom/nodelist.c b/ext/dom/nodelist.c index 46a10a362a07..5e3de728e4fa 100644 --- a/ext/dom/nodelist.c +++ b/ext/dom/nodelist.c @@ -22,6 +22,7 @@ #include "php.h" #if defined(HAVE_LIBXML) && defined(HAVE_DOM) #include "php_dom.h" +#include "obj_map.h" #include "nodelist.h" #include "zend_interfaces.h" @@ -63,15 +64,6 @@ PHP_METHOD(DOMNodeList, count) } /* }}} end dom_nodelist_count */ -void php_dom_nodelist_get_item_into_zval(dom_nnodemap_object *objmap, zend_long index, zval *return_value) -{ - if (EXPECTED(objmap)) { - objmap->handler->get_item(objmap, index, return_value); - } else { - RETURN_NULL(); - } -} - /* {{{ URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ID-844377136 Since: */ @@ -85,7 +77,7 @@ PHP_METHOD(DOMNodeList, item) zval *id = ZEND_THIS; dom_object *intern = Z_DOMOBJ_P(id); dom_nnodemap_object *objmap = intern->ptr; - php_dom_nodelist_get_item_into_zval(objmap, index, return_value); + php_dom_obj_map_get_item_into_zval(objmap, index, return_value); } /* }}} end dom_nodelist_item */ @@ -136,7 +128,7 @@ zval *dom_modern_nodelist_read_dimension(zend_object *object, zval *offset, int return NULL; } - php_dom_nodelist_get_item_into_zval(php_dom_obj_from_obj(object)->ptr, index.lval, rv); + php_dom_obj_map_get_item_into_zval(php_dom_obj_from_obj(object)->ptr, index.lval, rv); return rv; } diff --git a/ext/dom/nodelist.h b/ext/dom/nodelist.h index 5ac3de1e46c4..5c5653eea6dc 100644 --- a/ext/dom/nodelist.h +++ b/ext/dom/nodelist.h @@ -31,8 +31,6 @@ typedef struct dom_nodelist_dimension_index { enum dom_nodelist_dimension_index_type type; } dom_nodelist_dimension_index; -void php_dom_nodelist_get_item_into_zval(dom_nnodemap_object *objmap, zend_long index, zval *return_value); -zend_long php_dom_get_nodelist_length(dom_object *obj); dom_nodelist_dimension_index dom_modern_nodelist_get_index(const zval *offset); zval *dom_modern_nodelist_read_dimension(zend_object *object, zval *offset, int type, zval *rv); int dom_modern_nodelist_has_dimension(zend_object *object, zval *member, int check_empty); diff --git a/ext/dom/obj_map.c b/ext/dom/obj_map.c index f2a93fe3ef87..12407a560112 100644 --- a/ext/dom/obj_map.c +++ b/ext/dom/obj_map.c @@ -55,8 +55,7 @@ static zend_long dom_map_get_xmlht_length(dom_nnodemap_object *map) static zend_long dom_map_get_nodeset_length(dom_nnodemap_object *map) { - HashTable *nodeht = Z_ARRVAL(map->baseobj_zv); - return zend_hash_num_elements(nodeht); + return zend_hash_num_elements(map->array); } static zend_long dom_map_get_prop_length(dom_nnodemap_object *map) @@ -132,8 +131,7 @@ static void dom_map_get_notation_item(dom_nnodemap_object *map, zend_long index, static void dom_map_get_nodeset_item(dom_nnodemap_object *map, zend_long index, zval *return_value) { - HashTable *nodeht = Z_ARRVAL(map->baseobj_zv); - zval *entry = zend_hash_index_find(nodeht, index); + zval *entry = zend_hash_index_find(map->array, index); if (entry) { RETURN_COPY(entry); } else { @@ -288,6 +286,67 @@ zend_long php_dom_get_nodelist_length(dom_object *obj) return count; } +void php_dom_create_obj_map(dom_object *basenode, dom_object *intern, xmlHashTablePtr ht, zend_string *local, zend_string *ns, const php_dom_obj_map_handler *handler) +{ + dom_nnodemap_object *mapptr = intern->ptr; + + ZEND_ASSERT(basenode != NULL); + + GC_ADDREF(&basenode->std); + + xmlDocPtr doc = basenode->document ? basenode->document->ptr : NULL; + + mapptr->handler = handler; + mapptr->baseobj = basenode; + mapptr->ht = ht; + if (EXPECTED(doc != NULL)) { + mapptr->dict = doc->dict; + xmlDictReference(doc->dict); + } + + const xmlChar* tmp; + + if (local) { + int len = (int) ZSTR_LEN(local); + if (doc != NULL && (tmp = xmlDictExists(doc->dict, (const xmlChar *)ZSTR_VAL(local), len)) != NULL) { + mapptr->local = BAD_CAST tmp; + } else { + mapptr->local = BAD_CAST ZSTR_VAL(zend_string_copy(local)); + mapptr->release_local = true; + } + mapptr->local_lower = zend_string_tolower(local); + } + + if (ns) { + int len = (int) ZSTR_LEN(ns); + if (doc != NULL && (tmp = xmlDictExists(doc->dict, (const xmlChar *)ZSTR_VAL(ns), len)) != NULL) { + mapptr->ns = BAD_CAST tmp; + } else { + mapptr->ns = BAD_CAST ZSTR_VAL(zend_string_copy(ns)); + mapptr->release_ns = true; + } + } +} + +void php_dom_obj_map_get_item_into_zval(dom_nnodemap_object *objmap, zend_long index, zval *return_value) +{ + if (EXPECTED(objmap)) { + objmap->handler->get_item(objmap, index, return_value); + } else { + RETURN_NULL(); + } +} + +void php_dom_obj_map_get_named_item_into_zval(dom_nnodemap_object *objmap, const zend_string *named, const char *ns, zval *return_value) +{ + xmlNodePtr itemnode = objmap->handler->get_named_item(objmap, named, ns); + if (itemnode) { + DOM_RET_OBJ(itemnode, objmap->baseobj); + } else { + RETURN_NULL(); + } +} + /********************** * === Named item === * **********************/ diff --git a/ext/dom/obj_map.h b/ext/dom/obj_map.h index 511b71fcc748..e1de9addd98f 100644 --- a/ext/dom/obj_map.h +++ b/ext/dom/obj_map.h @@ -20,14 +20,41 @@ typedef struct dom_nnodemap_object dom_nnodemap_object; typedef struct php_dom_obj_map_handler { - zend_long (*length)(dom_nnodemap_object *); - void (*get_item)(dom_nnodemap_object *, zend_long, zval *); - xmlNodePtr (*get_named_item)(dom_nnodemap_object *, const zend_string *, const char *); - bool (*has_named_item)(dom_nnodemap_object *, const zend_string *, const char *); - bool use_cache; - bool nameless; + zend_long (*length)(dom_nnodemap_object *); + void (*get_item)(dom_nnodemap_object *, zend_long, zval *); + xmlNodePtr (*get_named_item)(dom_nnodemap_object *, const zend_string *, const char *); + bool (*has_named_item)(dom_nnodemap_object *, const zend_string *, const char *); + bool use_cache; + bool nameless; } php_dom_obj_map_handler; +typedef struct dom_nnodemap_object { + dom_object *baseobj; + zend_long cached_length; + union { + xmlHashTable *ht; + HashTable *array; + struct { + xmlChar *local; + zend_string *local_lower; + xmlChar *ns; + }; + }; + php_libxml_cache_tag cache_tag; + dom_object *cached_obj; + zend_long cached_obj_index; + xmlDictPtr dict; + const php_dom_obj_map_handler *handler; + bool release_local; + bool release_ns; + bool release_array; +} dom_nnodemap_object; + +void php_dom_create_obj_map(dom_object *basenode, dom_object *intern, xmlHashTablePtr ht, zend_string *local, zend_string *ns, const php_dom_obj_map_handler *handler); +void php_dom_obj_map_get_named_item_into_zval(dom_nnodemap_object *objmap, const zend_string *named, const char *ns, zval *return_value); +void php_dom_obj_map_get_item_into_zval(dom_nnodemap_object *objmap, zend_long index, zval *return_value); +zend_long php_dom_get_nodelist_length(dom_object *obj); + extern const php_dom_obj_map_handler php_dom_obj_map_attributes; extern const php_dom_obj_map_handler php_dom_obj_map_by_tag_name; extern const php_dom_obj_map_handler php_dom_obj_map_child_nodes; diff --git a/ext/dom/parentnode/css_selectors.c b/ext/dom/parentnode/css_selectors.c index 10b517a248d4..4f77359835ce 100644 --- a/ext/dom/parentnode/css_selectors.c +++ b/ext/dom/parentnode/css_selectors.c @@ -21,6 +21,7 @@ #include "php.h" #if defined(HAVE_LIBXML) && defined(HAVE_DOM) #include "../php_dom.h" +#include "../obj_map.h" #include "ext/lexbor/lexbor/css/parser.h" #include "../lexbor/selectors-adapted/selectors.h" @@ -248,7 +249,8 @@ void dom_parent_node_query_selector_all(xmlNodePtr thisp, dom_object *intern, zv object_init_ex(return_value, dom_modern_nodelist_class_entry); dom_object *ret_obj = Z_DOMOBJ_P(return_value); dom_nnodemap_object *mapptr = (dom_nnodemap_object *) ret_obj->ptr; - ZVAL_ARR(&mapptr->baseobj_zv, list); + mapptr->array = list; + mapptr->release_array = true; mapptr->handler = &php_dom_obj_map_nodeset; } } diff --git a/ext/dom/php_dom.c b/ext/dom/php_dom.c index d9ed01d2e7d6..6e85ea887e4e 100644 --- a/ext/dom/php_dom.c +++ b/ext/dom/php_dom.c @@ -24,6 +24,7 @@ #if defined(HAVE_LIBXML) && defined(HAVE_DOM) #include "zend_enum.h" #include "php_dom.h" +#include "obj_map.h" #include "nodelist.h" #include "html_collection.h" #include "namespace_compat.h" @@ -1456,50 +1457,6 @@ void dom_objects_free_storage(zend_object *object) } /* }}} */ -/* TODO: move me to obj_map.c */ -void dom_namednode_iter(dom_object *basenode, dom_object *intern, xmlHashTablePtr ht, zend_string *local, zend_string *ns, const php_dom_obj_map_handler *handler) /* {{{ */ -{ - dom_nnodemap_object *mapptr = (dom_nnodemap_object *) intern->ptr; - - ZEND_ASSERT(basenode != NULL); - - ZVAL_OBJ_COPY(&mapptr->baseobj_zv, &basenode->std); - - xmlDocPtr doc = basenode->document ? basenode->document->ptr : NULL; - - mapptr->handler = handler; - mapptr->baseobj = basenode; - mapptr->ht = ht; - if (EXPECTED(doc != NULL)) { - mapptr->dict = doc->dict; - xmlDictReference(doc->dict); - } - - const xmlChar* tmp; - - if (local) { - int len = (int) ZSTR_LEN(local); - if (doc != NULL && (tmp = xmlDictExists(doc->dict, (const xmlChar *)ZSTR_VAL(local), len)) != NULL) { - mapptr->local = BAD_CAST tmp; - } else { - mapptr->local = BAD_CAST ZSTR_VAL(zend_string_copy(local)); - mapptr->release_local = true; - } - mapptr->local_lower = zend_string_tolower(local); - } - - if (ns) { - int len = (int) ZSTR_LEN(ns); - if (doc != NULL && (tmp = xmlDictExists(doc->dict, (const xmlChar *)ZSTR_VAL(ns), len)) != NULL) { - mapptr->ns = BAD_CAST tmp; - } else { - mapptr->ns = BAD_CAST ZSTR_VAL(zend_string_copy(ns)); - mapptr->release_ns = true; - } - } -} -/* }}} */ - static void dom_objects_set_class_ex(zend_class_entry *class_type, dom_object *intern) { zend_class_entry *base_class = class_type; @@ -1588,8 +1545,11 @@ void dom_nnodemap_objects_free_storage(zend_object *object) /* {{{ */ if (objmap->local_lower) { zend_string_release(objmap->local_lower); } - if (!Z_ISUNDEF(objmap->baseobj_zv)) { - zval_ptr_dtor(&objmap->baseobj_zv); + if (objmap->release_array) { + zend_array_release(objmap->array); + } + if (objmap->baseobj) { + OBJ_RELEASE(&objmap->baseobj->std); } xmlDictFree(objmap->dict); efree(objmap); @@ -2294,7 +2254,7 @@ static zval *dom_nodelist_read_dimension(zend_object *object, zval *offset, int return rv; } - php_dom_nodelist_get_item_into_zval(php_dom_obj_from_obj(object)->ptr, lval, rv); + php_dom_obj_map_get_item_into_zval(php_dom_obj_from_obj(object)->ptr, lval, rv); return rv; } @@ -2382,7 +2342,7 @@ static zval *dom_nodemap_read_dimension(zend_object *object, zval *offset, int t zend_long lval; if (dom_nodemap_or_nodelist_process_offset_as_named(offset, &lval)) { /* exceptional case, switch to named lookup */ - php_dom_named_node_map_get_named_item_into_zval(php_dom_obj_from_obj(object)->ptr, Z_STR_P(offset), NULL, rv); + php_dom_obj_map_get_named_item_into_zval(php_dom_obj_from_obj(object)->ptr, Z_STR_P(offset), NULL, rv); return rv; } @@ -2429,7 +2389,7 @@ static zval *dom_modern_nodemap_read_dimension(zend_object *object, zval *offset if (ZEND_HANDLE_NUMERIC(Z_STR_P(offset), lval)) { map->handler->get_item(map, (zend_long) lval, rv); } else { - php_dom_named_node_map_get_named_item_into_zval(map, Z_STR_P(offset), NULL, rv); + php_dom_obj_map_get_named_item_into_zval(map, Z_STR_P(offset), NULL, rv); } } else if (Z_TYPE_P(offset) == IS_LONG) { map->handler->get_item(map, Z_LVAL_P(offset), rv); diff --git a/ext/dom/php_dom.h b/ext/dom/php_dom.h index 571f99cfe2be..0ff8692c4cc7 100644 --- a/ext/dom/php_dom.h +++ b/ext/dom/php_dom.h @@ -56,7 +56,7 @@ extern zend_module_entry dom_module_entry; #include "xpath_callbacks.h" #include "zend_exceptions.h" #include "dom_ce.h" -#include "obj_map.h" + /* DOM API_VERSION, please bump it up, if you change anything in the API therefore it's easier for the script-programmers to check, what's working how Can be checked with phpversion("dom"); @@ -76,23 +76,6 @@ static inline dom_xpath_object *php_xpath_obj_from_obj(zend_object *obj) { #define Z_XPATHOBJ_P(zv) php_xpath_obj_from_obj(Z_OBJ_P((zv))) -typedef struct dom_nnodemap_object { - dom_object *baseobj; - zval baseobj_zv; - int cached_length; - xmlHashTable *ht; - xmlChar *local; - zend_string *local_lower; - xmlChar *ns; - php_libxml_cache_tag cache_tag; - dom_object *cached_obj; - zend_long cached_obj_index; - xmlDictPtr dict; - const php_dom_obj_map_handler *handler; - bool release_local : 1; - bool release_ns : 1; -} dom_nnodemap_object; - typedef struct { zend_object_iterator intern; zval curobj; @@ -145,7 +128,6 @@ int dom_hierarchy(xmlNodePtr parent, xmlNodePtr child); bool dom_has_feature(zend_string *feature, zend_string *version); bool dom_node_is_read_only(const xmlNode *node); bool dom_node_children_valid(const xmlNode *node); -void dom_namednode_iter(dom_object *basenode, dom_object *intern, xmlHashTablePtr ht, zend_string *local, zend_string *ns, const php_dom_obj_map_handler *handler); xmlNodePtr create_notation(const xmlChar *name, const xmlChar *ExternalID, const xmlChar *SystemID); xmlNode *php_dom_libxml_hash_iter(xmlHashTable *ht, int index); zend_object_iterator *php_dom_get_iterator(zend_class_entry *ce, zval *object, int by_ref); @@ -210,8 +192,6 @@ void dom_element_closest(xmlNodePtr thisp, dom_object *intern, zval *return_valu xmlNodePtr dom_parse_fragment(dom_object *obj, xmlNodePtr context_node, const zend_string *input); /* nodemap and nodelist APIs */ -void php_dom_named_node_map_get_named_item_into_zval(dom_nnodemap_object *objmap, const zend_string *named, const char *ns, zval *return_value); -xmlNodePtr php_dom_named_node_map_get_item(dom_nnodemap_object *objmap, zend_long index); zend_long php_dom_get_namednodemap_length(dom_object *obj); xmlNodePtr dom_nodelist_iter_start_first_child(xmlNodePtr nodep); diff --git a/ext/dom/xpath.c b/ext/dom/xpath.c index b410f7b26499..21baa59ffed0 100644 --- a/ext/dom/xpath.c +++ b/ext/dom/xpath.c @@ -22,8 +22,8 @@ #include "php.h" #if defined(HAVE_LIBXML) && defined(HAVE_DOM) #include "php_dom.h" +#include "obj_map.h" #include "namespace_compat.h" -#include "private_data.h" #include "internal_helpers.h" #define PHP_DOM_XPATH_QUERY 0 @@ -234,15 +234,6 @@ PHP_METHOD(DOMXPath, registerNamespace) } /* }}} */ -static void dom_xpath_iter(zval *baseobj, dom_object *intern) /* {{{ */ -{ - dom_nnodemap_object *mapptr = (dom_nnodemap_object *) intern->ptr; - - ZVAL_COPY_VALUE(&mapptr->baseobj_zv, baseobj); - mapptr->handler = &php_dom_obj_map_nodeset; -} -/* }}} */ - static void php_xpath_eval(INTERNAL_FUNCTION_PARAMETERS, int type, bool modern) /* {{{ */ { zval *context = NULL; @@ -335,6 +326,7 @@ static void php_xpath_eval(INTERNAL_FUNCTION_PARAMETERS, int type, bool modern) { xmlNodeSetPtr nodesetp; zval retval; + bool release_array = false; if (xpathobjp->type == XPATH_NODESET && NULL != (nodesetp = xpathobjp->nodesetval) && nodesetp->nodeNr) { array_init_size(&retval, nodesetp->nodeNr); @@ -369,12 +361,18 @@ static void php_xpath_eval(INTERNAL_FUNCTION_PARAMETERS, int type, bool modern) } add_next_index_zval(&retval, &child); } + release_array = true; } else { ZVAL_EMPTY_ARRAY(&retval); } + object_init_ex(return_value, dom_get_nodelist_ce(modern)); nodeobj = Z_DOMOBJ_P(return_value); - dom_xpath_iter(&retval, nodeobj); + dom_nnodemap_object *mapptr = nodeobj->ptr; + + mapptr->array = Z_ARR(retval); + mapptr->release_array = release_array; + mapptr->handler = &php_dom_obj_map_nodeset; break; }