]> granicus.if.org Git - php/commitdiff
Fix remaining XPath issue
authorNikita Popov <nikic@php.net>
Wed, 16 Apr 2014 14:57:05 +0000 (16:57 +0200)
committerNikita Popov <nikic@php.net>
Wed, 16 Apr 2014 15:14:34 +0000 (17:14 +0200)
ext/dom/php_dom.c
ext/dom/php_dom.h
ext/dom/xpath.c

index a15cd255b7423b7686ec08b2780a012bdd06f4bb..c584ef39b70d6e58a9c46791b2ed6592d73bc931 100644 (file)
@@ -842,7 +842,7 @@ PHP_MINIT_FUNCTION(dom)
 
 #if defined(LIBXML_XPATH_ENABLED)
        memcpy(&dom_xpath_object_handlers, &dom_object_handlers, sizeof(zend_object_handlers));
-       dom_xpath_object_handlers.offset = XtOffsetOf(dom_xpath_object, std);
+       dom_xpath_object_handlers.offset = XtOffsetOf(dom_xpath_object, dom) + XtOffsetOf(dom_object, std);
        dom_xpath_object_handlers.free_obj = dom_xpath_objects_free_storage;
 
        INIT_CLASS_ENTRY(ce, "DOMXPath", php_dom_xpath_class_functions);
@@ -1011,12 +1011,11 @@ void dom_xpath_objects_free_storage(zend_object *object TSRMLS_DC)
 {
        dom_xpath_object *intern = php_xpath_obj_from_obj(object);
 
-       zend_object_std_dtor(&intern->std TSRMLS_CC);
+       zend_object_std_dtor(&intern->dom.std TSRMLS_CC);
 
-       if (intern->ptr != NULL) {
-               xmlXPathFreeContext((xmlXPathContextPtr) intern->ptr);
-               php_libxml_decrement_doc_ref((php_libxml_node_object *) intern TSRMLS_CC);
-               intern->ptr = NULL;
+       if (intern->dom.ptr != NULL) {
+               xmlXPathFreeContext((xmlXPathContextPtr) intern->dom.ptr);
+               php_libxml_decrement_doc_ref((php_libxml_node_object *) &intern->dom TSRMLS_CC);
        }
 
        if (intern->registered_phpfunctions) {
@@ -1143,13 +1142,13 @@ zend_object *dom_xpath_objects_new(zend_class_entry *class_type TSRMLS_DC)
        ALLOC_HASHTABLE(intern->registered_phpfunctions);
        zend_hash_init(intern->registered_phpfunctions, 0, NULL, ZVAL_PTR_DTOR, 0);
 
-       intern->prop_handler = &dom_xpath_prop_handlers;
-       intern->std.handlers = &dom_xpath_object_handlers;
+       intern->dom.prop_handler = &dom_xpath_prop_handlers;
+       intern->dom.std.handlers = &dom_xpath_object_handlers;
 
-       zend_object_std_init(&intern->std, class_type TSRMLS_CC);
-       object_properties_init(&intern->std, class_type);
+       zend_object_std_init(&intern->dom.std, class_type TSRMLS_CC);
+       object_properties_init(&intern->dom.std, class_type);
 
-       return &intern->std;
+       return &intern->dom.std;
 }
 /* }}} */
 #endif
index 82ba681ff8fe599eabee7a06d0077e4067761ae0..628a19e9787c6d43407da08826c378a7143a3e89 100644 (file)
@@ -68,17 +68,15 @@ extern zend_module_entry dom_module_entry;
 #define DOM_NODESET XML_XINCLUDE_START
 
 typedef struct _dom_xpath_object {
-       void *ptr;
-       php_libxml_ref_obj *document;
-       HashTable *prop_handler;
        int registerPhpFunctions;
        HashTable *registered_phpfunctions;
        HashTable *node_list;
-       zend_object std;
+       dom_object dom;
 } dom_xpath_object;
 
 static inline dom_xpath_object *php_xpath_obj_from_obj(zend_object *obj) {
-       return (dom_xpath_object*)((char*)(obj) - XtOffsetOf(dom_xpath_object, std));
+       return (dom_xpath_object*)((char*)(obj)
+               - XtOffsetOf(dom_xpath_object, dom) - XtOffsetOf(dom_object, std));
 }
 
 #define Z_XPATHOBJ_P(zv)  php_xpath_obj_from_obj(Z_OBJ_P((zv)))
index de5f244b4df7509a902b6444a653c9a26ad45dbf..08bb8603a50a02830d62056ff5a16ec0ed4a7815 100644 (file)
@@ -159,7 +159,7 @@ static void dom_xpath_ext_function_php(xmlXPathParserContextPtr ctxt, int nargs,
                                                                node->parent = nsparent;
                                                                node->ns = curns;
                                                        }
-                                                       php_dom_create_object(node, &child, (dom_object *)intern TSRMLS_CC);
+                                                       php_dom_create_object(node, &child, &intern->dom TSRMLS_CC);
                                                        add_next_index_zval(&fci.params[i], &child);
                                                }
                                        }
@@ -277,9 +277,9 @@ PHP_METHOD(domxpath, __construct)
 
        intern = Z_XPATHOBJ_P(id);
        if (intern != NULL) {
-               oldctx = (xmlXPathContextPtr)intern->ptr;
+               oldctx = (xmlXPathContextPtr)intern->dom.ptr;
                if (oldctx != NULL) {
-                       php_libxml_decrement_doc_ref((php_libxml_node_object *)intern TSRMLS_CC);
+                       php_libxml_decrement_doc_ref((php_libxml_node_object *) &intern->dom TSRMLS_CC);
                        xmlXPathFreeContext(oldctx);
                }
 
@@ -290,10 +290,10 @@ PHP_METHOD(domxpath, __construct)
                                           (const xmlChar *) "http://php.net/xpath",
                                           dom_xpath_ext_function_object_php);
 
-               intern->ptr = ctx;
+               intern->dom.ptr = ctx;
                ctx->userData = (void *)intern;
-               intern->document = docobj->document;
-               php_libxml_increment_doc_ref((php_libxml_node_object *)intern, docp TSRMLS_CC);
+               intern->dom.document = docobj->document;
+               php_libxml_increment_doc_ref((php_libxml_node_object *) &intern->dom, docp TSRMLS_CC);
        }
 }
 /* }}} end DOMXPath::__construct */
@@ -328,7 +328,7 @@ PHP_FUNCTION(dom_xpath_register_ns)
 
        intern = Z_XPATHOBJ_P(id);
 
-       ctxp = (xmlXPathContextPtr) intern->ptr;
+       ctxp = (xmlXPathContextPtr) intern->dom.ptr;
        if (ctxp == NULL) {
                php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid XPath Context");
                RETURN_FALSE;
@@ -370,7 +370,7 @@ static void php_xpath_eval(INTERNAL_FUNCTION_PARAMETERS, int type) /* {{{ */
 
        intern = Z_XPATHOBJ_P(id);
 
-       ctxp = (xmlXPathContextPtr) intern->ptr;
+       ctxp = (xmlXPathContextPtr) intern->dom.ptr;
        if (ctxp == NULL) {
                php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid XPath Context");
                RETURN_FALSE;
@@ -463,7 +463,7 @@ static void php_xpath_eval(INTERNAL_FUNCTION_PARAMETERS, int type) /* {{{ */
                                                node->parent = nsparent;
                                                node->ns = curns;
                                        }
-                                       php_dom_create_object(node, &child, (dom_object *)intern TSRMLS_CC);
+                                       php_dom_create_object(node, &child, &intern->dom TSRMLS_CC);
                                        add_next_index_zval(&retval, &child);
                                }
                        }