From 19e3fc35383451f880dd7c0a6714f1988710bec9 Mon Sep 17 00:00:00 2001 From: Vladimir Kolesnikov Date: Tue, 8 Oct 2013 04:11:37 +0300 Subject: [PATCH] phalcon_fetch_parameters_ex() (cherry picked from commit cc8bc086381dc0b8d2b8a2751f29c0667545da33) Conflicts: ext/kernel/main.h --- ext/kernel/main.c | 25 +++++++++++++++++++++++++ ext/kernel/main.h | 10 ++++++++-- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/ext/kernel/main.c b/ext/kernel/main.c index fd829e24754..260013fa7f6 100644 --- a/ext/kernel/main.c +++ b/ext/kernel/main.c @@ -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; +} diff --git a/ext/kernel/main.h b/ext/kernel/main.h index c81c3f5b852..889eaf4b08f 100644 --- a/ext/kernel/main.h +++ b/ext/kernel/main.h @@ -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 @@ -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) \