diff options
| author | Andi Gutmans <andi@php.net> | 2003-11-24 18:13:29 +0000 |
|---|---|---|
| committer | Andi Gutmans <andi@php.net> | 2003-11-24 18:13:29 +0000 |
| commit | d344648b072c37ae82374fb8804ac4fcd9c7beca (patch) | |
| tree | 3ef8c0c2327678bd9f12dd71d2b53abf8e387131 | |
| parent | 83650e4e679aef3905397862d00b4c4dc5194418 (diff) | |
| download | php-git-d344648b072c37ae82374fb8804ac4fcd9c7beca.tar.gz | |
- Fix __autoload() to preserve class case.
- Heads up, this patch might break stuff so please let me know if you
- bump into any problems.
| -rw-r--r-- | Zend/zend_API.c | 4 | ||||
| -rw-r--r-- | Zend/zend_builtin_functions.c | 28 | ||||
| -rw-r--r-- | Zend/zend_compile.c | 10 | ||||
| -rw-r--r-- | Zend/zend_compile.h | 2 | ||||
| -rw-r--r-- | Zend/zend_constants.c | 12 | ||||
| -rw-r--r-- | Zend/zend_execute.c | 9 | ||||
| -rw-r--r-- | Zend/zend_execute_API.c | 22 | ||||
| -rw-r--r-- | Zend/zend_reflection_api.c | 14 | ||||
| -rw-r--r-- | ext/reflection/php_reflection.c | 14 |
9 files changed, 32 insertions, 83 deletions
diff --git a/Zend/zend_API.c b/Zend/zend_API.c index a18de9fda7..7352bea999 100644 --- a/Zend/zend_API.c +++ b/Zend/zend_API.c @@ -1622,13 +1622,11 @@ ZEND_API zend_bool zend_is_callable(zval *callable, zend_bool syntax_only, char if (syntax_only) return 1; - lcname = zend_str_tolower_dup(Z_STRVAL_PP(obj), Z_STRLEN_PP(obj)); - if (EG(active_op_array) && strcmp(lcname, "self") == 0) { ce = EG(active_op_array)->scope; } else if (strcmp(lcname, "parent") == 0 && EG(active_op_array) && EG(active_op_array)->scope) { ce = EG(active_op_array)->scope->parent; - } else if (zend_lookup_class(lcname, Z_STRLEN_PP(obj), &pce TSRMLS_CC) == SUCCESS) { + } else if (zend_lookup_class(Z_STRVAL_PP(obj), Z_STRLEN_PP(obj), &pce TSRMLS_CC) == SUCCESS) { ce = *pce; } diff --git a/Zend/zend_builtin_functions.c b/Zend/zend_builtin_functions.c index 252ebf4ed2..6abbad5e6d 100644 --- a/Zend/zend_builtin_functions.c +++ b/Zend/zend_builtin_functions.c @@ -567,8 +567,6 @@ ZEND_FUNCTION(get_parent_class) } else if (Z_TYPE_PP(arg) == IS_STRING) { zend_class_entry **pce; - SEPARATE_ZVAL(arg); - zend_str_tolower(Z_STRVAL_PP(arg), Z_STRLEN_PP(arg)); if (zend_lookup_class(Z_STRVAL_PP(arg), Z_STRLEN_PP(arg), &pce TSRMLS_CC) == SUCCESS) { ce = *pce; } @@ -586,7 +584,6 @@ ZEND_FUNCTION(get_parent_class) static void is_a_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool only_subclass) { zval **obj, **class_name; - char *lcname; zend_class_entry *instance_ce; zend_class_entry **ce; zend_bool retval; @@ -606,9 +603,7 @@ static void is_a_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool only_subclass) convert_to_string_ex(class_name); - lcname = zend_str_tolower_dup(Z_STRVAL_PP(class_name), Z_STRLEN_PP(class_name)); - - if (zend_lookup_class(lcname, Z_STRLEN_PP(class_name), &ce TSRMLS_CC) == FAILURE) { + if (zend_lookup_class(Z_STRVAL_PP(class_name), Z_STRLEN_PP(class_name), &ce TSRMLS_CC) == FAILURE) { retval = 0; } else { if (only_subclass) { @@ -618,7 +613,6 @@ static void is_a_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool only_subclass) } if (!instance_ce) { - efree(lcname); RETURN_FALSE; } @@ -629,8 +623,6 @@ static void is_a_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool only_subclass) } } - efree(lcname); - RETURN_BOOL(retval); } @@ -659,7 +651,6 @@ ZEND_FUNCTION(is_a) ZEND_FUNCTION(get_class_vars) { zval **class_name; - char *lcname; zend_class_entry *ce, **pce; zval *tmp; @@ -668,14 +659,11 @@ ZEND_FUNCTION(get_class_vars) } convert_to_string_ex(class_name); - lcname = zend_str_tolower_dup((*class_name)->value.str.val, (*class_name)->value.str.len); - - if (zend_lookup_class(lcname, Z_STRLEN_PP(class_name), &pce TSRMLS_CC) == FAILURE) { - efree(lcname); + + if (zend_lookup_class(Z_STRVAL_PP(class_name), Z_STRLEN_PP(class_name), &pce TSRMLS_CC) == FAILURE) { RETURN_FALSE; } else { ce = *pce; - efree(lcname); array_init(return_value); if (!ce->constants_updated) { zend_hash_apply_with_argument(&ce->default_properties, (apply_func_arg_t) zval_update_constant, (void *) 1 TSRMLS_CC); @@ -746,9 +734,6 @@ ZEND_FUNCTION(get_class_methods) } ce = Z_OBJCE_PP(class); } else if (Z_TYPE_PP(class) == IS_STRING) { - SEPARATE_ZVAL(class); - zend_str_tolower(Z_STRVAL_PP(class), Z_STRLEN_PP(class)); - if (zend_lookup_class(Z_STRVAL_PP(class), Z_STRLEN_PP(class), &pce TSRMLS_CC) == SUCCESS) { ce = *pce; } @@ -807,7 +792,6 @@ ZEND_FUNCTION(method_exists) ZEND_FUNCTION(class_exists) { zval **class_name; - char *lcname; zend_class_entry **ce; if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &class_name)==FAILURE) { @@ -815,12 +799,10 @@ ZEND_FUNCTION(class_exists) } convert_to_string_ex(class_name); - lcname = zend_str_tolower_dup((*class_name)->value.str.val, (*class_name)->value.str.len); - if (zend_lookup_class(lcname, Z_STRLEN_PP(class_name), &ce TSRMLS_CC) == SUCCESS) { - efree(lcname); + + if (zend_lookup_class(Z_STRVAL_PP(class_name), Z_STRLEN_PP(class_name), &ce TSRMLS_CC) == SUCCESS) { RETURN_TRUE; } else { - efree(lcname); RETURN_FALSE; } } diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index bccf78cae1..3440584e72 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -1128,7 +1128,6 @@ void zend_do_receive_arg(zend_uchar op, znode *var, znode *offset, znode *initia if (class_type->op_type != IS_UNUSED) { cur_arg_info->class_name = class_type->u.constant.value.str.val; cur_arg_info->class_name_len = class_type->u.constant.value.str.len; - zend_str_tolower(cur_arg_info->class_name, cur_arg_info->class_name_len); } else { cur_arg_info->class_name = NULL; cur_arg_info->class_name_len = 0; @@ -1236,7 +1235,6 @@ void zend_do_fetch_class(znode *result, znode *class_name TSRMLS_DC) if (class_name->op_type == IS_CONST) { int fetch_type; - zend_str_tolower(class_name->u.constant.value.str.val, class_name->u.constant.value.str.len); fetch_type = zend_get_class_fetch_type(class_name->u.constant.value.str.val, class_name->u.constant.value.str.len); switch (fetch_type) { case ZEND_FETCH_CLASS_SELF: @@ -1258,7 +1256,7 @@ void zend_do_fetch_class(znode *result, znode *class_name TSRMLS_DC) } -void zend_do_fetch_class_name(znode *result, znode *class_name_entry, znode *class_name, zend_bool case_sensitive TSRMLS_DC) +void zend_do_fetch_class_name(znode *result, znode *class_name_entry, znode *class_name TSRMLS_DC) { zend_uint length; @@ -1267,9 +1265,6 @@ void zend_do_fetch_class_name(znode *result, znode *class_name_entry, znode *cla } else { *result = *class_name_entry; } - if (!case_sensitive) { - zend_str_tolower(class_name->u.constant.value.str.val, class_name->u.constant.value.str.len); - } length = sizeof("::")-1 + result->u.constant.value.str.len + class_name->u.constant.value.str.len; result->u.constant.value.str.val = erealloc(result->u.constant.value.str.val, length+1); @@ -2665,8 +2660,7 @@ void zend_do_fetch_constant(znode *result, znode *constant_container, znode *con switch (mode) { case ZEND_CT: if (constant_container) { - zend_str_tolower(constant_container->u.constant.value.str.val, constant_container->u.constant.value.str.len); - zend_do_fetch_class_name(NULL, constant_container, constant_name, 1 TSRMLS_CC); + zend_do_fetch_class_name(NULL, constant_container, constant_name TSRMLS_CC); *result = *constant_container; } else { *result = *constant_name; diff --git a/Zend/zend_compile.h b/Zend/zend_compile.h index d53c242ade..381b82190e 100644 --- a/Zend/zend_compile.h +++ b/Zend/zend_compile.h @@ -343,7 +343,7 @@ int zend_do_begin_function_call(znode *function_name TSRMLS_DC); void zend_do_begin_method_call(znode *left_bracket TSRMLS_DC); void zend_do_begin_dynamic_function_call(znode *function_name TSRMLS_DC); void zend_do_fetch_class(znode *result, znode *class_name TSRMLS_DC); -void zend_do_fetch_class_name(znode *result, znode *class_entry, znode *class_name, zend_bool case_sensitive TSRMLS_DC); +void zend_do_fetch_class_name(znode *result, znode *class_entry, znode *class_name TSRMLS_DC); void zend_do_begin_class_member_function_call(TSRMLS_D); void zend_do_end_function_call(znode *function_name, znode *result, znode *argument_list, int is_method, int is_dynamic_fcall TSRMLS_DC); void zend_do_return(znode *expr, int do_end_vparse TSRMLS_DC); diff --git a/Zend/zend_constants.c b/Zend/zend_constants.c index 137e82f99c..75837e8703 100644 --- a/Zend/zend_constants.c +++ b/Zend/zend_constants.c @@ -212,8 +212,8 @@ ZEND_API void zend_register_string_constant(char *name, uint name_len, char *str ZEND_API int zend_get_constant(char *name, uint name_len, zval *result TSRMLS_DC) { zend_constant *c; - char *lookup_name; int retval = 1; + char *lookup_name; char *colon; if ((colon = memchr(name, ':', name_len)) && colon[1] == ':') { @@ -230,17 +230,14 @@ ZEND_API int zend_get_constant(char *name, uint name_len, zval *result TSRMLS_DC scope = CG(active_class_entry); } - lookup_name = do_alloca(class_name_len+1); - zend_str_tolower_copy(lookup_name, name, class_name_len); - lookup_name[class_name_len] = '\0'; - if (class_name_len == sizeof("self")-1 && strcmp(lookup_name, "self") == 0) { + if (class_name_len == sizeof("self")-1 && strcmp(name, "self") == 0) { if (scope) { ce = &scope; } else { zend_error(E_ERROR, "Cannot access self:: when no class scope is active"); retval = 0; } - } else if (class_name_len == sizeof("parent")-1 && strcmp(lookup_name, "parent") == 0) { + } else if (class_name_len == sizeof("parent")-1 && strcmp(name, "parent") == 0) { if (!scope) { zend_error(E_ERROR, "Cannot access parent:: when no class scope is active"); } else if (!scope->parent) { @@ -249,7 +246,7 @@ ZEND_API int zend_get_constant(char *name, uint name_len, zval *result TSRMLS_DC ce = &scope->parent; } } else { - if (zend_lookup_class(lookup_name, class_name_len, &ce TSRMLS_CC) != SUCCESS) { + if (zend_lookup_class(name, class_name_len, &ce TSRMLS_CC) != SUCCESS) { retval = 0; } } @@ -267,7 +264,6 @@ ZEND_API int zend_get_constant(char *name, uint name_len, zval *result TSRMLS_DC zval_copy_ctor(result); } - free_alloca(lookup_name); return retval; } diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c index 36b4bb9f4b..21d80531a1 100644 --- a/Zend/zend_execute.c +++ b/Zend/zend_execute.c @@ -2272,7 +2272,6 @@ int zend_add_var_handler(ZEND_OPCODE_HANDLER_ARGS) int zend_fetch_class_handler(ZEND_OPCODE_HANDLER_ARGS) { - char *class_name_strval; zval *class_name; @@ -2288,13 +2287,7 @@ int zend_fetch_class_handler(ZEND_OPCODE_HANDLER_ARGS) EX_T(EX(opline)->result.u.var).EA.class_entry = Z_OBJCE_P(class_name); break; case IS_STRING: - if (EX(opline)->op2.op_type != IS_CONST) { - class_name_strval = zend_str_tolower_dup(class_name->value.str.val, class_name->value.str.len); - EX_T(EX(opline)->result.u.var).EA.class_entry = zend_fetch_class(class_name_strval, Z_STRLEN_P(class_name), ZEND_FETCH_CLASS_DEFAULT TSRMLS_CC); - efree(class_name_strval); - } else { - EX_T(EX(opline)->result.u.var).EA.class_entry = zend_fetch_class(Z_STRVAL_P(class_name), Z_STRLEN_P(class_name), ZEND_FETCH_CLASS_DEFAULT TSRMLS_CC); - } + EX_T(EX(opline)->result.u.var).EA.class_entry = zend_fetch_class(Z_STRVAL_P(class_name), Z_STRLEN_P(class_name), ZEND_FETCH_CLASS_DEFAULT TSRMLS_CC); break; default: zend_error(E_ERROR, "Class name must be a valid object or a string"); diff --git a/Zend/zend_execute_API.c b/Zend/zend_execute_API.c index 621b234c2b..d4dd9a94aa 100644 --- a/Zend/zend_execute_API.c +++ b/Zend/zend_execute_API.c @@ -583,20 +583,17 @@ int zend_call_function(zend_fcall_info *fci, zend_fcall_info_cache *fci_cache TS EX(object) = *fci->object_pp; } else if (Z_TYPE_PP(fci->object_pp) == IS_STRING) { zend_class_entry **ce; - char *lc_class; int found = FAILURE; - lc_class = zend_str_tolower_dup(Z_STRVAL_PP(fci->object_pp), Z_STRLEN_PP(fci->object_pp)); - if (EG(active_op_array) && strcmp(lc_class, "self") == 0) { + if (EG(active_op_array) && strcmp(Z_STRVAL_PP(fci->object_pp), "self") == 0) { ce = &(EG(active_op_array)->scope); found = (*ce != NULL?SUCCESS:FAILURE); - } else if (strcmp(lc_class, "parent") == 0 && EG(active_op_array) && EG(active_op_array)->scope) { + } else if (strcmp(Z_STRVAL_PP(fci->object_pp), "parent") == 0 && EG(active_op_array) && EG(active_op_array)->scope) { ce = &(EG(active_op_array)->scope->parent); found = (*ce != NULL?SUCCESS:FAILURE); } else { - found = zend_lookup_class(lc_class, Z_STRLEN_PP(fci->object_pp), &ce TSRMLS_CC); + found = zend_lookup_class(Z_STRVAL_PP(fci->object_pp), Z_STRLEN_PP(fci->object_pp), &ce TSRMLS_CC); } - efree(lc_class); if (found == FAILURE) return FAILURE; @@ -782,8 +779,13 @@ ZEND_API int zend_lookup_class(char *name, int name_length, zend_class_entry *** zval class_name, *class_name_ptr = &class_name; zval *retval_ptr; int retval; + char *lc_name; - if (zend_hash_find(EG(class_table), name, name_length+1, (void **) ce) == SUCCESS) { + lc_name = do_alloca(name_length + 1); + zend_str_tolower_copy(lc_name, name, name_length+1); + + if (zend_hash_find(EG(class_table), lc_name, name_length+1, (void **) ce) == SUCCESS) { + free_alloca(lc_name); return SUCCESS; } @@ -797,17 +799,21 @@ ZEND_API int zend_lookup_class(char *name, int name_length, zend_class_entry *** retval = call_user_function_ex(EG(function_table), NULL, &autoload_function, &retval_ptr, 1, args, 0, NULL TSRMLS_CC); if (retval == FAILURE) { + free_alloca(lc_name); return FAILURE; } if (EG(exception)) { + free_alloca(lc_name); zend_error(E_ERROR, "__autoload threw an exception"); } /* If an exception is thrown retval_ptr will be NULL but we bailout before we reach this point */ zval_ptr_dtor(&retval_ptr); - return zend_hash_find(EG(class_table), name, name_length + 1, (void **) ce); + retval = zend_hash_find(EG(class_table), lc_name, name_length + 1, (void **) ce); + free_alloca(lc_name); + return retval; } ZEND_API int zend_eval_string(char *str, zval *retval_ptr, char *string_name TSRMLS_DC) diff --git a/Zend/zend_reflection_api.c b/Zend/zend_reflection_api.c index c7431e4290..6363497153 100644 --- a/Zend/zend_reflection_api.c +++ b/Zend/zend_reflection_api.c @@ -2386,7 +2386,6 @@ ZEND_METHOD(reflection_class, isSubclassOf) reflection_object *intern, *argument; zend_class_entry *ce, **pce, *class_ce; zval *class_name; - char *class_name_lc; METHOD_NOTSTATIC; GET_REFLECTION_OBJECT_PTR(ce); @@ -2397,15 +2396,11 @@ ZEND_METHOD(reflection_class, isSubclassOf) switch(class_name->type) { case IS_STRING: - class_name_lc = do_alloca(Z_STRLEN_P(class_name) + 1); - zend_str_tolower_copy(class_name_lc, Z_STRVAL_P(class_name), Z_STRLEN_P(class_name)+ 1); - if (zend_lookup_class(class_name_lc, Z_STRLEN_P(class_name), &pce TSRMLS_CC) == FAILURE) { - free_alloca(class_name_lc); + if (zend_lookup_class(Z_STRVAL_P(class_name), Z_STRLEN_P(class_name), &pce TSRMLS_CC) == FAILURE) { zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Interface %s doesn't exist", Z_STRVAL_P(class_name)); return; } - free_alloca(class_name_lc); class_ce = *pce; break; case IS_OBJECT: @@ -2437,7 +2432,6 @@ ZEND_METHOD(reflection_class, implementsInterface) reflection_object *intern, *argument; zend_class_entry *ce, *interface_ce, **pce; zval *interface; - char *interface_lc; METHOD_NOTSTATIC; GET_REFLECTION_OBJECT_PTR(ce); @@ -2448,15 +2442,11 @@ ZEND_METHOD(reflection_class, implementsInterface) switch(interface->type) { case IS_STRING: - interface_lc = do_alloca(Z_STRLEN_P(interface) + 1); - zend_str_tolower_copy(interface_lc, Z_STRVAL_P(interface), Z_STRLEN_P(interface)); - if (zend_lookup_class(interface_lc, Z_STRLEN_P(interface), &pce TSRMLS_CC) == FAILURE) { - free_alloca(interface_lc); + if (zend_lookup_class(Z_STRVAL_P(interface), Z_STRLEN_P(interface), &pce TSRMLS_CC) == FAILURE) { zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Interface %s doesn't exist", Z_STRVAL_P(interface)); return; } - free_alloca(interface_lc); interface_ce = *pce; break; case IS_OBJECT: diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index c7431e4290..6363497153 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -2386,7 +2386,6 @@ ZEND_METHOD(reflection_class, isSubclassOf) reflection_object *intern, *argument; zend_class_entry *ce, **pce, *class_ce; zval *class_name; - char *class_name_lc; METHOD_NOTSTATIC; GET_REFLECTION_OBJECT_PTR(ce); @@ -2397,15 +2396,11 @@ ZEND_METHOD(reflection_class, isSubclassOf) switch(class_name->type) { case IS_STRING: - class_name_lc = do_alloca(Z_STRLEN_P(class_name) + 1); - zend_str_tolower_copy(class_name_lc, Z_STRVAL_P(class_name), Z_STRLEN_P(class_name)+ 1); - if (zend_lookup_class(class_name_lc, Z_STRLEN_P(class_name), &pce TSRMLS_CC) == FAILURE) { - free_alloca(class_name_lc); + if (zend_lookup_class(Z_STRVAL_P(class_name), Z_STRLEN_P(class_name), &pce TSRMLS_CC) == FAILURE) { zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Interface %s doesn't exist", Z_STRVAL_P(class_name)); return; } - free_alloca(class_name_lc); class_ce = *pce; break; case IS_OBJECT: @@ -2437,7 +2432,6 @@ ZEND_METHOD(reflection_class, implementsInterface) reflection_object *intern, *argument; zend_class_entry *ce, *interface_ce, **pce; zval *interface; - char *interface_lc; METHOD_NOTSTATIC; GET_REFLECTION_OBJECT_PTR(ce); @@ -2448,15 +2442,11 @@ ZEND_METHOD(reflection_class, implementsInterface) switch(interface->type) { case IS_STRING: - interface_lc = do_alloca(Z_STRLEN_P(interface) + 1); - zend_str_tolower_copy(interface_lc, Z_STRVAL_P(interface), Z_STRLEN_P(interface)); - if (zend_lookup_class(interface_lc, Z_STRLEN_P(interface), &pce TSRMLS_CC) == FAILURE) { - free_alloca(interface_lc); + if (zend_lookup_class(Z_STRVAL_P(interface), Z_STRLEN_P(interface), &pce TSRMLS_CC) == FAILURE) { zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Interface %s doesn't exist", Z_STRVAL_P(interface)); return; } - free_alloca(interface_lc); interface_ce = *pce; break; case IS_OBJECT: |
