From cad9fb826bbbb2fa9dd6e79c8d391149714260d0 Mon Sep 17 00:00:00 2001 From: krakjoe Date: Wed, 20 Nov 2013 12:49:47 +0000 Subject: [PATCH] registered functions able to accept any number of arguments --- phpdbg_cmd.c | 2 +- phpdbg_prompt.c | 72 ++++++++++++++++++++++++------------------------- 2 files changed, 37 insertions(+), 37 deletions(-) diff --git a/phpdbg_cmd.c b/phpdbg_cmd.c index 27470be940..12dc2e35ec 100644 --- a/phpdbg_cmd.c +++ b/phpdbg_cmd.c @@ -130,7 +130,7 @@ phpdbg_input_t** phpdbg_read_argv(char *buffer, int *argc TSRMLS_DC) /* {{{ */ } state = IN_BETWEEN; phpdbg_input_t **argv = NULL; - argv = (phpdbg_input_t**) emalloc(sizeof(phpdbg_input_t**)); + argv = (phpdbg_input_t**) emalloc(sizeof(phpdbg_input_t*)); (*argc) = 0; #define RESET_STATE() do {\ diff --git a/phpdbg_prompt.c b/phpdbg_prompt.c index 0436e93f2f..57e759ad74 100644 --- a/phpdbg_prompt.c +++ b/phpdbg_prompt.c @@ -917,7 +917,7 @@ static PHPDBG_COMMAND(list) /* {{{ */ return SUCCESS; } /* }}} */ -static inline int phpdbg_call_register(phpdbg_input_t *input TSRMLS_DC) /* {{{ */ +int phpdbg_call_register(phpdbg_input_t *input TSRMLS_DC) /* {{{ */ { phpdbg_input_t *function = input->argv[0]; @@ -925,53 +925,47 @@ static inline int phpdbg_call_register(phpdbg_input_t *input TSRMLS_DC) /* {{{ * &PHPDBG_G(registered), function->string, function->length+1)) { zval fname, *fretval; - zend_fcall_info fci; + zend_fcall_info *fci = emalloc(sizeof(zend_fcall_info)); ZVAL_STRINGL(&fname, function->string, function->length, 1); - fci.size = sizeof(fci); - fci.function_table = &PHPDBG_G(registered); - fci.function_name = &fname; - fci.symbol_table = EG(active_symbol_table); - fci.object_ptr = NULL; - fci.retval_ptr_ptr = &fretval; - fci.no_separation = 1; + fci->size = sizeof(zend_fcall_info); + fci->function_table = &PHPDBG_G(registered); + fci->function_name = &fname; + fci->symbol_table = EG(active_symbol_table); + fci->object_ptr = NULL; + fci->retval_ptr_ptr = &fretval; + fci->no_separation = 1; if (input->argc > 1) { - int arg; - zval ***params; - zval *zparam; + int param; + zval params; - fci.param_count = (input->argc > 1) ? (input->argc-1) : 0; - fci.params = (zval***) emalloc(fci.param_count * sizeof(zval**)); + array_init(¶ms); - params = fci.params; + for (param = 0; param < (input->argc-1); param++) { + add_next_index_stringl( + ¶ms, + input->argv[param+1]->string, + input->argv[param+1]->length, 1); - for (arg = 1; arg <= (input->argc-1); arg++) { - MAKE_STD_ZVAL(zparam); - ZVAL_STRINGL( - zparam, - input->argv[arg]->string, - input->argv[arg]->length, 1); - - *params++ = &zparam; + phpdbg_debug( + "created param[%d] from argv[%d]: %s", + param, param+1, input->argv[param+1]->string); } - } else { - fci.params = NULL; - fci.param_count = 0; - } - - zend_call_function(&fci, NULL TSRMLS_CC); - - if (input->argc > 1) { - int param; - for (param = 0; param < fci.param_count; param++) { - zval_ptr_dtor(fci.params[param]); - } - efree(fci.params); + zend_fcall_info_args(fci, ¶ms TSRMLS_CC); + } else { + fci->params = NULL; + fci->param_count = 0; } + phpdbg_debug( + "created %d params from %d argvuments", + fci->param_count, input->argc); + + zend_call_function(fci, NULL TSRMLS_CC); + if (fretval) { zend_print_zval_r( fretval, 0 TSRMLS_CC); @@ -980,6 +974,12 @@ static inline int phpdbg_call_register(phpdbg_input_t *input TSRMLS_DC) /* {{{ * zval_dtor(&fname); + if (fci->params) { + efree(fci->params); + } + + efree(fci); + return SUCCESS; } -- 2.50.1