dmitry Thu Aug 18 07:47:04 2005 EDT
Modified files:
/php-src/ext/dom php_dom.c
/php-src/ext/dom/tests dom003.phpt
Log:
Unicode support
http://cvs.php.net/diff.php/php-src/ext/dom/php_dom.c?r1=1.77&r2=1.78&ty=u
Index: php-src/ext/dom/php_dom.c
diff -u php-src/ext/dom/php_dom.c:1.77 php-src/ext/dom/php_dom.c:1.78
--- php-src/ext/dom/php_dom.c:1.77 Fri Aug 12 10:57:58 2005
+++ php-src/ext/dom/php_dom.c Thu Aug 18 07:47:01 2005
@@ -18,7 +18,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_dom.c,v 1.77 2005/08/12 14:57:58 dmitry Exp $ */
+/* $Id: php_dom.c,v 1.78 2005/08/18 11:47:01 dmitry Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -72,29 +72,7 @@
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_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 @@
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 @@
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 @@
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 @@
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 @@
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_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_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 @@
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);
http://cvs.php.net/diff.php/php-src/ext/dom/tests/dom003.phpt?r1=1.11&r2=1.12&ty=u
Index: php-src/ext/dom/tests/dom003.phpt
diff -u php-src/ext/dom/tests/dom003.phpt:1.11
php-src/ext/dom/tests/dom003.phpt:1.12
--- php-src/ext/dom/tests/dom003.phpt:1.11 Mon Aug 15 03:55:34 2005
+++ php-src/ext/dom/tests/dom003.phpt Thu Aug 18 07:47:03 2005
@@ -62,3 +62,46 @@
#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))
+#1 {main}
+ thrown in %sdom003.php on line %d
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php