Skip to content

Commit 80386a3

Browse files
committed
improve R
1 parent dd71744 commit 80386a3

File tree

2 files changed

+60
-30
lines changed

2 files changed

+60
-30
lines changed

phpdbg_cmd.h

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,16 +84,38 @@ struct _phpdbg_command_t {
8484
#define PHPDBG_STRL(s) s, sizeof(s)-1
8585
#define PHPDBG_MAX_CMD 500
8686

87-
/**
88-
* Command Executor
89-
*/
87+
/*
88+
* Workflow:
89+
* 1) read input
90+
* input takes the line from console, creates argc/argv
91+
* 2) parse parameters into suitable types based on arg_type
92+
* takes input from 1) and arg_type and creates parameters
93+
* 3) do command
94+
* executes commands
95+
* 4) destroy parameters
96+
* cleans up what was allocated by creation of parameters
97+
* 5) destroy input
98+
* cleans up what was allocated by creation of input
99+
*/
100+
101+
/*
102+
* Input Management
103+
*/
90104
phpdbg_input_t* phpdbg_read_input(char *buffered TSRMLS_DC);
91105
phpdbg_input_t** phpdbg_read_argv(char *buffer, int *argc TSRMLS_DC);
92-
int phpdbg_do_cmd(const phpdbg_command_t*, phpdbg_input_t *input TSRMLS_DC);
106+
void phpdbg_destroy_input(phpdbg_input_t** TSRMLS_DC);
107+
108+
/*
109+
* Parameter Management
110+
*/
93111
phpdbg_param_type phpdbg_parse_param(const char*, size_t, phpdbg_param_t* TSRMLS_DC);
94112
void phpdbg_clear_param(phpdbg_param_t* TSRMLS_DC);
95113
const char* phpdbg_get_param_type(const phpdbg_param_t* TSRMLS_DC);
96-
void phpdbg_destroy_input(phpdbg_input_t** TSRMLS_DC);
114+
115+
/*
116+
* Command Executor
117+
*/
118+
int phpdbg_do_cmd(const phpdbg_command_t*, phpdbg_input_t *input TSRMLS_DC);
97119

98120
/**
99121
* Command Declarators

phpdbg_prompt.c

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -923,55 +923,63 @@ static inline int phpdbg_call_register(phpdbg_input_t *input TSRMLS_DC) /* {{{ *
923923

924924
if (zend_hash_exists(
925925
&PHPDBG_G(registered), function->string, function->length+1)) {
926+
926927
zval fname, *fretval;
927928
zend_fcall_info fci;
928-
zval **params = NULL;
929+
930+
ZVAL_STRINGL(&fname, function->string, function->length, 1);
929931

932+
fci.size = sizeof(fci);
933+
fci.function_table = &PHPDBG_G(registered);
934+
fci.function_name = &fname;
935+
fci.symbol_table = EG(active_symbol_table);
936+
fci.object_ptr = NULL;
937+
fci.retval_ptr_ptr = &fretval;
938+
fci.no_separation = 1;
939+
930940
if (input->argc > 1) {
931941
int arg;
942+
zval ***params;
943+
zval *zparam;
944+
945+
fci.param_count = (input->argc > 1) ? (input->argc-1) : 0;
946+
fci.params = (zval***) emalloc(fci.param_count * sizeof(zval**));
932947

933-
params = emalloc(sizeof(zval*) * input->argc);
948+
params = fci.params;
934949

935950
for (arg = 1; arg <= (input->argc-1); arg++) {
936-
MAKE_STD_ZVAL((params[arg-1]));
951+
MAKE_STD_ZVAL(zparam);
937952
ZVAL_STRINGL(
938-
(params[arg-1]),
953+
zparam,
939954
input->argv[arg]->string,
940955
input->argv[arg]->length, 1);
956+
957+
*params++ = &zparam;
941958
}
959+
} else {
960+
fci.params = NULL;
961+
fci.param_count = 0;
942962
}
943963

944-
ZVAL_STRINGL(&fname, function->string, function->length, 1);
945-
946-
fci.size = sizeof(fci);
947-
fci.function_table = &PHPDBG_G(registered);
948-
fci.function_name = &fname;
949-
fci.symbol_table = EG(active_symbol_table);
950-
fci.object_ptr = NULL;
951-
fci.retval_ptr_ptr = &fretval;
952-
953-
fci.param_count = (input->argc > 1) ? (input->argc-1) : 0;
954-
fci.params = (input->argc > 1) ? &params : NULL;
955-
fci.no_separation = 1;
956-
957-
zend_call_function(
958-
&fci, NULL TSRMLS_CC);
964+
zend_call_function(&fci, NULL TSRMLS_CC);
959965

960-
zval_dtor(&fname);
961-
962966
if (input->argc > 1) {
963-
int arg;
967+
int param;
964968

965-
for (arg = 1; arg <= (input->argc-1); arg++) {
966-
zval_ptr_dtor(&params[arg-1]);
969+
for (param = 0; param < fci.param_count; param++) {
970+
zval_ptr_dtor(fci.params[param]);
967971
}
968-
efree(params);
972+
efree(fci.params);
969973
}
974+
970975
if (fretval) {
971976
zend_print_zval_r(
972977
fretval, 0 TSRMLS_CC);
973978
phpdbg_writeln(EMPTY);
974979
}
980+
981+
zval_dtor(&fname);
982+
975983
return SUCCESS;
976984
}
977985

0 commit comments

Comments
 (0)