]> granicus.if.org Git - php/commitdiff
Unicode support
authorDmitry Stogov <dmitry@php.net>
Wed, 17 Aug 2005 13:10:04 +0000 (13:10 +0000)
committerDmitry Stogov <dmitry@php.net>
Wed, 17 Aug 2005 13:10:04 +0000 (13:10 +0000)
Zend/zend_interfaces.c
Zend/zend_object_handlers.c
Zend/zend_object_handlers.h
Zend/zend_reflection_api.c
Zend/zend_vm_def.h
Zend/zend_vm_execute.h
ext/reflection/php_reflection.c
ext/reflection/tests/006.phpt
ext/standard/var.c

index 8a10f18ba9eda56d3aeaa15e13ad7048f8d42493..031b71a62b2ea41bf22bf8b4d718208eee65695b 100755 (executable)
@@ -431,6 +431,11 @@ int zend_user_serialize(zval *object, unsigned char **buffer, zend_uint *buf_len
                        *buf_len = Z_STRLEN_P(retval);
                        result = SUCCESS;
                        break;
+               case IS_UNICODE:
+                       *buffer = eustrndup(Z_USTRVAL_P(retval), Z_USTRLEN_P(retval));
+                       *buf_len = Z_USTRLEN_P(retval);
+                       result = SUCCESS;
+                       break;
                default: /* failure */
                        result = FAILURE;
                        break;
@@ -439,7 +444,7 @@ int zend_user_serialize(zval *object, unsigned char **buffer, zend_uint *buf_len
        }
 
        if (result == FAILURE) {
-               zend_throw_exception_ex(NULL, 0 TSRMLS_CC, "%s::serialize() must return a string or NULL", ce->name);
+               zend_throw_exception_ex(NULL, 0 TSRMLS_CC, "%v::serialize() must return a string or NULL", ce->name);
        }
        return result;
 }
index c707126ac4a9c8f7152db4340ba9a062ab1bfad9..177048e6b41454ce58fe43ebab4703705e691610 100644 (file)
@@ -816,13 +816,12 @@ ZEND_API zend_function *zend_std_get_static_method(zend_class_entry *ce, char *f
 }
 
 
-ZEND_API zval **zend_std_get_static_property(zend_class_entry *ce, char *property_name, int property_name_len, zend_bool silent TSRMLS_DC)
+ZEND_API zval **zend_std_get_static_property(zend_class_entry *ce, zend_uchar type, void *property_name, int property_name_len, zend_bool silent TSRMLS_DC)
 {
        zval **retval = NULL;
        zend_class_entry *tmp_ce = ce;
        zend_property_info *property_info;
        zend_property_info std_property_info;
-       zend_uchar type = UG(unicode)?IS_UNICODE:IS_STRING;
 
        if (zend_u_hash_find(&ce->properties_info, type, property_name, property_name_len+1, (void **) &property_info)==FAILURE) {
                std_property_info.flags = ZEND_ACC_PUBLIC;
index 5399e2effc2a6fff67944b0ecea53125956913e8..07b50239dca6935dd52693d51520316d9dacecc5 100644 (file)
@@ -134,7 +134,7 @@ typedef struct _zend_object_handlers {
 extern ZEND_API zend_object_handlers std_object_handlers;
 BEGIN_EXTERN_C()
 ZEND_API union _zend_function *zend_std_get_static_method(zend_class_entry *ce, char *function_name_strval, int function_name_strlen TSRMLS_DC);
-ZEND_API zval **zend_std_get_static_property(zend_class_entry *ce, char *property_name, int property_name_len, zend_bool silent TSRMLS_DC);
+ZEND_API zval **zend_std_get_static_property(zend_class_entry *ce, zend_uchar type, void *property_name, int property_name_len, zend_bool silent TSRMLS_DC);
 ZEND_API zend_bool zend_std_unset_static_property(zend_class_entry *ce, char *property_name, int property_name_len TSRMLS_DC);
 ZEND_API struct _zend_property_info *zend_get_property_info(zend_class_entry *ce, zval *member, int silent TSRMLS_DC);
 
index d310f77819d2a3f667f917fe8f795a8b26afedd6..5eae777c02c87ab8b48f640966a929766d779f10 100644 (file)
@@ -577,13 +577,27 @@ static void _parameter_string(string *str, zend_function *fptr, struct _zend_arg
                                }
                        } else if (Z_TYPE_P(zv) == IS_NULL) {
                                string_write(str, "NULL", sizeof("NULL")-1);
-                       } else if (Z_TYPE_P(zv) == IS_STRING) {
+                       } else if (Z_TYPE_P(zv) == IS_STRING || Z_TYPE_P(zv) == IS_BINARY) {
+                               if (Z_TYPE_P(zv) == IS_BINARY) {
+                                       string_write(str, "b'", sizeof("b")-1);
+                               }
                                string_write(str, "'", sizeof("'")-1);
                                string_write(str, Z_STRVAL_P(zv), MIN(Z_STRLEN_P(zv), 15));
                                if (Z_STRLEN_P(zv) > 15) {
                                        string_write(str, "...", sizeof("...")-1);
                                }
                                string_write(str, "'", sizeof("'")-1);
+                       } else if (Z_TYPE_P(zv) == IS_UNICODE) {
+                               string_write(str, "'", sizeof("'")-1);
+                               zend_make_printable_zval(zv, &zv_copy, &use_copy);
+                               string_write(str, Z_STRVAL(zv_copy), MIN(Z_STRLEN(zv_copy), 15));
+                               if (Z_STRLEN(zv_copy) > 15) {
+                                       string_write(str, "...", sizeof("...")-1);
+                               }
+                               string_write(str, "'", sizeof("'")-1);
+                               if (use_copy) {
+                                       zval_dtor(&zv_copy);
+                               }
                        } else {
                                zend_make_printable_zval(zv, &zv_copy, &use_copy);
                                string_write(str, Z_STRVAL(zv_copy), Z_STRLEN(zv_copy));
@@ -2420,21 +2434,22 @@ ZEND_METHOD(reflection_class, getStaticPropertyValue)
        char *name;
        int name_len;
        zval **prop, *def_value = NULL;
+       zend_uchar name_type;
        
-       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|z", &name, &name_len, &def_value) == FAILURE) {
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "t|z", &name, &name_len, &name_type, &def_value) == FAILURE) {
                return;
        }
 
        GET_REFLECTION_OBJECT_PTR(ce);
 
        zend_update_class_constants(ce TSRMLS_CC);
-       prop = zend_std_get_static_property(ce, name, name_len, 1 TSRMLS_CC);
+       prop = zend_std_get_static_property(ce, name_type, name, name_len, 1 TSRMLS_CC);
        if (!prop) {
                if (def_value) {
                        RETURN_ZVAL(def_value, 1, 0);
                } else {
                        zend_throw_exception_ex(U_CLASS_ENTRY(reflection_exception_ptr), 0 TSRMLS_CC, 
-                               "Class %s does not have a property named %s", ce->name, name);
+                               "Class %v does not have a property named %R", ce->name, name_type, name);
                }
                return;
        } else {
@@ -2454,18 +2469,19 @@ ZEND_METHOD(reflection_class, setStaticPropertyValue)
        zval **variable_ptr, *value;
        int refcount;
        zend_uchar is_ref;
+       zend_uchar name_type;
        
-       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz", &name, &name_len, &value) == FAILURE) {
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "tz", &name, &name_len, &name_type, &value) == FAILURE) {
                return;
        }
 
        GET_REFLECTION_OBJECT_PTR(ce);
 
        zend_update_class_constants(ce TSRMLS_CC);
-       variable_ptr = zend_std_get_static_property(ce, name, name_len, 1 TSRMLS_CC);
+       variable_ptr = zend_std_get_static_property(ce, name_type, name, name_len, 1 TSRMLS_CC);
        if (!variable_ptr) {
                zend_throw_exception_ex(U_CLASS_ENTRY(reflection_exception_ptr), 0 TSRMLS_CC, 
-                               "Class %s does not have a property named %s", ce->name, name);
+                               "Class %v does not have a property named %R", ce->name, name_type, name);
                return;
        }       
        refcount = (*variable_ptr)->refcount;
index d8983cffe7c0abda0bc59b85fec5c110d386fd08..20097600fabed02e83cc008c9759b8f0fc63a314 100644 (file)
@@ -940,7 +940,7 @@ ZEND_VM_HELPER_EX(zend_fetch_var_address_helper, CONST|TMP|VAR|CV, ANY, int type
        }
 
        if (opline->op2.u.EA.type == ZEND_FETCH_STATIC_MEMBER) {
-               retval = zend_std_get_static_property(EX_T(opline->op2.u.var).class_entry, Z_STRVAL_P(varname), Z_STRLEN_P(varname), 0 TSRMLS_CC);
+               retval = zend_std_get_static_property(EX_T(opline->op2.u.var).class_entry, Z_TYPE_P(varname), Z_UNIVAL_P(varname), Z_UNILEN_P(varname), 0 TSRMLS_CC);
        } else {
                target_symbol_table = zend_get_target_symbol_table(opline, EX(Ts), type, varname TSRMLS_CC);
 /*
@@ -3333,7 +3333,7 @@ ZEND_VM_HANDLER(114, ZEND_ISSET_ISEMPTY_VAR, CONST|TMP|VAR|CV, ANY)
        }
 
        if (opline->op2.u.EA.type == ZEND_FETCH_STATIC_MEMBER) {
-               value = zend_std_get_static_property(EX_T(opline->op2.u.var).class_entry, Z_STRVAL_P(varname), Z_STRLEN_P(varname), 1 TSRMLS_CC);
+               value = zend_std_get_static_property(EX_T(opline->op2.u.var).class_entry, Z_TYPE_P(varname), Z_UNIVAL_P(varname), Z_UNILEN_P(varname), 1 TSRMLS_CC);
                if (!value) {
                        isset = 0;
                }
index 948fe2bca3208a83bb8dd545fd335385648db48e..0750bf917d2462727614090158616486861f7d04 100644 (file)
@@ -1400,7 +1400,7 @@ static int zend_fetch_var_address_helper_SPEC_CONST(int type, ZEND_OPCODE_HANDLE
        }
 
        if (opline->op2.u.EA.type == ZEND_FETCH_STATIC_MEMBER) {
-               retval = zend_std_get_static_property(EX_T(opline->op2.u.var).class_entry, Z_STRVAL_P(varname), Z_STRLEN_P(varname), 0 TSRMLS_CC);
+               retval = zend_std_get_static_property(EX_T(opline->op2.u.var).class_entry, Z_TYPE_P(varname), Z_UNIVAL_P(varname), Z_UNILEN_P(varname), 0 TSRMLS_CC);
        } else {
                target_symbol_table = zend_get_target_symbol_table(opline, EX(Ts), type, varname TSRMLS_CC);
 /*
@@ -2187,7 +2187,7 @@ static int ZEND_ISSET_ISEMPTY_VAR_SPEC_CONST_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
        }
 
        if (opline->op2.u.EA.type == ZEND_FETCH_STATIC_MEMBER) {
-               value = zend_std_get_static_property(EX_T(opline->op2.u.var).class_entry, Z_STRVAL_P(varname), Z_STRLEN_P(varname), 1 TSRMLS_CC);
+               value = zend_std_get_static_property(EX_T(opline->op2.u.var).class_entry, Z_TYPE_P(varname), Z_UNIVAL_P(varname), Z_UNILEN_P(varname), 1 TSRMLS_CC);
                if (!value) {
                        isset = 0;
                }
@@ -3908,7 +3908,7 @@ static int zend_fetch_var_address_helper_SPEC_TMP(int type, ZEND_OPCODE_HANDLER_
        }
 
        if (opline->op2.u.EA.type == ZEND_FETCH_STATIC_MEMBER) {
-               retval = zend_std_get_static_property(EX_T(opline->op2.u.var).class_entry, Z_STRVAL_P(varname), Z_STRLEN_P(varname), 0 TSRMLS_CC);
+               retval = zend_std_get_static_property(EX_T(opline->op2.u.var).class_entry, Z_TYPE_P(varname), Z_UNIVAL_P(varname), Z_UNILEN_P(varname), 0 TSRMLS_CC);
        } else {
                target_symbol_table = zend_get_target_symbol_table(opline, EX(Ts), type, varname TSRMLS_CC);
 /*
@@ -4695,7 +4695,7 @@ static int ZEND_ISSET_ISEMPTY_VAR_SPEC_TMP_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
        }
 
        if (opline->op2.u.EA.type == ZEND_FETCH_STATIC_MEMBER) {
-               value = zend_std_get_static_property(EX_T(opline->op2.u.var).class_entry, Z_STRVAL_P(varname), Z_STRLEN_P(varname), 1 TSRMLS_CC);
+               value = zend_std_get_static_property(EX_T(opline->op2.u.var).class_entry, Z_TYPE_P(varname), Z_UNIVAL_P(varname), Z_UNILEN_P(varname), 1 TSRMLS_CC);
                if (!value) {
                        isset = 0;
                }
@@ -6951,7 +6951,7 @@ static int zend_fetch_var_address_helper_SPEC_VAR(int type, ZEND_OPCODE_HANDLER_
        }
 
        if (opline->op2.u.EA.type == ZEND_FETCH_STATIC_MEMBER) {
-               retval = zend_std_get_static_property(EX_T(opline->op2.u.var).class_entry, Z_STRVAL_P(varname), Z_STRLEN_P(varname), 0 TSRMLS_CC);
+               retval = zend_std_get_static_property(EX_T(opline->op2.u.var).class_entry, Z_TYPE_P(varname), Z_UNIVAL_P(varname), Z_UNILEN_P(varname), 0 TSRMLS_CC);
        } else {
                target_symbol_table = zend_get_target_symbol_table(opline, EX(Ts), type, varname TSRMLS_CC);
 /*
@@ -7979,7 +7979,7 @@ static int ZEND_ISSET_ISEMPTY_VAR_SPEC_VAR_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
        }
 
        if (opline->op2.u.EA.type == ZEND_FETCH_STATIC_MEMBER) {
-               value = zend_std_get_static_property(EX_T(opline->op2.u.var).class_entry, Z_STRVAL_P(varname), Z_STRLEN_P(varname), 1 TSRMLS_CC);
+               value = zend_std_get_static_property(EX_T(opline->op2.u.var).class_entry, Z_TYPE_P(varname), Z_UNIVAL_P(varname), Z_UNILEN_P(varname), 1 TSRMLS_CC);
                if (!value) {
                        isset = 0;
                }
@@ -19645,7 +19645,7 @@ static int zend_fetch_var_address_helper_SPEC_CV(int type, ZEND_OPCODE_HANDLER_A
        }
 
        if (opline->op2.u.EA.type == ZEND_FETCH_STATIC_MEMBER) {
-               retval = zend_std_get_static_property(EX_T(opline->op2.u.var).class_entry, Z_STRVAL_P(varname), Z_STRLEN_P(varname), 0 TSRMLS_CC);
+               retval = zend_std_get_static_property(EX_T(opline->op2.u.var).class_entry, Z_TYPE_P(varname), Z_UNIVAL_P(varname), Z_UNILEN_P(varname), 0 TSRMLS_CC);
        } else {
                target_symbol_table = zend_get_target_symbol_table(opline, EX(Ts), type, varname TSRMLS_CC);
 /*
@@ -20502,7 +20502,7 @@ static int ZEND_ISSET_ISEMPTY_VAR_SPEC_CV_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
        }
 
        if (opline->op2.u.EA.type == ZEND_FETCH_STATIC_MEMBER) {
-               value = zend_std_get_static_property(EX_T(opline->op2.u.var).class_entry, Z_STRVAL_P(varname), Z_STRLEN_P(varname), 1 TSRMLS_CC);
+               value = zend_std_get_static_property(EX_T(opline->op2.u.var).class_entry, Z_TYPE_P(varname), Z_UNIVAL_P(varname), Z_UNILEN_P(varname), 1 TSRMLS_CC);
                if (!value) {
                        isset = 0;
                }
index d310f77819d2a3f667f917fe8f795a8b26afedd6..5eae777c02c87ab8b48f640966a929766d779f10 100644 (file)
@@ -577,13 +577,27 @@ static void _parameter_string(string *str, zend_function *fptr, struct _zend_arg
                                }
                        } else if (Z_TYPE_P(zv) == IS_NULL) {
                                string_write(str, "NULL", sizeof("NULL")-1);
-                       } else if (Z_TYPE_P(zv) == IS_STRING) {
+                       } else if (Z_TYPE_P(zv) == IS_STRING || Z_TYPE_P(zv) == IS_BINARY) {
+                               if (Z_TYPE_P(zv) == IS_BINARY) {
+                                       string_write(str, "b'", sizeof("b")-1);
+                               }
                                string_write(str, "'", sizeof("'")-1);
                                string_write(str, Z_STRVAL_P(zv), MIN(Z_STRLEN_P(zv), 15));
                                if (Z_STRLEN_P(zv) > 15) {
                                        string_write(str, "...", sizeof("...")-1);
                                }
                                string_write(str, "'", sizeof("'")-1);
+                       } else if (Z_TYPE_P(zv) == IS_UNICODE) {
+                               string_write(str, "'", sizeof("'")-1);
+                               zend_make_printable_zval(zv, &zv_copy, &use_copy);
+                               string_write(str, Z_STRVAL(zv_copy), MIN(Z_STRLEN(zv_copy), 15));
+                               if (Z_STRLEN(zv_copy) > 15) {
+                                       string_write(str, "...", sizeof("...")-1);
+                               }
+                               string_write(str, "'", sizeof("'")-1);
+                               if (use_copy) {
+                                       zval_dtor(&zv_copy);
+                               }
                        } else {
                                zend_make_printable_zval(zv, &zv_copy, &use_copy);
                                string_write(str, Z_STRVAL(zv_copy), Z_STRLEN(zv_copy));
@@ -2420,21 +2434,22 @@ ZEND_METHOD(reflection_class, getStaticPropertyValue)
        char *name;
        int name_len;
        zval **prop, *def_value = NULL;
+       zend_uchar name_type;
        
-       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|z", &name, &name_len, &def_value) == FAILURE) {
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "t|z", &name, &name_len, &name_type, &def_value) == FAILURE) {
                return;
        }
 
        GET_REFLECTION_OBJECT_PTR(ce);
 
        zend_update_class_constants(ce TSRMLS_CC);
-       prop = zend_std_get_static_property(ce, name, name_len, 1 TSRMLS_CC);
+       prop = zend_std_get_static_property(ce, name_type, name, name_len, 1 TSRMLS_CC);
        if (!prop) {
                if (def_value) {
                        RETURN_ZVAL(def_value, 1, 0);
                } else {
                        zend_throw_exception_ex(U_CLASS_ENTRY(reflection_exception_ptr), 0 TSRMLS_CC, 
-                               "Class %s does not have a property named %s", ce->name, name);
+                               "Class %v does not have a property named %R", ce->name, name_type, name);
                }
                return;
        } else {
@@ -2454,18 +2469,19 @@ ZEND_METHOD(reflection_class, setStaticPropertyValue)
        zval **variable_ptr, *value;
        int refcount;
        zend_uchar is_ref;
+       zend_uchar name_type;
        
-       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz", &name, &name_len, &value) == FAILURE) {
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "tz", &name, &name_len, &name_type, &value) == FAILURE) {
                return;
        }
 
        GET_REFLECTION_OBJECT_PTR(ce);
 
        zend_update_class_constants(ce TSRMLS_CC);
-       variable_ptr = zend_std_get_static_property(ce, name, name_len, 1 TSRMLS_CC);
+       variable_ptr = zend_std_get_static_property(ce, name_type, name, name_len, 1 TSRMLS_CC);
        if (!variable_ptr) {
                zend_throw_exception_ex(U_CLASS_ENTRY(reflection_exception_ptr), 0 TSRMLS_CC, 
-                               "Class %s does not have a property named %s", ce->name, name);
+                               "Class %v does not have a property named %R", ce->name, name_type, name);
                return;
        }       
        refcount = (*variable_ptr)->refcount;
index 72803c7bfe8b8eee08227b4121b7892c3cceb3e3..4e76fa7336fedb2a72e28a7d574302a3f216d543 100755 (executable)
@@ -109,7 +109,7 @@ EXCEPTION
 EXCEPTION
 unicode(7) "updated"
 unicode(7) "updated"
-unicede(7) "updated"
+unicode(7) "updated"
 EXCEPTION
 EXCEPTION
 unicode(7) "updated"
index 609a0d8fe4b14890029b4089e951e3564d5f7317..9636e9411a3e52875c5ad35235c8453b8cbe1776 100644 (file)
@@ -807,7 +807,7 @@ static void php_var_serialize_class(smart_str *buf, zval **struc, zval *retval_p
                                                        break;
                                                }
                                                efree(prot_name);
-                                               php_error_docref(NULL TSRMLS_CC, E_NOTICE, "\"%s\" returned as member variable from __sleep() but does not exist", Z_STRVAL_PP(name));
+                                               php_error_docref(NULL TSRMLS_CC, E_NOTICE, "\"%R\" returned as member variable from __sleep() but does not exist", Z_TYPE_PP(name), Z_UNIVAL_PP(name));
                                                if (Z_TYPE_PP(name) == IS_UNICODE) {
                                                        php_var_serialize_unicode(buf, Z_USTRVAL_PP(name), Z_USTRLEN_PP(name));
                                                } else {