diff --git a/common.h b/common.h index 7b1c3691..098eda0c 100644 --- a/common.h +++ b/common.h @@ -192,16 +192,20 @@ typedef enum { #define PHPREDIS_DEBUG_LOGGING 0 #if PHP_VERSION_ID < 80000 +#define Z_PARAM_ARRAY_OR_NULL(dest) \ + Z_PARAM_ARRAY_EX(dest, 1, 0) #define Z_PARAM_ARRAY_HT_OR_NULL(dest) \ Z_PARAM_ARRAY_HT_EX(dest, 1, 0) +#define Z_PARAM_STRING_OR_NULL(dest, dest_len) \ + Z_PARAM_STRING_EX(dest, dest_len, 1, 0) #define Z_PARAM_STR_OR_NULL(dest) \ Z_PARAM_STR_EX(dest, 1, 0) -#define Z_PARAM_ZVAL_OR_NULL(dest) \ - Z_PARAM_ZVAL_EX(dest, 1, 0) -#define Z_PARAM_BOOL_OR_NULL(dest, is_null) \ - Z_PARAM_BOOL_EX(dest, is_null, 1, 0) #define Z_PARAM_LONG_OR_NULL(dest, is_null) \ - Z_PARAM_LONG_EX(dest, is_null, 1, 0) + Z_PARAM_LONG_EX(dest, is_null, 1, 0) +#define Z_PARAM_ZVAL_OR_NULL(dest) \ + Z_PARAM_ZVAL_EX(dest, 1, 0) +#define Z_PARAM_BOOL_OR_NULL(dest, is_null) \ + Z_PARAM_BOOL_EX(dest, is_null, 1, 0) #endif #if PHPREDIS_DEBUG_LOGGING == 1 diff --git a/redis.c b/redis.c index 92e9fff9..d898e3af 100644 --- a/redis.c +++ b/redis.c @@ -296,14 +296,11 @@ redis_sock_get(zval *id, int no_throw) * Returns our attached RedisSock pointer if we're connected */ PHP_REDIS_API RedisSock *redis_sock_get_connected(INTERNAL_FUNCTION_PARAMETERS) { - zval *object; RedisSock *redis_sock; // If we can't grab our object, or get a socket, or we're not connected, // return NULL - if((zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", - &object, redis_ce) == FAILURE) || - (redis_sock = redis_sock_get(object, 1)) == NULL || + if ((redis_sock = redis_sock_get(getThis(), 1)) == NULL || redis_sock->status < REDIS_SOCK_STATUS_CONNECTED) { return NULL; @@ -544,7 +541,7 @@ PHP_METHOD(Redis, pconnect) PHP_REDIS_API int redis_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent) { - zval *object, *context = NULL, *ele; + zval *context = NULL, *ele; char *host = NULL, *persistent_id = NULL; zend_long port = -1, retry_interval = 0; size_t host_len, persistent_id_len; @@ -558,14 +555,16 @@ redis_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent) persistent = 0; #endif - if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), - "Os|lds!lda!", &object, redis_ce, &host, - &host_len, &port, &timeout, &persistent_id, - &persistent_id_len, &retry_interval, - &read_timeout, &context) == FAILURE) - { - return FAILURE; - } + ZEND_PARSE_PARAMETERS_START(1, 7) + Z_PARAM_STRING(host, host_len) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(port) + Z_PARAM_DOUBLE(timeout) + Z_PARAM_STRING_OR_NULL(persistent_id, persistent_id_len) + Z_PARAM_LONG(retry_interval) + Z_PARAM_DOUBLE(read_timeout) + Z_PARAM_ARRAY_OR_NULL(context) + ZEND_PARSE_PARAMETERS_END_EX(return FAILURE); /* Disregard persistent_id if we're not opening a persistent connection */ if (!persistent) { @@ -597,7 +596,7 @@ redis_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent) port = 6379; } - redis = PHPREDIS_ZVAL_GET_OBJECT(redis_object, object); + redis = PHPREDIS_ZVAL_GET_OBJECT(redis_object, getThis()); /* if there is a redis sock already we have to remove it */ if (redis->sock) { @@ -1414,18 +1413,19 @@ generic_sort_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, int desc, int alpha) { zend_string *key = NULL, *pattern = NULL, *store = NULL, *zpattern; - zval *object, *zele, *zget = NULL; + zval *zele, *zget = NULL; zend_long offset = -1, count = -1; RedisCmd *cmd; - /* Parse myriad of sort arguments */ - if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), - "OS|S!z!llS", &object, redis_ce, &key, - &pattern, &zget, &offset, &count, &store) - == FAILURE) - { - return NULL; - } + ZEND_PARSE_PARAMETERS_START(1, 6) + Z_PARAM_STR(key) + Z_PARAM_OPTIONAL + Z_PARAM_STR_OR_NULL(pattern) + Z_PARAM_ZVAL_OR_NULL(zget) + Z_PARAM_LONG(offset) + Z_PARAM_LONG(count) + Z_PARAM_STR(store) + ZEND_PARSE_PARAMETERS_END_EX(return NULL); /* Ensure we're sorting something, and we can get context */ if (ZSTR_LEN(key) == 0) @@ -2110,19 +2110,16 @@ PHP_METHOD(Redis, multi) RedisSock *redis_sock; char *resp; int resp_len; - zval *object; zend_long multi_value = MULTI; - if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), - "O|l", &object, redis_ce, &multi_value) - == FAILURE) - { - RETURN_FALSE; - } + ZEND_PARSE_PARAMETERS_START(0, 1) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(multi_value) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); /* if the flag is activated, send the command, the reply will be "QUEUED" * or -ERR */ - if ((redis_sock = redis_sock_get(object, 0)) == NULL) { + if ((redis_sock = redis_sock_get(getThis(), 0)) == NULL) { RETURN_FALSE; } @@ -2171,14 +2168,12 @@ PHP_METHOD(Redis, discard) { int ret = FAILURE; RedisSock *redis_sock; - zval *object; - if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", - &object, redis_ce) == FAILURE) { + if (zend_parse_parameters_none() == FAILURE) { RETURN_FALSE; } - if ((redis_sock = redis_sock_get(object, 0)) == NULL) { + if ((redis_sock = redis_sock_get(getThis(), 0)) == NULL) { RETURN_FALSE; } @@ -2228,12 +2223,9 @@ PHP_METHOD(Redis, exec) { RedisSock *redis_sock; int ret; - zval *object, z_ret; + zval z_ret; - if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), - "O", &object, redis_ce) == FAILURE || - (redis_sock = redis_sock_get(object, 0)) == NULL - ) { + if ((redis_sock = redis_sock_get(getThis(), 0)) == NULL) { RETURN_FALSE; } @@ -2351,12 +2343,8 @@ redis_sock_read_multibulk_multi_reply_loop(INTERNAL_FUNCTION_PARAMETERS, PHP_METHOD(Redis, pipeline) { RedisSock *redis_sock; - zval *object; - if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), - "O", &object, redis_ce) == FAILURE || - (redis_sock = redis_sock_get(object, 0)) == NULL - ) { + if ((redis_sock = redis_sock_get(getThis(), 0)) == NULL) { RETURN_FALSE; } @@ -2673,18 +2661,10 @@ PHP_METHOD(Redis, _unpack) { /* {{{ proto Redis::getLastError() */ PHP_METHOD(Redis, getLastError) { - zval *object; RedisSock *redis_sock; - // Grab our object - if(zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", - &object, redis_ce) == FAILURE) - { - RETURN_FALSE; - } - // Grab socket - if ((redis_sock = redis_sock_get_instance(object, 0)) == NULL) { + if ((redis_sock = redis_sock_get_instance(getThis(), 0)) == NULL) { RETURN_FALSE; } @@ -2697,17 +2677,10 @@ PHP_METHOD(Redis, getLastError) { /* {{{ proto Redis::clearLastError() */ PHP_METHOD(Redis, clearLastError) { - zval *object; RedisSock *redis_sock; - // Grab our object - if(zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", - &object, redis_ce) == FAILURE) - { - RETURN_FALSE; - } // Grab socket - if ((redis_sock = redis_sock_get_instance(object, 0)) == NULL) { + if ((redis_sock = redis_sock_get_instance(getThis(), 0)) == NULL) { RETURN_FALSE; } @@ -2720,16 +2693,10 @@ PHP_METHOD(Redis, clearLastError) { * {{{ proto long Redis::getMode() */ PHP_METHOD(Redis, getMode) { - zval *object; RedisSock *redis_sock; - /* Grab our object */ - if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &object, redis_ce) == FAILURE) { - RETURN_FALSE; - } - /* Grab socket */ - if ((redis_sock = redis_sock_get_instance(object, 0)) == NULL) { + if ((redis_sock = redis_sock_get_instance(getThis(), 0)) == NULL) { RETURN_FALSE; } @@ -2758,16 +2725,14 @@ PHP_METHOD(Redis, role) { /* {{{ proto Redis::IsConnected */ PHP_METHOD(Redis, isConnected) { - zval *object; RedisSock *redis_sock; - /* Grab our object */ - if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &object, redis_ce) == FAILURE) { + if (zend_parse_parameters_none() == FAILURE) { RETURN_FALSE; } /* Grab socket */ - if ((redis_sock = redis_sock_get_instance(object, 1)) == NULL) { + if ((redis_sock = redis_sock_get_instance(getThis(), 1)) == NULL) { RETURN_FALSE; } @@ -3015,7 +2980,7 @@ PHP_REDIS_API void generic_scan_cmd(INTERNAL_FUNCTION_PARAMETERS, REDIS_SCAN_TYPE type) { zend_string *key = NULL, *pattern = NULL; zend_string *match_type = NULL; - zval *object, *z_cursor; + zval *z_cursor; RedisSock *redis_sock; zend_bool pattern_free = 0; zend_long count = 0; @@ -3025,27 +2990,21 @@ generic_scan_cmd(INTERNAL_FUNCTION_PARAMETERS, REDIS_SCAN_TYPE type) { uint64_t cursor; RedisCmd *cmd; - /* Different prototype depending on if this is a key based scan */ - if(type != TYPE_SCAN) { - // Requires a key - if(zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), - "OS!z/|S!l", &object, redis_ce, &key, - &z_cursor, &pattern, &count)==FAILURE) - { - RETURN_FALSE; + ZEND_PARSE_PARAMETERS_START(1 + (type != TYPE_SCAN), 4) + if (type != TYPE_SCAN) { + Z_PARAM_STR_OR_NULL(key) } - } else { - // Doesn't require a key - if(zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), - "Oz/|S!lS!", &object, redis_ce, &z_cursor, - &pattern, &count, &match_type) == FAILURE) - { - RETURN_FALSE; + Z_PARAM_ZVAL_EX(z_cursor, 0, 1) + Z_PARAM_OPTIONAL + Z_PARAM_STR_OR_NULL(pattern) + Z_PARAM_LONG(count) + if (type == TYPE_SCAN) { + Z_PARAM_STR_OR_NULL(match_type) } - } + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); /* Grab our socket */ - if ((redis_sock = redis_sock_get(object, 0)) == NULL) { + if ((redis_sock = redis_sock_get(getThis(), 0)) == NULL) { RETURN_FALSE; } diff --git a/redis_array.c b/redis_array.c index ee4b8d78..f7e0e9a1 100644 --- a/redis_array.c +++ b/redis_array.c @@ -156,9 +156,11 @@ PHP_METHOD(RedisArray, __construct) zend_string *algorithm = NULL, *user = NULL, *pass = NULL; redis_array_object *obj; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "z|a", &z0, &z_opts) == FAILURE) { - RETURN_FALSE; - } + ZEND_PARSE_PARAMETERS_START(1, 2) + Z_PARAM_ZVAL(z0) + Z_PARAM_OPTIONAL + Z_PARAM_ARRAY(z_opts) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); /* Bail if z0 isn't a string or an array. * Note: WRONG_PARAM_COUNT seems wrong but this is what we have been doing @@ -333,19 +335,18 @@ ra_forward_call(INTERNAL_FUNCTION_PARAMETERS, RedisArray *ra, const char *cmd, PHP_METHOD(RedisArray, __call) { - zval *object; RedisArray *ra; zval *z_args; char *cmd; size_t cmd_len; - if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Osa", - &object, redis_array_ce, &cmd, &cmd_len, &z_args) == FAILURE) { - RETURN_FALSE; - } + ZEND_PARSE_PARAMETERS_START(2, 2) + Z_PARAM_STRING(cmd, cmd_len) + Z_PARAM_ARRAY(z_args) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); - if ((ra = redis_array_get(object)) == NULL) { + if ((ra = redis_array_get(getThis())) == NULL) { RETURN_FALSE; } @@ -354,16 +355,10 @@ PHP_METHOD(RedisArray, __call) PHP_METHOD(RedisArray, _hosts) { - zval *object; int i; RedisArray *ra; - if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", - &object, redis_array_ce) == FAILURE) { - RETURN_FALSE; - } - - if ((ra = redis_array_get(object)) == NULL) { + if ((ra = redis_array_get(getThis())) == NULL) { RETURN_FALSE; } @@ -375,19 +370,17 @@ PHP_METHOD(RedisArray, _hosts) PHP_METHOD(RedisArray, _target) { - zval *object; RedisArray *ra; char *key; size_t key_len; zval *redis_inst; int i; - if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Os", - &object, redis_array_ce, &key, &key_len) == FAILURE) { - RETURN_FALSE; - } + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_STRING(key, key_len) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); - if ((ra = redis_array_get(object)) == NULL) { + if ((ra = redis_array_get(getThis())) == NULL) { RETURN_FALSE; } @@ -401,17 +394,15 @@ PHP_METHOD(RedisArray, _target) PHP_METHOD(RedisArray, _instance) { - zval *object; RedisArray *ra; zend_string *host; zval *z_redis; - if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "OS", - &object, redis_array_ce, &host) == FAILURE) { - RETURN_FALSE; - } + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_STR(host) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); - if ((ra = redis_array_get(object)) == NULL) { + if ((ra = redis_array_get(getThis())) == NULL) { RETURN_FALSE; } @@ -423,15 +414,9 @@ PHP_METHOD(RedisArray, _instance) PHP_METHOD(RedisArray, _function) { - zval *object; RedisArray *ra; - if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", - &object, redis_array_ce) == FAILURE) { - RETURN_FALSE; - } - - if ((ra = redis_array_get(object)) == NULL) { + if ((ra = redis_array_get(getThis())) == NULL) { RETURN_FALSE; } @@ -440,15 +425,9 @@ PHP_METHOD(RedisArray, _function) PHP_METHOD(RedisArray, _distributor) { - zval *object; RedisArray *ra; - if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", - &object, redis_array_ce) == FAILURE) { - RETURN_FALSE; - } - - if ((ra = redis_array_get(object)) == NULL) { + if ((ra = redis_array_get(getThis())) == NULL) { RETURN_FALSE; } @@ -457,17 +436,16 @@ PHP_METHOD(RedisArray, _distributor) PHP_METHOD(RedisArray, _rehash) { - zval *object; RedisArray *ra; zend_fcall_info z_cb = {0}; zend_fcall_info_cache z_cb_cache = {0}; - if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O|f", - &object, redis_array_ce, &z_cb, &z_cb_cache) == FAILURE) { - RETURN_FALSE; - } + ZEND_PARSE_PARAMETERS_START(0, 1) + Z_PARAM_OPTIONAL + Z_PARAM_FUNC(z_cb, z_cb_cache) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); - if ((ra = redis_array_get(object)) == NULL) { + if ((ra = redis_array_get(getThis())) == NULL) { RETURN_FALSE; } @@ -481,15 +459,10 @@ PHP_METHOD(RedisArray, _rehash) PHP_METHOD(RedisArray, _continuum) { int i; - zval *object, z_ret; + zval z_ret; RedisArray *ra; - if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", - &object, redis_array_ce) == FAILURE) { - RETURN_FALSE; - } - - if ((ra = redis_array_get(object)) == NULL) { + if ((ra = redis_array_get(getThis())) == NULL) { RETURN_FALSE; } @@ -527,15 +500,10 @@ multihost_distribute_call(RedisArray *ra, zval *return_value, zval *z_fun, int a static void multihost_distribute(INTERNAL_FUNCTION_PARAMETERS, const char *method_name) { - zval *object, z_fun; + zval z_fun; RedisArray *ra; - if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", - &object, redis_array_ce) == FAILURE) { - RETURN_FALSE; - } - - if ((ra = redis_array_get(object)) == NULL) { + if ((ra = redis_array_get(getThis())) == NULL) { RETURN_FALSE; } @@ -550,16 +518,16 @@ multihost_distribute(INTERNAL_FUNCTION_PARAMETERS, const char *method_name) static void multihost_distribute_flush(INTERNAL_FUNCTION_PARAMETERS, const char *method_name) { - zval *object, z_fun, z_args[1]; + zval z_fun, z_args[1]; zend_bool async = 0; RedisArray *ra; - if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O|b", - &object, redis_array_ce, &async) == FAILURE) { - RETURN_FALSE; - } + ZEND_PARSE_PARAMETERS_START(0, 1) + Z_PARAM_OPTIONAL + Z_PARAM_BOOL(async) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); - if ((ra = redis_array_get(object)) == NULL) { + if ((ra = redis_array_get(getThis())) == NULL) { RETURN_FALSE; } @@ -605,20 +573,17 @@ PHP_METHOD(RedisArray, bgsave) PHP_METHOD(RedisArray, keys) { - zval *object, z_fun, z_args[1]; + zval z_fun, z_args[1]; RedisArray *ra; char *pattern; size_t pattern_len; - /* Make sure the prototype is correct */ - if(zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Os", - &object, redis_array_ce, &pattern, &pattern_len) == FAILURE) - { - RETURN_FALSE; - } + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_STRING(pattern, pattern_len) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); /* Make sure we can grab our RedisArray object */ - if ((ra = redis_array_get(object)) == NULL) { + if ((ra = redis_array_get(getThis())) == NULL) { RETURN_FALSE; } @@ -636,16 +601,15 @@ PHP_METHOD(RedisArray, keys) PHP_METHOD(RedisArray, getOption) { - zval *object, z_fun, z_args[1]; + zval z_fun, z_args[1]; RedisArray *ra; zend_long opt; - if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Ol", - &object, redis_array_ce, &opt) == FAILURE) { - RETURN_FALSE; - } + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_LONG(opt) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); - if ((ra = redis_array_get(object)) == NULL) { + if ((ra = redis_array_get(getThis())) == NULL) { RETURN_FALSE; } @@ -662,18 +626,18 @@ PHP_METHOD(RedisArray, getOption) PHP_METHOD(RedisArray, setOption) { - zval *object, z_fun, z_args[2]; + zval z_fun, z_args[2]; RedisArray *ra; zend_long opt; char *val_str; size_t val_len; - if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Ols", - &object, redis_array_ce, &opt, &val_str, &val_len) == FAILURE) { - RETURN_FALSE; - } + ZEND_PARSE_PARAMETERS_START(2, 2) + Z_PARAM_LONG(opt) + Z_PARAM_STRING(val_str, val_len) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); - if ((ra = redis_array_get(object)) == NULL) { + if ((ra = redis_array_get(getThis())) == NULL) { RETURN_FALSE; } @@ -692,16 +656,15 @@ PHP_METHOD(RedisArray, setOption) PHP_METHOD(RedisArray, select) { - zval *object, z_fun, z_args[1]; + zval z_fun, z_args[1]; RedisArray *ra; zend_long opt; - if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Ol", - &object, redis_array_ce, &opt) == FAILURE) { - RETURN_FALSE; - } + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_LONG(opt) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); - if ((ra = redis_array_get(object)) == NULL) { + if ((ra = redis_array_get(getThis())) == NULL) { RETURN_FALSE; } @@ -720,10 +683,9 @@ PHP_METHOD(RedisArray, select) if (ra && ra->z_multi_exec) { \ int i, num_varargs; \ zval *varargs = NULL, z_arg_array; \ - if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O*", \ - &object, redis_array_ce, &varargs, &num_varargs) == FAILURE) { \ - RETURN_FALSE;\ - } \ + ZEND_PARSE_PARAMETERS_START(0, -1) \ + Z_PARAM_VARIADIC('*', varargs, num_varargs) \ + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); \ /* copy all args into a zval hash table */\ array_init(&z_arg_array); \ for (i = 0; i < num_varargs; i++) { \ @@ -741,7 +703,7 @@ PHP_METHOD(RedisArray, select) /* MGET will distribute the call to several nodes and regroup the values. */ PHP_METHOD(RedisArray, mget) { - zval *object, *z_keys, *data, z_ret, *z_cur, z_tmp_array, z_fun, z_arg, **argv; + zval *z_keys, *data, z_ret, *z_cur, z_tmp_array, z_fun, z_arg, **argv; int i, j, n, *pos, argc, *argc_each; HashTable *h_keys; RedisArray *ra; @@ -753,11 +715,9 @@ PHP_METHOD(RedisArray, mget) /* Multi/exec support */ HANDLE_MULTI_EXEC(ra, "MGET", sizeof("MGET") - 1); - if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Oa", - &object, redis_array_ce, &z_keys) == FAILURE) { - RETURN_FALSE; - } - + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_ARRAY(z_keys) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); /* init data structures */ h_keys = Z_ARRVAL_P(z_keys); @@ -869,7 +829,7 @@ cleanup: /* MSET will distribute the call to several nodes and regroup the values. */ PHP_METHOD(RedisArray, mset) { - zval *object, *z_keys, z_argarray, *data, z_fun, z_ret, **argv; + zval *z_keys, z_argarray, *data, z_fun, z_ret, **argv; int i = 0, n, *pos, argc, *argc_each, key_len; RedisArray *ra; HashTable *h_keys; @@ -884,11 +844,9 @@ PHP_METHOD(RedisArray, mset) /* Multi/exec support */ HANDLE_MULTI_EXEC(ra, "MSET", sizeof("MSET") - 1); - if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Oa", - &object, redis_array_ce, &z_keys) == FAILURE) - { - RETURN_FALSE; - } + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_ARRAY(z_keys) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); /* init data structures */ h_keys = Z_ARRVAL_P(z_keys); @@ -992,7 +950,7 @@ PHP_METHOD(RedisArray, mset) static void ra_generic_del(INTERNAL_FUNCTION_PARAMETERS, char *kw, int kw_len) { - zval *object, z_keys, z_fun, *data, z_ret, *z_args, **argv; + zval z_keys, z_fun, *data, z_ret, *z_args, **argv; int i, n, *pos, argc = ZEND_NUM_ARGS(), *argc_each, free_zkeys = 0; HashTable *h_keys; RedisArray *ra; @@ -1124,15 +1082,18 @@ ra_generic_scan_cmd(INTERNAL_FUNCTION_PARAMETERS, const char *kw, int kw_len) { RedisArray *ra; zend_string *key, *pattern = NULL; - zval *object, *redis_inst, *z_cursor, z_fun, z_args[4]; + zval *redis_inst, *z_cursor, z_fun, z_args[4]; zend_long count = 0; - if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "OSz/|S!l", - &object, redis_array_ce, &key, &z_cursor, &pattern, &count) == FAILURE) { - RETURN_FALSE; - } + ZEND_PARSE_PARAMETERS_START(2, 4) + Z_PARAM_STR(key) + Z_PARAM_ZVAL_EX(z_cursor, 0, 1) + Z_PARAM_OPTIONAL + Z_PARAM_STR_OR_NULL(pattern) + Z_PARAM_LONG(count) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); - if ((ra = redis_array_get(object)) == NULL) { + if ((ra = redis_array_get(getThis())) == NULL) { RETURN_FALSE; } @@ -1172,15 +1133,18 @@ PHP_METHOD(RedisArray, scan) { RedisArray *ra; zend_string *host, *pattern = NULL; - zval *object, *redis_inst, *z_iter, z_fun, z_args[3]; + zval *redis_inst, *z_iter, z_fun, z_args[3]; zend_long count = 0; - if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Oz/S|S!l", - &object, redis_array_ce, &z_iter, &host, &pattern, &count) == FAILURE) { - RETURN_FALSE; - } + ZEND_PARSE_PARAMETERS_START(2, 4) + Z_PARAM_ZVAL_EX(z_iter, 0, 1) + Z_PARAM_STR(host) + Z_PARAM_OPTIONAL + Z_PARAM_STR_OR_NULL(pattern) + Z_PARAM_LONG(count) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); - if ((ra = redis_array_get(object)) == NULL) { + if ((ra = redis_array_get(getThis())) == NULL) { RETURN_FALSE; } @@ -1201,18 +1165,18 @@ PHP_METHOD(RedisArray, scan) PHP_METHOD(RedisArray, multi) { - zval *object; RedisArray *ra; zval *z_redis; zend_string *host; zend_long multi_value = MULTI; - if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "OS|l", - &object, redis_array_ce, &host, &multi_value) == FAILURE) { - RETURN_FALSE; - } + ZEND_PARSE_PARAMETERS_START(1, 2) + Z_PARAM_STR(host) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(multi_value) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); - if ((ra = redis_array_get(object)) == NULL) { + if ((ra = redis_array_get(getThis())) == NULL) { RETURN_FALSE; } @@ -1232,20 +1196,14 @@ PHP_METHOD(RedisArray, multi) ra_index_multi(z_redis, multi_value); /* return this. */ - RETURN_ZVAL(object, 1, 0); + RETURN_ZVAL(getThis(), 1, 0); } PHP_METHOD(RedisArray, exec) { - zval *object; RedisArray *ra; - if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", - &object, redis_array_ce) == FAILURE) { - RETURN_FALSE; - } - - if ((ra = redis_array_get(object)) == NULL || !ra->z_multi_exec) { + if ((ra = redis_array_get(getThis())) == NULL || !ra->z_multi_exec) { RETURN_FALSE; } @@ -1258,15 +1216,9 @@ PHP_METHOD(RedisArray, exec) PHP_METHOD(RedisArray, discard) { - zval *object; RedisArray *ra; - if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", - &object, redis_array_ce) == FAILURE) { - RETURN_FALSE; - } - - if ((ra = redis_array_get(object)) == NULL || !ra->z_multi_exec) { + if ((ra = redis_array_get(getThis())) == NULL || !ra->z_multi_exec) { RETURN_FALSE; } @@ -1279,15 +1231,9 @@ PHP_METHOD(RedisArray, discard) PHP_METHOD(RedisArray, unwatch) { - zval *object; RedisArray *ra; - if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", - &object, redis_array_ce) == FAILURE) { - RETURN_FALSE; - } - - if ((ra = redis_array_get(object)) == NULL || !ra->z_multi_exec) { + if ((ra = redis_array_get(getThis())) == NULL || !ra->z_multi_exec) { RETURN_FALSE; } diff --git a/redis_cluster.c b/redis_cluster.c index 66b513a0..4f238689 100644 --- a/redis_cluster.c +++ b/redis_cluster.c @@ -354,7 +354,7 @@ void redis_cluster_load(redisCluster *c, char *name, int name_len) { /* Create a RedisCluster Object */ PHP_METHOD(RedisCluster, __construct) { - zval *object, *z_seeds = NULL, *z_auth = NULL, *context = NULL; + zval *z_seeds = NULL, *z_auth = NULL, *context = NULL; zend_string *user = NULL, *pass = NULL; double timeout = 0.0, read_timeout = 0.0; size_t name_len; @@ -362,14 +362,16 @@ PHP_METHOD(RedisCluster, __construct) { redisCluster *c = GET_CONTEXT(); char *name; - // Parse arguments - if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), - "Os!|a!ddbza!", &object, redis_cluster_ce, &name, - &name_len, &z_seeds, &timeout, &read_timeout, - &persistent, &z_auth, &context) == FAILURE) - { - RETURN_FALSE; - } + ZEND_PARSE_PARAMETERS_START(1, 7) + Z_PARAM_STRING_OR_NULL(name, name_len) + Z_PARAM_OPTIONAL + Z_PARAM_ARRAY_OR_NULL(z_seeds) + Z_PARAM_DOUBLE(timeout) + Z_PARAM_DOUBLE(read_timeout) + Z_PARAM_BOOL(persistent) + Z_PARAM_ZVAL(z_auth) + Z_PARAM_ARRAY_OR_NULL(context) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); /* If we've got a string try to load from INI */ if (ZEND_NUM_ARGS() < 2 || z_seeds == NULL) { @@ -722,10 +724,9 @@ static int cluster_mset_cmd(INTERNAL_FUNCTION_PARAMETERS, char *kw, int kw_len, int i = 1, argc; short slot; - // Parse our arguments - if (zend_parse_parameters(ZEND_NUM_ARGS(), "a", &z_arr) == FAILURE) { - return -1; - } + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_ARRAY(z_arr) + ZEND_PARSE_PARAMETERS_END_EX(return FAILURE); // No reason to send zero args ht_arr = Z_ARRVAL_P(z_arr); @@ -957,9 +958,9 @@ PHP_METHOD(RedisCluster, keys) { RedisCmd *cmd; int i; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &pat) == FAILURE) { - RETURN_FALSE; - } + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_STR(pat) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); /* Prefix and then build our command */ cmd = redis_cmd_create_literal(c->flags, "KEYS"); @@ -2364,9 +2365,9 @@ static void cluster_empty_node_cmd(INTERNAL_FUNCTION_PARAMETERS, char *kw, zval *z_arg; short slot; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &z_arg) == FAILURE) { - RETURN_FALSE; - } + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_ZVAL(z_arg) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); // One argument means find the node (treated like a key), and two means // send the command to a specific host and port @@ -2402,9 +2403,11 @@ cluster_flush_cmd(INTERNAL_FUNCTION_PARAMETERS, char *kw, zend_bool async = 0; short slot; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "z|b", &z_arg, &async) == FAILURE) { - RETURN_FALSE; - } + ZEND_PARSE_PARAMETERS_START(1, 2) + Z_PARAM_ZVAL(z_arg) + Z_PARAM_OPTIONAL + Z_PARAM_BOOL(async) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); // One argument means find the node (treated like a key), and two means // send the command to a specific host and port @@ -2508,12 +2511,13 @@ static void cluster_kscan_cmd(INTERNAL_FUNCTION_PARAMETERS, RETURN_FALSE; } - /* Parse arguments */ - if (zend_parse_parameters(ZEND_NUM_ARGS(), "sz/|s!l", &key, - &key_len, &z_it, &pat, &pat_len, &count) == FAILURE) - { - RETURN_FALSE; - } + ZEND_PARSE_PARAMETERS_START(2, 4) + Z_PARAM_STRING(key, key_len) + Z_PARAM_ZVAL_EX(z_it, 0, 1) + Z_PARAM_OPTIONAL + Z_PARAM_STRING_OR_NULL(pat, pat_len) + Z_PARAM_LONG(count) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); /* Treat as readonly */ c->readonly = 1; @@ -2673,12 +2677,13 @@ PHP_METHOD(RedisCluster, scan) { RETURN_FALSE; } - /* Parse arguments */ - if (zend_parse_parameters(ZEND_NUM_ARGS(), "z/z|s!l", &zcursor, - &z_node, &pat, &pat_len, &count) == FAILURE) - { - RETURN_FALSE; - } + ZEND_PARSE_PARAMETERS_START(2, 4) + Z_PARAM_ZVAL_EX(zcursor, 0, 1) + Z_PARAM_ZVAL(z_node) + Z_PARAM_OPTIONAL + Z_PARAM_STRING_OR_NULL(pat, pat_len) + Z_PARAM_LONG(count) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); /* Get the scan cursor and return early if we're done */ cursor = redisGetScanCursor(zcursor, &completed); @@ -2868,12 +2873,12 @@ PHP_METHOD(RedisCluster, client) { zval *z_node; short slot; - /* Parse args */ - if (zend_parse_parameters(ZEND_NUM_ARGS(), "zS|S", &z_node, &op, &arg) - == FAILURE) - { - RETURN_FALSE; - } + ZEND_PARSE_PARAMETERS_START(2, 3) + Z_PARAM_ZVAL(z_node) + Z_PARAM_STR(op) + Z_PARAM_OPTIONAL + Z_PARAM_STR(arg) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); /* Make sure we can properly resolve the slot */ slot = cluster_cmd_get_slot(c, z_node); @@ -3151,10 +3156,11 @@ PHP_METHOD(RedisCluster, ping) { RedisCmd *cmd; short slot; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "z|S!", &z_node, &arg) == FAILURE) - { - RETURN_FALSE; - } + ZEND_PARSE_PARAMETERS_START(1, 2) + Z_PARAM_ZVAL(z_node) + Z_PARAM_OPTIONAL + Z_PARAM_STR_OR_NULL(arg) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); /* Treat this as a readonly command */ c->readonly = CLUSTER_IS_ATOMIC(c); @@ -3341,9 +3347,10 @@ PHP_METHOD(RedisCluster, echo) { zval *z_arg; short slot; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "zS", &z_arg, &msg) == FAILURE) { - RETURN_FALSE; - } + ZEND_PARSE_PARAMETERS_START(2, 2) + Z_PARAM_ZVAL(z_arg) + Z_PARAM_STR(msg) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); /* Treat this as a readonly command */ c->readonly = CLUSTER_IS_ATOMIC(c); diff --git a/redis_commands.c b/redis_commands.c index 560855a8..1f2964d1 100644 --- a/redis_commands.c +++ b/redis_commands.c @@ -418,9 +418,10 @@ RedisCmd *redis_kv_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, zend_string *key; zval *zv; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "Sz", &key, &zv) == FAILURE) { - return NULL; - } + ZEND_PARSE_PARAMETERS_START(2, 2) + Z_PARAM_STR(key) + Z_PARAM_ZVAL(zv) + ZEND_PARSE_PARAMETERS_END_EX(return NULL); return redis_cmd_fmt(redis_sock, kw, "Kv", key, zv); } @@ -431,10 +432,10 @@ RedisCmd *redis_key_str_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, { zend_string *key, *val; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "SS", &key, &val) == FAILURE) - { - return NULL; - } + ZEND_PARSE_PARAMETERS_START(2, 2) + Z_PARAM_STR(key) + Z_PARAM_STR(val) + ZEND_PARSE_PARAMETERS_END_EX(return NULL); return redis_cmd_fmt(redis_sock, kw, "KS", key, val); } @@ -517,11 +518,11 @@ RedisCmd *redis_key_long_long_cmd(INTERNAL_FUNCTION_PARAMETERS, zend_long val1, val2; zend_string *key; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "Sll", &key, &val1, &val2) - == FAILURE) - { - return NULL; - } + ZEND_PARSE_PARAMETERS_START(3, 3) + Z_PARAM_STR(key) + Z_PARAM_LONG(val1) + Z_PARAM_LONG(val2) + ZEND_PARSE_PARAMETERS_END_EX(return NULL); return redis_cmd_fmt(redis_sock, kw, "Kll", key, val1, val2); } @@ -548,11 +549,12 @@ redis_failover_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock) zval *z_to = NULL, *z_ele; RedisCmd *cmd; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "|a!bl", - &z_to, &abort, &timeout) == FAILURE) - { - return NULL; - } + ZEND_PARSE_PARAMETERS_START(0, 3) + Z_PARAM_OPTIONAL + Z_PARAM_ARRAY_OR_NULL(z_to) + Z_PARAM_BOOL(abort) + Z_PARAM_LONG(timeout) + ZEND_PARSE_PARAMETERS_END_EX(return NULL); if (z_to != NULL) { ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(z_to), zkey, z_ele) { @@ -629,8 +631,10 @@ RedisCmd *redis_key_dbl_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, zend_string *key; double val; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "Sd", &key, &val) == FAILURE) - return NULL; + ZEND_PARSE_PARAMETERS_START(2, 2) + Z_PARAM_STR(key) + Z_PARAM_DOUBLE(val) + ZEND_PARSE_PARAMETERS_END_EX(return NULL); return redis_cmd_fmt(redis_sock, kw, "Kf", key, val); } @@ -1189,11 +1193,11 @@ redis_zdiff_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock) RedisCmd *cmd; int numkeys, flags; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "a|a", - &z_keys, &z_opts) == FAILURE) - { - return NULL; - } + ZEND_PARSE_PARAMETERS_START(1, 2) + Z_PARAM_ARRAY(z_keys) + Z_PARAM_OPTIONAL + Z_PARAM_ARRAY(z_opts) + ZEND_PARSE_PARAMETERS_END_EX(return NULL); if ((numkeys = zend_hash_num_elements(Z_ARRVAL_P(z_keys))) == 0) { return NULL; @@ -1331,11 +1335,12 @@ redis_zinterunion_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, RedisCmd *cmd; int numkeys, flags; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "a|a!a", - &z_keys, &z_weights, &z_opts) == FAILURE) - { - return NULL; - } + ZEND_PARSE_PARAMETERS_START(1, 3) + Z_PARAM_ARRAY(z_keys) + Z_PARAM_OPTIONAL + Z_PARAM_ARRAY_OR_NULL(z_weights) + Z_PARAM_ARRAY(z_opts) + ZEND_PARSE_PARAMETERS_END_EX(return NULL); if ((numkeys = zend_hash_num_elements(Z_ARRVAL_P(z_keys))) == 0) { return NULL; @@ -1545,26 +1550,27 @@ redis_subscribe_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, { zval *z_arr, *z_chan; HashTable *ht_chan; - subscribeContext *sctx = ecalloc(1, sizeof(*sctx)); unsigned short shardslot = REDIS_CLUSTER_SLOTS; RedisCmd *cmd; + subscribeContext *sctx; + zend_fcall_info_cache fcc; + zend_fcall_info fci; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "af", &z_arr, - &sctx->cb.fci, &sctx->cb.fci_cache) == FAILURE) - { - efree(sctx); + ZEND_PARSE_PARAMETERS_START(2, 2) + Z_PARAM_ARRAY(z_arr) + Z_PARAM_FUNC(fci, fcc) + ZEND_PARSE_PARAMETERS_END_EX(return NULL); + + ht_chan = Z_ARRVAL_P(z_arr); + if (zend_hash_num_elements(ht_chan) == 0) return NULL; - } - ht_chan = Z_ARRVAL_P(z_arr); - sctx->kw = kw; + sctx = ecalloc(1, sizeof(*sctx)); + sctx->kw = kw; + sctx->cb.fci = fci; + sctx->cb.fci_cache = fcc; sctx->argc = zend_hash_num_elements(ht_chan); - if (sctx->argc == 0) { - efree(sctx); - return NULL; - } - if (strcasecmp(kw, "ssubscribe") == 0) { zend_hash_internal_pointer_reset(ht_chan); if ((z_chan = zend_hash_get_current_data(ht_chan)) == NULL) { @@ -1648,11 +1654,14 @@ RedisCmd *redis_zrangebylex_cmd(INTERNAL_FUNCTION_PARAMETERS, return NULL; } - if (zend_parse_parameters(argc, "SSS|ll", &key, &min, &max, &offset, - &count) == FAILURE) - { - return NULL; - } + ZEND_PARSE_PARAMETERS_START(3, 5) + Z_PARAM_STR(key) + Z_PARAM_STR(min) + Z_PARAM_STR(max) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(offset) + Z_PARAM_LONG(count) + ZEND_PARSE_PARAMETERS_END_EX(return NULL); /* min and max must start with '(' or '[', or be either '-' or '+' */ if (!validate_zlex_arg_zstr(min) || !validate_zlex_arg_zstr(max)) { @@ -1678,12 +1687,11 @@ RedisCmd *redis_gen_zlex_cmd(INTERNAL_FUNCTION_PARAMETERS, { zend_string *key, *min, *max; - /* Parse args */ - if (zend_parse_parameters(ZEND_NUM_ARGS(), "SSS", &key, &min, &max) - == FAILURE) - { - return NULL; - } + ZEND_PARSE_PARAMETERS_START(3, 3) + Z_PARAM_STR(key) + Z_PARAM_STR(min) + Z_PARAM_STR(max) + ZEND_PARSE_PARAMETERS_END_EX(return NULL); /* Quick sanity check on min/max */ if (!validate_zlex_arg_zstr(min) || !validate_zlex_arg_zstr(max)) { @@ -2044,12 +2052,11 @@ redis_pop_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, char *kw) zend_long count = 0; RedisCmd *cmd; - // Make sure the function is being called correctly - if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|l", - &key, &count) == FAILURE) - { - return NULL; - } + ZEND_PARSE_PARAMETERS_START(1, 2) + Z_PARAM_STR(key) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(count) + ZEND_PARSE_PARAMETERS_END_EX(return NULL); cmd = redis_cmd_create(redis_sock, kw, strlen(kw)); redis_cmd_cat_key_zstr(cmd, key); @@ -2457,11 +2464,11 @@ redis_getex_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock) zend_bool persist = 0; RedisCmd *cmd; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|a", &key, &z_opts) - == FAILURE) - { - return NULL; - } + ZEND_PARSE_PARAMETERS_START(1, 2) + Z_PARAM_STR(key) + Z_PARAM_OPTIONAL + Z_PARAM_ARRAY(z_opts) + ZEND_PARSE_PARAMETERS_END_EX(return NULL); if (z_opts != NULL) { ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(z_opts), zkey, z_ele) { @@ -2557,9 +2564,11 @@ redis_atomic_increment(INTERNAL_FUNCTION_PARAMETERS, int type, zend_long val = 1; zend_string *key; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|l", &key, &val) == FAILURE) { - return NULL; - } + ZEND_PARSE_PARAMETERS_START(1, 2) + Z_PARAM_STR(key) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(val) + ZEND_PARSE_PARAMETERS_END_EX(return NULL); /* If our value is 1 we use INCR/DECR. For other values, treat the call as * an INCRBY or DECRBY call */ @@ -2641,11 +2650,11 @@ RedisCmd *redis_hincrby_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock) zend_string *key, *mem; zend_long byval; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "SSl", &key, &mem, &byval) - == FAILURE) - { - return NULL; - } + ZEND_PARSE_PARAMETERS_START(3, 3) + Z_PARAM_STR(key) + Z_PARAM_STR(mem) + Z_PARAM_LONG(byval) + ZEND_PARSE_PARAMETERS_END_EX(return NULL); return redis_cmd_fmt(redis_sock, "HINCRBY", "KSl", key, mem, byval); } @@ -2657,11 +2666,11 @@ RedisCmd *redis_hincrbyfloat_cmd(INTERNAL_FUNCTION_PARAMETERS, zend_string *key, *mem; double dval; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "SSd", &key, &mem, &dval) - == FAILURE) - { - return NULL; - } + ZEND_PARSE_PARAMETERS_START(3, 3) + Z_PARAM_STR(key) + Z_PARAM_STR(mem) + Z_PARAM_DOUBLE(dval) + ZEND_PARSE_PARAMETERS_END_EX(return NULL); return redis_cmd_fmt(redis_sock, "HINCRBYFLOAT", "KSf", key, mem, dval); } @@ -2823,9 +2832,10 @@ redis_hstrlen_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock) { zend_string *key, *field; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "SS", &key, &field) == FAILURE) { - return NULL; - } + ZEND_PARSE_PARAMETERS_START(2, 2) + Z_PARAM_STR(key) + Z_PARAM_STR(field) + ZEND_PARSE_PARAMETERS_END_EX(return NULL); return redis_cmd_fmt(redis_sock, "HSTRLEN", "KS", key, field); } @@ -3200,9 +3210,11 @@ RedisCmd *redis_auth_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock) { RedisCmd *cmd; zval *ztest; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "z!", &ztest) == FAILURE || - redis_extract_auth_info(ztest, &user, &pass) == FAILURE) - { + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_ZVAL_OR_NULL(ztest) + ZEND_PARSE_PARAMETERS_END_EX(return NULL); + + if (redis_extract_auth_info(ztest, &user, &pass) == FAILURE) { return NULL; } @@ -5572,11 +5584,13 @@ redis_xrange_generic_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, zend_long count = -1; RedisCmd *cmd; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "SSS|l", &key, &start, &end, - &count) == FAILURE) - { - return NULL; - } + ZEND_PARSE_PARAMETERS_START(3, 4) + Z_PARAM_STR(key) + Z_PARAM_STR(start) + Z_PARAM_STR(end) + Z_PARAM_OPTIONAL + Z_PARAM_LONG(count) + ZEND_PARSE_PARAMETERS_END_EX(return NULL); cmd = redis_cmd_create(redis_sock, kw, strlen(kw)); @@ -5743,11 +5757,11 @@ RedisCmd *redis_xack_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock) RedisCmd *cmd; int idcount; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "SSa", &key, &group, &z_ids) - == FAILURE) - { - return NULL; - } + ZEND_PARSE_PARAMETERS_START(3, 3) + Z_PARAM_STR(key) + Z_PARAM_STR(group) + Z_PARAM_ARRAY(z_ids) + ZEND_PARSE_PARAMETERS_END_EX(return NULL); ht_ids = Z_ARRVAL_P(z_ids); if ((idcount = zend_hash_num_elements(ht_ids)) < 1) { @@ -6205,9 +6219,10 @@ redis_sentinel_str_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, { zend_string *name; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &name) == FAILURE) { - return NULL; - } + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_STR(name) + ZEND_PARSE_PARAMETERS_END_EX(return NULL); + return redis_cmd_fmt(redis_sock, "SENTINEL", "sS", kw, strlen(kw), name); } @@ -6705,11 +6720,9 @@ void redis_getoption_handler(INTERNAL_FUNCTION_PARAMETERS, { zend_long option; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &option) - == FAILURE) - { - RETURN_FALSE; - } + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_LONG(option) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); // Return the requested option switch(option) { @@ -6761,11 +6774,10 @@ void redis_setoption_handler(INTERNAL_FUNCTION_PARAMETERS, int tcp_keepalive = 0; php_netstream_data_t *sock; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "lz", &option, - &val) == FAILURE) - { - RETURN_FALSE; - } + ZEND_PARSE_PARAMETERS_START(2, 2) + Z_PARAM_LONG(option) + Z_PARAM_ZVAL(val) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); switch(option) { case REDIS_OPT_SERIALIZER: @@ -6923,10 +6935,9 @@ void redis_prefix_handler(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock) { size_t key_len; char *key; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &key, &key_len) == FAILURE) - { - RETURN_FALSE; - } + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_STRING(key, key_len) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); if (redis_sock->prefix) { int keyfree = redis_key_prefix(redis_sock, &key, &key_len); @@ -6944,9 +6955,9 @@ void redis_serialize_handler(INTERNAL_FUNCTION_PARAMETERS, char *val; size_t val_len; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &z_val) == FAILURE) { - RETURN_FALSE; - } + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_ZVAL(z_val) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); int val_free = redis_serialize(redis_sock, z_val, &val, &val_len); @@ -6960,12 +6971,9 @@ void redis_unserialize_handler(INTERNAL_FUNCTION_PARAMETERS, char *value; size_t value_len; - // Parse our arguments - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &value, &value_len) - == FAILURE) - { - RETURN_FALSE; - } + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_STRING(value, value_len) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); // We only need to attempt unserialization if we have a serializer running if (redis_sock->serializer == REDIS_SERIALIZER_NONE) { @@ -6988,9 +6996,9 @@ void redis_compress_handler(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock) char *buf; int cmp_free; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &zstr) == FAILURE) { - RETURN_FALSE; - } + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_STR(zstr) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); cmp_free = redis_compress(redis_sock, &buf, &len, ZSTR_VAL(zstr), ZSTR_LEN(zstr)); RETVAL_STRINGL(buf, len); @@ -7004,9 +7012,11 @@ void redis_uncompress_handler(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_soc size_t len; char *buf; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &zstr) == FAILURE) { - RETURN_FALSE; - } else if (ZSTR_LEN(zstr) == 0 || redis_sock->compression == REDIS_COMPRESSION_NONE) { + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_STR(zstr) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); + + if (ZSTR_LEN(zstr) == 0 || redis_sock->compression == REDIS_COMPRESSION_NONE) { RETURN_STR_COPY(zstr); } @@ -7025,9 +7035,9 @@ void redis_pack_handler(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock) { char *val; zval *zv; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &zv) == FAILURE) { - RETURN_FALSE; - } + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_ZVAL(zv) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); valfree = redis_pack(redis_sock, zv, &val, &len); RETVAL_STRINGL(val, len); @@ -7101,9 +7111,9 @@ void redis_digest_handler(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, void redis_unpack_handler(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock) { zend_string *str; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &str) == FAILURE) { - RETURN_FALSE; - } + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_STR(str) + ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); redis_unpack(redis_sock, ZSTR_VAL(str), ZSTR_LEN(str), return_value); }