diff options
author | Nikita Popov <nikic@php.net> | 2014-04-15 17:41:13 +0200 |
---|---|---|
committer | Nikita Popov <nikic@php.net> | 2014-04-15 20:32:46 +0200 |
commit | 2f0a758fbbf39ff8684d167f86c708cc361db782 (patch) | |
tree | f3179a8e1f589bb27ef892e953ed38607488394f /ext/dom/php_dom.c | |
parent | f9b26bc39a9ea9b1380628eeb0e6dad3c93cfcb0 (diff) | |
download | php-git-2f0a758fbbf39ff8684d167f86c708cc361db782.tar.gz |
Start working on dom extension
Nowhere near compiling yet...
Diffstat (limited to 'ext/dom/php_dom.c')
-rw-r--r-- | ext/dom/php_dom.c | 375 |
1 files changed, 145 insertions, 230 deletions
diff --git a/ext/dom/php_dom.c b/ext/dom/php_dom.c index f2c9afd6b3..d3aed667e3 100644 --- a/ext/dom/php_dom.c +++ b/ext/dom/php_dom.c @@ -99,7 +99,7 @@ static HashTable dom_xpath_prop_handlers; #endif /* }}} */ -typedef int (*dom_read_t)(dom_object *obj, zval **retval TSRMLS_DC); +typedef int (*dom_read_t)(dom_object *obj, zval *retval TSRMLS_DC); typedef int (*dom_write_t)(dom_object *obj, zval *newval TSRMLS_DC); typedef struct _dom_prop_handler { @@ -192,7 +192,7 @@ static void dom_copy_doc_props(php_libxml_ref_obj *source_doc, php_libxml_ref_ob if (source->classmap) { ALLOC_HASHTABLE(dest->classmap); zend_hash_init(dest->classmap, 0, NULL, NULL, 0); - zend_hash_copy(dest->classmap, source->classmap, NULL, NULL, sizeof(zend_class_entry *)); + zend_hash_copy(dest->classmap, source->classmap, NULL); } } @@ -212,9 +212,9 @@ int dom_set_doc_classmap(php_libxml_ref_obj *document, zend_class_entry *basece, zend_hash_init(doc_props->classmap, 0, NULL, NULL, 0); } if (ce) { - return zend_hash_update(doc_props->classmap, basece->name, basece->name_length + 1, &ce, sizeof(zend_class_entry *), NULL); + zend_hash_update_ptr(doc_props->classmap, basece->name, ce); } else { - zend_hash_del(doc_props->classmap, basece->name, basece->name_length + 1); + zend_hash_del(doc_props->classmap, basece->name); } } return SUCCESS; @@ -223,13 +223,13 @@ int dom_set_doc_classmap(php_libxml_ref_obj *document, zend_class_entry *basece, zend_class_entry *dom_get_doc_classmap(php_libxml_ref_obj *document, zend_class_entry *basece TSRMLS_DC) { dom_doc_propsptr doc_props; - zend_class_entry **ce = NULL; if (document) { doc_props = dom_get_doc_props(document); if (doc_props->classmap) { - if (zend_hash_find(doc_props->classmap, basece->name, basece->name_length + 1, (void**) &ce) == SUCCESS) { - return *ce; + zend_class_entry *ce = zend_hash_find_ptr(doc_props->classmap, basece->name); + if (ce) { + return ce; } } } @@ -276,9 +276,8 @@ PHP_DOM_EXPORT dom_object *php_dom_object_get_data(xmlNodePtr obj) /* }}} end php_dom_object_get_data */ /* {{{ dom_read_na */ -static int dom_read_na(dom_object *obj, zval **retval TSRMLS_DC) +static int dom_read_na(dom_object *obj, zval *retval TSRMLS_DC) { - *retval = NULL; php_error_docref(NULL TSRMLS_CC, E_ERROR, "Cannot read property"); return FAILURE; } @@ -299,33 +298,24 @@ static void dom_register_prop_handler(HashTable *prop_handler, char *name, dom_r hnd.read_func = read_func ? read_func : dom_read_na; hnd.write_func = write_func ? write_func : dom_write_na; - zend_hash_add(prop_handler, name, strlen(name)+1, &hnd, sizeof(dom_prop_handler), NULL); + zend_hash_str_add_mem(prop_handler, name, strlen(name), &hnd, sizeof(dom_prop_handler)); } /* }}} */ -static zval **dom_get_property_ptr_ptr(zval *object, zval *member, int type, const zend_literal *key TSRMLS_DC) /* {{{ */ +static zval *dom_get_property_ptr_ptr(zval *object, zval *member, int type, const zend_literal *key TSRMLS_DC) /* {{{ */ { - dom_object *obj; + dom_object *obj = Z_DOMOBJ_P(object); zval tmp_member; - zval **retval = NULL; - dom_prop_handler *hnd; - zend_object_handlers *std_hnd; - int ret = FAILURE; - - if (member->type != IS_STRING) { - tmp_member = *member; - zval_copy_ctor(&tmp_member); + zval *retval = NULL; + + if (Z_TYPE_P(member) != IS_STRING) { + ZVAL_DUP(&tmp_member, member); convert_to_string(&tmp_member); member = &tmp_member; } - obj = (dom_object *)zend_objects_get_address(object TSRMLS_CC); - - if (obj->prop_handler != NULL) { - ret = zend_hash_find(obj->prop_handler, Z_STRVAL_P(member), Z_STRLEN_P(member)+1, (void **) &hnd); - } - if (ret == FAILURE) { - std_hnd = zend_get_std_object_handlers(); + if (!obj->prop_handler || !zend_hash_exists(obj->prop_handler, Z_STR_P(member))) { + zend_object_handlers *std_hnd = zend_get_std_object_handlers(); retval = std_hnd->get_property_ptr_ptr(object, member, type, key TSRMLS_CC); } @@ -337,42 +327,35 @@ static zval **dom_get_property_ptr_ptr(zval *object, zval *member, int type, con /* }}} */ /* {{{ dom_read_property */ -zval *dom_read_property(zval *object, zval *member, int type, const zend_literal *key TSRMLS_DC) +zval *dom_read_property(zval *object, zval *member, int type, const zend_literal *key, zval *rv TSRMLS_DC) { - dom_object *obj; + dom_object *obj = Z_DOMOBJ_P(object); zval tmp_member; zval *retval; - dom_prop_handler *hnd; - zend_object_handlers *std_hnd; - int ret; + dom_prop_handler *hnd = NULL; - if (member->type != IS_STRING) { - tmp_member = *member; - zval_copy_ctor(&tmp_member); + if (Z_TYPE_P(member) != IS_STRING) { + ZVAL_DUP(&tmp_member, member); convert_to_string(&tmp_member); member = &tmp_member; } - ret = FAILURE; - obj = (dom_object *)zend_objects_get_address(object TSRMLS_CC); - if (obj->prop_handler != NULL) { - ret = zend_hash_find(obj->prop_handler, Z_STRVAL_P(member), Z_STRLEN_P(member)+1, (void **) &hnd); + hnd = zend_hash_find_ptr(obj->prop_handler, Z_STR_P(member)); } else if (instanceof_function(obj->std.ce, dom_node_class_entry TSRMLS_CC)) { - php_error(E_WARNING, "Couldn't fetch %s. Node no longer exists", obj->std.ce->name); + php_error(E_WARNING, "Couldn't fetch %s. Node no longer exists", obj->std.ce->name->val); } - if (ret == SUCCESS) { - ret = hnd->read_func(obj, &retval TSRMLS_CC); + + if (hnd) { + int ret = hnd->read_func(obj, rv TSRMLS_CC); if (ret == SUCCESS) { - /* ensure we're creating a temporary variable */ - Z_SET_REFCOUNT_P(retval, 0); - Z_UNSET_ISREF_P(retval); + retval = rv; } else { - retval = EG(uninitialized_zval_ptr); + retval = &EG(uninitialized_zval); } } else { - std_hnd = zend_get_std_object_handlers(); - retval = std_hnd->read_property(object, member, type, key TSRMLS_CC); + zend_object_handlers *std_hnd = zend_get_std_object_handlers(); + retval = std_hnd->read_property(object, member, type, key, rv TSRMLS_CC); } if (member == &tmp_member) { @@ -385,29 +368,23 @@ zval *dom_read_property(zval *object, zval *member, int type, const zend_literal /* {{{ dom_write_property */ void dom_write_property(zval *object, zval *member, zval *value, const zend_literal *key TSRMLS_DC) { - dom_object *obj; + dom_object *obj = Z_DOMOBJ_P(object); zval tmp_member; - dom_prop_handler *hnd; - zend_object_handlers *std_hnd; - int ret; + dom_prop_handler *hnd = NULL; - if (member->type != IS_STRING) { - tmp_member = *member; - zval_copy_ctor(&tmp_member); + if (Z_TYPE_P(member) != IS_STRING) { + ZVAL_DUP(&tmp_member, member); convert_to_string(&tmp_member); member = &tmp_member; } - ret = FAILURE; - obj = (dom_object *)zend_objects_get_address(object TSRMLS_CC); - if (obj->prop_handler != NULL) { - ret = zend_hash_find((HashTable *)obj->prop_handler, Z_STRVAL_P(member), Z_STRLEN_P(member)+1, (void **) &hnd); + hnd = zend_hash_find_ptr(obj->prop_handler, Z_STR_P(member)); } - if (ret == SUCCESS) { + if (hnd) { hnd->write_func(obj, value TSRMLS_CC); } else { - std_hnd = zend_get_std_object_handlers(); + zend_object_handlers *std_hnd = zend_get_std_object_handlers(); std_hnd->write_property(object, member, value, key TSRMLS_CC); } @@ -420,42 +397,35 @@ void dom_write_property(zval *object, zval *member, zval *value, const zend_lite /* {{{ dom_property_exists */ static int dom_property_exists(zval *object, zval *member, int check_empty, const zend_literal *key TSRMLS_DC) { - dom_object *obj; + dom_object *obj = Z_DOMOBJ_P(object); zval tmp_member; - dom_prop_handler *hnd; - zend_object_handlers *std_hnd; - int ret, retval=0; + dom_prop_handler *hnd = NULL; + int retval=0; - if (member->type != IS_STRING) { - tmp_member = *member; - zval_copy_ctor(&tmp_member); + if (Z_TYPE_P(member) != IS_STRING) { + ZVAL_DUP(&tmp_member, member); convert_to_string(&tmp_member); member = &tmp_member; } - ret = FAILURE; - obj = (dom_object *)zend_objects_get_address(object TSRMLS_CC); - if (obj->prop_handler != NULL) { - ret = zend_hash_find((HashTable *)obj->prop_handler, Z_STRVAL_P(member), Z_STRLEN_P(member)+1, (void **) &hnd); + hnd = zend_hash_find_ptr(obj->prop_handler, Z_STR_P(member)); } - if (ret == SUCCESS) { - zval *tmp; + if (hnd) { + zval tmp; if (check_empty == 2) { retval = 1; } else if (hnd->read_func(obj, &tmp TSRMLS_CC) == SUCCESS) { - Z_SET_REFCOUNT_P(tmp, 1); - Z_UNSET_ISREF_P(tmp); if (check_empty == 1) { - retval = zend_is_true(tmp TSRMLS_CC); + retval = zend_is_true(&tmp TSRMLS_CC); } else if (check_empty == 0) { - retval = (Z_TYPE_P(tmp) != IS_NULL); + retval = (Z_TYPE(tmp) != IS_NULL); } - zval_ptr_dtor(&tmp); + zval_dtor(&tmp); } } else { - std_hnd = zend_get_std_object_handlers(); + zend_object_handlers *std_hnd = zend_get_std_object_handlers(); retval = std_hnd->has_property(object, member, check_empty, key TSRMLS_CC); } @@ -468,14 +438,13 @@ static int dom_property_exists(zval *object, zval *member, int check_empty, cons 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); + dom_object *obj = Z_DOMOBJ_P(object); HashTable *debug_info, *prop_handlers = obj->prop_handler, *std_props; HashPosition pos; dom_prop_handler *entry; - zval *object_value, - *null_value; + zval object_value; *is_temp = 1; @@ -483,59 +452,39 @@ static HashTable* dom_get_debug_info_helper(zval *object, int *is_temp TSRMLS_DC 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*)); + zend_hash_copy(debug_info, std_props, (copy_ctor_func_t) zval_add_ref); 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); + ZVAL_STRING(&object_value, "(object value omitted)"); for (zend_hash_internal_pointer_reset_ex(prop_handlers, &pos); - zend_hash_get_current_data_ex(prop_handlers, (void **)&entry, &pos) - == SUCCESS; + entry = zend_hash_get_current_data_ptr_ex(prop_handlers, &pos); zend_hash_move_forward_ex(prop_handlers, &pos)) { - zval *value; - char *string_key = NULL; - uint string_length = 0; - ulong num_key; + zval value; + zend_string *string_key; + 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) { + &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); + if (Z_TYPE(value) == IS_OBJECT) { + zval_dtor(&value); + ZVAL_COPY(&value, &object_value); } - zval_add_ref(&value); - zend_hash_add(debug_info, string_key, string_length, - &value, sizeof(zval *), NULL); + zend_hash_add(debug_info, string_key, &value); } - zval_ptr_dtor(&null_value); - zval_ptr_dtor(&object_value); + zval_dtor(&object_value); return debug_info; } @@ -586,13 +535,11 @@ PHP_FUNCTION(dom_import_simplexml) } /* }}} */ -zend_object_value dom_objects_store_clone_obj(zval *zobject TSRMLS_DC) /* {{{ */ +zend_object *dom_objects_store_clone_obj(zval *zobject TSRMLS_DC) /* {{{ */ { - zend_object_value retval; - void *new_object; + /*void *new_object; dom_object *intern; dom_object *old_object; - struct _store_object *obj; zend_object_handle handle = Z_OBJ_HANDLE_P(zobject); obj = &EG(objects_store).object_buckets[handle].bucket.obj; @@ -611,7 +558,15 @@ zend_object_value dom_objects_store_clone_obj(zval *zobject TSRMLS_DC) /* {{{ */ old_object = (dom_object *) obj->object; zend_objects_clone_members(&intern->std, retval, &old_object->std, intern->handle TSRMLS_CC); - return retval; + return retval;*/ +} +/* }}} */ + +static void dom_copy_prop_handler(zval *zv) /* {{{ */ +{ + dom_prop_handler *hnd = Z_PTR_P(zv); + Z_PTR_P(zv) = malloc(sizeof(dom_prop_handler)); + memcpy(Z_PTR_P(zv), hnd, sizeof(dom_prop_handler)); } /* }}} */ @@ -679,19 +634,19 @@ PHP_MINIT_FUNCTION(dom) zend_hash_init(&dom_domstringlist_prop_handlers, 0, NULL, NULL, 1); dom_register_prop_handler(&dom_domstringlist_prop_handlers, "length", dom_domstringlist_length_read, NULL TSRMLS_CC); - zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_domstringlist_prop_handlers, sizeof(dom_domstringlist_prop_handlers), NULL); + zend_hash_add_mem(&classes, ce.name, &dom_domstringlist_prop_handlers, sizeof(dom_domstringlist_prop_handlers)); REGISTER_DOM_CLASS(ce, "DOMNameList", NULL, php_dom_namelist_class_functions, dom_namelist_class_entry); zend_hash_init(&dom_namelist_prop_handlers, 0, NULL, NULL, 1); dom_register_prop_handler(&dom_namelist_prop_handlers, "length", dom_namelist_length_read, NULL TSRMLS_CC); - zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_namelist_prop_handlers, sizeof(dom_namelist_prop_handlers), NULL); + zend_hash_add_mem(&classes, ce.name, &dom_namelist_prop_handlers, sizeof(dom_namelist_prop_handlers)); REGISTER_DOM_CLASS(ce, "DOMImplementationList", NULL, php_dom_domimplementationlist_class_functions, dom_domimplementationlist_class_entry); zend_hash_init(&dom_domimplementationlist_prop_handlers, 0, NULL, NULL, 1); dom_register_prop_handler(&dom_domimplementationlist_prop_handlers, "length", dom_domimplementationlist_length_read, NULL TSRMLS_CC); - zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_domimplementationlist_prop_handlers, sizeof(dom_domimplementationlist_prop_handlers), NULL); + zend_hash_add_mem(&classes, ce.name, &dom_domimplementationlist_prop_handlers, sizeof(dom_domimplementationlist_prop_handlers)); REGISTER_DOM_CLASS(ce, "DOMImplementationSource", NULL, php_dom_domimplementationsource_class_functions, dom_domimplementationsource_class_entry); REGISTER_DOM_CLASS(ce, "DOMImplementation", NULL, php_dom_domimplementation_class_functions, dom_domimplementation_class_entry); @@ -715,7 +670,7 @@ PHP_MINIT_FUNCTION(dom) dom_register_prop_handler(&dom_node_prop_handlers, "localName", dom_node_local_name_read, NULL TSRMLS_CC); dom_register_prop_handler(&dom_node_prop_handlers, "baseURI", dom_node_base_uri_read, NULL TSRMLS_CC); dom_register_prop_handler(&dom_node_prop_handlers, "textContent", dom_node_text_content_read, dom_node_text_content_write TSRMLS_CC); - zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_node_prop_handlers, sizeof(dom_node_prop_handlers), NULL); + zend_hash_add_mem(&classes, ce.name, &dom_node_prop_handlers, sizeof(dom_node_prop_handlers)); REGISTER_DOM_CLASS(ce, "DOMNameSpaceNode", NULL, NULL, dom_namespace_node_class_entry); @@ -728,10 +683,10 @@ PHP_MINIT_FUNCTION(dom) dom_register_prop_handler(&dom_namespace_node_prop_handlers, "namespaceURI", dom_node_namespace_uri_read, NULL TSRMLS_CC); dom_register_prop_handler(&dom_namespace_node_prop_handlers, "ownerDocument", dom_node_owner_document_read, NULL TSRMLS_CC); dom_register_prop_handler(&dom_namespace_node_prop_handlers, "parentNode", dom_node_parent_node_read, NULL TSRMLS_CC); - zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_namespace_node_prop_handlers, sizeof(dom_namespace_node_prop_handlers), NULL); + zend_hash_add_mem(&classes, ce.name, &dom_namespace_node_prop_handlers, sizeof(dom_namespace_node_prop_handlers)); REGISTER_DOM_CLASS(ce, "DOMDocumentFragment", dom_node_class_entry, php_dom_documentfragment_class_functions, dom_documentfragment_class_entry); - zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_node_prop_handlers, sizeof(dom_node_prop_handlers), NULL); + zend_hash_add_mem(&classes, ce.name, &dom_node_prop_handlers, sizeof(dom_node_prop_handlers)); REGISTER_DOM_CLASS(ce, "DOMDocument", dom_node_class_entry, php_dom_document_class_functions, dom_document_class_entry); zend_hash_init(&dom_document_prop_handlers, 0, NULL, NULL, 1); @@ -755,8 +710,8 @@ PHP_MINIT_FUNCTION(dom) dom_register_prop_handler(&dom_document_prop_handlers, "recover", dom_document_recover_read, dom_document_recover_write TSRMLS_CC); dom_register_prop_handler(&dom_document_prop_handlers, "substituteEntities", dom_document_substitue_entities_read, dom_document_substitue_entities_write TSRMLS_CC); - zend_hash_merge(&dom_document_prop_handlers, &dom_node_prop_handlers, NULL, NULL, sizeof(dom_prop_handler), 0); - zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_document_prop_handlers, sizeof(dom_document_prop_handlers), NULL); + zend_hash_merge(&dom_document_prop_handlers, &dom_node_prop_handlers, dom_copy_prop_handler, 0); + zend_hash_add_mem(&classes, ce.name, &dom_document_prop_handlers, sizeof(dom_document_prop_handlers)); INIT_CLASS_ENTRY(ce, "DOMNodeList", php_dom_nodelist_class_functions); ce.create_object = dom_nnodemap_objects_new; @@ -766,7 +721,7 @@ PHP_MINIT_FUNCTION(dom) zend_hash_init(&dom_nodelist_prop_handlers, 0, NULL, NULL, 1); dom_register_prop_handler(&dom_nodelist_prop_handlers, "length", dom_nodelist_length_read, NULL TSRMLS_CC); - zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_nodelist_prop_handlers, sizeof(dom_nodelist_prop_handlers), NULL); + zend_hash_add_mem(&classes, ce.name, &dom_nodelist_prop_handlers, sizeof(dom_nodelist_prop_handlers)); INIT_CLASS_ENTRY(ce, "DOMNamedNodeMap", php_dom_namednodemap_class_functions); ce.create_object = dom_nnodemap_objects_new; @@ -776,15 +731,15 @@ PHP_MINIT_FUNCTION(dom) zend_hash_init(&dom_namednodemap_prop_handlers, 0, NULL, NULL, 1); dom_register_prop_handler(&dom_namednodemap_prop_handlers, "length", dom_namednodemap_length_read, NULL TSRMLS_CC); - zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_namednodemap_prop_handlers, sizeof(dom_namednodemap_prop_handlers), NULL); + zend_hash_add_mem(&classes, ce.name, &dom_namednodemap_prop_handlers, sizeof(dom_namednodemap_prop_handlers)); REGISTER_DOM_CLASS(ce, "DOMCharacterData", dom_node_class_entry, php_dom_characterdata_class_functions, dom_characterdata_class_entry); zend_hash_init(&dom_characterdata_prop_handlers, 0, NULL, NULL, 1); dom_register_prop_handler(&dom_characterdata_prop_handlers, "data", dom_characterdata_data_read, dom_characterdata_data_write TSRMLS_CC); dom_register_prop_handler(&dom_characterdata_prop_handlers, "length", dom_characterdata_length_read, NULL TSRMLS_CC); - zend_hash_merge(&dom_characterdata_prop_handlers, &dom_node_prop_handlers, NULL, NULL, sizeof(dom_prop_handler), 0); - zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_characterdata_prop_handlers, sizeof(dom_characterdata_prop_handlers), NULL); + zend_hash_merge(&dom_characterdata_prop_handlers, &dom_node_prop_handlers, dom_copy_prop_handler, 0); + zend_hash_add_mem(&classes, ce.name, &dom_characterdata_prop_handlers, sizeof(dom_characterdata_prop_handlers)); REGISTER_DOM_CLASS(ce, "DOMAttr", dom_node_class_entry, php_dom_attr_class_functions, dom_attr_class_entry); @@ -794,33 +749,33 @@ PHP_MINIT_FUNCTION(dom) dom_register_prop_handler(&dom_attr_prop_handlers, "value", dom_attr_value_read, dom_attr_value_write TSRMLS_CC); dom_register_prop_handler(&dom_attr_prop_handlers, "ownerElement", dom_attr_owner_element_read, NULL TSRMLS_CC); dom_register_prop_handler(&dom_attr_prop_handlers, "schemaTypeInfo", dom_attr_schema_type_info_read, NULL TSRMLS_CC); - zend_hash_merge(&dom_attr_prop_handlers, &dom_node_prop_handlers, NULL, NULL, sizeof(dom_prop_handler), 0); - zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_attr_prop_handlers, sizeof(dom_attr_prop_handlers), NULL); + zend_hash_merge(&dom_attr_prop_handlers, &dom_node_prop_handlers, dom_copy_prop_handler, 0); + zend_hash_add_mem(&classes, ce.name, &dom_attr_prop_handlers, sizeof(dom_attr_prop_handlers)); REGISTER_DOM_CLASS(ce, "DOMElement", dom_node_class_entry, php_dom_element_class_functions, dom_element_class_entry); zend_hash_init(&dom_element_prop_handlers, 0, NULL, NULL, 1); dom_register_prop_handler(&dom_element_prop_handlers, "tagName", dom_element_tag_name_read, NULL TSRMLS_CC); dom_register_prop_handler(&dom_element_prop_handlers, "schemaTypeInfo", dom_element_schema_type_info_read, NULL TSRMLS_CC); - zend_hash_merge(&dom_element_prop_handlers, &dom_node_prop_handlers, NULL, NULL, sizeof(dom_prop_handler), 0); - zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_element_prop_handlers, sizeof(dom_element_prop_handlers), NULL); + zend_hash_merge(&dom_element_prop_handlers, &dom_node_prop_handlers, dom_copy_prop_handler, 0); + zend_hash_add_mem(&classes, ce.name, &dom_element_prop_handlers, sizeof(dom_element_prop_handlers)); REGISTER_DOM_CLASS(ce, "DOMText", dom_characterdata_class_entry, php_dom_text_class_functions, dom_text_class_entry); zend_hash_init(&dom_text_prop_handlers, 0, NULL, NULL, 1); dom_register_prop_handler(&dom_text_prop_handlers, "wholeText", dom_text_whole_text_read, NULL TSRMLS_CC); - zend_hash_merge(&dom_text_prop_handlers, &dom_characterdata_prop_handlers, NULL, NULL, sizeof(dom_prop_handler), 0); - zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_text_prop_handlers, sizeof(dom_text_prop_handlers), NULL); + zend_hash_merge(&dom_text_prop_handlers, &dom_characterdata_prop_handlers, dom_copy_prop_handler, 0); + zend_hash_add_mem(&classes, ce.name, &dom_text_prop_handlers, sizeof(dom_text_prop_handlers)); REGISTER_DOM_CLASS(ce, "DOMComment", dom_characterdata_class_entry, php_dom_comment_class_functions, dom_comment_class_entry); - zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_characterdata_prop_handlers, sizeof(dom_typeinfo_prop_handlers), NULL); + zend_hash_add_mem(&classes, ce.name, &dom_characterdata_prop_handlers, sizeof(dom_characterdata_prop_handlers)); REGISTER_DOM_CLASS(ce, "DOMTypeinfo", NULL, php_dom_typeinfo_class_functions, dom_typeinfo_class_entry); zend_hash_init(&dom_typeinfo_prop_handlers, 0, NULL, NULL, 1); dom_register_prop_handler(&dom_typeinfo_prop_handlers, "typeName", dom_typeinfo_type_name_read, NULL TSRMLS_CC); dom_register_prop_handler(&dom_typeinfo_prop_handlers, "typeNamespace", dom_typeinfo_type_namespace_read, NULL TSRMLS_CC); - zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_typeinfo_prop_handlers, sizeof(dom_typeinfo_prop_handlers), NULL); + zend_hash_add_mem(&classes, ce.name, &dom_typeinfo_prop_handlers, sizeof(dom_typeinfo_prop_handlers)); REGISTER_DOM_CLASS(ce, "DOMUserDataHandler", NULL, php_dom_userdatahandler_class_functions, dom_userdatahandler_class_entry); REGISTER_DOM_CLASS(ce, "DOMDomError", NULL, php_dom_domerror_class_functions, dom_domerror_class_entry); @@ -832,7 +787,7 @@ PHP_MINIT_FUNCTION(dom) dom_register_prop_handler(&dom_domerror_prop_handlers, "relatedException", dom_domerror_related_exception_read, NULL TSRMLS_CC); dom_register_prop_handler(&dom_domerror_prop_handlers, "related_data", dom_domerror_related_data_read, NULL TSRMLS_CC); dom_register_prop_handler(&dom_domerror_prop_handlers, "location", dom_domerror_location_read, NULL TSRMLS_CC); - zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_domerror_prop_handlers, sizeof(dom_domerror_prop_handlers), NULL); + zend_hash_add_mem(&classes, ce.name, &dom_domerror_prop_handlers, sizeof(dom_domerror_prop_handlers)); REGISTER_DOM_CLASS(ce, "DOMErrorHandler", NULL, php_dom_domerrorhandler_class_functions, dom_domerrorhandler_class_entry); REGISTER_DOM_CLASS(ce, "DOMLocator", NULL, php_dom_domlocator_class_functions, dom_domlocator_class_entry); @@ -843,11 +798,11 @@ PHP_MINIT_FUNCTION(dom) dom_register_prop_handler(&dom_domlocator_prop_handlers, "offset", dom_domlocator_offset_read, NULL TSRMLS_CC); dom_register_prop_handler(&dom_domlocator_prop_handlers, "relatedNode", dom_domlocator_related_node_read, NULL TSRMLS_CC); dom_register_prop_handler(&dom_domlocator_prop_handlers, "uri", dom_domlocator_uri_read, NULL TSRMLS_CC); - zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_domlocator_prop_handlers, sizeof(dom_domlocator_prop_handlers), NULL); + zend_hash_add_mem(&classes, ce.name, &dom_domlocator_prop_handlers, sizeof(dom_domlocator_prop_handlers)); REGISTER_DOM_CLASS(ce, "DOMConfiguration", NULL, php_dom_domconfiguration_class_functions, dom_domconfiguration_class_entry); REGISTER_DOM_CLASS(ce, "DOMCdataSection", dom_text_class_entry, php_dom_cdatasection_class_functions, dom_cdatasection_class_entry); - zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_text_prop_handlers, sizeof(dom_documenttype_prop_handlers), NULL); + zend_hash_add_mem(&classes, ce.name, &dom_text_prop_handlers, sizeof(dom_text_prop_handlers)); REGISTER_DOM_CLASS(ce, "DOMDocumentType", dom_node_class_entry, php_dom_documenttype_class_functions, dom_documenttype_class_entry); @@ -858,16 +813,16 @@ PHP_MINIT_FUNCTION(dom) dom_register_prop_handler(&dom_documenttype_prop_handlers, "publicId", dom_documenttype_public_id_read, NULL TSRMLS_CC); dom_register_prop_handler(&dom_documenttype_prop_handlers, "systemId", dom_documenttype_system_id_read, NULL TSRMLS_CC); dom_register_prop_handler(&dom_documenttype_prop_handlers, "internalSubset", dom_documenttype_internal_subset_read, NULL TSRMLS_CC); - zend_hash_merge(&dom_documenttype_prop_handlers, &dom_node_prop_handlers, NULL, NULL, sizeof(dom_prop_handler), 0); - zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_documenttype_prop_handlers, sizeof(dom_documenttype_prop_handlers), NULL); + zend_hash_merge(&dom_documenttype_prop_handlers, &dom_node_prop_handlers, dom_copy_prop_handler, 0); + zend_hash_add_mem(&classes, ce.name, &dom_documenttype_prop_handlers, sizeof(dom_documenttype_prop_handlers)); REGISTER_DOM_CLASS(ce, "DOMNotation", dom_node_class_entry, php_dom_notation_class_functions, dom_notation_class_entry); zend_hash_init(&dom_notation_prop_handlers, 0, NULL, NULL, 1); dom_register_prop_handler(&dom_notation_prop_handlers, "publicId", dom_notation_public_id_read, NULL TSRMLS_CC); dom_register_prop_handler(&dom_notation_prop_handlers, "systemId", dom_notation_system_id_read, NULL TSRMLS_CC); - zend_hash_merge(&dom_notation_prop_handlers, &dom_node_prop_handlers, NULL, NULL, sizeof(dom_prop_handler), 0); - zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_notation_prop_handlers, sizeof(dom_notation_prop_handlers), NULL); + zend_hash_merge(&dom_notation_prop_handlers, &dom_node_prop_handlers, dom_copy_prop_handler, 0); + zend_hash_add_mem(&classes, ce.name, &dom_notation_prop_handlers, sizeof(dom_notation_prop_handlers)); REGISTER_DOM_CLASS(ce, "DOMEntity", dom_node_class_entry, php_dom_entity_class_functions, dom_entity_class_entry); @@ -878,20 +833,19 @@ PHP_MINIT_FUNCTION(dom) dom_register_prop_handler(&dom_entity_prop_handlers, "actualEncoding", dom_entity_actual_encoding_read, dom_entity_actual_encoding_write TSRMLS_CC); dom_register_prop_handler(&dom_entity_prop_handlers, "encoding", dom_entity_encoding_read, dom_entity_encoding_write TSRMLS_CC); dom_register_prop_handler(&dom_entity_prop_handlers, "version", dom_entity_version_read, dom_entity_version_write TSRMLS_CC); - zend_hash_merge(&dom_entity_prop_handlers, &dom_node_prop_handlers, NULL, NULL, sizeof(dom_prop_handler), 0); - - zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_entity_prop_handlers, sizeof(dom_entity_prop_handlers), NULL); + zend_hash_merge(&dom_entity_prop_handlers, &dom_node_prop_handlers, dom_copy_prop_handler, 0); + zend_hash_add_mem(&classes, ce.name, &dom_entity_prop_handlers, sizeof(dom_entity_prop_handlers)); REGISTER_DOM_CLASS(ce, "DOMEntityReference", dom_node_class_entry, php_dom_entityreference_class_functions, dom_entityreference_class_entry); - zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_node_prop_handlers, sizeof(dom_entity_prop_handlers), NULL); + zend_hash_add_mem(&classes, ce.name, &dom_node_prop_handlers, sizeof(dom_node_prop_handlers)); REGISTER_DOM_CLASS(ce, "DOMProcessingInstruction", dom_node_class_entry, php_dom_processinginstruction_class_functions, dom_processinginstruction_class_entry); zend_hash_init(&dom_processinginstruction_prop_handlers, 0, NULL, NULL, 1); dom_register_prop_handler(&dom_processinginstruction_prop_handlers, "target", dom_processinginstruction_target_read, NULL TSRMLS_CC); dom_register_prop_handler(&dom_processinginstruction_prop_handlers, "data", dom_processinginstruction_data_read, dom_processinginstruction_data_write TSRMLS_CC); - zend_hash_merge(&dom_processinginstruction_prop_handlers, &dom_node_prop_handlers, NULL, NULL, sizeof(dom_prop_handler), 0); - zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_processinginstruction_prop_handlers, sizeof(dom_processinginstruction_prop_handlers), NULL); + zend_hash_merge(&dom_processinginstruction_prop_handlers, &dom_node_prop_handlers, dom_copy_prop_handler, 0); + zend_hash_add_mem(&classes, ce.name, &dom_processinginstruction_prop_handlers, sizeof(dom_processinginstruction_prop_handlers)); REGISTER_DOM_CLASS(ce, "DOMStringExtend", NULL, php_dom_string_extend_class_functions, dom_string_extend_class_entry); @@ -902,7 +856,7 @@ PHP_MINIT_FUNCTION(dom) zend_hash_init(&dom_xpath_prop_handlers, 0, NULL, NULL, 1); dom_register_prop_handler(&dom_xpath_prop_handlers, "document", dom_xpath_document_read, NULL TSRMLS_CC); - zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_xpath_prop_handlers, sizeof(dom_xpath_prop_handlers), NULL); + zend_hash_add_mem(&classes, ce.name, &dom_xpath_prop_handlers, sizeof(dom_xpath_prop_handlers)); #endif REGISTER_LONG_CONSTANT("XML_ELEMENT_NODE", XML_ELEMENT_NODE, CONST_CS | CONST_PERSISTENT); @@ -1113,49 +1067,33 @@ void dom_objects_free_storage(void *object TSRMLS_DC) void dom_namednode_iter(dom_object *basenode, int ntype, dom_object *intern, xmlHashTablePtr ht, xmlChar *local, xmlChar *ns TSRMLS_DC) /* {{{ */ { - dom_nnodemap_object *mapptr; - zval *baseobj = NULL; + dom_nnodemap_object *mapptr = (dom_nnodemap_object *) intern->ptr; - mapptr = (dom_nnodemap_object *)intern->ptr; if (basenode) { - MAKE_STD_ZVAL(baseobj); - baseobj->type = IS_OBJECT; - Z_SET_ISREF_P(baseobj); - baseobj->value.obj.handle = basenode->handle; - baseobj->value.obj.handlers = dom_get_obj_handlers(TSRMLS_C); - zval_copy_ctor(baseobj); + GC_REFCOUNT(&basenode->std)++; } - mapptr->baseobjptr = baseobj; + mapptr->baseobj = basenode; mapptr->nodetype = ntype; mapptr->ht = ht; mapptr->local = local; mapptr->ns = ns; - } /* }}} */ static dom_object* dom_objects_set_class(zend_class_entry *class_type, zend_bool hash_copy TSRMLS_DC) /* {{{ */ { zend_class_entry *base_class; - dom_object *intern; - - if (instanceof_function(class_type, dom_xpath_class_entry TSRMLS_CC)) { - intern = emalloc(sizeof(dom_xpath_object)); - memset(intern, 0, sizeof(dom_xpath_object)); - } else { - intern = emalloc(sizeof(dom_object)); - } - intern->ptr = NULL; - intern->prop_handler = NULL; - intern->document = NULL; + size_t dom_object_size = instanceof_function(class_type, dom_xpath_class_entry TSRMLS_CC) + ? sizeof(dom_xpath_object) : sizeof(dom_object); + dom_object *intern = ecalloc(1, dom_object_size + sizeof(zval) * (class_type->default_properties_count - 1)); base_class = class_type; - while(base_class->type != ZEND_INTERNAL_CLASS && base_class->parent != NULL) { + while (base_class->type != ZEND_INTERNAL_CLASS && base_class->parent != NULL) { base_class = base_class->parent; } - zend_hash_find(&classes, base_class->name, base_class->name_length + 1, (void **) &intern->prop_handler); + intern->prop_handler = zend_hash_find_ptr(&classes, base_class->name); zend_object_std_init(&intern->std, class_type TSRMLS_CC); if (hash_copy) { @@ -1200,45 +1138,33 @@ void dom_objects_clone(void *object, void **object_clone TSRMLS_DC) /* }}} */ /* {{{ dom_objects_new */ -zend_object_value dom_objects_new(zend_class_entry *class_type TSRMLS_DC) +zend_object *dom_objects_new(zend_class_entry *class_type TSRMLS_DC) { - zend_object_value retval; - dom_object *intern; - - intern = dom_objects_set_class(class_type, 1 TSRMLS_CC); - - retval.handle = zend_objects_store_put(intern, (zend_objects_store_dtor_t)zend_objects_destroy_object, (zend_objects_free_object_storage_t)dom_objects_free_storage, dom_objects_clone TSRMLS_CC); - intern->handle = retval.handle; - retval.handlers = dom_get_obj_handlers(TSRMLS_C); - - return retval; + dom_object *intern = dom_objects_set_class(class_type, 1 TSRMLS_CC); + intern->std.handlers = dom_get_obj_handlers(TSRMLS_C); + return &intern->std; } /* }}} */ #if defined(LIBXML_XPATH_ENABLED) /* {{{ zend_object_value dom_xpath_objects_new(zend_class_entry *class_type TSRMLS_DC) */ -zend_object_value dom_xpath_objects_new(zend_class_entry *class_type TSRMLS_DC) +zend_object *dom_xpath_objects_new(zend_class_entry *class_type TSRMLS_DC) { - zend_object_value retval; - dom_xpath_object *intern; - - intern = (dom_xpath_object *)dom_objects_set_class(class_type, 1 TSRMLS_CC); + dom_xpath_object *intern = (dom_xpath_object *) dom_objects_set_class(class_type, 1 TSRMLS_CC); intern->registerPhpFunctions = 0; - intern->registered_phpfunctions = NULL; intern->node_list = NULL; ALLOC_HASHTABLE(intern->registered_phpfunctions); zend_hash_init(intern->registered_phpfunctions, 0, NULL, ZVAL_PTR_DTOR, 0); - retval.handle = zend_objects_store_put(intern, (zend_objects_store_dtor_t)zend_objects_destroy_object, (zend_objects_free_object_storage_t)dom_xpath_objects_free_storage, dom_objects_clone TSRMLS_CC); - intern->handle = retval.handle; - retval.handlers = dom_get_obj_handlers(TSRMLS_C); + intern->std.handlers = dom_get_obj_handlers(TSRMLS_C); - return retval; + return &intern->std; } /* }}} */ #endif +#if 0 static void dom_nnodemap_object_dtor(void *object, zend_object_handle handle TSRMLS_DC) /* {{{ */ { zval *baseobj; @@ -1266,22 +1192,21 @@ static void dom_nnodemap_object_dtor(void *object, zend_object_handle handle TSR } /* }}} */ +#endif -void dom_nnodemap_objects_free_storage(void *object TSRMLS_DC) /* {{{ */ +void dom_nnodemap_objects_free_storage(zend_object *object TSRMLS_DC) /* {{{ */ { - dom_object *intern = (dom_object *)object; + dom_object *intern = php_dom_obj_from_obj(object); php_libxml_decrement_doc_ref((php_libxml_node_object *)intern TSRMLS_CC); zend_object_std_dtor(&intern->std TSRMLS_CC); - - efree(object); } /* }}} */ -zend_object_value dom_nnodemap_objects_new(zend_class_entry *class_type TSRMLS_DC) /* {{{ */ +zend_object *dom_nnodemap_objects_new(zend_class_entry *class_type TSRMLS_DC) /* {{{ */ { - zend_object_value retval; + /*zend_object_value retval; dom_object *intern; dom_nnodemap_object *objmap; @@ -1299,7 +1224,7 @@ zend_object_value dom_nnodemap_objects_new(zend_class_entry *class_type TSRMLS_D intern->handle = retval.handle; retval.handlers = dom_get_obj_handlers(TSRMLS_C); - return retval; + return retval;*/ } /* }}} */ @@ -1318,32 +1243,22 @@ void php_dom_create_interator(zval *return_value, int ce_type TSRMLS_DC) /* {{{ /* }}} */ /* {{{ php_dom_create_object */ -PHP_DOM_EXPORT zval *php_dom_create_object(xmlNodePtr obj, int *found, zval *return_value, dom_object *domobj TSRMLS_DC) +PHP_DOM_EXPORT zend_bool php_dom_create_object(xmlNodePtr obj, zval *return_value, dom_object *domobj TSRMLS_DC) { - zval *wrapper; zend_class_entry *ce; dom_object *intern; - *found = 0; - if (!obj) { - ALLOC_ZVAL(wrapper); - ZVAL_NULL(wrapper); - return wrapper; + ZVAL_NULL(return_value); + return 0; } if ((intern = (dom_object *) php_dom_object_get_data((void *) obj))) { - return_value->type = IS_OBJECT; - Z_SET_ISREF_P(return_value); - return_value->value.obj.handle = intern->handle; - return_value->value.obj.handlers = dom_get_obj_handlers(TSRMLS_C); - zval_copy_ctor(return_value); - *found = 1; - return return_value; + GC_REFCOUNT(&intern->std)++; + ZVAL_OBJ(return_value, &intern->std); + return 1; } - wrapper = return_value; - switch (obj->type) { case XML_DOCUMENT_NODE: case XML_HTML_DOCUMENT_NODE: @@ -1414,17 +1329,17 @@ PHP_DOM_EXPORT zval *php_dom_create_object(xmlNodePtr obj, int *found, zval *ret break; } default: - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unsupported node type: %d", Z_TYPE_P(obj)); - ZVAL_NULL(wrapper); - return wrapper; + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unsupported node type: %d", obj->type); + ZVAL_NULL(return_value); + return 0; } if (domobj && domobj->document) { ce = dom_get_doc_classmap(domobj->document, ce TSRMLS_CC); } - object_init_ex(wrapper, ce); + object_init_ex(return_value, ce); - intern = (dom_object *)zend_objects_get_address(wrapper TSRMLS_CC); + intern = Z_DOMOBJ_P(return_value); if (obj->doc != NULL) { if (domobj != NULL) { intern->document = domobj->document; @@ -1433,12 +1348,12 @@ PHP_DOM_EXPORT zval *php_dom_create_object(xmlNodePtr obj, int *found, zval *ret } php_libxml_increment_node_ptr((php_libxml_node_object *)intern, obj, (void *)intern TSRMLS_CC); - return (wrapper); + return 0; } /* }}} end php_domobject_new */ -void php_dom_create_implementation(zval **retval TSRMLS_DC) { - object_init_ex(*retval, dom_domimplementation_class_entry); +void php_dom_create_implementation(zval *retval TSRMLS_DC) { + object_init_ex(retval, dom_domimplementation_class_entry); } /* {{{ int dom_hierarchy(xmlNodePtr parent, xmlNodePtr child) */ |