com php-src: improve R: phpdbg_cmd.h phpdbg_prompt.c

From: Date: Wed, 20 Nov 2013 10:49:39 +0000
Subject: com php-src: improve R: phpdbg_cmd.h phpdbg_prompt.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-74779@lists.php.net to get a copy of this message
Commit: 80386a329b531e4dba70a85c3e87b291e2f37c51 Author: krakjoe <joe.watkins@live.co.uk> Wed, 20 Nov 2013 10:49:39 +0000 Parents: dd71744d4858499bb009b89643a3a1a98b311fcd Branches: PHP-5.6 Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=80386a329b531e4dba70a85c3e87b291e2f37c51 Log: improve R Changed paths: M phpdbg_cmd.h M phpdbg_prompt.c Diff: diff --git a/phpdbg_cmd..h b/phpdbg_cmd.h index 12cda59..ae50d28 100644 --- a/phpdbg_cmd.h +++ b/phpdbg_cmd.h @@ -84,16 +84,38 @@ struct _phpdbg_command_t { #define PHPDBG_STRL(s) s, sizeof(s)-1 #define PHPDBG_MAX_CMD 500 -/** - * Command Executor - */ +/* +* Workflow: +* 1) read input +* input takes the line from console, creates argc/argv +* 2) parse parameters into suitable types based on arg_type +* takes input from 1) and arg_type and creates parameters +* 3) do command +* executes commands +* 4) destroy parameters +* cleans up what was allocated by creation of parameters +* 5) destroy input +* cleans up what was allocated by creation of input +*/ + +/* +* Input Management +*/ phpdbg_input_t* phpdbg_read_input(char *buffered TSRMLS_DC); phpdbg_input_t** phpdbg_read_argv(char *buffer, int *argc TSRMLS_DC); -int phpdbg_do_cmd(const phpdbg_command_t*, phpdbg_input_t *input TSRMLS_DC); +void phpdbg_destroy_input(phpdbg_input_t** TSRMLS_DC); + +/* +* Parameter Management +*/ phpdbg_param_type phpdbg_parse_param(const char*, size_t, phpdbg_param_t* TSRMLS_DC); void phpdbg_clear_param(phpdbg_param_t* TSRMLS_DC); const char* phpdbg_get_param_type(const phpdbg_param_t* TSRMLS_DC); -void phpdbg_destroy_input(phpdbg_input_t** TSRMLS_DC); + +/* +* Command Executor +*/ +int phpdbg_do_cmd(const phpdbg_command_t*, phpdbg_input_t *input TSRMLS_DC); /** * Command Declarators diff --git a/phpdbg_prompt.c b/phpdbg_prompt.c index 366a67a..0436e93 100644 --- a/phpdbg_prompt.c +++ b/phpdbg_prompt.c @@ -923,55 +923,63 @@ static inline int phpdbg_call_register(phpdbg_input_t *input TSRMLS_DC) /* {{{ * if (zend_hash_exists( &PHPDBG_G(registered), function->string, function->length+1)) { + zval fname, *fretval; zend_fcall_info fci; - zval **params = NULL; + + 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; + if (input->argc > 1) { int arg; + zval ***params; + zval *zparam; + + fci.param_count = (input->argc > 1) ? (input->argc-1) : 0; + fci.params = (zval***) emalloc(fci.param_count * sizeof(zval**)); - params = emalloc(sizeof(zval*) * input->argc); + params = fci.params; for (arg = 1; arg <= (input->argc-1); arg++) { - MAKE_STD_ZVAL((params[arg-1])); + MAKE_STD_ZVAL(zparam); ZVAL_STRINGL( - (params[arg-1]), + zparam, input->argv[arg]->string, input->argv[arg]->length, 1); + + *params++ = &zparam; } + } else { + fci.params = NULL; + fci.param_count = 0; } - 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.param_count = (input->argc > 1) ? (input->argc-1) : 0; - fci.params = (input->argc > 1) ? &params : NULL; - fci.no_separation = 1; - - zend_call_function( - &fci, NULL TSRMLS_CC); + zend_call_function(&fci, NULL TSRMLS_CC); - zval_dtor(&fname); - if (input->argc > 1) { - int arg; + int param; - for (arg = 1; arg <= (input->argc-1); arg++) { - zval_ptr_dtor(&params[arg-1]); + for (param = 0; param < fci.param_count; param++) { + zval_ptr_dtor(fci.params[param]); } - efree(params); + efree(fci.params); } + if (fretval) { zend_print_zval_r( fretval, 0 TSRMLS_CC); phpdbg_writeln(EMPTY); } + + zval_dtor(&fname); + return SUCCESS; }

« previous php.cvs (#74779) next »