Skip to content

Commit

Permalink
phalcon_fetch_parameters_ex()
Browse files Browse the repository at this point in the history
(cherry picked from commit cc8bc08)

Conflicts:
	ext/kernel/main.h
  • Loading branch information
sjinks committed Oct 9, 2013
1 parent bf32b51 commit 19e3fc3
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
25 changes: 25 additions & 0 deletions ext/kernel/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -360,3 +360,28 @@ int phalcon_fetch_parameters(int num_args TSRMLS_DC, int required_args, int opti

return SUCCESS;
}

int phalcon_fetch_parameters_ex(int dummy TSRMLS_DC, int n_req, int n_opt, ...)
{
void **p;
int arg_count, param_count;
va_list ptr;

p = zend_vm_stack_top(TSRMLS_C) - 1;
arg_count = (int)(zend_uintptr_t)*p;
param_count = n_req + n_opt;

if (param_count < arg_count || n_req > arg_count) {
return FAILURE;
}

va_start(ptr, n_opt);
while (arg_count > 0) {
zval ***param = va_arg(ptr, zval ***);
*param = (zval**)p - arg_count;
--arg_count;
}

va_end(ptr);
return SUCCESS;
}
10 changes: 8 additions & 2 deletions ext/kernel/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ extern int phalcon_is_iterable_ex(zval *arr, HashTable **arr_hash, HashPosition

/* Fetch Parameters */
extern int phalcon_fetch_parameters(int num_args TSRMLS_DC, int required_args, int optional_args, ...);
int phalcon_fetch_parameters_ex(int dummy TSRMLS_DC, int n_req, int n_opt, ...);

/* Compatibility with PHP 5.3 */
#ifndef ZVAL_COPY_VALUE
Expand Down Expand Up @@ -321,9 +322,14 @@ extern int phalcon_fetch_parameters(int num_args TSRMLS_DC, int required_args, i
if (phalcon_fetch_parameters(ZEND_NUM_ARGS() TSRMLS_CC, required_params, optional_params, __VA_ARGS__) == FAILURE) { \
if (memory_grow) { \
RETURN_MM_NULL(); \
} else { \
RETURN_NULL(); \
} \
RETURN_NULL(); \
}

#define phalcon_fetch_params_ex(required_params, optional_params, ...) \
if (phalcon_fetch_parameters_ex(0 TSRMLS_CC, required_params, optional_params, __VA_ARGS__) == FAILURE) { \
zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, "Wrong number of parameters"); \
return; \
}

#define PHALCON_VERIFY_INTERFACE(instance, interface_ce) \
Expand Down

0 comments on commit 19e3fc3

Please sign in to comment.