]> granicus.if.org Git - php/commitdiff
improve R
authorkrakjoe <joe.watkins@live.co.uk>
Wed, 20 Nov 2013 10:49:39 +0000 (10:49 +0000)
committerkrakjoe <joe.watkins@live.co.uk>
Wed, 20 Nov 2013 10:49:39 +0000 (10:49 +0000)
phpdbg_cmd.h
phpdbg_prompt.c

index 12cda59c98ebdd1e4ca9911050c2046b5a65df3e..ae50d2859f56573ac0fb3c4a6ea76563f77a243f 100644 (file)
@@ -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
index 366a67a5500cc5cf274186f5555fe704f0d3ac02..0436e93f2fe1a46aa0958c1bb6b103db23094161 100644 (file)
@@ -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;
        }