From: krakjoe Date: Tue, 19 Nov 2013 21:54:58 +0000 (+0000) Subject: more on functions X-Git-Tag: php-5.6.0alpha1~110^2~192 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b65cef950a0a34d31208ff87beb9223bde1aebc7;p=php more on functions --- diff --git a/phpdbg_cmd.c b/phpdbg_cmd.c index 8eb38d7e4f..13356f4a1c 100644 --- a/phpdbg_cmd.c +++ b/phpdbg_cmd.c @@ -331,17 +331,33 @@ int phpdbg_do_cmd_ex(const phpdbg_command_t *command, phpdbg_input_t *input TSRM (command->alias && (input->argv[0]->length == 1) && (command->alias == *input->argv[0]->string))) { - if (command->subs && input->argc > 1) { - phpdbg_input_t sub; - - sub.argc = input->argc-1; - sub.argv = &input->argv[1]; + + phpdbg_param_t param; + + param.type = EMPTY_PARAM; + + if (input->argc > 1) { + if (command->subs) { + phpdbg_input_t sub; + + sub.argc = input->argc-1; + sub.argv = &input->argv[1]; + + phpdbg_debug( + "trying sub commands in \"%s\" for \"%s\" with %d arguments", + command->name, sub.argv[0]->string, sub.argc-1); - return phpdbg_do_cmd_ex(command->subs, &sub TSRMLS_CC); + return phpdbg_do_cmd_ex(command->subs, &sub TSRMLS_CC); + } else { + phpdbg_parse_param( + input->argv[1]->string, + input->argv[1]->length, + ¶m TSRMLS_CC); + } } phpdbg_debug( - "found command %s for %s with %d arguments", + "found command \"%s\" for \"%s\" have %d arguments", command->name, input->argv[0]->string, input->argc-1); { int arg; @@ -353,6 +369,14 @@ int phpdbg_do_cmd_ex(const phpdbg_command_t *command, phpdbg_input_t *input TSRM input->argv[arg]->length); } } + + PHPDBG_G(lcmd) = (phpdbg_command_t*) command; + phpdbg_clear_param( + &PHPDBG_G(lparam) TSRMLS_CC); + PHPDBG_G(lparam) = param; + + rc = command->handler(¶m TSRMLS_CC); + break; } command++; diff --git a/phpdbg_prompt.c b/phpdbg_prompt.c index bb7dc001e5..2fc29dd62f 100644 --- a/phpdbg_prompt.c +++ b/phpdbg_prompt.c @@ -153,7 +153,7 @@ void phpdbg_init(char *init_file, size_t init_file_len, zend_bool use_default TS } goto next_line; } - + switch (phpdbg_do_cmd(phpdbg_prompt_commands, cmd, cmd_len TSRMLS_CC)) { case FAILURE: phpdbg_error( @@ -914,26 +914,29 @@ static PHPDBG_COMMAND(list) /* {{{ */ static inline int phpdbg_call_register(phpdbg_input_t *input TSRMLS_DC) /* {{{ */ { - /* temporary, until we can handle arrays of strings */ - const char *cmd = input->string; - size_t cmd_len = input->length; - const char *start = (const char*) input->start; - size_t offset = strlen(cmd)+(sizeof(" ")-1); + phpdbg_input_t *function = input->argv[0]; - if (zend_hash_exists(&PHPDBG_G(registered), cmd, strlen(cmd)+1)) { - zval fname, *fretval, *farg = NULL; + if (zend_hash_exists( + &PHPDBG_G(registered), function->string, function->length+1)) { + zval fname, *fretval; zend_fcall_info fci; - zend_fcall_info_cache fcic; - - zval **params[1]; + zval **params = NULL; - if (offset < cmd_len) { - ALLOC_INIT_ZVAL(farg); - ZVAL_STRING(farg, &start[offset], 1); - params[0] = &farg; + if (input->argc > 1) { + int arg; + + params = emalloc(sizeof(zval*) * input->argc); + + for (arg = 1; arg <= (input->argc-1); arg++) { + MAKE_STD_ZVAL((params[arg-1])); + ZVAL_STRINGL( + (params[arg-1]), + input->argv[arg]->string, + input->argv[arg]->length, 1); + } } - ZVAL_STRINGL(&fname, cmd, strlen(cmd), 1); + ZVAL_STRINGL(&fname, function->string, function->length, 1); fci.size = sizeof(fci); fci.function_table = &PHPDBG_G(registered); @@ -942,17 +945,22 @@ static inline int phpdbg_call_register(phpdbg_input_t *input TSRMLS_DC) /* {{{ * fci.object_ptr = NULL; fci.retval_ptr_ptr = &fretval; - /* todo parse parameters better */ - fci.param_count = (offset < cmd_len) ? 1 : 0; - fci.params = (offset < cmd_len) ? params : NULL; + fci.param_count = (input->argc > 1) ? (input->argc-1) : 0; + fci.params = (input->argc > 1) ? ¶ms : NULL; fci.no_separation = 1; zend_call_function( &fci, NULL TSRMLS_CC); zval_dtor(&fname); - if (offset < cmd_len) { - zval_ptr_dtor(&farg); + + if (input->argc > 1) { + int arg; + + for (arg = 1; arg <= (input->argc-1); arg++) { + zval_ptr_dtor(¶ms[arg-1]); + } + efree(params); } if (fretval) { zend_print_zval_r( @@ -973,9 +981,7 @@ int phpdbg_interactive(TSRMLS_D) /* {{{ */ if (input && input->length > 0L) { do { - phpdbg_do_cmd_ex(phpdbg_prompt_commands, input TSRMLS_CC); - - switch (ret = phpdbg_do_cmd(phpdbg_prompt_commands, input->string, input->length TSRMLS_CC)) { + switch (ret = phpdbg_do_cmd_ex(phpdbg_prompt_commands, input TSRMLS_CC)) { case FAILURE: if (!(PHPDBG_G(flags) & PHPDBG_IS_QUITTING)) { if (phpdbg_call_register(input TSRMLS_CC) == FAILURE) {