--- embedaddon/php/ext/dom/php_dom.c 2012/02/21 23:47:54 1.1.1.1 +++ embedaddon/php/ext/dom/php_dom.c 2012/05/29 12:34:37 1.1.1.2 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_dom.c,v 1.1.1.1 2012/02/21 23:47:54 misho Exp $ */ +/* $Id: php_dom.c,v 1.1.1.2 2012/05/29 12:34:37 misho Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -303,7 +303,7 @@ static void dom_register_prop_handler(HashTable *prop_ } /* }}} */ -static zval **dom_get_property_ptr_ptr(zval *object, zval *member TSRMLS_DC) /* {{{ */ +static zval **dom_get_property_ptr_ptr(zval *object, zval *member, const zend_literal *key TSRMLS_DC) /* {{{ */ { dom_object *obj; zval tmp_member; @@ -326,7 +326,7 @@ static zval **dom_get_property_ptr_ptr(zval *object, z } if (ret == FAILURE) { std_hnd = zend_get_std_object_handlers(); - retval = std_hnd->get_property_ptr_ptr(object, member TSRMLS_CC); + retval = std_hnd->get_property_ptr_ptr(object, member, key TSRMLS_CC); } if (member == &tmp_member) { @@ -337,7 +337,7 @@ static zval **dom_get_property_ptr_ptr(zval *object, z /* }}} */ /* {{{ dom_read_property */ -zval *dom_read_property(zval *object, zval *member, int type TSRMLS_DC) +zval *dom_read_property(zval *object, zval *member, int type, const zend_literal *key TSRMLS_DC) { dom_object *obj; zval tmp_member; @@ -372,7 +372,7 @@ zval *dom_read_property(zval *object, zval *member, in } } else { std_hnd = zend_get_std_object_handlers(); - retval = std_hnd->read_property(object, member, type TSRMLS_CC); + retval = std_hnd->read_property(object, member, type, key TSRMLS_CC); } if (member == &tmp_member) { @@ -383,7 +383,7 @@ zval *dom_read_property(zval *object, zval *member, in /* }}} */ /* {{{ dom_write_property */ -void dom_write_property(zval *object, zval *member, zval *value TSRMLS_DC) +void dom_write_property(zval *object, zval *member, zval *value, const zend_literal *key TSRMLS_DC) { dom_object *obj; zval tmp_member; @@ -408,7 +408,7 @@ void dom_write_property(zval *object, zval *member, zv hnd->write_func(obj, value TSRMLS_CC); } else { std_hnd = zend_get_std_object_handlers(); - std_hnd->write_property(object, member, value TSRMLS_CC); + std_hnd->write_property(object, member, value, key TSRMLS_CC); } if (member == &tmp_member) { @@ -418,7 +418,7 @@ void dom_write_property(zval *object, zval *member, zv /* }}} */ /* {{{ dom_property_exists */ -static int dom_property_exists(zval *object, zval *member, int check_empty TSRMLS_DC) +static int dom_property_exists(zval *object, zval *member, int check_empty, const zend_literal *key TSRMLS_DC) { dom_object *obj; zval tmp_member; @@ -456,7 +456,7 @@ static int dom_property_exists(zval *object, zval *mem } } else { std_hnd = zend_get_std_object_handlers(); - retval = std_hnd->has_property(object, member, check_empty TSRMLS_CC); + retval = std_hnd->has_property(object, member, check_empty, key TSRMLS_CC); } if (member == &tmp_member) { @@ -466,6 +466,87 @@ static int dom_property_exists(zval *object, zval *mem } /* }}} */ +static HashTable* dom_get_debug_info_helper(zval *object, int *is_temp TSRMLS_DC) /* {{{ */ +{ + dom_object *obj = zend_object_store_get_object(object TSRMLS_CC); + HashTable *debug_info, + *prop_handlers = obj->prop_handler, + *std_props; + HashPosition pos; + dom_prop_handler *entry; + zval *object_value, + *null_value; + + *is_temp = 1; + + ALLOC_HASHTABLE(debug_info); + ZEND_INIT_SYMTABLE_EX(debug_info, 32, 0); + + std_props = zend_std_get_properties(object TSRMLS_CC); + zend_hash_copy(debug_info, std_props, (copy_ctor_func_t)zval_add_ref, + NULL, sizeof(zval*)); + + if (!prop_handlers) { + return debug_info; + } + + ALLOC_INIT_ZVAL(object_value); + ZVAL_STRING(object_value, "(object value omitted)", 1); + + ALLOC_INIT_ZVAL(null_value); + ZVAL_NULL(null_value); + + for (zend_hash_internal_pointer_reset_ex(prop_handlers, &pos); + zend_hash_get_current_data_ex(prop_handlers, (void **)&entry, &pos) + == SUCCESS; + zend_hash_move_forward_ex(prop_handlers, &pos)) { + zval *value; + char *string_key = NULL; + uint string_length = 0; + ulong num_key; + + if (entry->read_func(obj, &value TSRMLS_CC) == FAILURE) { + continue; + } + + if (zend_hash_get_current_key_ex(prop_handlers, &string_key, + &string_length, &num_key, 0, &pos) != HASH_KEY_IS_STRING) { + continue; + } + + if (value == EG(uninitialized_zval_ptr)) { + value = null_value; + } else if (Z_TYPE_P(value) == IS_OBJECT) { + /* these are zvalues create on demand, with refcount and is_ref + * status left in an uninitalized stated */ + zval_dtor(value); + efree(value); + + value = object_value; + } else { + /* see comment above */ + Z_SET_REFCOUNT_P(value, 0); + Z_UNSET_ISREF_P(value); + } + + zval_add_ref(&value); + zend_hash_add(debug_info, string_key, string_length, + &value, sizeof(zval *), NULL); + } + + zval_ptr_dtor(&null_value); + zval_ptr_dtor(&object_value); + + return debug_info; +} +/* }}} */ + +static HashTable* dom_get_debug_info(zval *object, int *is_temp TSRMLS_DC) /* {{{ */ +{ + return dom_get_debug_info_helper(object, is_temp TSRMLS_CC); +} +/* }}} */ + void *php_dom_export_node(zval *object TSRMLS_DC) /* {{{ */ { php_libxml_node_object *intern; @@ -484,7 +565,6 @@ void *php_dom_export_node(zval *object TSRMLS_DC) /* { Get a simplexml_element object from dom to allow for processing */ PHP_FUNCTION(dom_import_simplexml) { - zval *rv = NULL; zval *node; xmlNodePtr nodep = NULL; php_libxml_node_object *nodeobj; @@ -498,7 +578,7 @@ PHP_FUNCTION(dom_import_simplexml) nodep = php_libxml_import_node(node TSRMLS_CC); if (nodep && nodeobj && (nodep->type == XML_ELEMENT_NODE || nodep->type == XML_ATTRIBUTE_NODE)) { - DOM_RET_OBJ(rv, (xmlNodePtr) nodep, &ret, (dom_object *)nodeobj); + DOM_RET_OBJ((xmlNodePtr) nodep, &ret, (dom_object *)nodeobj); } else { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid Nodetype to import"); RETURN_NULL(); @@ -586,6 +666,7 @@ PHP_MINIT_FUNCTION(dom) dom_object_handlers.get_property_ptr_ptr = dom_get_property_ptr_ptr; dom_object_handlers.clone_obj = dom_objects_store_clone_obj; dom_object_handlers.has_property = dom_property_exists; + dom_object_handlers.get_debug_info = dom_get_debug_info; zend_hash_init(&classes, 0, NULL, NULL, 1); @@ -1053,7 +1134,6 @@ void dom_namednode_iter(dom_object *basenode, int ntyp static dom_object* dom_objects_set_class(zend_class_entry *class_type, zend_bool hash_copy TSRMLS_DC) /* {{{ */ { zend_class_entry *base_class; - zval *tmp; dom_object *intern; if (instanceof_function(class_type, dom_xpath_class_entry TSRMLS_CC)) { @@ -1075,7 +1155,7 @@ static dom_object* dom_objects_set_class(zend_class_en zend_object_std_init(&intern->std, class_type TSRMLS_CC); if (hash_copy) { - zend_hash_copy(intern->std.properties, &class_type->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *)); + object_properties_init(&intern->std, class_type); } return intern; @@ -1234,7 +1314,7 @@ void php_dom_create_interator(zval *return_value, int /* }}} */ /* {{{ php_dom_create_object */ -PHP_DOM_EXPORT zval *php_dom_create_object(xmlNodePtr obj, int *found, zval *wrapper_in, zval *return_value, dom_object *domobj TSRMLS_DC) +PHP_DOM_EXPORT zval *php_dom_create_object(xmlNodePtr obj, int *found, zval *return_value, dom_object *domobj TSRMLS_DC) { zval *wrapper; zend_class_entry *ce;