From c0d060f5c02db168f1de895b41afffbc6e3cacfb Mon Sep 17 00:00:00 2001 From: Xinchen Hui Date: Fri, 3 Jan 2014 11:04:26 +0800 Subject: Bump year --- ext/spl/php_spl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ext/spl/php_spl.c') diff --git a/ext/spl/php_spl.c b/ext/spl/php_spl.c index 35f4e5056b..a37a453c8c 100644 --- a/ext/spl/php_spl.c +++ b/ext/spl/php_spl.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2013 The PHP Group | + | Copyright (c) 1997-2014 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | -- cgit v1.2.1 From 47c902777297ce895aa915c13efdb00881af3669 Mon Sep 17 00:00:00 2001 From: Xinchen Hui Date: Fri, 3 Jan 2014 11:06:16 +0800 Subject: Bump year --- ext/spl/php_spl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ext/spl/php_spl.c') diff --git a/ext/spl/php_spl.c b/ext/spl/php_spl.c index 716990d80f..5927e05562 100644 --- a/ext/spl/php_spl.c +++ b/ext/spl/php_spl.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2013 The PHP Group | + | Copyright (c) 1997-2014 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | -- cgit v1.2.1 From c081ce628f0d76d44784d7bb8e06428b06142ac0 Mon Sep 17 00:00:00 2001 From: Xinchen Hui Date: Fri, 3 Jan 2014 11:08:10 +0800 Subject: Bump year --- ext/spl/php_spl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ext/spl/php_spl.c') diff --git a/ext/spl/php_spl.c b/ext/spl/php_spl.c index 716990d80f..5927e05562 100644 --- a/ext/spl/php_spl.c +++ b/ext/spl/php_spl.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2013 The PHP Group | + | Copyright (c) 1997-2014 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | -- cgit v1.2.1 From f4cfaf36e23ca47da3e352e1c60909104c059647 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Mon, 10 Feb 2014 10:04:30 +0400 Subject: Use better data structures (incomplete) --- ext/spl/php_spl.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'ext/spl/php_spl.c') diff --git a/ext/spl/php_spl.c b/ext/spl/php_spl.c index 5927e05562..de787ae7b6 100644 --- a/ext/spl/php_spl.c +++ b/ext/spl/php_spl.c @@ -454,12 +454,24 @@ PHP_FUNCTION(spl_autoload_call) } /* }}} */ #define HT_MOVE_TAIL_TO_HEAD(ht) \ - (ht)->pListTail->pListNext = (ht)->pListHead; \ - (ht)->pListHead = (ht)->pListTail; \ - (ht)->pListTail = (ht)->pListHead->pListLast; \ - (ht)->pListHead->pListNext->pListLast = (ht)->pListHead;\ - (ht)->pListTail->pListNext = NULL; \ - (ht)->pListHead->pListLast = NULL; + do { \ + uint first = 0; \ + uint last = (ht)->nNumUsed; \ + while (first < last) { \ + if ((ht)->arData[first].xData) break; \ + first++; \ + } \ + while (last > first) { \ + last--; \ + if ((ht)->arData[last].xData) break; \ + } \ + if (first != last) { \ + Bucket tmp = (ht)->arData[first]; \ + (ht)->arData[first] = (ht)->arData[last]; \ + (ht)->arData[last] = tmp; \ + zend_hash_rehash(ht); \ + } \ + } while (0) /* {{{ proto bool spl_autoload_register([mixed autoload_function = "spl_autoload" [, throw = true [, prepend]]]) Register given function as __autoload() implementation */ -- cgit v1.2.1 From 3f4c877bf7cff179b719364de1c6fd5ff8dd105f Mon Sep 17 00:00:00 2001 From: Xinchen Hui Date: Tue, 11 Feb 2014 19:30:42 +0800 Subject: Use better data structures (incomplete) --- ext/spl/php_spl.c | 312 +++++++++++++++++++++++++++--------------------------- 1 file changed, 154 insertions(+), 158 deletions(-) (limited to 'ext/spl/php_spl.c') diff --git a/ext/spl/php_spl.c b/ext/spl/php_spl.c index de787ae7b6..09c1e8f4a9 100644 --- a/ext/spl/php_spl.c +++ b/ext/spl/php_spl.c @@ -56,35 +56,30 @@ ZEND_DECLARE_MODULE_GLOBALS(spl) static PHP_GINIT_FUNCTION(spl) { spl_globals->autoload_extensions = NULL; - spl_globals->autoload_extensions_len = 0; spl_globals->autoload_functions = NULL; spl_globals->autoload_running = 0; } /* }}} */ -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_string *name, zend_bool autoload TSRMLS_DC) { - zend_class_entry **ce; - int found; + zend_class_entry *ce; if (!autoload) { - char *lc_name; - ALLOCA_FLAG(use_heap) - - lc_name = do_alloca(len + 1, use_heap); - zend_str_tolower_copy(lc_name, name, len); + zend_string *lc_name = STR_ALLOC(name->len, 0); + zend_str_tolower_copy(lc_name->val, name->val, name->len); - found = zend_hash_find(EG(class_table), lc_name, len +1, (void **) &ce); - free_alloca(lc_name, use_heap); + ce = zend_hash_find_ptr(EG(class_table), lc_name); + STR_FREE(lc_name); } else { - found = zend_lookup_class(name, len, &ce TSRMLS_CC); + ce = zend_lookup_class(name 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" : ""); + if (ce == NULL) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Class %s does not exist%s", name->val, autoload ? " and could not be loaded" : ""); return NULL; } - return *ce; + return ce; } /* {{{ proto array class_parents(object instance [, boolean autoload = true]) @@ -105,7 +100,7 @@ PHP_FUNCTION(class_parents) } 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 (NULL == (ce = spl_find_ce_by_name(Z_STR_P(obj), autoload TSRMLS_CC))) { RETURN_FALSE; } } else { @@ -138,7 +133,7 @@ PHP_FUNCTION(class_implements) } 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 (NULL == (ce = spl_find_ce_by_name(Z_STR_P(obj), autoload TSRMLS_CC))) { RETURN_FALSE; } } else { @@ -167,7 +162,7 @@ PHP_FUNCTION(class_uses) } 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 (NULL == (ce = spl_find_ce_by_name(Z_STR_P(obj), autoload TSRMLS_CC))) { RETURN_FALSE; } } else { @@ -250,17 +245,17 @@ PHP_FUNCTION(spl_classes) } /* }}} */ -static int spl_autoload(const char *class_name, const char * lc_name, int class_name_len, const char * file_extension TSRMLS_DC) /* {{{ */ +static int spl_autoload(zend_string *class_name, zend_string *lc_name, const char *ext, int ext_len TSRMLS_DC) /* {{{ */ { char *class_file; int class_file_len; - int dummy = 1; + zval dummy; zend_file_handle file_handle; zend_op_array *new_op_array; zval *result = NULL; int ret; - class_file_len = spprintf(&class_file, 0, "%s%s", lc_name, file_extension); + class_file_len = spprintf(&class_file, 0, "%s%.*s", lc_name->val, ext_len, ext); #if DEFAULT_SLASH != '\\' { @@ -276,18 +271,22 @@ static int spl_autoload(const char *class_name, const char * lc_name, int class_ ret = php_stream_open_for_zend_ex(class_file, &file_handle, USE_PATH|STREAM_OPEN_FOR_INCLUDE TSRMLS_CC); if (ret == SUCCESS) { + zend_string *opened_path; if (!file_handle.opened_path) { file_handle.opened_path = estrndup(class_file, class_file_len); } - if (zend_hash_add(&EG(included_files), file_handle.opened_path, strlen(file_handle.opened_path)+1, (void *)&dummy, sizeof(int), NULL)==SUCCESS) { + opened_path = STR_INIT(file_handle.opened_path, strlen(file_handle.opened_path), 0); + ZVAL_NULL(&dummy); + if (zend_hash_add(&EG(included_files), opened_path, &dummy)) { new_op_array = zend_compile_file(&file_handle, ZEND_REQUIRE TSRMLS_CC); zend_destroy_file_handle(&file_handle TSRMLS_CC); } else { new_op_array = NULL; zend_file_handle_dtor(&file_handle TSRMLS_CC); } + STR_FREE(opened_path); if (new_op_array) { - EG(return_value_ptr_ptr) = &result; +//!!! EG(return_value_ptr_ptr) = &result; EG(active_op_array) = new_op_array; if (!EG(active_symbol_table)) { zend_rebuild_symbol_table(TSRMLS_C); @@ -298,13 +297,14 @@ static int spl_autoload(const char *class_name, const char * lc_name, int class_ destroy_op_array(new_op_array TSRMLS_CC); efree(new_op_array); if (!EG(exception)) { - if (EG(return_value_ptr_ptr)) { +/*!!! if (EG(return_value_ptr_ptr)) { zval_ptr_dtor(EG(return_value_ptr_ptr)); } +*/ } efree(class_file); - return zend_hash_exists(EG(class_table), (char*)lc_name, class_name_len+1); + return zend_hash_exists(EG(class_table), lc_name); } } efree(class_file); @@ -315,41 +315,45 @@ static int spl_autoload(const char *class_name, const char * lc_name, int class_ Default implementation for __autoload() */ PHP_FUNCTION(spl_autoload) { - char *class_name, *lc_name, *file_exts = SPL_G(autoload_extensions); - int class_name_len, file_exts_len = SPL_G(autoload_extensions_len), found = 0; - char *copy, *pos1, *pos2; - zval **original_return_value = EG(return_value_ptr_ptr); + int found = 0, pos_len; + char *pos, *pos1; + zend_string *class_name, *lc_name, *file_exts = SPL_G(autoload_extensions); +//!!! zval **original_return_value = EG(return_value_ptr_ptr); zend_op **original_opline_ptr = EG(opline_ptr); zend_op_array *original_active_op_array = EG(active_op_array); - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s", &class_name, &class_name_len, &file_exts, &file_exts_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "S|S", &class_name, &file_exts) == FAILURE) { RETURN_FALSE; } if (file_exts == NULL) { /* autoload_extensions is not intialzed, set to defaults */ - copy = pos1 = estrndup(SPL_DEFAULT_FILE_EXTENSIONS, sizeof(SPL_DEFAULT_FILE_EXTENSIONS)-1); + pos = SPL_DEFAULT_FILE_EXTENSIONS; + pos_len = sizeof(SPL_DEFAULT_FILE_EXTENSIONS) - 1; } else { - copy = pos1 = estrndup(file_exts, file_exts_len); + pos = file_exts->val; + pos_len = file_exts->len; } - lc_name = zend_str_tolower_dup(class_name, class_name_len); - while(pos1 && *pos1 && !EG(exception)) { - EG(return_value_ptr_ptr) = original_return_value; + + lc_name = STR_ALLOC(class_name->len, 0); + zend_str_tolower_copy(lc_name->val, class_name->val, class_name->len); + while (pos && *pos && !EG(exception)) { + //!!! EG(return_value_ptr_ptr) = original_return_value; EG(opline_ptr) = original_opline_ptr; EG(active_op_array) = original_active_op_array; - pos2 = strchr(pos1, ','); - if (pos2) *pos2 = '\0'; - if (spl_autoload(class_name, lc_name, class_name_len, pos1 TSRMLS_CC)) { + pos1 = strchr(pos, ','); + if (pos1) { + pos_len = pos1 - pos; + } + if (spl_autoload(class_name, lc_name, pos, pos_len TSRMLS_CC)) { found = 1; break; /* loaded */ } - pos1 = pos2 ? pos2 + 1 : NULL; - } - efree(lc_name); - if (copy) { - efree(copy); + pos = pos1 ? pos1 + 1 : NULL; + pos_len = pos1 ? pos1 - pos : pos_len; } + STR_FREE(lc_name); - EG(return_value_ptr_ptr) = original_return_value; +//!!! EG(return_value_ptr_ptr) = original_return_value; EG(opline_ptr) = original_opline_ptr; EG(active_op_array) = original_active_op_array; @@ -370,24 +374,22 @@ PHP_FUNCTION(spl_autoload) Register and return default file extensions for spl_autoload */ PHP_FUNCTION(spl_autoload_extensions) { - char *file_exts = NULL; - int file_exts_len; + zend_string *file_exts = NULL; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &file_exts, &file_exts_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|S", &file_exts) == FAILURE) { return; } if (file_exts) { if (SPL_G(autoload_extensions)) { - efree(SPL_G(autoload_extensions)); + STR_REFCOUNT(SPL_G(autoload_extensions)); } - SPL_G(autoload_extensions) = estrndup(file_exts, file_exts_len); - SPL_G(autoload_extensions_len) = file_exts_len; + SPL_G(autoload_extensions) = STR_DUP(file_exts, 0); } if (SPL_G(autoload_extensions) == NULL) { - RETURN_STRINGL(SPL_DEFAULT_FILE_EXTENSIONS, sizeof(SPL_DEFAULT_FILE_EXTENSIONS) - 1, 1); + RETURN_STRINGL(SPL_DEFAULT_FILE_EXTENSIONS, sizeof(SPL_DEFAULT_FILE_EXTENSIONS) - 1); } else { - RETURN_STRINGL(SPL_G(autoload_extensions), SPL_G(autoload_extensions_len), 1); + RETURN_STR(SPL_G(autoload_extensions)); } } /* }}} */ @@ -401,10 +403,10 @@ typedef struct { static void autoload_func_info_dtor(autoload_func_info *alfi) { if (alfi->obj) { - zval_ptr_dtor(&alfi->obj); + zval_ptr_dtor(alfi->obj); } if (alfi->closure) { - zval_ptr_dtor(&alfi->closure); + zval_ptr_dtor(alfi->closure); } } @@ -412,40 +414,38 @@ static void autoload_func_info_dtor(autoload_func_info *alfi) Try all registerd autoload function to load the requested class */ PHP_FUNCTION(spl_autoload_call) { - zval *class_name, *retval = NULL; - int class_name_len; - char *func_name, *lc_name; - uint func_name_len; ulong dummy; + zval *class_name, *retval = NULL; + zend_string *lc_name, *func_name; HashPosition function_pos; autoload_func_info *alfi; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &class_name) == FAILURE || Z_TYPE_P(class_name) != IS_STRING) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Z", &class_name) == FAILURE || Z_TYPE_P(class_name) != IS_STRING) { return; } if (SPL_G(autoload_functions)) { int l_autoload_running = SPL_G(autoload_running); SPL_G(autoload_running) = 1; - class_name_len = Z_STRLEN_P(class_name); - lc_name = zend_str_tolower_dup(Z_STRVAL_P(class_name), class_name_len); + lc_name = STR_ALLOC(Z_STRLEN_P(class_name), 0); + zend_str_tolower_copy(lc_name->val, Z_STRVAL_P(class_name), Z_STRLEN_P(class_name)); zend_hash_internal_pointer_reset_ex(SPL_G(autoload_functions), &function_pos); while(zend_hash_has_more_elements_ex(SPL_G(autoload_functions), &function_pos) == SUCCESS) { - zend_hash_get_current_key_ex(SPL_G(autoload_functions), &func_name, &func_name_len, &dummy, 0, &function_pos); - zend_hash_get_current_data_ex(SPL_G(autoload_functions), (void **) &alfi, &function_pos); - zend_call_method(alfi->obj ? &alfi->obj : NULL, alfi->ce, &alfi->func_ptr, func_name, func_name_len, &retval, 1, class_name, NULL TSRMLS_CC); + zend_hash_get_current_key_ex(SPL_G(autoload_functions), &func_name, &dummy, 0, &function_pos); + alfi = zend_hash_get_current_data_ptr_ex(SPL_G(autoload_functions), &function_pos); + zend_call_method(alfi->obj, alfi->ce, &alfi->func_ptr, func_name->val, func_name->len, retval, 1, class_name, NULL TSRMLS_CC); zend_exception_save(TSRMLS_C); if (retval) { - zval_ptr_dtor(&retval); + zval_ptr_dtor(retval); retval = NULL; } - if (zend_hash_exists(EG(class_table), lc_name, class_name_len + 1)) { + if (zend_hash_exists(EG(class_table), lc_name)) { break; } zend_hash_move_forward_ex(SPL_G(autoload_functions), &function_pos); } zend_exception_restore(TSRMLS_C); - efree(lc_name); + STR_FREE(lc_name); SPL_G(autoload_running) = l_autoload_running; } else { /* do not use or overwrite &EG(autoload_func) here */ @@ -453,24 +453,26 @@ PHP_FUNCTION(spl_autoload_call) } } /* }}} */ -#define HT_MOVE_TAIL_TO_HEAD(ht) \ - do { \ - uint first = 0; \ - uint last = (ht)->nNumUsed; \ - while (first < last) { \ - if ((ht)->arData[first].xData) break; \ - first++; \ - } \ - while (last > first) { \ - last--; \ - if ((ht)->arData[last].xData) break; \ - } \ - if (first != last) { \ - Bucket tmp = (ht)->arData[first]; \ - (ht)->arData[first] = (ht)->arData[last]; \ - (ht)->arData[last] = tmp; \ - zend_hash_rehash(ht); \ - } \ +#define HT_MOVE_TAIL_TO_HEAD(ht) \ + do { \ + uint first = 0; \ + uint last = (ht)->nNumUsed; \ + while (first < last) { \ + if (Z_TYPE((ht)->arData[first].val) != IS_UNDEF) \ + break; \ + first++; \ + } \ + while (last > first) { \ + last--; \ + if (Z_TYPE((ht)->arData[last].val) != IS_UNDEF) \ + break; \ + } \ + if (first != last) { \ + Bucket tmp = (ht)->arData[first]; \ + (ht)->arData[first] = (ht)->arData[last]; \ + (ht)->arData[last] = tmp; \ + zend_hash_rehash(ht); \ + } \ } while (0) /* {{{ proto bool spl_autoload_register([mixed autoload_function = "spl_autoload" [, throw = true [, prepend]]]) @@ -479,7 +481,7 @@ PHP_FUNCTION(spl_autoload_register) { char *func_name, *error = NULL; int func_name_len; - char *lc_name = NULL; + zend_string *lc_name; zval *zcallable = NULL; zend_bool do_throw = 1; zend_bool prepend = 0; @@ -493,17 +495,6 @@ PHP_FUNCTION(spl_autoload_register) } if (ZEND_NUM_ARGS()) { - if (Z_TYPE_P(zcallable) == IS_STRING) { - if (Z_STRLEN_P(zcallable) == sizeof("spl_autoload_call") - 1) { - if (!zend_binary_strcasecmp(Z_STRVAL_P(zcallable), sizeof("spl_autoload_call"), "spl_autoload_call", sizeof("spl_autoload_call"))) { - if (do_throw) { - zend_throw_exception_ex(spl_ce_LogicException, 0 TSRMLS_CC, "Function spl_autoload_call() cannot be registered"); - } - RETURN_FALSE; - } - } - } - if (!zend_is_callable_ex(zcallable, NULL, IS_CALLABLE_STRICT, &func_name, &func_name_len, &fcc, &error TSRMLS_CC)) { alfi.ce = fcc.calling_scope; alfi.func_ptr = fcc.function_handler; @@ -518,8 +509,7 @@ PHP_FUNCTION(spl_autoload_register) } efree(func_name); RETURN_FALSE; - } - else if (do_throw) { + } else if (do_throw) { zend_throw_exception_ex(spl_ce_LogicException, 0 TSRMLS_CC, "Passed array does not specify %s %smethod (%s)", alfi.func_ptr ? "a callable" : "an existing", !obj_ptr ? "static " : "", error); } if (error) { @@ -546,6 +536,16 @@ PHP_FUNCTION(spl_autoload_register) efree(func_name); RETURN_FALSE; } + } else if (fcc.function_handler->type == ZEND_INTERNAL_FUNCTION && + fcc.function_handler->internal_function.handler == zif_spl_autoload_call) { + if (do_throw) { + zend_throw_exception_ex(spl_ce_LogicException, 0 TSRMLS_CC, "Function spl_autoload_call() cannot be registered"); + } + if (error) { + efree(error); + } + efree(func_name); + RETURN_FALSE; } alfi.closure = NULL; alfi.ce = fcc.calling_scope; @@ -554,23 +554,23 @@ PHP_FUNCTION(spl_autoload_register) if (error) { efree(error); } - - lc_name = safe_emalloc(func_name_len, 1, sizeof(long) + 1); - zend_str_tolower_copy(lc_name, func_name, func_name_len); - efree(func_name); if (Z_TYPE_P(zcallable) == IS_OBJECT) { alfi.closure = zcallable; Z_ADDREF_P(zcallable); - lc_name = erealloc(lc_name, func_name_len + 2 + sizeof(zend_object_handle)); - memcpy(lc_name + func_name_len, &Z_OBJ_HANDLE_P(zcallable), - sizeof(zend_object_handle)); - func_name_len += sizeof(zend_object_handle); - lc_name[func_name_len] = '\0'; + lc_name = STR_ALLOC(func_name_len + 2 + sizeof(zend_uint), 0); + zend_str_tolower_copy(lc_name->val, func_name, func_name_len); + memcpy(lc_name->val + func_name_len, &Z_OBJ_HANDLE_P(zcallable), sizeof(zend_uint)); + lc_name->len += sizeof(zend_uint); + lc_name->val[lc_name->len] = '\0'; + } else { + lc_name = STR_ALLOC(func_name_len, 0); + zend_str_tolower_copy(lc_name->val, func_name, func_name_len); } + efree(func_name); - if (SPL_G(autoload_functions) && zend_hash_exists(SPL_G(autoload_functions), (char*)lc_name, func_name_len+1)) { + if (SPL_G(autoload_functions) && zend_hash_exists(SPL_G(autoload_functions), lc_name)) { if (alfi.closure) { Z_DELREF_P(zcallable); } @@ -579,10 +579,9 @@ PHP_FUNCTION(spl_autoload_register) if (obj_ptr && !(alfi.func_ptr->common.fn_flags & ZEND_ACC_STATIC)) { /* add object id to the hash to ensure uniqueness, for more reference look at bug #40091 */ - lc_name = erealloc(lc_name, func_name_len + 2 + sizeof(zend_object_handle)); - memcpy(lc_name + func_name_len, &Z_OBJ_HANDLE_P(obj_ptr), sizeof(zend_object_handle)); - func_name_len += sizeof(zend_object_handle); - lc_name[func_name_len] = '\0'; + STR_EREALLOC(lc_name, lc_name->len + 2 + sizeof(zend_uint)); + memcpy(lc_name->val + lc_name->len - 2 - sizeof(zend_uint), &Z_OBJ_HANDLE_P(obj_ptr), sizeof(zend_uint)); + lc_name->val[lc_name->len] = '\0'; alfi.obj = obj_ptr; Z_ADDREF_P(alfi.obj); } else { @@ -594,7 +593,7 @@ PHP_FUNCTION(spl_autoload_register) zend_hash_init(SPL_G(autoload_functions), 1, NULL, (dtor_func_t) autoload_func_info_dtor, 0); } - zend_hash_find(EG(function_table), "spl_autoload", sizeof("spl_autoload"), (void **) &spl_func_ptr); + spl_func_ptr = zend_hash_str_find_ptr(EG(function_table), "spl_autoload", sizeof("spl_autoload") - 1); if (EG(autoload_func) == spl_func_ptr) { /* registered already, so we insert that first */ autoload_func_info spl_alfi; @@ -603,14 +602,15 @@ PHP_FUNCTION(spl_autoload_register) spl_alfi.obj = NULL; spl_alfi.ce = NULL; spl_alfi.closure = NULL; - zend_hash_add(SPL_G(autoload_functions), "spl_autoload", sizeof("spl_autoload"), &spl_alfi, sizeof(autoload_func_info), NULL); + zend_hash_str_add_mem(SPL_G(autoload_functions), "spl_autoload", sizeof("spl_autoload") - 1, + (void *)&spl_alfi, sizeof(autoload_func_info)); if (prepend && SPL_G(autoload_functions)->nNumOfElements > 1) { /* Move the newly created element to the head of the hashtable */ HT_MOVE_TAIL_TO_HEAD(SPL_G(autoload_functions)); } } - if (zend_hash_add(SPL_G(autoload_functions), lc_name, func_name_len+1, &alfi.func_ptr, sizeof(autoload_func_info), NULL) == FAILURE) { + if (zend_hash_add_mem(SPL_G(autoload_functions), lc_name, &alfi.func_ptr, sizeof(autoload_func_info)) == NULL) { if (obj_ptr && !(alfi.func_ptr->common.fn_flags & ZEND_ACC_STATIC)) { Z_DELREF_P(alfi.obj); } @@ -623,14 +623,15 @@ PHP_FUNCTION(spl_autoload_register) HT_MOVE_TAIL_TO_HEAD(SPL_G(autoload_functions)); } skip: - efree(lc_name); + STR_FREE(lc_name); } if (SPL_G(autoload_functions)) { - zend_hash_find(EG(function_table), "spl_autoload_call", sizeof("spl_autoload_call"), (void **) &EG(autoload_func)); + EG(autoload_func) = zend_hash_str_find_ptr(EG(function_table), "spl_autoload_call", sizeof("spl_autoload_call") - 1); } else { - zend_hash_find(EG(function_table), "spl_autoload", sizeof("spl_autoload"), (void **) &EG(autoload_func)); + EG(autoload_func) = zend_hash_str_find_ptr(EG(function_table), "spl_autoload", sizeof("spl_autoload") - 1); } + RETURN_TRUE; } /* }}} */ @@ -640,7 +641,7 @@ PHP_FUNCTION(spl_autoload_unregister) { char *func_name, *error = NULL; int func_name_len; - char *lc_name = NULL; + zend_string *lc_name; zval *zcallable; int success = FAILURE; zend_function *spl_func_ptr; @@ -666,20 +667,20 @@ PHP_FUNCTION(spl_autoload_unregister) efree(error); } - lc_name = safe_emalloc(func_name_len, 1, sizeof(long) + 1); - zend_str_tolower_copy(lc_name, func_name, func_name_len); - efree(func_name); - if (Z_TYPE_P(zcallable) == IS_OBJECT) { - lc_name = erealloc(lc_name, func_name_len + 2 + sizeof(zend_object_handle)); - memcpy(lc_name + func_name_len, &Z_OBJ_HANDLE_P(zcallable), - sizeof(zend_object_handle)); - func_name_len += sizeof(zend_object_handle); - lc_name[func_name_len] = '\0'; + lc_name = STR_ALLOC(func_name_len + 2 + sizeof(zend_uint), 0); + zend_str_tolower_copy(lc_name->val, func_name, func_name_len); + memcpy(lc_name->val + func_name_len, &Z_OBJ_HANDLE_P(zcallable), sizeof(zend_uint)); + lc_name->len += sizeof(zend_uint); + lc_name->val[lc_name->len] = '\0'; + } else { + lc_name = STR_ALLOC(func_name_len, 0); + zend_str_tolower_copy(lc_name->val, func_name, func_name_len); } + efree(func_name); if (SPL_G(autoload_functions)) { - if (func_name_len == sizeof("spl_autoload_call")-1 && !strcmp(lc_name, "spl_autoload_call")) { + if (func_name_len == sizeof("spl_autoload_call") - 1 && !strcmp(lc_name->val, "spl_autoload_call")) { /* remove all */ zend_hash_destroy(SPL_G(autoload_functions)); FREE_HASHTABLE(SPL_G(autoload_functions)); @@ -688,18 +689,17 @@ PHP_FUNCTION(spl_autoload_unregister) success = SUCCESS; } else { /* remove specific */ - success = zend_hash_del(SPL_G(autoload_functions), lc_name, func_name_len+1); + success = zend_hash_del(SPL_G(autoload_functions), lc_name); if (success != SUCCESS && obj_ptr) { - lc_name = erealloc(lc_name, func_name_len + 2 + sizeof(zend_object_handle)); - memcpy(lc_name + func_name_len, &Z_OBJ_HANDLE_P(obj_ptr), sizeof(zend_object_handle)); - func_name_len += sizeof(zend_object_handle); - lc_name[func_name_len] = '\0'; - success = zend_hash_del(SPL_G(autoload_functions), lc_name, func_name_len+1); + STR_EREALLOC(lc_name, lc_name->len + 2 + sizeof(zend_uint)); + memcpy(lc_name->val + lc_name->len - 2 - sizeof(zend_uint), &Z_OBJ_HANDLE_P(obj_ptr), sizeof(zend_uint)); + lc_name->val[lc_name->len] = '\0'; + success = zend_hash_del(SPL_G(autoload_functions), lc_name); } } - } else if (func_name_len == sizeof("spl_autoload")-1 && !strcmp(lc_name, "spl_autoload")) { + } else if (func_name_len == sizeof("spl_autoload")-1 && !strcmp(lc_name->val, "spl_autoload")) { /* register single spl_autoload() */ - zend_hash_find(EG(function_table), "spl_autoload", sizeof("spl_autoload"), (void **) &spl_func_ptr); + spl_func_ptr = zend_hash_str_find_ptr(EG(function_table), "spl_autoload", sizeof("spl_autoload")); if (EG(autoload_func) == spl_func_ptr) { success = SUCCESS; @@ -707,7 +707,7 @@ PHP_FUNCTION(spl_autoload_unregister) } } - efree(lc_name); + STR_FREE(lc_name); RETURN_BOOL(success == SUCCESS); } /* }}} */ @@ -724,7 +724,7 @@ PHP_FUNCTION(spl_autoload_functions) } if (!EG(autoload_func)) { - if (zend_hash_find(EG(function_table), ZEND_AUTOLOAD_FUNC_NAME, sizeof(ZEND_AUTOLOAD_FUNC_NAME), (void **) &fptr) == SUCCESS) { + if ((fptr = zend_hash_str_find_ptr(EG(function_table), ZEND_AUTOLOAD_FUNC_NAME, sizeof(ZEND_AUTOLOAD_FUNC_NAME) - 1))) { array_init(return_value); add_next_index_stringl(return_value, ZEND_AUTOLOAD_FUNC_NAME, sizeof(ZEND_AUTOLOAD_FUNC_NAME)-1, 1); return; @@ -732,13 +732,13 @@ PHP_FUNCTION(spl_autoload_functions) RETURN_FALSE; } - zend_hash_find(EG(function_table), "spl_autoload_call", sizeof("spl_autoload_call"), (void **) &fptr); + fptr = zend_hash_str_find_ptr(EG(function_table), "spl_autoload_call", sizeof("spl_autoload_call") - 1); if (EG(autoload_func) == fptr) { array_init(return_value); zend_hash_internal_pointer_reset_ex(SPL_G(autoload_functions), &function_pos); while(zend_hash_has_more_elements_ex(SPL_G(autoload_functions), &function_pos) == SUCCESS) { - zend_hash_get_current_data_ex(SPL_G(autoload_functions), (void **) &alfi, &function_pos); + alfi = zend_hash_get_current_data_ptr_ex(SPL_G(autoload_functions), &function_pos); if (alfi->closure) { Z_ADDREF_P(alfi->closure); add_next_index_zval(return_value, alfi->closure); @@ -751,19 +751,18 @@ PHP_FUNCTION(spl_autoload_functions) Z_ADDREF_P(alfi->obj); add_next_index_zval(tmp, alfi->obj); } else { - add_next_index_string(tmp, alfi->ce->name, 1); + add_next_index_str(tmp, alfi->ce->name); } - add_next_index_string(tmp, alfi->func_ptr->common.function_name, 1); + add_next_index_str(tmp, alfi->func_ptr->common.function_name); add_next_index_zval(return_value, tmp); } else { - if (strncmp(alfi->func_ptr->common.function_name, "__lambda_func", sizeof("__lambda_func") - 1)) { - add_next_index_string(return_value, alfi->func_ptr->common.function_name, 1); + if (strncmp(alfi->func_ptr->common.function_name->val, "__lambda_func", sizeof("__lambda_func") - 1)) { + add_next_index_str(return_value, alfi->func_ptr->common.function_name); } else { - char *key; - uint len; - long dummy; - zend_hash_get_current_key_ex(SPL_G(autoload_functions), &key, &len, &dummy, 0, &function_pos); - add_next_index_stringl(return_value, key, len - 1, 1); + zend_string *key; + ulong dummy; + zend_hash_get_current_key_ex(SPL_G(autoload_functions), &key, &dummy, 0, &function_pos); + add_next_index_str(return_value, key); } } @@ -773,7 +772,7 @@ PHP_FUNCTION(spl_autoload_functions) } array_init(return_value); - add_next_index_string(return_value, EG(autoload_func)->common.function_name, 1); + add_next_index_str(return_value, EG(autoload_func)->common.function_name); } /* }}} */ /* {{{ proto string spl_object_hash(object obj) @@ -781,16 +780,15 @@ PHP_FUNCTION(spl_autoload_functions) PHP_FUNCTION(spl_object_hash) { zval *obj; - char* hash; + char hash[33]; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o", &obj) == FAILURE) { return; } - hash = emalloc(33); php_spl_object_hash(obj, hash TSRMLS_CC); - RETVAL_STRING(hash, 0); + RETURN_STRING(hash); } /* }}} */ @@ -968,7 +966,6 @@ PHP_MINIT_FUNCTION(spl) PHP_RINIT_FUNCTION(spl) /* {{{ */ { SPL_G(autoload_extensions) = NULL; - SPL_G(autoload_extensions_len) = 0; SPL_G(autoload_functions) = NULL; SPL_G(hash_mask_init) = 0; return SUCCESS; @@ -977,9 +974,8 @@ PHP_RINIT_FUNCTION(spl) /* {{{ */ PHP_RSHUTDOWN_FUNCTION(spl) /* {{{ */ { if (SPL_G(autoload_extensions)) { - efree(SPL_G(autoload_extensions)); + STR_RELEASE(SPL_G(autoload_extensions)); SPL_G(autoload_extensions) = NULL; - SPL_G(autoload_extensions_len) = 0; } if (SPL_G(autoload_functions)) { zend_hash_destroy(SPL_G(autoload_functions)); -- cgit v1.2.1 From 4e66abad54b25ca367fcb6da78524e3c4024e2a0 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Wed, 12 Feb 2014 14:29:51 +0400 Subject: Use better data structures (incomplete) - refactored return_value handling --- ext/spl/php_spl.c | 35 +++++++++++++---------------------- 1 file changed, 13 insertions(+), 22 deletions(-) (limited to 'ext/spl/php_spl.c') diff --git a/ext/spl/php_spl.c b/ext/spl/php_spl.c index 09c1e8f4a9..35b6e549f2 100644 --- a/ext/spl/php_spl.c +++ b/ext/spl/php_spl.c @@ -252,7 +252,7 @@ static int spl_autoload(zend_string *class_name, zend_string *lc_name, const cha zval dummy; zend_file_handle file_handle; zend_op_array *new_op_array; - zval *result = NULL; + zval result; int ret; class_file_len = spprintf(&class_file, 0, "%s%.*s", lc_name->val, ext_len, ext); @@ -286,21 +286,18 @@ static int spl_autoload(zend_string *class_name, zend_string *lc_name, const cha } STR_FREE(opened_path); if (new_op_array) { -//!!! EG(return_value_ptr_ptr) = &result; EG(active_op_array) = new_op_array; if (!EG(active_symbol_table)) { zend_rebuild_symbol_table(TSRMLS_C); } - zend_execute(new_op_array TSRMLS_CC); + ZVAL_UNDEF(&result); + zend_execute(new_op_array, &result TSRMLS_CC); destroy_op_array(new_op_array TSRMLS_CC); efree(new_op_array); if (!EG(exception)) { -/*!!! if (EG(return_value_ptr_ptr)) { - zval_ptr_dtor(EG(return_value_ptr_ptr)); - } -*/ + zval_ptr_dtor(&result); } efree(class_file); @@ -318,7 +315,6 @@ PHP_FUNCTION(spl_autoload) int found = 0, pos_len; char *pos, *pos1; zend_string *class_name, *lc_name, *file_exts = SPL_G(autoload_extensions); -//!!! zval **original_return_value = EG(return_value_ptr_ptr); zend_op **original_opline_ptr = EG(opline_ptr); zend_op_array *original_active_op_array = EG(active_op_array); @@ -337,7 +333,6 @@ PHP_FUNCTION(spl_autoload) lc_name = STR_ALLOC(class_name->len, 0); zend_str_tolower_copy(lc_name->val, class_name->val, class_name->len); while (pos && *pos && !EG(exception)) { - //!!! EG(return_value_ptr_ptr) = original_return_value; EG(opline_ptr) = original_opline_ptr; EG(active_op_array) = original_active_op_array; pos1 = strchr(pos, ','); @@ -353,7 +348,6 @@ PHP_FUNCTION(spl_autoload) } STR_FREE(lc_name); -//!!! EG(return_value_ptr_ptr) = original_return_value; EG(opline_ptr) = original_opline_ptr; EG(active_op_array) = original_active_op_array; @@ -365,7 +359,7 @@ PHP_FUNCTION(spl_autoload) if (active_opline->opcode != ZEND_FETCH_CLASS) { zend_throw_exception_ex(spl_ce_LogicException, 0 TSRMLS_CC, "Class %s could not be loaded", class_name); } else { - php_error_docref(NULL TSRMLS_CC, E_ERROR, "Class %s could not be loaded", class_name); + php_error_docref(NULL TSRMLS_CC, E_ERROR, "Class %s could not be loaded", class_name->val); } } } /* }}} */ @@ -743,18 +737,17 @@ PHP_FUNCTION(spl_autoload_functions) Z_ADDREF_P(alfi->closure); add_next_index_zval(return_value, alfi->closure); } else if (alfi->func_ptr->common.scope) { - zval *tmp; - MAKE_STD_ZVAL(tmp); - array_init(tmp); + zval tmp; + array_init(&tmp); if (alfi->obj) { Z_ADDREF_P(alfi->obj); - add_next_index_zval(tmp, alfi->obj); + add_next_index_zval(&tmp, alfi->obj); } else { - add_next_index_str(tmp, alfi->ce->name); + add_next_index_str(&tmp, alfi->ce->name); } - add_next_index_str(tmp, alfi->func_ptr->common.function_name); - add_next_index_zval(return_value, tmp); + add_next_index_str(&tmp, alfi->func_ptr->common.function_name); + add_next_index_zval(return_value, &tmp); } else { if (strncmp(alfi->func_ptr->common.function_name->val, "__lambda_func", sizeof("__lambda_func") - 1)) { add_next_index_str(return_value, alfi->func_ptr->common.function_name); @@ -817,11 +810,11 @@ PHPAPI void php_spl_object_hash(zval *obj, char *result TSRMLS_DC) /* {{{*/ } /* }}} */ -int spl_build_class_list_string(zval **entry, char **list TSRMLS_DC) /* {{{ */ +int spl_build_class_list_string(zval *entry, char **list TSRMLS_DC) /* {{{ */ { char *res; - spprintf(&res, 0, "%s, %s", *list, Z_STRVAL_PP(entry)); + spprintf(&res, 0, "%s, %s", *list, Z_STRVAL_P(entry)); efree(*list); *list = res; return ZEND_HASH_APPLY_KEEP; @@ -837,7 +830,6 @@ PHP_MINFO_FUNCTION(spl) php_info_print_table_start(); php_info_print_table_header(2, "SPL support", "enabled"); - INIT_PZVAL(&list); array_init(&list); SPL_LIST_CLASSES(&list, 0, 1, ZEND_ACC_INTERFACE) strg = estrdup(""); @@ -846,7 +838,6 @@ PHP_MINFO_FUNCTION(spl) php_info_print_table_row(2, "Interfaces", strg + 2); efree(strg); - INIT_PZVAL(&list); array_init(&list); SPL_LIST_CLASSES(&list, 0, -1, ZEND_ACC_INTERFACE) strg = estrdup(""); -- cgit v1.2.1 From 2b9b9afa7a9a66f9c80013ce4121183bdff434e8 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Mon, 17 Feb 2014 17:59:18 +0400 Subject: Use better data structures (incomplete) --- ext/spl/php_spl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'ext/spl/php_spl.c') diff --git a/ext/spl/php_spl.c b/ext/spl/php_spl.c index 35b6e549f2..238b7574a0 100644 --- a/ext/spl/php_spl.c +++ b/ext/spl/php_spl.c @@ -573,7 +573,7 @@ PHP_FUNCTION(spl_autoload_register) if (obj_ptr && !(alfi.func_ptr->common.fn_flags & ZEND_ACC_STATIC)) { /* add object id to the hash to ensure uniqueness, for more reference look at bug #40091 */ - STR_EREALLOC(lc_name, lc_name->len + 2 + sizeof(zend_uint)); + STR_REALLOC(lc_name, lc_name->len + 2 + sizeof(zend_uint), 0); memcpy(lc_name->val + lc_name->len - 2 - sizeof(zend_uint), &Z_OBJ_HANDLE_P(obj_ptr), sizeof(zend_uint)); lc_name->val[lc_name->len] = '\0'; alfi.obj = obj_ptr; @@ -685,7 +685,7 @@ PHP_FUNCTION(spl_autoload_unregister) /* remove specific */ success = zend_hash_del(SPL_G(autoload_functions), lc_name); if (success != SUCCESS && obj_ptr) { - STR_EREALLOC(lc_name, lc_name->len + 2 + sizeof(zend_uint)); + STR_REALLOC(lc_name, lc_name->len + 2 + sizeof(zend_uint), 0); memcpy(lc_name->val + lc_name->len - 2 - sizeof(zend_uint), &Z_OBJ_HANDLE_P(obj_ptr), sizeof(zend_uint)); lc_name->val[lc_name->len] = '\0'; success = zend_hash_del(SPL_G(autoload_functions), lc_name); -- cgit v1.2.1 From 52bd62eca819e43e0fc6788c0ec4670ca4c8cddf Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Fri, 21 Feb 2014 20:35:40 +0400 Subject: Fixed assertions --- ext/spl/php_spl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'ext/spl/php_spl.c') diff --git a/ext/spl/php_spl.c b/ext/spl/php_spl.c index 238b7574a0..90d4e2f054 100644 --- a/ext/spl/php_spl.c +++ b/ext/spl/php_spl.c @@ -414,7 +414,7 @@ PHP_FUNCTION(spl_autoload_call) HashPosition function_pos; autoload_func_info *alfi; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Z", &class_name) == FAILURE || Z_TYPE_P(class_name) != IS_STRING) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &class_name) == FAILURE || Z_TYPE_P(class_name) != IS_STRING) { return; } @@ -617,7 +617,7 @@ PHP_FUNCTION(spl_autoload_register) HT_MOVE_TAIL_TO_HEAD(SPL_G(autoload_functions)); } skip: - STR_FREE(lc_name); + STR_RELEASE(lc_name); } if (SPL_G(autoload_functions)) { -- cgit v1.2.1 From 71dac3d54f8c3dd80d5669846601a6980a7c3067 Mon Sep 17 00:00:00 2001 From: Xinchen Hui Date: Tue, 25 Feb 2014 15:47:24 +0800 Subject: Don't add_ref in add_*_str functions --- ext/spl/php_spl.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'ext/spl/php_spl.c') diff --git a/ext/spl/php_spl.c b/ext/spl/php_spl.c index 90d4e2f054..26f39eb513 100644 --- a/ext/spl/php_spl.c +++ b/ext/spl/php_spl.c @@ -744,18 +744,18 @@ PHP_FUNCTION(spl_autoload_functions) Z_ADDREF_P(alfi->obj); add_next_index_zval(&tmp, alfi->obj); } else { - add_next_index_str(&tmp, alfi->ce->name); + add_next_index_str(&tmp, STR_COPY(alfi->ce->name)); } - add_next_index_str(&tmp, alfi->func_ptr->common.function_name); + add_next_index_str(&tmp, STR_COPY(alfi->func_ptr->common.function_name)); add_next_index_zval(return_value, &tmp); } else { if (strncmp(alfi->func_ptr->common.function_name->val, "__lambda_func", sizeof("__lambda_func") - 1)) { - add_next_index_str(return_value, alfi->func_ptr->common.function_name); + add_next_index_str(return_value, STR_COPY(alfi->func_ptr->common.function_name)); } else { zend_string *key; ulong dummy; zend_hash_get_current_key_ex(SPL_G(autoload_functions), &key, &dummy, 0, &function_pos); - add_next_index_str(return_value, key); + add_next_index_str(return_value, STR_COPY(key)); } } @@ -765,7 +765,7 @@ PHP_FUNCTION(spl_autoload_functions) } array_init(return_value); - add_next_index_str(return_value, EG(autoload_func)->common.function_name); + add_next_index_str(return_value, STR_COPY(EG(autoload_func)->common.function_name)); } /* }}} */ /* {{{ proto string spl_object_hash(object obj) -- cgit v1.2.1 From 595741f6ece88c79d368a20c14786268a8e35434 Mon Sep 17 00:00:00 2001 From: Xinchen Hui Date: Tue, 25 Feb 2014 17:58:01 +0800 Subject: Fixed test fail in ext/standard/tests/serialize/bug64354_1.php --- ext/spl/php_spl.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'ext/spl/php_spl.c') diff --git a/ext/spl/php_spl.c b/ext/spl/php_spl.c index 26f39eb513..002820b6fc 100644 --- a/ext/spl/php_spl.c +++ b/ext/spl/php_spl.c @@ -394,14 +394,16 @@ typedef struct { zend_class_entry *ce; } autoload_func_info; -static void autoload_func_info_dtor(autoload_func_info *alfi) +static void autoload_func_info_dtor(zval *element) { + autoload_func_info *alfi = (autoload_func_info*)Z_PTR_P(element); if (alfi->obj) { zval_ptr_dtor(alfi->obj); } if (alfi->closure) { zval_ptr_dtor(alfi->closure); } + efree(alfi); } /* {{{ proto void spl_autoload_call(string class_name) @@ -553,10 +555,9 @@ PHP_FUNCTION(spl_autoload_register) alfi.closure = zcallable; Z_ADDREF_P(zcallable); - lc_name = STR_ALLOC(func_name_len + 2 + sizeof(zend_uint), 0); + lc_name = STR_ALLOC(func_name_len + sizeof(zend_uint), 0); zend_str_tolower_copy(lc_name->val, func_name, func_name_len); memcpy(lc_name->val + func_name_len, &Z_OBJ_HANDLE_P(zcallable), sizeof(zend_uint)); - lc_name->len += sizeof(zend_uint); lc_name->val[lc_name->len] = '\0'; } else { lc_name = STR_ALLOC(func_name_len, 0); @@ -597,14 +598,14 @@ PHP_FUNCTION(spl_autoload_register) spl_alfi.ce = NULL; spl_alfi.closure = NULL; zend_hash_str_add_mem(SPL_G(autoload_functions), "spl_autoload", sizeof("spl_autoload") - 1, - (void *)&spl_alfi, sizeof(autoload_func_info)); + &spl_alfi, sizeof(autoload_func_info)); if (prepend && SPL_G(autoload_functions)->nNumOfElements > 1) { /* Move the newly created element to the head of the hashtable */ HT_MOVE_TAIL_TO_HEAD(SPL_G(autoload_functions)); } } - if (zend_hash_add_mem(SPL_G(autoload_functions), lc_name, &alfi.func_ptr, sizeof(autoload_func_info)) == NULL) { + if (zend_hash_add_mem(SPL_G(autoload_functions), lc_name, &alfi, sizeof(autoload_func_info)) == NULL) { if (obj_ptr && !(alfi.func_ptr->common.fn_flags & ZEND_ACC_STATIC)) { Z_DELREF_P(alfi.obj); } -- cgit v1.2.1 From 639e4e1afac8c79d28e1a4c3df48fc060b35b68e Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Tue, 25 Feb 2014 16:03:34 +0400 Subject: Changes zend_is_callable() to use zend_string* instead of char* --- ext/spl/php_spl.c | 54 +++++++++++++++++++++++++++--------------------------- 1 file changed, 27 insertions(+), 27 deletions(-) (limited to 'ext/spl/php_spl.c') diff --git a/ext/spl/php_spl.c b/ext/spl/php_spl.c index 002820b6fc..8674645924 100644 --- a/ext/spl/php_spl.c +++ b/ext/spl/php_spl.c @@ -475,8 +475,8 @@ PHP_FUNCTION(spl_autoload_call) Register given function as __autoload() implementation */ PHP_FUNCTION(spl_autoload_register) { - char *func_name, *error = NULL; - int func_name_len; + zend_string *func_name; + char *error = NULL; zend_string *lc_name; zval *zcallable = NULL; zend_bool do_throw = 1; @@ -491,7 +491,7 @@ PHP_FUNCTION(spl_autoload_register) } if (ZEND_NUM_ARGS()) { - if (!zend_is_callable_ex(zcallable, NULL, IS_CALLABLE_STRICT, &func_name, &func_name_len, &fcc, &error TSRMLS_CC)) { + if (!zend_is_callable_ex(zcallable, NULL, IS_CALLABLE_STRICT, &func_name, &fcc, &error TSRMLS_CC)) { alfi.ce = fcc.calling_scope; alfi.func_ptr = fcc.function_handler; obj_ptr = fcc.object_ptr; @@ -503,7 +503,7 @@ PHP_FUNCTION(spl_autoload_register) if (error) { efree(error); } - efree(func_name); + STR_RELEASE(func_name); RETURN_FALSE; } else if (do_throw) { zend_throw_exception_ex(spl_ce_LogicException, 0 TSRMLS_CC, "Passed array does not specify %s %smethod (%s)", alfi.func_ptr ? "a callable" : "an existing", !obj_ptr ? "static " : "", error); @@ -511,16 +511,16 @@ PHP_FUNCTION(spl_autoload_register) if (error) { efree(error); } - efree(func_name); + STR_RELEASE(func_name); RETURN_FALSE; } else if (Z_TYPE_P(zcallable) == IS_STRING) { if (do_throw) { - zend_throw_exception_ex(spl_ce_LogicException, 0 TSRMLS_CC, "Function '%s' not %s (%s)", func_name, alfi.func_ptr ? "callable" : "found", error); + zend_throw_exception_ex(spl_ce_LogicException, 0 TSRMLS_CC, "Function '%s' not %s (%s)", func_name->val, alfi.func_ptr ? "callable" : "found", error); } if (error) { efree(error); } - efree(func_name); + STR_RELEASE(func_name); RETURN_FALSE; } else { if (do_throw) { @@ -529,7 +529,7 @@ PHP_FUNCTION(spl_autoload_register) if (error) { efree(error); } - efree(func_name); + STR_RELEASE(func_name); RETURN_FALSE; } } else if (fcc.function_handler->type == ZEND_INTERNAL_FUNCTION && @@ -540,7 +540,7 @@ PHP_FUNCTION(spl_autoload_register) if (error) { efree(error); } - efree(func_name); + STR_RELEASE(func_name); RETURN_FALSE; } alfi.closure = NULL; @@ -555,15 +555,15 @@ PHP_FUNCTION(spl_autoload_register) alfi.closure = zcallable; Z_ADDREF_P(zcallable); - lc_name = STR_ALLOC(func_name_len + sizeof(zend_uint), 0); - zend_str_tolower_copy(lc_name->val, func_name, func_name_len); - memcpy(lc_name->val + func_name_len, &Z_OBJ_HANDLE_P(zcallable), sizeof(zend_uint)); + lc_name = STR_ALLOC(func_name->len + sizeof(zend_uint), 0); + zend_str_tolower_copy(lc_name->val, func_name->val, func_name->len); + memcpy(lc_name->val + func_name->len, &Z_OBJ_HANDLE_P(zcallable), sizeof(zend_uint)); lc_name->val[lc_name->len] = '\0'; } else { - lc_name = STR_ALLOC(func_name_len, 0); - zend_str_tolower_copy(lc_name->val, func_name, func_name_len); + lc_name = STR_ALLOC(func_name->len, 0); + zend_str_tolower_copy(lc_name->val, func_name->val, func_name->len); } - efree(func_name); + STR_RELEASE(func_name); if (SPL_G(autoload_functions) && zend_hash_exists(SPL_G(autoload_functions), lc_name)) { if (alfi.closure) { @@ -634,8 +634,8 @@ skip: Unregister given function as __autoload() implementation */ PHP_FUNCTION(spl_autoload_unregister) { - char *func_name, *error = NULL; - int func_name_len; + zend_string *func_name = NULL; + char *error = NULL; zend_string *lc_name; zval *zcallable; int success = FAILURE; @@ -647,13 +647,13 @@ PHP_FUNCTION(spl_autoload_unregister) return; } - if (!zend_is_callable_ex(zcallable, NULL, IS_CALLABLE_CHECK_SYNTAX_ONLY, &func_name, &func_name_len, &fcc, &error TSRMLS_CC)) { + if (!zend_is_callable_ex(zcallable, NULL, IS_CALLABLE_CHECK_SYNTAX_ONLY, &func_name, &fcc, &error TSRMLS_CC)) { zend_throw_exception_ex(spl_ce_LogicException, 0 TSRMLS_CC, "Unable to unregister invalid function (%s)", error); if (error) { efree(error); } if (func_name) { - efree(func_name); + STR_RELEASE(func_name); } RETURN_FALSE; } @@ -663,19 +663,19 @@ PHP_FUNCTION(spl_autoload_unregister) } if (Z_TYPE_P(zcallable) == IS_OBJECT) { - lc_name = STR_ALLOC(func_name_len + 2 + sizeof(zend_uint), 0); - zend_str_tolower_copy(lc_name->val, func_name, func_name_len); - memcpy(lc_name->val + func_name_len, &Z_OBJ_HANDLE_P(zcallable), sizeof(zend_uint)); + lc_name = STR_ALLOC(func_name->len + 2 + sizeof(zend_uint), 0); + zend_str_tolower_copy(lc_name->val, func_name->val, func_name->len); + memcpy(lc_name->val + func_name->len, &Z_OBJ_HANDLE_P(zcallable), sizeof(zend_uint)); lc_name->len += sizeof(zend_uint); lc_name->val[lc_name->len] = '\0'; } else { - lc_name = STR_ALLOC(func_name_len, 0); - zend_str_tolower_copy(lc_name->val, func_name, func_name_len); + lc_name = STR_ALLOC(func_name->len, 0); + zend_str_tolower_copy(lc_name->val, func_name->val, func_name->len); } - efree(func_name); + STR_RELEASE(func_name); if (SPL_G(autoload_functions)) { - if (func_name_len == sizeof("spl_autoload_call") - 1 && !strcmp(lc_name->val, "spl_autoload_call")) { + if (lc_name->len == sizeof("spl_autoload_call") - 1 && !strcmp(lc_name->val, "spl_autoload_call")) { /* remove all */ zend_hash_destroy(SPL_G(autoload_functions)); FREE_HASHTABLE(SPL_G(autoload_functions)); @@ -692,7 +692,7 @@ PHP_FUNCTION(spl_autoload_unregister) success = zend_hash_del(SPL_G(autoload_functions), lc_name); } } - } else if (func_name_len == sizeof("spl_autoload")-1 && !strcmp(lc_name->val, "spl_autoload")) { + } else if (lc_name->len == sizeof("spl_autoload")-1 && !strcmp(lc_name->val, "spl_autoload")) { /* register single spl_autoload() */ spl_func_ptr = zend_hash_str_find_ptr(EG(function_table), "spl_autoload", sizeof("spl_autoload")); -- cgit v1.2.1 From 0680cdb4ac1c78b24be4433441b21c1f1fa348e6 Mon Sep 17 00:00:00 2001 From: Xinchen Hui Date: Fri, 28 Feb 2014 22:44:50 +0800 Subject: Fixed refcount handling --- ext/spl/php_spl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ext/spl/php_spl.c') diff --git a/ext/spl/php_spl.c b/ext/spl/php_spl.c index 8674645924..64cfd7b55d 100644 --- a/ext/spl/php_spl.c +++ b/ext/spl/php_spl.c @@ -284,7 +284,7 @@ static int spl_autoload(zend_string *class_name, zend_string *lc_name, const cha new_op_array = NULL; zend_file_handle_dtor(&file_handle TSRMLS_CC); } - STR_FREE(opened_path); + STR_RELEASE(opened_path); if (new_op_array) { EG(active_op_array) = new_op_array; if (!EG(active_symbol_table)) { -- cgit v1.2.1 From 7208b9660cc5d174e90e38e897b8828464b2fa56 Mon Sep 17 00:00:00 2001 From: Xinchen Hui Date: Fri, 28 Feb 2014 23:05:13 +0800 Subject: Fixed autoload_func_info using zval instead of zval * --- ext/spl/php_spl.c | 50 ++++++++++++++++++++++++-------------------------- 1 file changed, 24 insertions(+), 26 deletions(-) (limited to 'ext/spl/php_spl.c') diff --git a/ext/spl/php_spl.c b/ext/spl/php_spl.c index 64cfd7b55d..a033b0bc37 100644 --- a/ext/spl/php_spl.c +++ b/ext/spl/php_spl.c @@ -389,19 +389,19 @@ PHP_FUNCTION(spl_autoload_extensions) typedef struct { zend_function *func_ptr; - zval *obj; - zval *closure; + zval obj; + zval closure; zend_class_entry *ce; } autoload_func_info; static void autoload_func_info_dtor(zval *element) { autoload_func_info *alfi = (autoload_func_info*)Z_PTR_P(element); - if (alfi->obj) { - zval_ptr_dtor(alfi->obj); + if (!ZVAL_IS_UNDEF(&alfi->obj)) { + zval_ptr_dtor(&alfi->obj); } - if (alfi->closure) { - zval_ptr_dtor(alfi->closure); + if (!ZVAL_IS_UNDEF(&alfi->closure)) { + zval_ptr_dtor(&alfi->closure); } efree(alfi); } @@ -429,7 +429,7 @@ PHP_FUNCTION(spl_autoload_call) while(zend_hash_has_more_elements_ex(SPL_G(autoload_functions), &function_pos) == SUCCESS) { zend_hash_get_current_key_ex(SPL_G(autoload_functions), &func_name, &dummy, 0, &function_pos); alfi = zend_hash_get_current_data_ptr_ex(SPL_G(autoload_functions), &function_pos); - zend_call_method(alfi->obj, alfi->ce, &alfi->func_ptr, func_name->val, func_name->len, retval, 1, class_name, NULL TSRMLS_CC); + zend_call_method(&alfi->obj, alfi->ce, &alfi->func_ptr, func_name->val, func_name->len, retval, 1, class_name, NULL TSRMLS_CC); zend_exception_save(TSRMLS_C); if (retval) { zval_ptr_dtor(retval); @@ -543,7 +543,7 @@ PHP_FUNCTION(spl_autoload_register) STR_RELEASE(func_name); RETURN_FALSE; } - alfi.closure = NULL; + ZVAL_UNDEF(&alfi.closure); alfi.ce = fcc.calling_scope; alfi.func_ptr = fcc.function_handler; obj_ptr = fcc.object_ptr; @@ -552,8 +552,7 @@ PHP_FUNCTION(spl_autoload_register) } if (Z_TYPE_P(zcallable) == IS_OBJECT) { - alfi.closure = zcallable; - Z_ADDREF_P(zcallable); + ZVAL_COPY(&alfi.closure, zcallable); lc_name = STR_ALLOC(func_name->len + sizeof(zend_uint), 0); zend_str_tolower_copy(lc_name->val, func_name->val, func_name->len); @@ -566,8 +565,8 @@ PHP_FUNCTION(spl_autoload_register) STR_RELEASE(func_name); if (SPL_G(autoload_functions) && zend_hash_exists(SPL_G(autoload_functions), lc_name)) { - if (alfi.closure) { - Z_DELREF_P(zcallable); + if (!ZVAL_IS_UNDEF(&alfi.closure)) { + Z_DELREF_P(&alfi.closure); } goto skip; } @@ -577,10 +576,9 @@ PHP_FUNCTION(spl_autoload_register) STR_REALLOC(lc_name, lc_name->len + 2 + sizeof(zend_uint), 0); memcpy(lc_name->val + lc_name->len - 2 - sizeof(zend_uint), &Z_OBJ_HANDLE_P(obj_ptr), sizeof(zend_uint)); lc_name->val[lc_name->len] = '\0'; - alfi.obj = obj_ptr; - Z_ADDREF_P(alfi.obj); + ZVAL_COPY(&alfi.obj, obj_ptr); } else { - alfi.obj = NULL; + ZVAL_UNDEF(&alfi.obj); } if (!SPL_G(autoload_functions)) { @@ -594,9 +592,9 @@ PHP_FUNCTION(spl_autoload_register) autoload_func_info spl_alfi; spl_alfi.func_ptr = spl_func_ptr; - spl_alfi.obj = NULL; + ZVAL_UNDEF(&spl_alfi.obj); + ZVAL_UNDEF(&spl_alfi.closure); spl_alfi.ce = NULL; - spl_alfi.closure = NULL; zend_hash_str_add_mem(SPL_G(autoload_functions), "spl_autoload", sizeof("spl_autoload") - 1, &spl_alfi, sizeof(autoload_func_info)); if (prepend && SPL_G(autoload_functions)->nNumOfElements > 1) { @@ -607,10 +605,10 @@ PHP_FUNCTION(spl_autoload_register) if (zend_hash_add_mem(SPL_G(autoload_functions), lc_name, &alfi, sizeof(autoload_func_info)) == NULL) { if (obj_ptr && !(alfi.func_ptr->common.fn_flags & ZEND_ACC_STATIC)) { - Z_DELREF_P(alfi.obj); + Z_DELREF(alfi.obj); } - if (alfi.closure) { - Z_DELREF_P(alfi.closure); + if (!ZVAL_IS_UNDEF(&alfi.closure)) { + Z_DELREF(alfi.closure); } } if (prepend && SPL_G(autoload_functions)->nNumOfElements > 1) { @@ -734,16 +732,16 @@ PHP_FUNCTION(spl_autoload_functions) zend_hash_internal_pointer_reset_ex(SPL_G(autoload_functions), &function_pos); while(zend_hash_has_more_elements_ex(SPL_G(autoload_functions), &function_pos) == SUCCESS) { alfi = zend_hash_get_current_data_ptr_ex(SPL_G(autoload_functions), &function_pos); - if (alfi->closure) { - Z_ADDREF_P(alfi->closure); - add_next_index_zval(return_value, alfi->closure); + if (!ZVAL_IS_UNDEF(&alfi->closure)) { + Z_ADDREF(alfi->closure); + add_next_index_zval(return_value, &alfi->closure); } else if (alfi->func_ptr->common.scope) { zval tmp; array_init(&tmp); - if (alfi->obj) { - Z_ADDREF_P(alfi->obj); - add_next_index_zval(&tmp, alfi->obj); + if (!ZVAL_IS_UNDEF(&alfi->obj)) { + Z_ADDREF(alfi->obj); + add_next_index_zval(&tmp, &alfi->obj); } else { add_next_index_str(&tmp, STR_COPY(alfi->ce->name)); } -- cgit v1.2.1 From 7235048ca17580fc1fd1197ea6cbc909f0e3000f Mon Sep 17 00:00:00 2001 From: Xinchen Hui Date: Sat, 1 Mar 2014 00:07:11 +0800 Subject: Fixing spl_autoload functional (one test failed due to get_closure) --- ext/spl/php_spl.c | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) (limited to 'ext/spl/php_spl.c') diff --git a/ext/spl/php_spl.c b/ext/spl/php_spl.c index a033b0bc37..e9f6ba33d2 100644 --- a/ext/spl/php_spl.c +++ b/ext/spl/php_spl.c @@ -312,7 +312,7 @@ static int spl_autoload(zend_string *class_name, zend_string *lc_name, const cha Default implementation for __autoload() */ PHP_FUNCTION(spl_autoload) { - int found = 0, pos_len; + int found = 0, pos_len, pos1_len; char *pos, *pos1; zend_string *class_name, *lc_name, *file_exts = SPL_G(autoload_extensions); zend_op **original_opline_ptr = EG(opline_ptr); @@ -337,14 +337,16 @@ PHP_FUNCTION(spl_autoload) EG(active_op_array) = original_active_op_array; pos1 = strchr(pos, ','); if (pos1) { - pos_len = pos1 - pos; + pos1_len = pos1 - pos; + } else { + pos1_len = pos_len; } - if (spl_autoload(class_name, lc_name, pos, pos_len TSRMLS_CC)) { + if (spl_autoload(class_name, lc_name, pos, pos1_len TSRMLS_CC)) { found = 1; break; /* loaded */ } pos = pos1 ? pos1 + 1 : NULL; - pos_len = pos1 ? pos1 - pos : pos_len; + pos_len = pos1? pos_len - pos1_len - 1 : 0; } STR_FREE(lc_name); @@ -357,7 +359,7 @@ PHP_FUNCTION(spl_autoload) * the Zend engine. */ if (active_opline->opcode != ZEND_FETCH_CLASS) { - zend_throw_exception_ex(spl_ce_LogicException, 0 TSRMLS_CC, "Class %s could not be loaded", class_name); + zend_throw_exception_ex(spl_ce_LogicException, 0 TSRMLS_CC, "Class %s could not be loaded", class_name->val); } else { php_error_docref(NULL TSRMLS_CC, E_ERROR, "Class %s could not be loaded", class_name->val); } @@ -375,9 +377,9 @@ PHP_FUNCTION(spl_autoload_extensions) } if (file_exts) { if (SPL_G(autoload_extensions)) { - STR_REFCOUNT(SPL_G(autoload_extensions)); + STR_RELEASE(SPL_G(autoload_extensions)); } - SPL_G(autoload_extensions) = STR_DUP(file_exts, 0); + SPL_G(autoload_extensions) = STR_COPY(file_exts); } if (SPL_G(autoload_extensions) == NULL) { @@ -426,10 +428,10 @@ PHP_FUNCTION(spl_autoload_call) lc_name = STR_ALLOC(Z_STRLEN_P(class_name), 0); zend_str_tolower_copy(lc_name->val, Z_STRVAL_P(class_name), Z_STRLEN_P(class_name)); zend_hash_internal_pointer_reset_ex(SPL_G(autoload_functions), &function_pos); - while(zend_hash_has_more_elements_ex(SPL_G(autoload_functions), &function_pos) == SUCCESS) { + while (zend_hash_has_more_elements_ex(SPL_G(autoload_functions), &function_pos) == SUCCESS) { zend_hash_get_current_key_ex(SPL_G(autoload_functions), &func_name, &dummy, 0, &function_pos); alfi = zend_hash_get_current_data_ptr_ex(SPL_G(autoload_functions), &function_pos); - zend_call_method(&alfi->obj, alfi->ce, &alfi->func_ptr, func_name->val, func_name->len, retval, 1, class_name, NULL TSRMLS_CC); + zend_call_method(ZVAL_IS_UNDEF(&alfi->obj)? NULL : &alfi->obj, alfi->ce, &alfi->func_ptr, func_name->val, func_name->len, retval, 1, class_name, NULL TSRMLS_CC); zend_exception_save(TSRMLS_C); if (retval) { zval_ptr_dtor(retval); @@ -543,7 +545,6 @@ PHP_FUNCTION(spl_autoload_register) STR_RELEASE(func_name); RETURN_FALSE; } - ZVAL_UNDEF(&alfi.closure); alfi.ce = fcc.calling_scope; alfi.func_ptr = fcc.function_handler; obj_ptr = fcc.object_ptr; @@ -559,6 +560,7 @@ PHP_FUNCTION(spl_autoload_register) memcpy(lc_name->val + func_name->len, &Z_OBJ_HANDLE_P(zcallable), sizeof(zend_uint)); lc_name->val[lc_name->len] = '\0'; } else { + ZVAL_UNDEF(&alfi.closure); lc_name = STR_ALLOC(func_name->len, 0); zend_str_tolower_copy(lc_name->val, func_name->val, func_name->len); } @@ -573,8 +575,8 @@ PHP_FUNCTION(spl_autoload_register) if (obj_ptr && !(alfi.func_ptr->common.fn_flags & ZEND_ACC_STATIC)) { /* add object id to the hash to ensure uniqueness, for more reference look at bug #40091 */ - STR_REALLOC(lc_name, lc_name->len + 2 + sizeof(zend_uint), 0); - memcpy(lc_name->val + lc_name->len - 2 - sizeof(zend_uint), &Z_OBJ_HANDLE_P(obj_ptr), sizeof(zend_uint)); + lc_name = STR_REALLOC(lc_name, lc_name->len + sizeof(zend_uint), 0); + memcpy(lc_name->val + lc_name->len - sizeof(zend_uint), &Z_OBJ_HANDLE_P(obj_ptr), sizeof(zend_uint)); lc_name->val[lc_name->len] = '\0'; ZVAL_COPY(&alfi.obj, obj_ptr); } else { @@ -661,7 +663,7 @@ PHP_FUNCTION(spl_autoload_unregister) } if (Z_TYPE_P(zcallable) == IS_OBJECT) { - lc_name = STR_ALLOC(func_name->len + 2 + sizeof(zend_uint), 0); + lc_name = STR_ALLOC(func_name->len + sizeof(zend_uint), 0); zend_str_tolower_copy(lc_name->val, func_name->val, func_name->len); memcpy(lc_name->val + func_name->len, &Z_OBJ_HANDLE_P(zcallable), sizeof(zend_uint)); lc_name->len += sizeof(zend_uint); @@ -684,15 +686,15 @@ PHP_FUNCTION(spl_autoload_unregister) /* remove specific */ success = zend_hash_del(SPL_G(autoload_functions), lc_name); if (success != SUCCESS && obj_ptr) { - STR_REALLOC(lc_name, lc_name->len + 2 + sizeof(zend_uint), 0); - memcpy(lc_name->val + lc_name->len - 2 - sizeof(zend_uint), &Z_OBJ_HANDLE_P(obj_ptr), sizeof(zend_uint)); + STR_REALLOC(lc_name, lc_name->len + sizeof(zend_uint), 0); + memcpy(lc_name->val + lc_name->len - sizeof(zend_uint), &Z_OBJ_HANDLE_P(obj_ptr), sizeof(zend_uint)); lc_name->val[lc_name->len] = '\0'; success = zend_hash_del(SPL_G(autoload_functions), lc_name); } } } else if (lc_name->len == sizeof("spl_autoload")-1 && !strcmp(lc_name->val, "spl_autoload")) { /* register single spl_autoload() */ - spl_func_ptr = zend_hash_str_find_ptr(EG(function_table), "spl_autoload", sizeof("spl_autoload")); + spl_func_ptr = zend_hash_str_find_ptr(EG(function_table), "spl_autoload", sizeof("spl_autoload") - 1); if (EG(autoload_func) == spl_func_ptr) { success = SUCCESS; @@ -730,7 +732,7 @@ PHP_FUNCTION(spl_autoload_functions) if (EG(autoload_func) == fptr) { array_init(return_value); zend_hash_internal_pointer_reset_ex(SPL_G(autoload_functions), &function_pos); - while(zend_hash_has_more_elements_ex(SPL_G(autoload_functions), &function_pos) == SUCCESS) { + while (zend_hash_has_more_elements_ex(SPL_G(autoload_functions), &function_pos) == SUCCESS) { alfi = zend_hash_get_current_data_ptr_ex(SPL_G(autoload_functions), &function_pos); if (!ZVAL_IS_UNDEF(&alfi->closure)) { Z_ADDREF(alfi->closure); -- cgit v1.2.1 From 19670c2bbcd5fc1339e160929cc81db3ae940392 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Wed, 5 Mar 2014 01:54:21 +0400 Subject: Fixied calling object closures from internal functions --- ext/spl/php_spl.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'ext/spl/php_spl.c') diff --git a/ext/spl/php_spl.c b/ext/spl/php_spl.c index e9f6ba33d2..66da18a771 100644 --- a/ext/spl/php_spl.c +++ b/ext/spl/php_spl.c @@ -496,9 +496,9 @@ PHP_FUNCTION(spl_autoload_register) if (!zend_is_callable_ex(zcallable, NULL, IS_CALLABLE_STRICT, &func_name, &fcc, &error TSRMLS_CC)) { alfi.ce = fcc.calling_scope; alfi.func_ptr = fcc.function_handler; - obj_ptr = fcc.object_ptr; + obj_ptr = &fcc.object; if (Z_TYPE_P(zcallable) == IS_ARRAY) { - if (!obj_ptr && alfi.func_ptr && !(alfi.func_ptr->common.fn_flags & ZEND_ACC_STATIC)) { + if (Z_TYPE_P(obj_ptr) == IS_UNDEF && alfi.func_ptr && !(alfi.func_ptr->common.fn_flags & ZEND_ACC_STATIC)) { if (do_throw) { zend_throw_exception_ex(spl_ce_LogicException, 0 TSRMLS_CC, "Passed array specifies a non static method but no object (%s)", error); } @@ -508,7 +508,7 @@ PHP_FUNCTION(spl_autoload_register) STR_RELEASE(func_name); RETURN_FALSE; } else if (do_throw) { - zend_throw_exception_ex(spl_ce_LogicException, 0 TSRMLS_CC, "Passed array does not specify %s %smethod (%s)", alfi.func_ptr ? "a callable" : "an existing", !obj_ptr ? "static " : "", error); + zend_throw_exception_ex(spl_ce_LogicException, 0 TSRMLS_CC, "Passed array does not specify %s %smethod (%s)", alfi.func_ptr ? "a callable" : "an existing", Z_TYPE_P(obj_ptr) == IS_UNDEF ? "static " : "", error); } if (error) { efree(error); @@ -547,7 +547,7 @@ PHP_FUNCTION(spl_autoload_register) } alfi.ce = fcc.calling_scope; alfi.func_ptr = fcc.function_handler; - obj_ptr = fcc.object_ptr; + obj_ptr = &fcc.object; if (error) { efree(error); } @@ -573,7 +573,7 @@ PHP_FUNCTION(spl_autoload_register) goto skip; } - if (obj_ptr && !(alfi.func_ptr->common.fn_flags & ZEND_ACC_STATIC)) { + if (Z_TYPE_P(obj_ptr) == IS_OBJECT && !(alfi.func_ptr->common.fn_flags & ZEND_ACC_STATIC)) { /* add object id to the hash to ensure uniqueness, for more reference look at bug #40091 */ lc_name = STR_REALLOC(lc_name, lc_name->len + sizeof(zend_uint), 0); memcpy(lc_name->val + lc_name->len - sizeof(zend_uint), &Z_OBJ_HANDLE_P(obj_ptr), sizeof(zend_uint)); @@ -606,7 +606,7 @@ PHP_FUNCTION(spl_autoload_register) } if (zend_hash_add_mem(SPL_G(autoload_functions), lc_name, &alfi, sizeof(autoload_func_info)) == NULL) { - if (obj_ptr && !(alfi.func_ptr->common.fn_flags & ZEND_ACC_STATIC)) { + if (Z_TYPE_P(obj_ptr) == IS_OBJECT && !(alfi.func_ptr->common.fn_flags & ZEND_ACC_STATIC)) { Z_DELREF(alfi.obj); } if (!ZVAL_IS_UNDEF(&alfi.closure)) { @@ -657,7 +657,7 @@ PHP_FUNCTION(spl_autoload_unregister) } RETURN_FALSE; } - obj_ptr = fcc.object_ptr; + obj_ptr = &fcc.object; if (error) { efree(error); } @@ -685,7 +685,7 @@ PHP_FUNCTION(spl_autoload_unregister) } else { /* remove specific */ success = zend_hash_del(SPL_G(autoload_functions), lc_name); - if (success != SUCCESS && obj_ptr) { + if (success != SUCCESS && Z_TYPE_P(obj_ptr) == IS_OBJECT) { STR_REALLOC(lc_name, lc_name->len + sizeof(zend_uint), 0); memcpy(lc_name->val + lc_name->len - sizeof(zend_uint), &Z_OBJ_HANDLE_P(obj_ptr), sizeof(zend_uint)); lc_name->val[lc_name->len] = '\0'; -- cgit v1.2.1 From 34dac6ddbc0fdcbfe4fbcb73bcc70a7d9b2a55e5 Mon Sep 17 00:00:00 2001 From: Xinchen Hui Date: Sat, 15 Mar 2014 19:34:07 +0800 Subject: Fixed several bugs in spl_autoload --- ext/spl/php_spl.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'ext/spl/php_spl.c') diff --git a/ext/spl/php_spl.c b/ext/spl/php_spl.c index 66da18a771..935e64be60 100644 --- a/ext/spl/php_spl.c +++ b/ext/spl/php_spl.c @@ -585,7 +585,7 @@ PHP_FUNCTION(spl_autoload_register) if (!SPL_G(autoload_functions)) { ALLOC_HASHTABLE(SPL_G(autoload_functions)); - zend_hash_init(SPL_G(autoload_functions), 1, NULL, (dtor_func_t) autoload_func_info_dtor, 0); + zend_hash_init(SPL_G(autoload_functions), 1, NULL, autoload_func_info_dtor, 0); } spl_func_ptr = zend_hash_str_find_ptr(EG(function_table), "spl_autoload", sizeof("spl_autoload") - 1); @@ -666,7 +666,6 @@ PHP_FUNCTION(spl_autoload_unregister) lc_name = STR_ALLOC(func_name->len + sizeof(zend_uint), 0); zend_str_tolower_copy(lc_name->val, func_name->val, func_name->len); memcpy(lc_name->val + func_name->len, &Z_OBJ_HANDLE_P(zcallable), sizeof(zend_uint)); - lc_name->len += sizeof(zend_uint); lc_name->val[lc_name->len] = '\0'; } else { lc_name = STR_ALLOC(func_name->len, 0); @@ -686,7 +685,7 @@ PHP_FUNCTION(spl_autoload_unregister) /* remove specific */ success = zend_hash_del(SPL_G(autoload_functions), lc_name); if (success != SUCCESS && Z_TYPE_P(obj_ptr) == IS_OBJECT) { - STR_REALLOC(lc_name, lc_name->len + sizeof(zend_uint), 0); + lc_name = STR_REALLOC(lc_name, lc_name->len + sizeof(zend_uint), 0); memcpy(lc_name->val + lc_name->len - sizeof(zend_uint), &Z_OBJ_HANDLE_P(obj_ptr), sizeof(zend_uint)); lc_name->val[lc_name->len] = '\0'; success = zend_hash_del(SPL_G(autoload_functions), lc_name); @@ -702,7 +701,7 @@ PHP_FUNCTION(spl_autoload_unregister) } } - STR_FREE(lc_name); + STR_RELEASE(lc_name); RETURN_BOOL(success == SUCCESS); } /* }}} */ -- cgit v1.2.1 From ea85451b65b904d0670c4011c819a15431720432 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Fri, 28 Mar 2014 02:11:22 +0400 Subject: Refactored data structures to keep zend_object* instead of a whole zval in some places --- ext/spl/php_spl.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) (limited to 'ext/spl/php_spl.c') diff --git a/ext/spl/php_spl.c b/ext/spl/php_spl.c index 935e64be60..55d72e6753 100644 --- a/ext/spl/php_spl.c +++ b/ext/spl/php_spl.c @@ -485,7 +485,7 @@ PHP_FUNCTION(spl_autoload_register) zend_bool prepend = 0; zend_function *spl_func_ptr; autoload_func_info alfi; - zval *obj_ptr; + zend_object *obj_ptr; zend_fcall_info_cache fcc; if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, "|zbb", &zcallable, &do_throw, &prepend) == FAILURE) { @@ -496,9 +496,9 @@ PHP_FUNCTION(spl_autoload_register) if (!zend_is_callable_ex(zcallable, NULL, IS_CALLABLE_STRICT, &func_name, &fcc, &error TSRMLS_CC)) { alfi.ce = fcc.calling_scope; alfi.func_ptr = fcc.function_handler; - obj_ptr = &fcc.object; + obj_ptr = fcc.object; if (Z_TYPE_P(zcallable) == IS_ARRAY) { - if (Z_TYPE_P(obj_ptr) == IS_UNDEF && alfi.func_ptr && !(alfi.func_ptr->common.fn_flags & ZEND_ACC_STATIC)) { + if (!obj_ptr && alfi.func_ptr && !(alfi.func_ptr->common.fn_flags & ZEND_ACC_STATIC)) { if (do_throw) { zend_throw_exception_ex(spl_ce_LogicException, 0 TSRMLS_CC, "Passed array specifies a non static method but no object (%s)", error); } @@ -508,7 +508,7 @@ PHP_FUNCTION(spl_autoload_register) STR_RELEASE(func_name); RETURN_FALSE; } else if (do_throw) { - zend_throw_exception_ex(spl_ce_LogicException, 0 TSRMLS_CC, "Passed array does not specify %s %smethod (%s)", alfi.func_ptr ? "a callable" : "an existing", Z_TYPE_P(obj_ptr) == IS_UNDEF ? "static " : "", error); + zend_throw_exception_ex(spl_ce_LogicException, 0 TSRMLS_CC, "Passed array does not specify %s %smethod (%s)", alfi.func_ptr ? "a callable" : "an existing", !obj_ptr ? "static " : "", error); } if (error) { efree(error); @@ -547,7 +547,7 @@ PHP_FUNCTION(spl_autoload_register) } alfi.ce = fcc.calling_scope; alfi.func_ptr = fcc.function_handler; - obj_ptr = &fcc.object; + obj_ptr = fcc.object; if (error) { efree(error); } @@ -573,12 +573,13 @@ PHP_FUNCTION(spl_autoload_register) goto skip; } - if (Z_TYPE_P(obj_ptr) == IS_OBJECT && !(alfi.func_ptr->common.fn_flags & ZEND_ACC_STATIC)) { + if (obj_ptr && !(alfi.func_ptr->common.fn_flags & ZEND_ACC_STATIC)) { /* add object id to the hash to ensure uniqueness, for more reference look at bug #40091 */ lc_name = STR_REALLOC(lc_name, lc_name->len + sizeof(zend_uint), 0); - memcpy(lc_name->val + lc_name->len - sizeof(zend_uint), &Z_OBJ_HANDLE_P(obj_ptr), sizeof(zend_uint)); + memcpy(lc_name->val + lc_name->len - sizeof(zend_uint), &obj_ptr->handle, sizeof(zend_uint)); lc_name->val[lc_name->len] = '\0'; - ZVAL_COPY(&alfi.obj, obj_ptr); + ZVAL_OBJ(&alfi.obj, obj_ptr); + Z_ADDREF(alfi.obj); } else { ZVAL_UNDEF(&alfi.obj); } @@ -606,7 +607,7 @@ PHP_FUNCTION(spl_autoload_register) } if (zend_hash_add_mem(SPL_G(autoload_functions), lc_name, &alfi, sizeof(autoload_func_info)) == NULL) { - if (Z_TYPE_P(obj_ptr) == IS_OBJECT && !(alfi.func_ptr->common.fn_flags & ZEND_ACC_STATIC)) { + if (obj_ptr && !(alfi.func_ptr->common.fn_flags & ZEND_ACC_STATIC)) { Z_DELREF(alfi.obj); } if (!ZVAL_IS_UNDEF(&alfi.closure)) { @@ -640,7 +641,7 @@ PHP_FUNCTION(spl_autoload_unregister) zval *zcallable; int success = FAILURE; zend_function *spl_func_ptr; - zval *obj_ptr; + zend_object *obj_ptr; zend_fcall_info_cache fcc; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &zcallable) == FAILURE) { @@ -657,7 +658,7 @@ PHP_FUNCTION(spl_autoload_unregister) } RETURN_FALSE; } - obj_ptr = &fcc.object; + obj_ptr = fcc.object; if (error) { efree(error); } @@ -684,9 +685,9 @@ PHP_FUNCTION(spl_autoload_unregister) } else { /* remove specific */ success = zend_hash_del(SPL_G(autoload_functions), lc_name); - if (success != SUCCESS && Z_TYPE_P(obj_ptr) == IS_OBJECT) { + if (success != SUCCESS && obj_ptr) { lc_name = STR_REALLOC(lc_name, lc_name->len + sizeof(zend_uint), 0); - memcpy(lc_name->val + lc_name->len - sizeof(zend_uint), &Z_OBJ_HANDLE_P(obj_ptr), sizeof(zend_uint)); + memcpy(lc_name->val + lc_name->len - sizeof(zend_uint), &obj_ptr->handle, sizeof(zend_uint)); lc_name->val[lc_name->len] = '\0'; success = zend_hash_del(SPL_G(autoload_functions), lc_name); } -- cgit v1.2.1 From 050d7e38ad4163e7fa65e26724d3516ce7b33601 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Tue, 15 Apr 2014 15:40:40 +0400 Subject: Cleanup (1-st round) --- ext/spl/php_spl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ext/spl/php_spl.c') diff --git a/ext/spl/php_spl.c b/ext/spl/php_spl.c index 55d72e6753..763996ad2a 100644 --- a/ext/spl/php_spl.c +++ b/ext/spl/php_spl.c @@ -721,7 +721,7 @@ PHP_FUNCTION(spl_autoload_functions) if (!EG(autoload_func)) { if ((fptr = zend_hash_str_find_ptr(EG(function_table), ZEND_AUTOLOAD_FUNC_NAME, sizeof(ZEND_AUTOLOAD_FUNC_NAME) - 1))) { array_init(return_value); - add_next_index_stringl(return_value, ZEND_AUTOLOAD_FUNC_NAME, sizeof(ZEND_AUTOLOAD_FUNC_NAME)-1, 1); + add_next_index_stringl(return_value, ZEND_AUTOLOAD_FUNC_NAME, sizeof(ZEND_AUTOLOAD_FUNC_NAME)-1); return; } RETURN_FALSE; -- cgit v1.2.1 From 62016f5ab34166f1defc90fdda6e11025db823eb Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Wed, 16 Apr 2014 14:15:24 +0400 Subject: Fixed reference counting --- ext/spl/php_spl.c | 1 + 1 file changed, 1 insertion(+) (limited to 'ext/spl/php_spl.c') diff --git a/ext/spl/php_spl.c b/ext/spl/php_spl.c index 763996ad2a..30ecf67824 100644 --- a/ext/spl/php_spl.c +++ b/ext/spl/php_spl.c @@ -385,6 +385,7 @@ PHP_FUNCTION(spl_autoload_extensions) if (SPL_G(autoload_extensions) == NULL) { RETURN_STRINGL(SPL_DEFAULT_FILE_EXTENSIONS, sizeof(SPL_DEFAULT_FILE_EXTENSIONS) - 1); } else { + STR_ADDREF(SPL_G(autoload_extensions)); RETURN_STR(SPL_G(autoload_extensions)); } } /* }}} */ -- cgit v1.2.1 From d8651fbe1c4caaaedc42cef1dee0dd3b3f1e447e Mon Sep 17 00:00:00 2001 From: Xinchen Hui Date: Sat, 3 May 2014 16:06:27 +0800 Subject: Make they are in the same style of Z_ISREF --- ext/spl/php_spl.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'ext/spl/php_spl.c') diff --git a/ext/spl/php_spl.c b/ext/spl/php_spl.c index 30ecf67824..22e2a0c671 100644 --- a/ext/spl/php_spl.c +++ b/ext/spl/php_spl.c @@ -400,10 +400,10 @@ typedef struct { static void autoload_func_info_dtor(zval *element) { autoload_func_info *alfi = (autoload_func_info*)Z_PTR_P(element); - if (!ZVAL_IS_UNDEF(&alfi->obj)) { + if (!Z_ISUNDEF(alfi->obj)) { zval_ptr_dtor(&alfi->obj); } - if (!ZVAL_IS_UNDEF(&alfi->closure)) { + if (!Z_ISUNDEF(alfi->closure)) { zval_ptr_dtor(&alfi->closure); } efree(alfi); @@ -432,7 +432,7 @@ PHP_FUNCTION(spl_autoload_call) while (zend_hash_has_more_elements_ex(SPL_G(autoload_functions), &function_pos) == SUCCESS) { zend_hash_get_current_key_ex(SPL_G(autoload_functions), &func_name, &dummy, 0, &function_pos); alfi = zend_hash_get_current_data_ptr_ex(SPL_G(autoload_functions), &function_pos); - zend_call_method(ZVAL_IS_UNDEF(&alfi->obj)? NULL : &alfi->obj, alfi->ce, &alfi->func_ptr, func_name->val, func_name->len, retval, 1, class_name, NULL TSRMLS_CC); + zend_call_method(Z_ISUNDEF(alfi->obj)? NULL : &alfi->obj, alfi->ce, &alfi->func_ptr, func_name->val, func_name->len, retval, 1, class_name, NULL TSRMLS_CC); zend_exception_save(TSRMLS_C); if (retval) { zval_ptr_dtor(retval); @@ -568,7 +568,7 @@ PHP_FUNCTION(spl_autoload_register) STR_RELEASE(func_name); if (SPL_G(autoload_functions) && zend_hash_exists(SPL_G(autoload_functions), lc_name)) { - if (!ZVAL_IS_UNDEF(&alfi.closure)) { + if (!Z_ISUNDEF(alfi.closure)) { Z_DELREF_P(&alfi.closure); } goto skip; @@ -611,7 +611,7 @@ PHP_FUNCTION(spl_autoload_register) if (obj_ptr && !(alfi.func_ptr->common.fn_flags & ZEND_ACC_STATIC)) { Z_DELREF(alfi.obj); } - if (!ZVAL_IS_UNDEF(&alfi.closure)) { + if (!Z_ISUNDEF(alfi.closure)) { Z_DELREF(alfi.closure); } } @@ -735,14 +735,14 @@ PHP_FUNCTION(spl_autoload_functions) zend_hash_internal_pointer_reset_ex(SPL_G(autoload_functions), &function_pos); while (zend_hash_has_more_elements_ex(SPL_G(autoload_functions), &function_pos) == SUCCESS) { alfi = zend_hash_get_current_data_ptr_ex(SPL_G(autoload_functions), &function_pos); - if (!ZVAL_IS_UNDEF(&alfi->closure)) { + if (!Z_ISUNDEF(alfi->closure)) { Z_ADDREF(alfi->closure); add_next_index_zval(return_value, &alfi->closure); } else if (alfi->func_ptr->common.scope) { zval tmp; array_init(&tmp); - if (!ZVAL_IS_UNDEF(&alfi->obj)) { + if (!Z_ISUNDEF(alfi->obj)) { Z_ADDREF(alfi->obj); add_next_index_zval(&tmp, &alfi->obj); } else { -- cgit v1.2.1 From c69781393cd42db7479d24f39e0f55f1b7f1d355 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Thu, 26 Jun 2014 23:51:14 +0400 Subject: Refactoring: merge call_frame and end_execute_data into single data structure. Keep only single copy of each argument on VM stack (previously ZE kept two copies of each arguments for user functions) --- ext/spl/php_spl.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'ext/spl/php_spl.c') diff --git a/ext/spl/php_spl.c b/ext/spl/php_spl.c index 22e2a0c671..5ec20cd563 100644 --- a/ext/spl/php_spl.c +++ b/ext/spl/php_spl.c @@ -292,6 +292,10 @@ static int spl_autoload(zend_string *class_name, zend_string *lc_name, const cha } ZVAL_UNDEF(&result); + if (EG(current_execute_data)) { + EG(current_execute_data)->call = zend_vm_stack_push_call_frame( + (zend_function*)new_op_array, 0, 0, EG(called_scope), Z_OBJ(EG(This)), EG(current_execute_data)->call TSRMLS_CC); + } zend_execute(new_op_array, &result TSRMLS_CC); destroy_op_array(new_op_array TSRMLS_CC); -- cgit v1.2.1 From 4b09dd69e6bd31f4010bf48e9e07e63cb5f3c2a4 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Wed, 2 Jul 2014 22:03:21 +0400 Subject: Removed EG(active_op_array) and use corresponding value from EG(current_execute_data) --- ext/spl/php_spl.c | 4 ---- 1 file changed, 4 deletions(-) (limited to 'ext/spl/php_spl.c') diff --git a/ext/spl/php_spl.c b/ext/spl/php_spl.c index 5ec20cd563..2daeff6603 100644 --- a/ext/spl/php_spl.c +++ b/ext/spl/php_spl.c @@ -286,7 +286,6 @@ static int spl_autoload(zend_string *class_name, zend_string *lc_name, const cha } STR_RELEASE(opened_path); if (new_op_array) { - EG(active_op_array) = new_op_array; if (!EG(active_symbol_table)) { zend_rebuild_symbol_table(TSRMLS_C); } @@ -320,7 +319,6 @@ PHP_FUNCTION(spl_autoload) char *pos, *pos1; zend_string *class_name, *lc_name, *file_exts = SPL_G(autoload_extensions); zend_op **original_opline_ptr = EG(opline_ptr); - zend_op_array *original_active_op_array = EG(active_op_array); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "S|S", &class_name, &file_exts) == FAILURE) { RETURN_FALSE; @@ -338,7 +336,6 @@ PHP_FUNCTION(spl_autoload) zend_str_tolower_copy(lc_name->val, class_name->val, class_name->len); while (pos && *pos && !EG(exception)) { EG(opline_ptr) = original_opline_ptr; - EG(active_op_array) = original_active_op_array; pos1 = strchr(pos, ','); if (pos1) { pos1_len = pos1 - pos; @@ -355,7 +352,6 @@ PHP_FUNCTION(spl_autoload) STR_FREE(lc_name); EG(opline_ptr) = original_opline_ptr; - EG(active_op_array) = original_active_op_array; if (!found && !SPL_G(autoload_running)) { /* For internal errors, we generate E_ERROR, for direct calls an exception is thrown. -- cgit v1.2.1 From 63c057e3313918a800ad7faebdb648216ddba4c0 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Wed, 2 Jul 2014 23:29:53 +0400 Subject: Removed EG(opline_ptr) and use corresponding value from EG(current_execute_data) --- ext/spl/php_spl.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'ext/spl/php_spl.c') diff --git a/ext/spl/php_spl.c b/ext/spl/php_spl.c index 2daeff6603..8bab4ae3cf 100644 --- a/ext/spl/php_spl.c +++ b/ext/spl/php_spl.c @@ -318,7 +318,6 @@ PHP_FUNCTION(spl_autoload) int found = 0, pos_len, pos1_len; char *pos, *pos1; zend_string *class_name, *lc_name, *file_exts = SPL_G(autoload_extensions); - zend_op **original_opline_ptr = EG(opline_ptr); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "S|S", &class_name, &file_exts) == FAILURE) { RETURN_FALSE; @@ -335,7 +334,6 @@ PHP_FUNCTION(spl_autoload) lc_name = STR_ALLOC(class_name->len, 0); zend_str_tolower_copy(lc_name->val, class_name->val, class_name->len); while (pos && *pos && !EG(exception)) { - EG(opline_ptr) = original_opline_ptr; pos1 = strchr(pos, ','); if (pos1) { pos1_len = pos1 - pos; @@ -351,14 +349,17 @@ PHP_FUNCTION(spl_autoload) } STR_FREE(lc_name); - EG(opline_ptr) = original_opline_ptr; - if (!found && !SPL_G(autoload_running)) { /* For internal errors, we generate E_ERROR, for direct calls an exception is thrown. * The "scope" is determined by an opcode, if it is ZEND_FETCH_CLASS we know function was called indirectly by * the Zend engine. */ - if (active_opline->opcode != ZEND_FETCH_CLASS) { + zend_execute_data *ex = EG(current_execute_data); + + while (ex && (!ex->func || !ZEND_USER_CODE(ex->func->type))) { + ex = ex->prev_execute_data; + } + if (ex && ex->opline && ex->opline->opcode != ZEND_FETCH_CLASS) { zend_throw_exception_ex(spl_ce_LogicException, 0 TSRMLS_CC, "Class %s could not be loaded", class_name->val); } else { php_error_docref(NULL TSRMLS_CC, E_ERROR, "Class %s could not be loaded", class_name->val); -- cgit v1.2.1 From c4d99ec982e214d05b398694dc76a9caac16fbd1 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Thu, 3 Jul 2014 02:34:43 +0400 Subject: Removed EG(called_scope) and use corresponding value from EG(current_execute_data) --- ext/spl/php_spl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ext/spl/php_spl.c') diff --git a/ext/spl/php_spl.c b/ext/spl/php_spl.c index 8bab4ae3cf..3730adc699 100644 --- a/ext/spl/php_spl.c +++ b/ext/spl/php_spl.c @@ -293,7 +293,7 @@ static int spl_autoload(zend_string *class_name, zend_string *lc_name, const cha ZVAL_UNDEF(&result); if (EG(current_execute_data)) { EG(current_execute_data)->call = zend_vm_stack_push_call_frame( - (zend_function*)new_op_array, 0, 0, EG(called_scope), Z_OBJ(EG(This)), EG(current_execute_data)->call TSRMLS_CC); + (zend_function*)new_op_array, 0, 0, EG(current_execute_data)->called_scope, Z_OBJ(EG(This)), EG(current_execute_data)->call TSRMLS_CC); } zend_execute(new_op_array, &result TSRMLS_CC); -- cgit v1.2.1 From 6bf24f4dd01331122a0f10db392c08605f159826 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Fri, 4 Jul 2014 18:03:45 +0400 Subject: Removed EG(active_symbol_table) and use corresponding value from EG(current_execute_data) --- ext/spl/php_spl.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'ext/spl/php_spl.c') diff --git a/ext/spl/php_spl.c b/ext/spl/php_spl.c index 3730adc699..e5f968e26b 100644 --- a/ext/spl/php_spl.c +++ b/ext/spl/php_spl.c @@ -286,14 +286,11 @@ static int spl_autoload(zend_string *class_name, zend_string *lc_name, const cha } STR_RELEASE(opened_path); if (new_op_array) { - if (!EG(active_symbol_table)) { - zend_rebuild_symbol_table(TSRMLS_C); - } - ZVAL_UNDEF(&result); if (EG(current_execute_data)) { EG(current_execute_data)->call = zend_vm_stack_push_call_frame( (zend_function*)new_op_array, 0, 0, EG(current_execute_data)->called_scope, Z_OBJ(EG(This)), EG(current_execute_data)->call TSRMLS_CC); + EG(current_execute_data)->call->symbol_table = zend_rebuild_symbol_table(TSRMLS_C); } zend_execute(new_op_array, &result TSRMLS_CC); -- cgit v1.2.1 From 5aa91be509731eb46acff242412941325122ab03 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Mon, 7 Jul 2014 15:50:44 +0400 Subject: Simplify call-frame handling --- ext/spl/php_spl.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'ext/spl/php_spl.c') diff --git a/ext/spl/php_spl.c b/ext/spl/php_spl.c index e5f968e26b..cd0a050b98 100644 --- a/ext/spl/php_spl.c +++ b/ext/spl/php_spl.c @@ -287,11 +287,6 @@ static int spl_autoload(zend_string *class_name, zend_string *lc_name, const cha STR_RELEASE(opened_path); if (new_op_array) { ZVAL_UNDEF(&result); - if (EG(current_execute_data)) { - EG(current_execute_data)->call = zend_vm_stack_push_call_frame( - (zend_function*)new_op_array, 0, 0, EG(current_execute_data)->called_scope, Z_OBJ(EG(This)), EG(current_execute_data)->call TSRMLS_CC); - EG(current_execute_data)->call->symbol_table = zend_rebuild_symbol_table(TSRMLS_C); - } zend_execute(new_op_array, &result TSRMLS_CC); destroy_op_array(new_op_array TSRMLS_CC); @@ -356,7 +351,7 @@ PHP_FUNCTION(spl_autoload) while (ex && (!ex->func || !ZEND_USER_CODE(ex->func->type))) { ex = ex->prev_execute_data; } - if (ex && ex->opline && ex->opline->opcode != ZEND_FETCH_CLASS) { + if (ex && ex->opline->opcode != ZEND_FETCH_CLASS) { zend_throw_exception_ex(spl_ce_LogicException, 0 TSRMLS_CC, "Class %s could not be loaded", class_name->val); } else { php_error_docref(NULL TSRMLS_CC, E_ERROR, "Class %s could not be loaded", class_name->val); -- cgit v1.2.1 From fa82e05e4c8cc3f9496301997b57ab606a074fdd Mon Sep 17 00:00:00 2001 From: Xinchen Hui Date: Wed, 9 Jul 2014 15:13:56 +0800 Subject: Use ZEND_HASH_FOREACH_* macros --- ext/spl/php_spl.c | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) (limited to 'ext/spl/php_spl.c') diff --git a/ext/spl/php_spl.c b/ext/spl/php_spl.c index cd0a050b98..d765d6b754 100644 --- a/ext/spl/php_spl.c +++ b/ext/spl/php_spl.c @@ -406,10 +406,8 @@ static void autoload_func_info_dtor(zval *element) Try all registerd autoload function to load the requested class */ PHP_FUNCTION(spl_autoload_call) { - ulong dummy; zval *class_name, *retval = NULL; zend_string *lc_name, *func_name; - HashPosition function_pos; autoload_func_info *alfi; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &class_name) == FAILURE || Z_TYPE_P(class_name) != IS_STRING) { @@ -421,10 +419,7 @@ PHP_FUNCTION(spl_autoload_call) SPL_G(autoload_running) = 1; lc_name = STR_ALLOC(Z_STRLEN_P(class_name), 0); zend_str_tolower_copy(lc_name->val, Z_STRVAL_P(class_name), Z_STRLEN_P(class_name)); - zend_hash_internal_pointer_reset_ex(SPL_G(autoload_functions), &function_pos); - while (zend_hash_has_more_elements_ex(SPL_G(autoload_functions), &function_pos) == SUCCESS) { - zend_hash_get_current_key_ex(SPL_G(autoload_functions), &func_name, &dummy, 0, &function_pos); - alfi = zend_hash_get_current_data_ptr_ex(SPL_G(autoload_functions), &function_pos); + ZEND_HASH_FOREACH_STR_KEY_PTR(SPL_G(autoload_functions), func_name, alfi) { zend_call_method(Z_ISUNDEF(alfi->obj)? NULL : &alfi->obj, alfi->ce, &alfi->func_ptr, func_name->val, func_name->len, retval, 1, class_name, NULL TSRMLS_CC); zend_exception_save(TSRMLS_C); if (retval) { @@ -434,8 +429,7 @@ PHP_FUNCTION(spl_autoload_call) if (zend_hash_exists(EG(class_table), lc_name)) { break; } - zend_hash_move_forward_ex(SPL_G(autoload_functions), &function_pos); - } + } ZEND_HASH_FOREACH_END(); zend_exception_restore(TSRMLS_C); STR_FREE(lc_name); SPL_G(autoload_running) = l_autoload_running; @@ -705,7 +699,6 @@ PHP_FUNCTION(spl_autoload_unregister) PHP_FUNCTION(spl_autoload_functions) { zend_function *fptr; - HashPosition function_pos; autoload_func_info *alfi; if (zend_parse_parameters_none() == FAILURE) { @@ -724,10 +717,9 @@ PHP_FUNCTION(spl_autoload_functions) fptr = zend_hash_str_find_ptr(EG(function_table), "spl_autoload_call", sizeof("spl_autoload_call") - 1); if (EG(autoload_func) == fptr) { + zend_string *key; array_init(return_value); - zend_hash_internal_pointer_reset_ex(SPL_G(autoload_functions), &function_pos); - while (zend_hash_has_more_elements_ex(SPL_G(autoload_functions), &function_pos) == SUCCESS) { - alfi = zend_hash_get_current_data_ptr_ex(SPL_G(autoload_functions), &function_pos); + ZEND_HASH_FOREACH_STR_KEY_PTR(SPL_G(autoload_functions), key, alfi) { if (!Z_ISUNDEF(alfi->closure)) { Z_ADDREF(alfi->closure); add_next_index_zval(return_value, &alfi->closure); @@ -747,15 +739,10 @@ PHP_FUNCTION(spl_autoload_functions) if (strncmp(alfi->func_ptr->common.function_name->val, "__lambda_func", sizeof("__lambda_func") - 1)) { add_next_index_str(return_value, STR_COPY(alfi->func_ptr->common.function_name)); } else { - zend_string *key; - ulong dummy; - zend_hash_get_current_key_ex(SPL_G(autoload_functions), &key, &dummy, 0, &function_pos); add_next_index_str(return_value, STR_COPY(key)); } } - - zend_hash_move_forward_ex(SPL_G(autoload_functions), &function_pos); - } + } ZEND_HASH_FOREACH_END(); return; } -- cgit v1.2.1 From 46fcd3fc08de938293a8a4fe25f9d1ed18457f4a Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Tue, 29 Jul 2014 16:23:56 +0400 Subject: Fixed callback registraion order in spl_autoload_register() --- ext/spl/php_spl.c | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) (limited to 'ext/spl/php_spl.c') diff --git a/ext/spl/php_spl.c b/ext/spl/php_spl.c index d765d6b754..62cf6ae144 100644 --- a/ext/spl/php_spl.c +++ b/ext/spl/php_spl.c @@ -441,24 +441,11 @@ PHP_FUNCTION(spl_autoload_call) #define HT_MOVE_TAIL_TO_HEAD(ht) \ do { \ - uint first = 0; \ - uint last = (ht)->nNumUsed; \ - while (first < last) { \ - if (Z_TYPE((ht)->arData[first].val) != IS_UNDEF) \ - break; \ - first++; \ - } \ - while (last > first) { \ - last--; \ - if (Z_TYPE((ht)->arData[last].val) != IS_UNDEF) \ - break; \ - } \ - if (first != last) { \ - Bucket tmp = (ht)->arData[first]; \ - (ht)->arData[first] = (ht)->arData[last]; \ - (ht)->arData[last] = tmp; \ - zend_hash_rehash(ht); \ - } \ + Bucket tmp = (ht)->arData[(ht)->nNumUsed-1]; \ + memmove((ht)->arData + 1, (ht)->arData, \ + sizeof(Bucket) * ((ht)->nNumUsed - 1)); \ + (ht)->arData[0] = tmp; \ + zend_hash_rehash(ht); \ } while (0) /* {{{ proto bool spl_autoload_register([mixed autoload_function = "spl_autoload" [, throw = true [, prepend]]]) -- cgit v1.2.1 From cb25136f4ef1042295650475b2c20ace81e2b9b7 Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Sat, 16 Aug 2014 11:37:14 +0200 Subject: fix macros in the 5 basic extensions --- ext/spl/php_spl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'ext/spl/php_spl.c') diff --git a/ext/spl/php_spl.c b/ext/spl/php_spl.c index 62cf6ae144..530a0c80ee 100644 --- a/ext/spl/php_spl.c +++ b/ext/spl/php_spl.c @@ -417,8 +417,8 @@ PHP_FUNCTION(spl_autoload_call) if (SPL_G(autoload_functions)) { int l_autoload_running = SPL_G(autoload_running); SPL_G(autoload_running) = 1; - lc_name = STR_ALLOC(Z_STRLEN_P(class_name), 0); - zend_str_tolower_copy(lc_name->val, Z_STRVAL_P(class_name), Z_STRLEN_P(class_name)); + lc_name = STR_ALLOC(Z_STRSIZE_P(class_name), 0); + zend_str_tolower_copy(lc_name->val, Z_STRVAL_P(class_name), Z_STRSIZE_P(class_name)); ZEND_HASH_FOREACH_STR_KEY_PTR(SPL_G(autoload_functions), func_name, alfi) { zend_call_method(Z_ISUNDEF(alfi->obj)? NULL : &alfi->obj, alfi->ce, &alfi->func_ptr, func_name->val, func_name->len, retval, 1, class_name, NULL TSRMLS_CC); zend_exception_save(TSRMLS_C); -- cgit v1.2.1 From 3f42f2f5d1c8026b6e1d21b91857a08d918c28c8 Mon Sep 17 00:00:00 2001 From: Veres Lajos Date: Tue, 12 Aug 2014 22:00:23 +0100 Subject: typofixes --- ext/spl/php_spl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ext/spl/php_spl.c') diff --git a/ext/spl/php_spl.c b/ext/spl/php_spl.c index a37a453c8c..473ab00963 100644 --- a/ext/spl/php_spl.c +++ b/ext/spl/php_spl.c @@ -326,7 +326,7 @@ PHP_FUNCTION(spl_autoload) RETURN_FALSE; } - if (file_exts == NULL) { /* autoload_extensions is not intialzed, set to defaults */ + if (file_exts == NULL) { /* autoload_extensions is not initialzed, set to defaults */ copy = pos1 = estrndup(SPL_DEFAULT_FILE_EXTENSIONS, sizeof(SPL_DEFAULT_FILE_EXTENSIONS)-1); } else { copy = pos1 = estrndup(file_exts, file_exts_len); -- cgit v1.2.1 From 1504f7d630c01fcfe9cd23b9e8aff7195a3864f7 Mon Sep 17 00:00:00 2001 From: Lior Kaplan Date: Sun, 17 Aug 2014 21:32:53 +0300 Subject: Correct typo in comments: 'initialized' --- ext/spl/php_spl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ext/spl/php_spl.c') diff --git a/ext/spl/php_spl.c b/ext/spl/php_spl.c index 473ab00963..515b5ccfe6 100644 --- a/ext/spl/php_spl.c +++ b/ext/spl/php_spl.c @@ -326,7 +326,7 @@ PHP_FUNCTION(spl_autoload) RETURN_FALSE; } - if (file_exts == NULL) { /* autoload_extensions is not initialzed, set to defaults */ + if (file_exts == NULL) { /* autoload_extensions is not initialized, set to defaults */ copy = pos1 = estrndup(SPL_DEFAULT_FILE_EXTENSIONS, sizeof(SPL_DEFAULT_FILE_EXTENSIONS)-1); } else { copy = pos1 = estrndup(file_exts, file_exts_len); -- cgit v1.2.1 From e9439f62e5e3696728accf21bf90b0c07fbed4df Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Thu, 21 Aug 2014 12:02:48 +0400 Subject: Avoid reallocation and copying --- ext/spl/php_spl.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) (limited to 'ext/spl/php_spl.c') diff --git a/ext/spl/php_spl.c b/ext/spl/php_spl.c index f9a642410f..5636a5f989 100644 --- a/ext/spl/php_spl.c +++ b/ext/spl/php_spl.c @@ -742,22 +742,18 @@ PHP_FUNCTION(spl_autoload_functions) PHP_FUNCTION(spl_object_hash) { zval *obj; - char hash[33]; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o", &obj) == FAILURE) { return; } - php_spl_object_hash(obj, hash TSRMLS_CC); - - RETURN_STRING(hash); + RETURN_NEW_STR(php_spl_object_hash(obj TSRMLS_CC)); } /* }}} */ -PHPAPI void php_spl_object_hash(zval *obj, char *result TSRMLS_DC) /* {{{*/ +PHPAPI zend_string *php_spl_object_hash(zval *obj TSRMLS_DC) /* {{{*/ { intptr_t hash_handle, hash_handlers; - char *hex; if (!SPL_G(hash_mask_init)) { if (!BG(mt_rand_is_seeded)) { @@ -772,10 +768,7 @@ PHPAPI void php_spl_object_hash(zval *obj, char *result TSRMLS_DC) /* {{{*/ hash_handle = SPL_G(hash_mask_handle)^(intptr_t)Z_OBJ_HANDLE_P(obj); hash_handlers = SPL_G(hash_mask_handlers)^(intptr_t)Z_OBJ_HT_P(obj); - spprintf(&hex, 32, "%016lx%016lx", hash_handle, hash_handlers); - - strlcpy(result, hex, 33); - efree(hex); + return strpprintf(32, "%016lx%016lx", hash_handle, hash_handlers); } /* }}} */ -- cgit v1.2.1 From c3e3c98ec666812daaaca896cf5ef758a8a6df14 Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Mon, 25 Aug 2014 19:24:55 +0200 Subject: master renames phase 1 --- ext/spl/php_spl.c | 68 +++++++++++++++++++++++++++---------------------------- 1 file changed, 34 insertions(+), 34 deletions(-) (limited to 'ext/spl/php_spl.c') diff --git a/ext/spl/php_spl.c b/ext/spl/php_spl.c index 5ca26d3f19..5d5f010f02 100644 --- a/ext/spl/php_spl.c +++ b/ext/spl/php_spl.c @@ -66,11 +66,11 @@ static zend_class_entry * spl_find_ce_by_name(zend_string *name, zend_bool autol zend_class_entry *ce; if (!autoload) { - zend_string *lc_name = STR_ALLOC(name->len, 0); + zend_string *lc_name = zend_string_alloc(name->len, 0); zend_str_tolower_copy(lc_name->val, name->val, name->len); ce = zend_hash_find_ptr(EG(class_table), lc_name); - STR_FREE(lc_name); + zend_string_free(lc_name); } else { ce = zend_lookup_class(name TSRMLS_CC); } @@ -275,7 +275,7 @@ static int spl_autoload(zend_string *class_name, zend_string *lc_name, const cha if (!file_handle.opened_path) { file_handle.opened_path = estrndup(class_file, class_file_len); } - opened_path = STR_INIT(file_handle.opened_path, strlen(file_handle.opened_path), 0); + opened_path = zend_string_init(file_handle.opened_path, strlen(file_handle.opened_path), 0); ZVAL_NULL(&dummy); if (zend_hash_add(&EG(included_files), opened_path, &dummy)) { new_op_array = zend_compile_file(&file_handle, ZEND_REQUIRE TSRMLS_CC); @@ -284,7 +284,7 @@ static int spl_autoload(zend_string *class_name, zend_string *lc_name, const cha new_op_array = NULL; zend_file_handle_dtor(&file_handle TSRMLS_CC); } - STR_RELEASE(opened_path); + zend_string_release(opened_path); if (new_op_array) { ZVAL_UNDEF(&result); zend_execute(new_op_array, &result TSRMLS_CC); @@ -323,7 +323,7 @@ PHP_FUNCTION(spl_autoload) pos_len = file_exts->len; } - lc_name = STR_ALLOC(class_name->len, 0); + lc_name = zend_string_alloc(class_name->len, 0); zend_str_tolower_copy(lc_name->val, class_name->val, class_name->len); while (pos && *pos && !EG(exception)) { pos1 = strchr(pos, ','); @@ -339,7 +339,7 @@ PHP_FUNCTION(spl_autoload) pos = pos1 ? pos1 + 1 : NULL; pos_len = pos1? pos_len - pos1_len - 1 : 0; } - STR_FREE(lc_name); + zend_string_free(lc_name); if (!found && !SPL_G(autoload_running)) { /* For internal errors, we generate E_ERROR, for direct calls an exception is thrown. @@ -370,15 +370,15 @@ PHP_FUNCTION(spl_autoload_extensions) } if (file_exts) { if (SPL_G(autoload_extensions)) { - STR_RELEASE(SPL_G(autoload_extensions)); + zend_string_release(SPL_G(autoload_extensions)); } - SPL_G(autoload_extensions) = STR_COPY(file_exts); + SPL_G(autoload_extensions) = zend_string_copy(file_exts); } if (SPL_G(autoload_extensions) == NULL) { RETURN_STRINGL(SPL_DEFAULT_FILE_EXTENSIONS, sizeof(SPL_DEFAULT_FILE_EXTENSIONS) - 1); } else { - STR_ADDREF(SPL_G(autoload_extensions)); + zend_string_addref(SPL_G(autoload_extensions)); RETURN_STR(SPL_G(autoload_extensions)); } } /* }}} */ @@ -417,8 +417,8 @@ PHP_FUNCTION(spl_autoload_call) if (SPL_G(autoload_functions)) { int l_autoload_running = SPL_G(autoload_running); SPL_G(autoload_running) = 1; - lc_name = STR_ALLOC(Z_STRSIZE_P(class_name), 0); - zend_str_tolower_copy(lc_name->val, Z_STRVAL_P(class_name), Z_STRSIZE_P(class_name)); + lc_name = zend_string_alloc(Z_STRLEN_P(class_name), 0); + zend_str_tolower_copy(lc_name->val, Z_STRVAL_P(class_name), Z_STRLEN_P(class_name)); ZEND_HASH_FOREACH_STR_KEY_PTR(SPL_G(autoload_functions), func_name, alfi) { zend_call_method(Z_ISUNDEF(alfi->obj)? NULL : &alfi->obj, alfi->ce, &alfi->func_ptr, func_name->val, func_name->len, retval, 1, class_name, NULL TSRMLS_CC); zend_exception_save(TSRMLS_C); @@ -431,7 +431,7 @@ PHP_FUNCTION(spl_autoload_call) } } ZEND_HASH_FOREACH_END(); zend_exception_restore(TSRMLS_C); - STR_FREE(lc_name); + zend_string_free(lc_name); SPL_G(autoload_running) = l_autoload_running; } else { /* do not use or overwrite &EG(autoload_func) here */ @@ -480,7 +480,7 @@ PHP_FUNCTION(spl_autoload_register) if (error) { efree(error); } - STR_RELEASE(func_name); + zend_string_release(func_name); RETURN_FALSE; } else if (do_throw) { zend_throw_exception_ex(spl_ce_LogicException, 0 TSRMLS_CC, "Passed array does not specify %s %smethod (%s)", alfi.func_ptr ? "a callable" : "an existing", !obj_ptr ? "static " : "", error); @@ -488,7 +488,7 @@ PHP_FUNCTION(spl_autoload_register) if (error) { efree(error); } - STR_RELEASE(func_name); + zend_string_release(func_name); RETURN_FALSE; } else if (Z_TYPE_P(zcallable) == IS_STRING) { if (do_throw) { @@ -497,7 +497,7 @@ PHP_FUNCTION(spl_autoload_register) if (error) { efree(error); } - STR_RELEASE(func_name); + zend_string_release(func_name); RETURN_FALSE; } else { if (do_throw) { @@ -506,7 +506,7 @@ PHP_FUNCTION(spl_autoload_register) if (error) { efree(error); } - STR_RELEASE(func_name); + zend_string_release(func_name); RETURN_FALSE; } } else if (fcc.function_handler->type == ZEND_INTERNAL_FUNCTION && @@ -517,7 +517,7 @@ PHP_FUNCTION(spl_autoload_register) if (error) { efree(error); } - STR_RELEASE(func_name); + zend_string_release(func_name); RETURN_FALSE; } alfi.ce = fcc.calling_scope; @@ -530,16 +530,16 @@ PHP_FUNCTION(spl_autoload_register) if (Z_TYPE_P(zcallable) == IS_OBJECT) { ZVAL_COPY(&alfi.closure, zcallable); - lc_name = STR_ALLOC(func_name->len + sizeof(zend_uint), 0); + lc_name = zend_string_alloc(func_name->len + sizeof(zend_uint), 0); zend_str_tolower_copy(lc_name->val, func_name->val, func_name->len); memcpy(lc_name->val + func_name->len, &Z_OBJ_HANDLE_P(zcallable), sizeof(zend_uint)); lc_name->val[lc_name->len] = '\0'; } else { ZVAL_UNDEF(&alfi.closure); - lc_name = STR_ALLOC(func_name->len, 0); + lc_name = zend_string_alloc(func_name->len, 0); zend_str_tolower_copy(lc_name->val, func_name->val, func_name->len); } - STR_RELEASE(func_name); + zend_string_release(func_name); if (SPL_G(autoload_functions) && zend_hash_exists(SPL_G(autoload_functions), lc_name)) { if (!Z_ISUNDEF(alfi.closure)) { @@ -550,7 +550,7 @@ PHP_FUNCTION(spl_autoload_register) if (obj_ptr && !(alfi.func_ptr->common.fn_flags & ZEND_ACC_STATIC)) { /* add object id to the hash to ensure uniqueness, for more reference look at bug #40091 */ - lc_name = STR_REALLOC(lc_name, lc_name->len + sizeof(zend_uint), 0); + lc_name = zend_string_realloc(lc_name, lc_name->len + sizeof(zend_uint), 0); memcpy(lc_name->val + lc_name->len - sizeof(zend_uint), &obj_ptr->handle, sizeof(zend_uint)); lc_name->val[lc_name->len] = '\0'; ZVAL_OBJ(&alfi.obj, obj_ptr); @@ -594,7 +594,7 @@ PHP_FUNCTION(spl_autoload_register) HT_MOVE_TAIL_TO_HEAD(SPL_G(autoload_functions)); } skip: - STR_RELEASE(lc_name); + zend_string_release(lc_name); } if (SPL_G(autoload_functions)) { @@ -629,7 +629,7 @@ PHP_FUNCTION(spl_autoload_unregister) efree(error); } if (func_name) { - STR_RELEASE(func_name); + zend_string_release(func_name); } RETURN_FALSE; } @@ -639,15 +639,15 @@ PHP_FUNCTION(spl_autoload_unregister) } if (Z_TYPE_P(zcallable) == IS_OBJECT) { - lc_name = STR_ALLOC(func_name->len + sizeof(zend_uint), 0); + lc_name = zend_string_alloc(func_name->len + sizeof(zend_uint), 0); zend_str_tolower_copy(lc_name->val, func_name->val, func_name->len); memcpy(lc_name->val + func_name->len, &Z_OBJ_HANDLE_P(zcallable), sizeof(zend_uint)); lc_name->val[lc_name->len] = '\0'; } else { - lc_name = STR_ALLOC(func_name->len, 0); + lc_name = zend_string_alloc(func_name->len, 0); zend_str_tolower_copy(lc_name->val, func_name->val, func_name->len); } - STR_RELEASE(func_name); + zend_string_release(func_name); if (SPL_G(autoload_functions)) { if (lc_name->len == sizeof("spl_autoload_call") - 1 && !strcmp(lc_name->val, "spl_autoload_call")) { @@ -661,7 +661,7 @@ PHP_FUNCTION(spl_autoload_unregister) /* remove specific */ success = zend_hash_del(SPL_G(autoload_functions), lc_name); if (success != SUCCESS && obj_ptr) { - lc_name = STR_REALLOC(lc_name, lc_name->len + sizeof(zend_uint), 0); + lc_name = zend_string_realloc(lc_name, lc_name->len + sizeof(zend_uint), 0); memcpy(lc_name->val + lc_name->len - sizeof(zend_uint), &obj_ptr->handle, sizeof(zend_uint)); lc_name->val[lc_name->len] = '\0'; success = zend_hash_del(SPL_G(autoload_functions), lc_name); @@ -677,7 +677,7 @@ PHP_FUNCTION(spl_autoload_unregister) } } - STR_RELEASE(lc_name); + zend_string_release(lc_name); RETURN_BOOL(success == SUCCESS); } /* }}} */ @@ -718,15 +718,15 @@ PHP_FUNCTION(spl_autoload_functions) Z_ADDREF(alfi->obj); add_next_index_zval(&tmp, &alfi->obj); } else { - add_next_index_str(&tmp, STR_COPY(alfi->ce->name)); + add_next_index_str(&tmp, zend_string_copy(alfi->ce->name)); } - add_next_index_str(&tmp, STR_COPY(alfi->func_ptr->common.function_name)); + add_next_index_str(&tmp, zend_string_copy(alfi->func_ptr->common.function_name)); add_next_index_zval(return_value, &tmp); } else { if (strncmp(alfi->func_ptr->common.function_name->val, "__lambda_func", sizeof("__lambda_func") - 1)) { - add_next_index_str(return_value, STR_COPY(alfi->func_ptr->common.function_name)); + add_next_index_str(return_value, zend_string_copy(alfi->func_ptr->common.function_name)); } else { - add_next_index_str(return_value, STR_COPY(key)); + add_next_index_str(return_value, zend_string_copy(key)); } } } ZEND_HASH_FOREACH_END(); @@ -734,7 +734,7 @@ PHP_FUNCTION(spl_autoload_functions) } array_init(return_value); - add_next_index_str(return_value, STR_COPY(EG(autoload_func)->common.function_name)); + add_next_index_str(return_value, zend_string_copy(EG(autoload_func)->common.function_name)); } /* }}} */ /* {{{ proto string spl_object_hash(object obj) @@ -927,7 +927,7 @@ PHP_RINIT_FUNCTION(spl) /* {{{ */ PHP_RSHUTDOWN_FUNCTION(spl) /* {{{ */ { if (SPL_G(autoload_extensions)) { - STR_RELEASE(SPL_G(autoload_extensions)); + zend_string_release(SPL_G(autoload_extensions)); SPL_G(autoload_extensions) = NULL; } if (SPL_G(autoload_functions)) { -- cgit v1.2.1 From 6f9f0bf2056f0dc17d9bcc6dd3b7d28ac878c6fc Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Mon, 25 Aug 2014 19:28:33 +0200 Subject: master renames phase 2 --- ext/spl/php_spl.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'ext/spl/php_spl.c') diff --git a/ext/spl/php_spl.c b/ext/spl/php_spl.c index 5d5f010f02..ad3bb85313 100644 --- a/ext/spl/php_spl.c +++ b/ext/spl/php_spl.c @@ -530,9 +530,9 @@ PHP_FUNCTION(spl_autoload_register) if (Z_TYPE_P(zcallable) == IS_OBJECT) { ZVAL_COPY(&alfi.closure, zcallable); - lc_name = zend_string_alloc(func_name->len + sizeof(zend_uint), 0); + lc_name = zend_string_alloc(func_name->len + sizeof(uint32_t), 0); zend_str_tolower_copy(lc_name->val, func_name->val, func_name->len); - memcpy(lc_name->val + func_name->len, &Z_OBJ_HANDLE_P(zcallable), sizeof(zend_uint)); + memcpy(lc_name->val + func_name->len, &Z_OBJ_HANDLE_P(zcallable), sizeof(uint32_t)); lc_name->val[lc_name->len] = '\0'; } else { ZVAL_UNDEF(&alfi.closure); @@ -550,8 +550,8 @@ PHP_FUNCTION(spl_autoload_register) if (obj_ptr && !(alfi.func_ptr->common.fn_flags & ZEND_ACC_STATIC)) { /* add object id to the hash to ensure uniqueness, for more reference look at bug #40091 */ - lc_name = zend_string_realloc(lc_name, lc_name->len + sizeof(zend_uint), 0); - memcpy(lc_name->val + lc_name->len - sizeof(zend_uint), &obj_ptr->handle, sizeof(zend_uint)); + lc_name = zend_string_realloc(lc_name, lc_name->len + sizeof(uint32_t), 0); + memcpy(lc_name->val + lc_name->len - sizeof(uint32_t), &obj_ptr->handle, sizeof(uint32_t)); lc_name->val[lc_name->len] = '\0'; ZVAL_OBJ(&alfi.obj, obj_ptr); Z_ADDREF(alfi.obj); @@ -639,9 +639,9 @@ PHP_FUNCTION(spl_autoload_unregister) } if (Z_TYPE_P(zcallable) == IS_OBJECT) { - lc_name = zend_string_alloc(func_name->len + sizeof(zend_uint), 0); + lc_name = zend_string_alloc(func_name->len + sizeof(uint32_t), 0); zend_str_tolower_copy(lc_name->val, func_name->val, func_name->len); - memcpy(lc_name->val + func_name->len, &Z_OBJ_HANDLE_P(zcallable), sizeof(zend_uint)); + memcpy(lc_name->val + func_name->len, &Z_OBJ_HANDLE_P(zcallable), sizeof(uint32_t)); lc_name->val[lc_name->len] = '\0'; } else { lc_name = zend_string_alloc(func_name->len, 0); @@ -661,8 +661,8 @@ PHP_FUNCTION(spl_autoload_unregister) /* remove specific */ success = zend_hash_del(SPL_G(autoload_functions), lc_name); if (success != SUCCESS && obj_ptr) { - lc_name = zend_string_realloc(lc_name, lc_name->len + sizeof(zend_uint), 0); - memcpy(lc_name->val + lc_name->len - sizeof(zend_uint), &obj_ptr->handle, sizeof(zend_uint)); + lc_name = zend_string_realloc(lc_name, lc_name->len + sizeof(uint32_t), 0); + memcpy(lc_name->val + lc_name->len - sizeof(uint32_t), &obj_ptr->handle, sizeof(uint32_t)); lc_name->val[lc_name->len] = '\0'; success = zend_hash_del(SPL_G(autoload_functions), lc_name); } -- cgit v1.2.1 From d0cb715373c3fbe9dc095378ec5ed8c71f799f67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Schl=C3=BCter?= Date: Fri, 19 Sep 2014 18:33:14 +0200 Subject: s/PHP 5/PHP 7/ --- ext/spl/php_spl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ext/spl/php_spl.c') diff --git a/ext/spl/php_spl.c b/ext/spl/php_spl.c index ad3bb85313..d38da10e65 100644 --- a/ext/spl/php_spl.c +++ b/ext/spl/php_spl.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2014 The PHP Group | +----------------------------------------------------------------------+ -- cgit v1.2.1 From bd9a234645772a4f3116b3c4f1d5a83efb158d80 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Fri, 3 Oct 2014 19:32:46 +0400 Subject: Replaced EG(This) and EX(object) with EX(This). Internal functions now recieves zend_execute_data as the first argument. --- ext/spl/php_spl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ext/spl/php_spl.c') diff --git a/ext/spl/php_spl.c b/ext/spl/php_spl.c index d38da10e65..44078733d6 100644 --- a/ext/spl/php_spl.c +++ b/ext/spl/php_spl.c @@ -346,7 +346,7 @@ PHP_FUNCTION(spl_autoload) * The "scope" is determined by an opcode, if it is ZEND_FETCH_CLASS we know function was called indirectly by * the Zend engine. */ - zend_execute_data *ex = EG(current_execute_data); + zend_execute_data *ex = EX(prev_execute_data); while (ex && (!ex->func || !ZEND_USER_CODE(ex->func->type))) { ex = ex->prev_execute_data; -- cgit v1.2.1