Skip to content

Commit cad9fb8

Browse files
committed
registered functions able to accept any number of arguments
1 parent 80386a3 commit cad9fb8

File tree

2 files changed

+37
-37
lines changed

2 files changed

+37
-37
lines changed

phpdbg_cmd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ phpdbg_input_t** phpdbg_read_argv(char *buffer, int *argc TSRMLS_DC) /* {{{ */
130130
} state = IN_BETWEEN;
131131
phpdbg_input_t **argv = NULL;
132132

133-
argv = (phpdbg_input_t**) emalloc(sizeof(phpdbg_input_t**));
133+
argv = (phpdbg_input_t**) emalloc(sizeof(phpdbg_input_t*));
134134
(*argc) = 0;
135135

136136
#define RESET_STATE() do {\

phpdbg_prompt.c

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -917,61 +917,55 @@ static PHPDBG_COMMAND(list) /* {{{ */
917917
return SUCCESS;
918918
} /* }}} */
919919

920-
static inline int phpdbg_call_register(phpdbg_input_t *input TSRMLS_DC) /* {{{ */
920+
int phpdbg_call_register(phpdbg_input_t *input TSRMLS_DC) /* {{{ */
921921
{
922922
phpdbg_input_t *function = input->argv[0];
923923

924924
if (zend_hash_exists(
925925
&PHPDBG_G(registered), function->string, function->length+1)) {
926926

927927
zval fname, *fretval;
928-
zend_fcall_info fci;
928+
zend_fcall_info *fci = emalloc(sizeof(zend_fcall_info));
929929

930930
ZVAL_STRINGL(&fname, function->string, function->length, 1);
931931

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;
932+
fci->size = sizeof(zend_fcall_info);
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;
939939

940940
if (input->argc > 1) {
941-
int arg;
942-
zval ***params;
943-
zval *zparam;
941+
int param;
942+
zval params;
944943

945-
fci.param_count = (input->argc > 1) ? (input->argc-1) : 0;
946-
fci.params = (zval***) emalloc(fci.param_count * sizeof(zval**));
944+
array_init(&params);
947945

948-
params = fci.params;
946+
for (param = 0; param < (input->argc-1); param++) {
947+
add_next_index_stringl(
948+
&params,
949+
input->argv[param+1]->string,
950+
input->argv[param+1]->length, 1);
949951

950-
for (arg = 1; arg <= (input->argc-1); arg++) {
951-
MAKE_STD_ZVAL(zparam);
952-
ZVAL_STRINGL(
953-
zparam,
954-
input->argv[arg]->string,
955-
input->argv[arg]->length, 1);
956-
957-
*params++ = &zparam;
952+
phpdbg_debug(
953+
"created param[%d] from argv[%d]: %s",
954+
param, param+1, input->argv[param+1]->string);
958955
}
959-
} else {
960-
fci.params = NULL;
961-
fci.param_count = 0;
962-
}
963-
964-
zend_call_function(&fci, NULL TSRMLS_CC);
965-
966-
if (input->argc > 1) {
967-
int param;
968956

969-
for (param = 0; param < fci.param_count; param++) {
970-
zval_ptr_dtor(fci.params[param]);
971-
}
972-
efree(fci.params);
957+
zend_fcall_info_args(fci, &params TSRMLS_CC);
958+
} else {
959+
fci->params = NULL;
960+
fci->param_count = 0;
973961
}
974962

963+
phpdbg_debug(
964+
"created %d params from %d argvuments",
965+
fci->param_count, input->argc);
966+
967+
zend_call_function(fci, NULL TSRMLS_CC);
968+
975969
if (fretval) {
976970
zend_print_zval_r(
977971
fretval, 0 TSRMLS_CC);
@@ -980,6 +974,12 @@ static inline int phpdbg_call_register(phpdbg_input_t *input TSRMLS_DC) /* {{{ *
980974

981975
zval_dtor(&fname);
982976

977+
if (fci->params) {
978+
efree(fci->params);
979+
}
980+
981+
efree(fci);
982+
983983
return SUCCESS;
984984
}
985985

0 commit comments

Comments
 (0)