]> granicus.if.org Git - php/commitdiff
Unicode support
authorDmitry Stogov <dmitry@php.net>
Thu, 18 Aug 2005 11:47:03 +0000 (11:47 +0000)
committerDmitry Stogov <dmitry@php.net>
Thu, 18 Aug 2005 11:47:03 +0000 (11:47 +0000)
ext/dom/php_dom.c
ext/dom/tests/dom003.phpt

index 3dbd3e9440340ee88e55a8cb51debe3bbe46616e..354c8dfcc8370f5fb37572d0121c5c621c961cdb 100644 (file)
@@ -72,29 +72,7 @@ zend_object_handlers dom_object_handlers;
 zend_object_handlers dom_ze1_object_handlers;
 
 static HashTable classes;
-
-static HashTable dom_domstringlist_prop_handlers;
-static HashTable dom_namelist_prop_handlers;
-static HashTable dom_domimplementationlist_prop_handlers;
-static HashTable dom_document_prop_handlers;
-static HashTable dom_node_prop_handlers;
-static HashTable dom_nodelist_prop_handlers;
-static HashTable dom_namednodemap_prop_handlers;
-static HashTable dom_characterdata_prop_handlers;
-static HashTable dom_attr_prop_handlers;
-static HashTable dom_element_prop_handlers;
-static HashTable dom_text_prop_handlers;
-static HashTable dom_typeinfo_prop_handlers;
-static HashTable dom_domerror_prop_handlers;
-static HashTable dom_domlocator_prop_handlers;
-static HashTable dom_documenttype_prop_handlers;
-static HashTable dom_notation_prop_handlers;
-static HashTable dom_entity_prop_handlers;
-static HashTable dom_processinginstruction_prop_handlers;
-static HashTable dom_namespace_node_prop_handlers;
-#if defined(LIBXML_XPATH_ENABLED)
-static HashTable dom_xpath_prop_handlers;
-#endif
+static HashTable u_classes;
 
 typedef int (*dom_read_t)(dom_object *obj, zval **retval TSRMLS_DC);
 typedef int (*dom_write_t)(dom_object *obj, zval *newval TSRMLS_DC);
@@ -465,10 +443,49 @@ zend_module_entry dom_module_entry = {
 ZEND_GET_MODULE(dom)
 #endif
 
+static void dom_prop_handlers_dtor(HashTable *ht)
+{
+       zend_hash_destroy(ht);
+}
+
+static void dom_prop_handlers_ctor(HashTable *ht)
+{
+       HashTable tmp = *ht;
+
+       zend_u_hash_init(ht, 0, NULL, NULL, 1, 1);
+       zend_hash_copy(ht, &tmp, NULL, NULL, sizeof(dom_prop_handler));
+}
+
 /* {{{ PHP_MINIT_FUNCTION(dom) */
 PHP_MINIT_FUNCTION(dom)
 {
        zend_class_entry ce;
+       HashTable dom_domstringlist_prop_handlers;
+       HashTable dom_namelist_prop_handlers;
+       HashTable dom_domimplementationlist_prop_handlers;
+       HashTable dom_document_prop_handlers;
+       HashTable dom_node_prop_handlers;
+       HashTable dom_document_fragment_prop_handlers;
+       HashTable dom_nodelist_prop_handlers;
+       HashTable dom_namednodemap_prop_handlers;
+       HashTable dom_characterdata_prop_handlers;
+       HashTable dom_attr_prop_handlers;
+       HashTable dom_element_prop_handlers;
+       HashTable dom_text_prop_handlers;
+       HashTable dom_cdata_prop_handlers;
+       HashTable dom_comment_prop_handlers;
+       HashTable dom_typeinfo_prop_handlers;
+       HashTable dom_domerror_prop_handlers;
+       HashTable dom_domlocator_prop_handlers;
+       HashTable dom_documenttype_prop_handlers;
+       HashTable dom_notation_prop_handlers;
+       HashTable dom_entity_prop_handlers;
+       HashTable dom_processinginstruction_prop_handlers;
+       HashTable dom_namespace_node_prop_handlers;
+       HashTable dom_entity_reference_prop_handlers;
+#if defined(LIBXML_XPATH_ENABLED)
+       HashTable dom_xpath_prop_handlers;
+#endif
 
        memcpy(&dom_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
        dom_object_handlers.read_property = dom_read_property;
@@ -482,7 +499,7 @@ PHP_MINIT_FUNCTION(dom)
        dom_object_handlers.get_property_ptr_ptr = dom_get_property_ptr_ptr;
        dom_ze1_object_handlers.clone_obj = dom_objects_ze1_clone_obj;
 
-       zend_hash_init(&classes, 0, NULL, NULL, 1);
+       zend_hash_init(&classes, 0, NULL, (void (*)(void *))dom_prop_handlers_dtor, 1);
 
        INIT_CLASS_ENTRY(ce, "DOMException", php_dom_domexception_class_functions);
        dom_domexception_class_entry = zend_register_internal_class_ex(&ce, zend_exception_get_default(TSRMLS_C), NULL TSRMLS_CC);
@@ -545,7 +562,9 @@ PHP_MINIT_FUNCTION(dom)
        zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_namespace_node_prop_handlers, sizeof(dom_namespace_node_prop_handlers), NULL);
 
        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_init(&dom_document_fragment_prop_handlers, 0, NULL, NULL, 1);
+       zend_hash_copy(&dom_document_fragment_prop_handlers, &dom_node_prop_handlers, NULL, NULL, sizeof(dom_prop_handler));
+       zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_document_fragment_prop_handlers, sizeof(dom_node_prop_handlers), NULL);
        
        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);
@@ -625,7 +644,9 @@ PHP_MINIT_FUNCTION(dom)
        zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_text_prop_handlers, sizeof(dom_text_prop_handlers), NULL);
 
        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_init(&dom_comment_prop_handlers, 0, NULL, NULL, 1);
+       zend_hash_copy(&dom_comment_prop_handlers, &dom_node_prop_handlers, NULL, NULL, sizeof(dom_prop_handler));
+       zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_comment_prop_handlers, sizeof(dom_typeinfo_prop_handlers), NULL);
 
        REGISTER_DOM_CLASS(ce, "DOMTypeinfo", NULL, php_dom_typeinfo_class_functions, dom_typeinfo_class_entry);
        
@@ -659,7 +680,9 @@ PHP_MINIT_FUNCTION(dom)
 
        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_init(&dom_cdata_prop_handlers, 0, NULL, NULL, 1);
+       zend_hash_copy(&dom_cdata_prop_handlers, &dom_text_prop_handlers, NULL, NULL, sizeof(dom_prop_handler));
+       zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_cdata_prop_handlers, sizeof(dom_documenttype_prop_handlers), NULL);
 
        REGISTER_DOM_CLASS(ce, "DOMDocumentType", dom_node_class_entry, php_dom_documenttype_class_functions, dom_documenttype_class_entry);
        
@@ -698,7 +721,9 @@ PHP_MINIT_FUNCTION(dom)
        zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_entity_prop_handlers, sizeof(dom_entity_prop_handlers), NULL);
 
        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_init(&dom_entity_reference_prop_handlers, 0, NULL, NULL, 1);
+       zend_hash_copy(&dom_entity_reference_prop_handlers, &dom_node_prop_handlers, NULL, NULL, sizeof(dom_prop_handler));
+       zend_hash_add(&classes, ce.name, ce.name_length + 1, &dom_entity_reference_prop_handlers, sizeof(dom_entity_prop_handlers), NULL);
 
        REGISTER_DOM_CLASS(ce, "DOMProcessingInstruction", dom_node_class_entry, php_dom_processinginstruction_class_functions, dom_processinginstruction_class_entry);
        
@@ -773,6 +798,9 @@ PHP_MINIT_FUNCTION(dom)
 
        php_libxml_register_export(dom_node_class_entry, php_dom_export_node);
 
+       zend_u_hash_init(&u_classes, 0, NULL, (void (*)(void *))dom_prop_handlers_dtor, 1, 1);
+       zend_hash_copy(&u_classes, &classes, (copy_ctor_func_t)dom_prop_handlers_ctor, NULL, sizeof(HashTable));
+
        return SUCCESS;
 }
 /* }}} */
@@ -803,29 +831,8 @@ PHP_MINFO_FUNCTION(dom)
 
 PHP_MSHUTDOWN_FUNCTION(dom)
 {
-       zend_hash_destroy(&dom_domstringlist_prop_handlers);
-       zend_hash_destroy(&dom_namelist_prop_handlers);
-       zend_hash_destroy(&dom_domimplementationlist_prop_handlers);
-       zend_hash_destroy(&dom_document_prop_handlers);
-       zend_hash_destroy(&dom_node_prop_handlers);
-       zend_hash_destroy(&dom_namespace_node_prop_handlers);
-       zend_hash_destroy(&dom_nodelist_prop_handlers);
-       zend_hash_destroy(&dom_namednodemap_prop_handlers);
-       zend_hash_destroy(&dom_characterdata_prop_handlers);
-       zend_hash_destroy(&dom_attr_prop_handlers);
-       zend_hash_destroy(&dom_element_prop_handlers);
-       zend_hash_destroy(&dom_text_prop_handlers);
-       zend_hash_destroy(&dom_typeinfo_prop_handlers);
-       zend_hash_destroy(&dom_domerror_prop_handlers);
-       zend_hash_destroy(&dom_domlocator_prop_handlers);
-       zend_hash_destroy(&dom_documenttype_prop_handlers);
-       zend_hash_destroy(&dom_notation_prop_handlers);
-       zend_hash_destroy(&dom_entity_prop_handlers);
-       zend_hash_destroy(&dom_processinginstruction_prop_handlers);
-#if defined(LIBXML_XPATH_ENABLED)
-       zend_hash_destroy(&dom_xpath_prop_handlers);
-#endif
        zend_hash_destroy(&classes);
+       zend_hash_destroy(&u_classes);
        
 /*     If you want do find memleaks in this module, compile libxml2 with --with-mem-debug and
        uncomment the following line, this will tell you the amount of not freed memory
@@ -952,7 +959,7 @@ static dom_object* dom_objects_set_class(zend_class_entry *class_type, zend_bool
                base_class = base_class->parent;
        }
 
-       zend_hash_find(&classes, base_class->name, base_class->name_length + 1, (void **) &intern->prop_handler);
+       zend_u_hash_find(UG(unicode)?&u_classes:&classes, UG(unicode)?IS_UNICODE:IS_STRING, base_class->name, base_class->name_length + 1, (void **) &intern->prop_handler);
 
        ALLOC_HASHTABLE(intern->std.properties);
        zend_hash_init(intern->std.properties, 0, NULL, ZVAL_PTR_DTOR, 0);
index bc864432b7134e4f395077e3274d5a741283be6d..c1f4d22082943e2a2045a80f98d696bf6ef613c1 100644 (file)
@@ -57,6 +57,49 @@ object(DOMException)#%d (6) {
 }
 --- Don't catch exception with try/catch
 
+Fatal error: Uncaught exception 'DOMException' with message 'Hierarchy Request Error' in %sdom003.php:%d
+Stack trace:
+#0 %sdom003.php(13): DOMNode->appendChild(Object(DOMElement))
+#1 {main}
+  thrown in %sdom003.php on line %d
+--UEXPECTF--
+--- Catch exception with try/catch
+object(DOMException)#%d (6) {
+  [u"message":protected]=>
+  unicode(23) "Hierarchy Request Error"
+  [u"string":u"Exception":private]=>
+  unicode(0) ""
+  [u"file":protected]=>
+  unicode(%d) "%sdom003.php"
+  [u"line":protected]=>
+  int(8)
+  [u"trace":u"Exception":private]=>
+  array(1) {
+    [0]=>
+    array(6) {
+      [u"file"]=>
+      unicode(%d) "%sdom003.php"
+      [u"line"]=>
+      int(8)
+      [u"function"]=>
+      unicode(11) "appendChild"
+      [u"class"]=>
+      unicode(7) "DOMNode"
+      [u"type"]=>
+      unicode(2) "->"
+      [u"args"]=>
+      array(1) {
+        [0]=>
+        object(DOMElement)#%d (0) {
+        }
+      }
+    }
+  }
+  [u"code"]=>
+  int(3)
+}
+--- Don't catch exception with try/catch
+
 Fatal error: Uncaught exception 'DOMException' with message 'Hierarchy Request Error' in %sdom003.php:%d
 Stack trace:
 #0 %sdom003.php(13): DOMNode->appendChild(Object(DOMElement))