From 90b29aa076f1a5ef1b36b20cef925aac932d66b5 Mon Sep 17 00:00:00 2001 From: Zeev Suraski Date: Tue, 5 Aug 2003 10:29:03 +0000 Subject: [PATCH] Replace fast_call_user_function() with zend_call_function() --- ext/curl/interface.c | 47 +++++++++++++++--- ext/curl/php_curl.h | 22 ++++----- ext/standard/array.c | 87 ++++++++++++++++++++++++++++------ ext/standard/basic_functions.c | 4 +- ext/standard/basic_functions.h | 6 +-- ext/xml/xml.c | 14 +++++- 6 files changed, 142 insertions(+), 38 deletions(-) diff --git a/ext/curl/interface.c b/ext/curl/interface.c index 0f46ec28a9..feec10b1ff 100644 --- a/ext/curl/interface.c +++ b/ext/curl/interface.c @@ -403,6 +403,7 @@ static size_t curl_write(char *data, size_t size, size_t nmemb, void *ctx) zval *handle = NULL; zval *zdata = NULL; int error; + zend_fcall_info fci; MAKE_STD_ZVAL(handle); ZVAL_RESOURCE(handle, ch->id); @@ -413,7 +414,17 @@ static size_t curl_write(char *data, size_t size, size_t nmemb, void *ctx) ZVAL_STRINGL(zdata, data, length, 1); argv[1] = &zdata; - error = fast_call_user_function(EG(function_table), NULL, t->func_name, &retval_ptr, 2, argv, 0, NULL, &t->func_ptr TSRMLS_CC); + fci.size = sizeof(fci); + fci.function_table = EG(function_table); + fci.object_pp = NULL; + fci.function_name = t->func_name; + fci.retval_ptr_ptr = &retval_ptr; + fci.param_count = 2; + fci.params = argv; + fci.no_separation = 0; + fci.symbol_table = NULL; + + error = zend_call_function(&fci, &t->fci_cache TSRMLS_CC); if (error == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not call the CURLOPT_WRITEFUNCTION"); length = -1; @@ -454,6 +465,7 @@ static size_t curl_read(char *data, size_t size, size_t nmemb, void *ctx) zval *retval_ptr; int length; int error; + zend_fcall_info fci; TSRMLS_FETCH_FROM_CTX(ch->thread_ctx); MAKE_STD_ZVAL(handle); @@ -470,7 +482,17 @@ static size_t curl_read(char *data, size_t size, size_t nmemb, void *ctx) argv[1] = &zfd; argv[2] = &zlength; - error = fast_call_user_function(EG(function_table), NULL, t->func_name, &retval_ptr, 3, argv, 0, NULL, &t->func_ptr TSRMLS_CC); + fci.size = sizeof(fci); + fci.function_table = EG(function_table); + fci.function_name = t->func_name; + fci.object_pp = NULL; + fci.retval_ptr_ptr = &retval_ptr; + fci.param_count = 3; + fci.params = argv; + fci.no_separation = 0; + fci.symbol_table = NULL; + + error = zend_call_function(&fci, &t->fci_cache TSRMLS_CC); if (error == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot call the CURLOPT_READFUNCTION"); length = -1; @@ -518,6 +540,7 @@ static size_t curl_write_header(char *data, size_t size, size_t nmemb, void *ctx zval *zdata = NULL; zval *retval_ptr; int error; + zend_fcall_info fci; MAKE_STD_ZVAL(handle); MAKE_STD_ZVAL(zdata); @@ -528,8 +551,18 @@ static size_t curl_write_header(char *data, size_t size, size_t nmemb, void *ctx argv[0] = &handle; argv[1] = &zdata; - - error = fast_call_user_function(EG(function_table), NULL, t->func_name, &retval_ptr, 2, argv, 0, NULL, &t->func_ptr TSRMLS_CC); + + fci.size = sizeof(fci); + fci.function_table = EG(function_table); + fci.function_name = t->func_name; + fci.symbol_table = NULL; + fci.object_pp = NULL; + fci.retval_ptr_ptr = &retval_ptr; + fci.param_count = 2; + fci.params = argv; + fci.no_separation = 0; + + error = zend_call_user_function(&fci, &t->fci_cache TSRMLS_CC); if (error == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not call the CURLOPT_HEADERFUNCTION"); length = -1; @@ -894,7 +927,7 @@ PHP_FUNCTION(curl_setopt) case CURLOPT_WRITEFUNCTION: if (ch->handlers->write->func_name) { zval_ptr_dtor(&ch->handlers->write->func_name); - ch->handlers->write->func_ptr = NULL; + ch->handlers->write->fci_cache = empty_fcall_info_cache; } zval_add_ref(zvalue); ch->handlers->write->func_name = *zvalue; @@ -903,7 +936,7 @@ PHP_FUNCTION(curl_setopt) case CURLOPT_READFUNCTION: if (ch->handlers->read->func_name) { zval_ptr_dtor(&ch->handlers->read->func_name); - ch->handlers->write->func_ptr = NULL; + ch->handlers->write->fci_cache = empty_fcall_info_cache; } zval_add_ref(zvalue); ch->handlers->read->func_name = *zvalue; @@ -912,7 +945,7 @@ PHP_FUNCTION(curl_setopt) case CURLOPT_HEADERFUNCTION: if (ch->handlers->write_header->func_name) { zval_ptr_dtor(&ch->handlers->write_header->func_name); - ch->handlers->write->func_ptr = NULL; + ch->handlers->write->fci_cache = empty_fcall_info_cache; } zval_add_ref(zvalue); ch->handlers->write_header->func_name = *zvalue; diff --git a/ext/curl/php_curl.h b/ext/curl/php_curl.h index bd4f20aaa9..46d5509a50 100644 --- a/ext/curl/php_curl.h +++ b/ext/curl/php_curl.h @@ -78,20 +78,20 @@ PHP_FUNCTION(curl_multi_close); void _php_curl_multi_close(zend_rsrc_list_entry * TSRMLS_DC); typedef struct { - zval *func_name; - zend_function *func_ptr; - FILE *fp; - smart_str buf; - int method; - int type; + zval *func_name; + zend_fcall_info fci_cache; + FILE *fp; + smart_str buf; + int method; + int type; } php_curl_write; typedef struct { - zval *func_name; - zend_function *func_ptr; - FILE *fp; - long fd; - int method; + zval *func_name; + zend_fcall_info fci_cache; + FILE *fp; + long fd; + int method; } php_curl_read; typedef struct { diff --git a/ext/standard/array.c b/ext/standard/array.c index 2825718461..8020d468b1 100644 --- a/ext/standard/array.c +++ b/ext/standard/array.c @@ -523,6 +523,7 @@ static int array_user_compare(const void *a, const void *b TSRMLS_DC) Bucket *s; zval **args[2]; zval *retval_ptr; + zend_fcall_info fci; f = *((Bucket **) a); s = *((Bucket **) b); @@ -530,7 +531,17 @@ static int array_user_compare(const void *a, const void *b TSRMLS_DC) args[0] = (zval **) f->pData; args[1] = (zval **) s->pData; - if (fast_call_user_function(EG(function_table), NULL, *BG(user_compare_func_name), &retval_ptr, 2, args, 0, NULL, &BG(user_compare_func_ptr) TSRMLS_CC)== SUCCESS + fci.size = sizeof(fci); + fci.function_table = EG(function_table); + fci.function_name = *BG(user_compare_func_name); + fci.symbol_table = NULL; + fci.object_pp = NULL; + fci.retval_ptr_ptr = &retval_ptr; + fci.param_count = 2; + fci.params = args; + fci.no_separation = 0; + + if (zend_call_function(&fci, &BG(user_compare_fci_cache) TSRMLS_CC)== SUCCESS && retval_ptr) { long retval; @@ -552,7 +563,7 @@ PHP_FUNCTION(usort) HashTable *target_hash; old_compare_func = BG(user_compare_func_name); - BG(user_compare_func_ptr) = NULL; + BG(user_compare_fci_cache) = empty_fcall_info_cache; if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &array, &BG(user_compare_func_name)) == FAILURE) { BG(user_compare_func_name) = old_compare_func; @@ -582,7 +593,7 @@ PHP_FUNCTION(uasort) HashTable *target_hash; old_compare_func = BG(user_compare_func_name); - BG(user_compare_func_ptr) = NULL; + BG(user_compare_fci_cache) = empty_fcall_info_cache; if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &array, &BG(user_compare_func_name)) == FAILURE) { BG(user_compare_func_name) = old_compare_func; WRONG_PARAM_COUNT; @@ -975,6 +986,8 @@ static int php_array_walk(HashTable *target_hash, zval **userdata, int recursive } php_array_walk(thash, userdata, recursive TSRMLS_CC); } else { + zend_fcall_info fci; + /* Allocate space for key */ MAKE_STD_ZVAL(key); @@ -985,11 +998,19 @@ static int php_array_walk(HashTable *target_hash, zval **userdata, int recursive } else { ZVAL_STRINGL(key, string_key, string_key_len-1, 1); } - + + fci.size = sizeof(fci); + fci.function_table = EG(function_table); + fci.function_name = *BG(array_walk_func_name); + fci.symbol_table = NULL; + fci.object_pp = NULL; + fci.retval_ptr_ptr = &retval_ptr; + fci.param_count = userdata ? 3 : 2; + fci.params = args; + fci.no_separation = 0; + /* Call the userland function */ - if (fast_call_user_function(EG(function_table), NULL, *BG(array_walk_func_name), - &retval_ptr, userdata ? 3 : 2, args, 0, NULL, &BG(array_walk_func_ptr) TSRMLS_CC) == SUCCESS) { - + if (zend_call_function(&fci, &BG(array_walk_fci_cache) TSRMLS_CC) == SUCCESS) { zval_ptr_dtor(&retval_ptr); } else { char *func_name; @@ -1023,7 +1044,7 @@ PHP_FUNCTION(array_walk) HashTable *target_hash; argc = ZEND_NUM_ARGS(); - BG(array_walk_func_ptr) = NULL; + BG(array_walk_fci_cache) = empty_fcall_info_cache; old_walk_func_name = BG(array_walk_func_name); if (argc < 2 || argc > 3 || zend_get_parameters_ex(argc, &array, &BG(array_walk_func_name), &userdata) == FAILURE) { @@ -3329,7 +3350,7 @@ PHP_FUNCTION(array_reduce) zval **operand; zval *result = NULL; zval *retval; - zend_function *func_ptr = NULL; + zend_fcall_info_cache fci_cache = empty_fcall_info_cache; char *callback_name; HashPosition pos; HashTable *htbl; @@ -3373,9 +3394,22 @@ PHP_FUNCTION(array_reduce) zend_hash_internal_pointer_reset_ex(htbl, &pos); while (zend_hash_get_current_data_ex(htbl, (void **)&operand, &pos) == SUCCESS) { if (result) { + zend_fcall_info fci; + args[0] = &result; args[1] = operand; - if (fast_call_user_function(EG(function_table), NULL, *callback, &retval, 2, args, 0, NULL, &func_ptr TSRMLS_CC) == SUCCESS && retval) { + + fci.size = sizeof(fci); + fci.function_table = EG(function_table); + fci.function_name = *callback; + fci.symbol_table = NULL; + fci.object_pp = NULL; + fci.retval_ptr_ptr = &retval; + fci.param_count = 2; + fci.params = args; + fci.no_separation = 0; + + if (zend_call_function(&fci, &fci_cache TSRMLS_CC) == SUCCESS && retval) { zval_ptr_dtor(&result); result = retval; } else { @@ -3407,7 +3441,7 @@ PHP_FUNCTION(array_filter) zval *retval = NULL; char *callback_name; char *string_key; - zend_function *func_ptr = NULL; + zend_fcall_info_cache fci_cache = empty_fcall_info_cache; uint string_key_len; ulong num_key; HashPosition pos; @@ -3441,8 +3475,21 @@ PHP_FUNCTION(array_filter) zend_hash_move_forward_ex(Z_ARRVAL_PP(input), &pos)) { if (callback) { + zend_fcall_info fci; + args[0] = operand; - if (fast_call_user_function(EG(function_table), NULL, *callback, &retval, 1, args, 0, NULL, &func_ptr TSRMLS_CC) == SUCCESS && retval) { + + fci.size = sizeof(fci); + fci.function_table = EG(function_table); + fci.function_name = *callback; + fci.symbol_table = NULL; + fci.object_pp = NULL; + fci.retval_ptr_ptr = &retval; + fci.param_count = 1; + fci.params = args; + fci.no_separation = 0; + + if (zend_call_function(&fci, &fci_cache TSRMLS_CC) == SUCCESS && retval) { if (!zend_is_true(retval)) { zval_ptr_dtor(&retval); continue; @@ -3483,7 +3530,7 @@ PHP_FUNCTION(array_map) HashPosition *array_pos; zval **args; char *callback_name; - zend_function *func_ptr = NULL; + zend_fcall_info_cache fci_cache = empty_fcall_info_cache; int i, k, maxlen = 0; int *array_len; @@ -3593,7 +3640,19 @@ PHP_FUNCTION(array_map) } if (Z_TYPE_P(callback) != IS_NULL) { - if (!fast_call_user_function(EG(function_table), NULL, callback, &result, ZEND_NUM_ARGS() - 1, ¶ms[1], 0, NULL, &func_ptr TSRMLS_CC) == SUCCESS && result) { + zend_fcall_info fci; + + fci.size = sizeof(fci); + fci.function_table = EG(function_table); + fci.function_name = callback; + fci.symbol_table = NULL; + fci.object_pp = NULL; + fci.retval_ptr_ptr = &result; + fci.param_count = ZEND_NUM_ARGS()-1; + fci.params = ¶ms[1]; + fci.no_separation = 0; + + if (!zend_call_function(&fci, &fci_cache TSRMLS_CC) == SUCCESS && result) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "An error occurred while invoking the map callback"); efree(array_len); efree(args); diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index 5354e16858..a6c380428e 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -1024,8 +1024,8 @@ static void basic_globals_ctor(php_basic_globals *basic_globals_p TSRMLS_DC) BG(left) = -1; BG(user_tick_functions) = NULL; BG(user_filter_map) = NULL; - BG(user_compare_func_ptr) = NULL; - BG(array_walk_func_ptr) = NULL; + BG(user_compare_fci_cache) = empty_fcall_info_cache; + /*BG(array_walk_fci_cache) = empty_fcall_info_cache;*/ zend_hash_init(&BG(sm_protected_env_vars), 5, NULL, NULL, 1); BG(sm_allowed_env_vars) = NULL; diff --git a/ext/standard/basic_functions.h b/ext/standard/basic_functions.h index 19b07c086d..4d60602366 100644 --- a/ext/standard/basic_functions.h +++ b/ext/standard/basic_functions.h @@ -137,7 +137,7 @@ typedef signed int php_int32; #define MT_N (624) -typedef struct { +typedef struct _php_basic_globals { HashTable *user_shutdown_function_names; HashTable putenv_ht; zval *strtok_zval; @@ -148,9 +148,9 @@ typedef struct { ulong strtok_len; char str_ebuf[40]; zval **array_walk_func_name; - zend_function *array_walk_func_ptr; + zend_fcall_info_cache array_walk_fci_cache; zval **user_compare_func_name; - zend_function *user_compare_func_ptr; + zend_fcall_info_cache user_compare_fci_cache; zend_llist *user_tick_functions; zval *active_ini_file_section; diff --git a/ext/xml/xml.c b/ext/xml/xml.c index 2504a94460..ef6f762ea4 100644 --- a/ext/xml/xml.c +++ b/ext/xml/xml.c @@ -406,13 +406,25 @@ static zval *xml_call_handler(xml_parser *parser, zval *handler, zend_function * zval *retval; int i; int result; + zend_fcall_info fci; args = emalloc(sizeof(zval **) * argc); for (i = 0; i < argc; i++) { args[i] = &argv[i]; } - result = fast_call_user_function(EG(function_table), &parser->object, handler, &retval, argc, args, 0, NULL, &function_ptr TSRMLS_CC); + fci.size = sizeof(fci); + fci.function_table = EG(function_table); + fci.function_name = handler; + fci.symbol_table = NULL; + fci.object_pp = &parser->object; + fci.retval_ptr_ptr = &retval; + fci.param_count = argc; + fci.params = args; + fci.no_separation = 0; + /*fci.function_handler_cache = &function_ptr;*/ + + result = zend_call_function(&fci, NULL TSRMLS_CC); if (result == FAILURE) { zval **method; zval **obj; -- 2.40.0