]> granicus.if.org Git - php/commitdiff
Unicode support
authorDmitry Stogov <dmitry@php.net>
Mon, 15 Aug 2005 17:29:07 +0000 (17:29 +0000)
committerDmitry Stogov <dmitry@php.net>
Mon, 15 Aug 2005 17:29:07 +0000 (17:29 +0000)
ext/spl/php_spl.c
ext/spl/spl_functions.c
ext/spl/spl_functions.h
ext/spl/spl_iterators.c
ext/spl/tests/spl_003.phpt
ext/standard/array.c

index ea8c1f4ea2b83d2f73a8b72f53492206efd31ad1..1b0fdcc9bb0bf3a565be4b92f498374037b65d50 100755 (executable)
@@ -59,23 +59,22 @@ static void spl_init_globals(zend_spl_globals *spl_globals)
 }
 /* }}} */
 
-static zend_class_entry * spl_find_ce_by_name(char *name, int len, zend_bool autoload TSRMLS_DC)
+static zend_class_entry * spl_find_ce_by_name(zend_uchar ztype, void *name, int len, zend_bool autoload TSRMLS_DC)
 {
        zend_class_entry **ce;
        int found;
+
        if (!autoload) {
                char *lc_name;
 
-               lc_name = do_alloca(len + 1);
-               zend_str_tolower_copy(lc_name, name, len);
-
-               found = zend_hash_find(EG(class_table), lc_name, len +1, (void **) &ce);
-               free_alloca(lc_name);
+               lc_name = zend_u_str_tolower_dup(ztype, name, len);
+               found = zend_u_hash_find(EG(class_table), ztype, lc_name, len +1, (void **) &ce);
+               efree(lc_name);
        } else {
-               found = zend_lookup_class(name, len, &ce TSRMLS_CC);
+               found = zend_u_lookup_class(ztype, name, len, &ce TSRMLS_CC);
        }
        if (found != SUCCESS) {
-               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Class %s does not exist%s", name, autoload ? " and could not be loaded" : "");
+               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Class %v does not exist%s", name, autoload ? " and could not be loaded" : "");
                return NULL;
        }
        
@@ -94,13 +93,13 @@ PHP_FUNCTION(class_parents)
                RETURN_FALSE;
        }
        
-       if (Z_TYPE_P(obj) != IS_OBJECT && Z_TYPE_P(obj) != IS_STRING) {
+       if (Z_TYPE_P(obj) != IS_OBJECT && Z_TYPE_P(obj) != IS_STRING && Z_TYPE_P(obj) != IS_UNICODE) {
                php_error_docref(NULL TSRMLS_CC, E_WARNING, "object or string expected");
                RETURN_FALSE;
        }
        
-       if (Z_TYPE_P(obj) == IS_STRING) {
-               if (NULL == (ce = spl_find_ce_by_name(Z_STRVAL_P(obj), Z_STRLEN_P(obj), autoload TSRMLS_CC))) {
+       if (Z_TYPE_P(obj) == IS_STRING || Z_TYPE_P(obj) == IS_UNICODE) {
+               if (NULL == (ce = spl_find_ce_by_name(Z_TYPE_P(obj), Z_UNIVAL_P(obj), Z_UNILEN_P(obj), autoload TSRMLS_CC))) {
                        RETURN_FALSE;
                }
        } else {
@@ -127,13 +126,13 @@ PHP_FUNCTION(class_implements)
        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|b", &obj, &autoload) == FAILURE) {
                RETURN_FALSE;
        }
-       if (Z_TYPE_P(obj) != IS_OBJECT && Z_TYPE_P(obj) != IS_STRING) {
+       if (Z_TYPE_P(obj) != IS_OBJECT && Z_TYPE_P(obj) != IS_STRING && Z_TYPE_P(obj) != IS_UNICODE) {
                php_error_docref(NULL TSRMLS_CC, E_WARNING, "object or string expected");
                RETURN_FALSE;
        }
        
-       if (Z_TYPE_P(obj) == IS_STRING) {
-               if (NULL == (ce = spl_find_ce_by_name(Z_STRVAL_P(obj), Z_STRLEN_P(obj), autoload TSRMLS_CC))) {
+       if (Z_TYPE_P(obj) == IS_STRING || Z_TYPE_P(obj) == IS_UNICODE) {
+               if (NULL == (ce = spl_find_ce_by_name(Z_TYPE_P(obj), Z_UNIVAL_P(obj), Z_UNILEN_P(obj), autoload TSRMLS_CC))) {
                        RETURN_FALSE;
                }
        } else {
@@ -146,7 +145,7 @@ PHP_FUNCTION(class_implements)
 /* }}} */
 
 #define SPL_ADD_CLASS(class_name, z_list, sub, allow, ce_flags) \
-       spl_add_classes(&spl_ce_ ## class_name, z_list, sub, allow, ce_flags TSRMLS_CC)
+       spl_add_classes(U_CLASS_ENTRY(spl_ce_ ## class_name), z_list, sub, allow, ce_flags TSRMLS_CC)
 
 #define SPL_LIST_CLASSES(z_list, sub, allow, ce_flags) \
        SPL_ADD_CLASS(AppendIterator, z_list, sub, allow, ce_flags); \
index 82a6bfb8b907bf14973cc623bc45d3cece1c3542..e86d72323476b41b1c89e3443e72485e07135cef 100755 (executable)
@@ -115,11 +115,16 @@ void spl_add_class_name(zval *list, zend_class_entry * pce, int allow, int ce_fl
        if (!allow || (allow > 0 && pce->ce_flags & ce_flags) || (allow < 0 && !(pce->ce_flags & ce_flags))) {
                size_t len = pce->name_length;
                zval *tmp;
+               zend_uchar ztype = UG(unicode)?IS_UNICODE:IS_STRING;
 
-               if (zend_hash_find(Z_ARRVAL_P(list), pce->name, len+1, (void*)&tmp) == FAILURE) {
+               if (zend_u_hash_find(Z_ARRVAL_P(list), ztype, pce->name, len+1, (void*)&tmp) == FAILURE) {
                        MAKE_STD_ZVAL(tmp);
-                       ZVAL_STRING(tmp, pce->name, 1);
-                       zend_hash_add(Z_ARRVAL_P(list), pce->name, len+1, &tmp, sizeof(zval *), NULL);
+                       if (UG(unicode)) {
+                               ZVAL_UNICODEL(tmp, pce->name, pce->name_length, 1);
+                       } else {
+                               ZVAL_STRINGL(tmp, pce->name, pce->name_length, 1);
+                       }
+                       zend_u_hash_add(Z_ARRVAL_P(list), ztype, pce->name, len+1, &tmp, sizeof(zval *), NULL);
                }
        }
 }
@@ -137,10 +142,8 @@ void spl_add_interfaces(zval *list, zend_class_entry * pce, int allow, int ce_fl
 /* }}} */
 
 /* {{{ spl_add_classes */
-int spl_add_classes(zend_class_entry ** ppce, zval *list, int sub, int allow, int ce_flags TSRMLS_DC)
+int spl_add_classes(zend_class_entry *pce, zval *list, int sub, int allow, int ce_flags TSRMLS_DC)
 {
-       zend_class_entry *pce = *ppce;
-
        if (!pce) {
                return 0;
        }
@@ -149,7 +152,7 @@ int spl_add_classes(zend_class_entry ** ppce, zval *list, int sub, int allow, in
                spl_add_interfaces(list, pce, allow, ce_flags TSRMLS_CC);
                while (pce->parent) {
                        pce = pce->parent;
-                       spl_add_classes(&pce, list, sub, allow, ce_flags TSRMLS_CC);
+                       spl_add_classes(pce, list, sub, allow, ce_flags TSRMLS_CC);
                }
        }
        return 0;
index 61dae21e68cc756ffdbaa466d12a0ad16acaa087..ac39a6052880dbbcda55db1d2a8de15ad7f1be4c 100755 (executable)
@@ -70,7 +70,7 @@ void spl_register_property( zend_class_entry * class_entry, char *prop_name, zva
  */
 void spl_add_class_name(zval * list, zend_class_entry * pce, int allow, int ce_flags TSRMLS_DC);
 void spl_add_interfaces(zval * list, zend_class_entry * pce, int allow, int ce_flags TSRMLS_DC);
-int spl_add_classes(zend_class_entry ** ppce, zval *list, int sub, int allow, int ce_flags TSRMLS_DC);
+int spl_add_classes(zend_class_entry *pce, zval *list, int sub, int allow, int ce_flags TSRMLS_DC);
 
 #define SPL_ME(class_name, function_name, arg_info, flags) \
        PHP_ME( spl_ ## class_name, function_name, arg_info, flags)
index c70573d5c246f81b0158672a0b6bba9ec0a06f75..3a85e1855c4a9cb7ea2fdfb82660eafc95d98671 100755 (executable)
@@ -1503,7 +1503,11 @@ SPL_METHOD(CachingIterator, __toString)
                zend_throw_exception_ex(U_CLASS_ENTRY(spl_ce_BadMethodCallException), 0 TSRMLS_CC, "%v does not fetch string value (see CachingIterator::__construct)", Z_OBJCE_P(getThis())->name);
        }
        if (intern->u.caching.zstr) {
-               RETURN_STRINGL(Z_STRVAL_P(intern->u.caching.zstr), Z_STRLEN_P(intern->u.caching.zstr), 1);
+               *return_value = *intern->u.caching.zstr;
+               zval_copy_ctor(return_value);
+               convert_to_text(return_value);
+               INIT_PZVAL(return_value);
+//             RETURN_STRINGL(Z_STRVAL_P(intern->u.caching.zstr), Z_STRLEN_P(intern->u.caching.zstr), 1);
        } else {
                RETURN_NULL();
        }
index cadf3b5a6c8f90b55a2b2809292a2cd664ac63ca..141138861290971920a872fdb9eb9fcd47896f0d 100755 (executable)
@@ -66,6 +66,47 @@ string(3) "aaa"
 
 Warning: class_implements(): Class aaa does not exist and could not be loaded in %sspl_003.php on line %d
 
+Warning: class_implements(): Class bbb does not exist in %sspl_003.php on line %d
+array(0) {
+}
+array(0) {
+}
+bool(false)
+bool(false)
+===DONE===
+--UEXPECTF--
+Warning: class_parents(): Class foo does not exist in %sspl_003.php on line %d
+unicode(3) "foo"
+
+Warning: class_parents(): Class foo does not exist and could not be loaded in %sspl_003.php on line %d
+array(2) {
+  [u"b"]=>
+  unicode(1) "b"
+  [u"a"]=>
+  unicode(1) "a"
+}
+array(2) {
+  [u"b"]=>
+  unicode(1) "b"
+  [u"a"]=>
+  unicode(1) "a"
+}
+array(1) {
+  [u"a"]=>
+  unicode(1) "a"
+}
+array(1) {
+  [u"a"]=>
+  unicode(1) "a"
+}
+array(0) {
+}
+bool(false)
+bool(false)
+unicode(3) "aaa"
+
+Warning: class_implements(): Class aaa does not exist and could not be loaded in %sspl_003.php on line %d
+
 Warning: class_implements(): Class bbb does not exist in %sspl_003.php on line %d
 array(0) {
 }
index 320625da01ffb6579f05195dcc017979763b2dcf..b51a07089003367f06187a05b6b9b74c53714f0b 100644 (file)
@@ -331,7 +331,7 @@ PHP_FUNCTION(count)
                        /* it the object implements Countable we call its count() method */
                        zval *retval;
 
-                       if (Z_OBJ_HT_P(array)->get_class_entry && instanceof_function(Z_OBJCE_P(array), spl_ce_Countable TSRMLS_CC)) {
+                       if (Z_OBJ_HT_P(array)->get_class_entry && instanceof_function(Z_OBJCE_P(array), U_CLASS_ENTRY(spl_ce_Countable) TSRMLS_CC)) {
                                zend_call_method_with_0_params(&array, NULL, NULL, "count", &retval);
                                RETVAL_LONG(Z_LVAL_P(retval));
                                zval_ptr_dtor(&retval);