]> granicus.if.org Git - php/commitdiff
Fixed several unicode related bugs
authorDmitry Stogov <dmitry@php.net>
Mon, 15 Aug 2005 14:39:18 +0000 (14:39 +0000)
committerDmitry Stogov <dmitry@php.net>
Mon, 15 Aug 2005 14:39:18 +0000 (14:39 +0000)
Zend/zend.c
Zend/zend_API.c
Zend/zend_API.h
Zend/zend_builtin_functions.c
Zend/zend_compile.c
Zend/zend_constants.c
Zend/zend_hash.c
Zend/zend_object_handlers.c
Zend/zend_objects.c
Zend/zend_operators.c

index 35d4f4317428147468c63da81526f2b52586e5db..b904fbd0f1fff8b9d07d537f3a2346dccf8bf747 100644 (file)
@@ -320,6 +320,12 @@ static void print_flat_hash(HashTable *ht TSRMLS_DC)
                        case HASH_KEY_IS_STRING:
                                ZEND_PUTS(string_key);
                                break;
+                       case HASH_KEY_IS_BINARY:
+                               zend_printf("b\"%s\"", string_key);
+                               break;
+                       case HASH_KEY_IS_UNICODE:
+                               zend_printf("%r", string_key);
+                               break;
                        case HASH_KEY_IS_LONG:
                                zend_printf("%ld", num_key);
                                break;
index f6ac43a8006f4f3b6e594df9f43450fbfcdd7e3a..f1cac21a146e657a5aa4eda4435f2e59feac4d4b 100644 (file)
@@ -165,7 +165,7 @@ ZEND_API int _zend_get_parameters_array_ex(int param_count, zval ***argument_arr
                        ALLOC_ZVAL(value_ptr);
                        *value_ptr = **value;
                        INIT_PZVAL(value_ptr);
-                       zend_error(E_STRICT, "Implicit cloning object of class '%s' because of 'zend.ze1_compatibility_mode'", class_name);
+                       zend_error(E_STRICT, "Implicit cloning object of class '%v' because of 'zend.ze1_compatibility_mode'", class_name);
                        if(!dup) {
                                efree(class_name);
                        }
index 8442d38cf19981676e10aed46b2b9d0da6ccb41b..0a425e8fa77d66e529ff83521e892c744438e400 100644 (file)
@@ -218,6 +218,7 @@ ZEND_API int zend_declare_property_string(zend_class_entry *ce, char *name, int
 ZEND_API int zend_declare_property_stringl(zend_class_entry *ce, char *name, int name_length, char *value, int value_len, int access_type TSRMLS_DC);
 
 ZEND_API int zend_u_declare_property(zend_class_entry *ce, zend_uchar type, void *name, int name_length, zval *property, int access_type TSRMLS_DC);
+ZEND_API int zend_u_declare_property_ex(zend_class_entry *ce, zend_uchar type, void *name, int name_length, zval *property, int access_type, char *doc_comment, int doc_comment_len TSRMLS_DC);
 
 ZEND_API void zend_update_class_constants(zend_class_entry *class_type TSRMLS_DC);
 ZEND_API void zend_update_property(zend_class_entry *scope, zval *object, char *name, int name_length, zval *value TSRMLS_DC);
index c1ca31c25e7e781688899d9f6e7e2d8b6e76fc5f..10296d09a983b1b260af9cb545dd527c010d8746 100644 (file)
@@ -920,8 +920,8 @@ ZEND_FUNCTION(method_exists)
        }
        if (Z_TYPE_PP(klass) == IS_OBJECT) {
                ce = Z_OBJCE_PP(klass);
-       } else if (Z_TYPE_PP(klass) == IS_STRING) {
-               if (zend_lookup_class(Z_STRVAL_PP(klass), Z_STRLEN_PP(klass), &pce TSRMLS_CC) == FAILURE) {
+       } else if (Z_TYPE_PP(klass) == IS_STRING || Z_TYPE_PP(klass) == IS_UNICODE) {
+               if (zend_u_lookup_class(Z_TYPE_PP(klass), Z_STRVAL_PP(klass), Z_STRLEN_PP(klass), &pce TSRMLS_CC) == FAILURE) {
                        RETURN_FALSE;
                }
                ce = *pce;
@@ -929,7 +929,9 @@ ZEND_FUNCTION(method_exists)
                RETURN_FALSE;
        }
 
-       convert_to_string_ex(method_name);
+       if (Z_TYPE_PP(method_name) != IS_STRING || Z_TYPE_PP(method_name) == IS_UNICODE) {
+               convert_to_text_ex(method_name);
+       }
        lcname = zend_u_str_case_fold(Z_TYPE_PP(method_name), Z_UNIVAL_PP(method_name), Z_UNILEN_PP(method_name), 1, &lcname_len);
        if (zend_u_hash_exists(&ce->function_table, Z_TYPE_PP(method_name), lcname, lcname_len+1)) {
                efree(lcname);
@@ -968,17 +970,22 @@ ZEND_FUNCTION(property_exists)
        if (ZEND_NUM_ARGS()!= 2 || zend_get_parameters_ex(2, &object, &property)==FAILURE) {
                ZEND_WRONG_PARAM_COUNT();
        }
-       convert_to_string_ex(property);
-       if (!Z_STRLEN_PP(property)) {
+
+       if (Z_TYPE_PP(property) != IS_STRING && Z_TYPE_PP(property) != IS_UNICODE) {
+               convert_to_text_ex(property);
+       }
+
+       if (!Z_UNILEN_PP(property)) {
                RETURN_FALSE;
        }
 
        switch((*object)->type) {
        case IS_STRING:
-               if (!Z_STRLEN_PP(object)) {
+       case IS_UNICODE:
+               if (!Z_UNILEN_PP(object)) {
                        RETURN_FALSE;
                }
-               if (zend_lookup_class(Z_STRVAL_PP(object), Z_STRLEN_PP(object), &pce TSRMLS_CC) == SUCCESS) {
+               if (zend_u_lookup_class(Z_TYPE_PP(object), Z_UNIVAL_PP(object), Z_UNILEN_PP(object), &pce TSRMLS_CC) == SUCCESS) {
                        ce = *pce;
                } else {
                        RETURN_FALSE;
@@ -992,14 +999,14 @@ ZEND_FUNCTION(property_exists)
                if (property_info->flags & ZEND_ACC_PUBLIC) {
                        RETURN_TRUE;
                }
-               zend_unmangle_property_name(property_info->name, &class_name, &prop_name);
-               if (!strncmp(class_name, "*", 1)) {
+               zend_u_unmangle_property_name(Z_TYPE_PP(property), property_info->name, &class_name, &prop_name);
+               if (class_name[0] ==  '*') {
                        if (instanceof_function(EG(scope), ce TSRMLS_CC)) {
                                RETURN_TRUE;
                        }
                        RETURN_FALSE;
                }
-               if (zend_lookup_class(Z_STRVAL_PP(object), Z_STRLEN_PP(object), &pce TSRMLS_CC) == SUCCESS) {
+               if (zend_u_lookup_class(Z_TYPE_PP(object), Z_UNIVAL_PP(object), Z_UNILEN_PP(object), &pce TSRMLS_CC) == SUCCESS) {
                        ce = *pce;
                } else {
                        RETURN_FALSE; /* shouldn't happen */
@@ -1880,7 +1887,7 @@ ZEND_FUNCTION(debug_print_backtrace)
                zend_printf("#%-2d ", indent);
                if (class_name) {
                        if (UG(unicode)) {
-                               zend_printf("%r(", class_name);
+                               zend_printf("%r", class_name);
                        } else {
                                ZEND_PUTS(class_name);
                        }
index 319bdb8e25f9d75c7b7b55f653b78eb3c4d1b69d..947cd7e465ff81a9f4966a3e5ff02c1416823eed 100644 (file)
@@ -2962,7 +2962,7 @@ void zend_do_declare_property(znode *var_name, znode *value, zend_uint access_ty
                CG(doc_comment_len) = 0;
        }
 
-       zend_u_declare_property(CG(active_class_entry), Z_TYPE(var_name->u.constant), Z_UNIVAL(var_name->u.constant), Z_UNILEN(var_name->u.constant), property, access_type TSRMLS_CC);
+       zend_u_declare_property_ex(CG(active_class_entry), Z_TYPE(var_name->u.constant), Z_UNIVAL(var_name->u.constant), Z_UNILEN(var_name->u.constant), property, access_type, comment, comment_len TSRMLS_CC);
        efree(var_name->u.constant.value.str.val);
 }
 
index 613bc0a962a694a8307efd6342a7504dc884e87c..1389144abb21ebb65cfa088f30a3052e748d0a25 100644 (file)
@@ -332,7 +332,7 @@ ZEND_API int zend_u_register_constant(zend_uchar type, zend_constant *c TSRMLS_D
        }
 
        if (zend_u_hash_add(EG(zend_constants), type, name, lookup_name_len, (void *) c, sizeof(zend_constant), NULL)==FAILURE) {
-               zend_error(E_NOTICE,"Constant %s already defined", name);
+               zend_error(E_NOTICE,"Constant %R already defined", type, name);
                free(c->name);
                if (!(c->flags & CONST_PERSISTENT)) {
                        zval_dtor(&c->value);
index e020319ab07ba5878d8af88a3ff13db32f38afc5..bfe203d0888bf307f402c7a0fae4205496540d96 100644 (file)
@@ -1297,6 +1297,7 @@ ZEND_API int zend_hash_get_current_data_ex(HashTable *ht, void **pData, HashPosi
 ZEND_API int zend_hash_update_current_key_ex(HashTable *ht, int key_type, char *str_index, uint str_length, ulong num_index, HashPosition *pos)
 {
        Bucket *p;
+       uint real_length;
 
        p = pos ? (*pos) : ht->pInternalPointer;
 
@@ -1304,12 +1305,13 @@ ZEND_API int zend_hash_update_current_key_ex(HashTable *ht, int key_type, char *
 
        if (p) {
                if (key_type == HASH_KEY_IS_LONG) {
-                       str_length = 0;
+                       real_length = str_length = 0;
                        if (!p->nKeyLength && p->h == num_index) {
                                return SUCCESS;
                        }
                        zend_hash_index_del(ht, num_index);
                } else if (key_type == HASH_KEY_IS_STRING || key_type == HASH_KEY_IS_BINARY) {
+                       real_length = str_length;
                        if (p->nKeyLength == str_length &&
                            p->key.type == ((key_type == HASH_KEY_IS_STRING)?IS_STRING:IS_BINARY) &&
                            memcmp(p->key.u.string, str_index, str_length) == 0) {
@@ -1317,9 +1319,10 @@ ZEND_API int zend_hash_update_current_key_ex(HashTable *ht, int key_type, char *
                        }
                        zend_u_hash_del(ht, (key_type == HASH_KEY_IS_STRING)?IS_STRING:IS_BINARY, str_index, str_length);
                } else if (key_type == HASH_KEY_IS_UNICODE) {
+                       real_length = str_length * sizeof(UChar);
                        if (p->nKeyLength == str_length &&
                            p->key.type == IS_UNICODE &&
-                           memcmp(p->key.u.string, str_index, str_length * sizeof(UChar*)) == 0) {
+                           memcmp(p->key.u.string, str_index, real_length) == 0) {
                                return SUCCESS;
                        }
                        zend_u_hash_del(ht, IS_UNICODE, str_index, str_length);
@@ -1339,7 +1342,7 @@ ZEND_API int zend_hash_update_current_key_ex(HashTable *ht, int key_type, char *
                }
 
                if (p->nKeyLength != str_length) {
-                       Bucket *q = (Bucket *) pemalloc(sizeof(Bucket) - 1 + str_length, ht->persistent);
+                       Bucket *q = (Bucket *) pemalloc(sizeof(Bucket) - 1 + real_length, ht->persistent);
 
                        q->nKeyLength = str_length;
                        if (p->pData == &p->pDataPtr) {
@@ -1373,11 +1376,11 @@ ZEND_API int zend_hash_update_current_key_ex(HashTable *ht, int key_type, char *
                if (key_type == HASH_KEY_IS_LONG) {
                        p->h = num_index;
                } else if (key_type == HASH_KEY_IS_UNICODE) {
-                       memcpy(p->key.u.unicode, str_index, str_length * sizeof(UChar));
+                       memcpy(p->key.u.unicode, str_index, real_length);
            p->key.type = IS_UNICODE;
                        p->h = zend_u_inline_hash_func(IS_UNICODE, str_index, str_length);
                } else {
-                       memcpy(p->key.u.string, str_index, str_length);
+                       memcpy(p->key.u.string, str_index, real_length);
            p->key.type = (key_type == HASH_KEY_IS_STRING)?IS_STRING:IS_BINARY;
                        p->h = zend_u_inline_hash_func(p->key.type, str_index, str_length);
                }
index 3a5014c948495a6060b2f4ebbcbe9ca653b97b56..c707126ac4a9c8f7152db4340ba9a062ab1bfad9 100644 (file)
@@ -266,7 +266,10 @@ ZEND_API int zend_check_property_access(zend_object *zobj, char *prop_info_name
                if (!(property_info->flags & ZEND_ACC_PRIVATE)) {
                        /* we we're looking for a private prop but found a non private one of the same name */
                        return FAILURE;
-               } else if (strcmp(prop_info_name+1, property_info->name+1)) {
+               } else if (!UG(unicode) && strcmp(prop_info_name+1, property_info->name+1)) {
+                       /* we we're looking for a private prop but found a private one of the same name but another class */
+                       return FAILURE;
+               } else if (UG(unicode) && u_strcmp(((UChar*)prop_info_name)+1, ((UChar*)property_info->name)+1)) {
                        /* we we're looking for a private prop but found a private one of the same name but another class */
                        return FAILURE;
                }
index 83f0d809b595d35ba47cd9ab40efe2fec5c2fa25..c9299c4efb871214b6cc43a2a0b7223d500a3568 100644 (file)
@@ -119,7 +119,7 @@ static void zval_add_ref_or_clone(zval **p)
                TSRMLS_FETCH();
 
                if (Z_OBJ_HANDLER_PP(p, clone_obj) == NULL) {
-                       zend_error(E_ERROR, "Trying to clone an uncloneable object of class %s",  Z_OBJCE_PP(p)->name);
+                       zend_error(E_ERROR, "Trying to clone an uncloneable object of class %v",  Z_OBJCE_PP(p)->name);
                } else {
                        zval *orig = *p;
 
index fc032d4c321bbd691ca766e5dd1c3f7731b7d64e..1de3975a20ca6a86d6d3bf928cfd1a9bef242a2f 100644 (file)
@@ -398,7 +398,7 @@ ZEND_API void convert_to_long_base(zval *op, int base)
                                                retval = (zend_hash_num_elements(ht)?1:0);
                                        }
                                } else {
-                                       zend_error(E_NOTICE, "Object of class %s could not be converted to int", Z_OBJCE_P(op)->name);
+                                       zend_error(E_NOTICE, "Object of class %v could not be converted to int", Z_OBJCE_P(op)->name);
                                }
                                zval_dtor(op);
                                ZVAL_LONG(op, retval);