Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c2d2254

Browse files
yatsukhnenkomichael-grunder
authored andcommitted
Switch to Fast Parameter Parsing API
1 parent b0d534e commit c2d2254

5 files changed

Lines changed: 350 additions & 424 deletions

File tree

common.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,16 +192,20 @@ typedef enum {
192192
#define PHPREDIS_DEBUG_LOGGING 0
193193

194194
#if PHP_VERSION_ID < 80000
195+
#define Z_PARAM_ARRAY_OR_NULL(dest) \
196+
Z_PARAM_ARRAY_EX(dest, 1, 0)
195197
#define Z_PARAM_ARRAY_HT_OR_NULL(dest) \
196198
Z_PARAM_ARRAY_HT_EX(dest, 1, 0)
199+
#define Z_PARAM_STRING_OR_NULL(dest, dest_len) \
200+
Z_PARAM_STRING_EX(dest, dest_len, 1, 0)
197201
#define Z_PARAM_STR_OR_NULL(dest) \
198202
Z_PARAM_STR_EX(dest, 1, 0)
203+
#define Z_PARAM_LONG_OR_NULL(dest, is_null) \
204+
Z_PARAM_LONG_EX(dest, is_null, 1, 0)
199205
#define Z_PARAM_ZVAL_OR_NULL(dest) \
200-
Z_PARAM_ZVAL_EX(dest, 1, 0)
206+
Z_PARAM_ZVAL_EX(dest, 1, 0)
201207
#define Z_PARAM_BOOL_OR_NULL(dest, is_null) \
202-
Z_PARAM_BOOL_EX(dest, is_null, 1, 0)
203-
#define Z_PARAM_LONG_OR_NULL(dest, is_null) \
204-
Z_PARAM_LONG_EX(dest, is_null, 1, 0)
208+
Z_PARAM_BOOL_EX(dest, is_null, 1, 0)
205209
#endif
206210

207211
#if PHPREDIS_DEBUG_LOGGING == 1

redis.c

Lines changed: 50 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -296,14 +296,11 @@ redis_sock_get(zval *id, int no_throw)
296296
* Returns our attached RedisSock pointer if we're connected
297297
*/
298298
PHP_REDIS_API RedisSock *redis_sock_get_connected(INTERNAL_FUNCTION_PARAMETERS) {
299-
zval *object;
300299
RedisSock *redis_sock;
301300

302301
// If we can't grab our object, or get a socket, or we're not connected,
303302
// return NULL
304-
if((zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O",
305-
&object, redis_ce) == FAILURE) ||
306-
(redis_sock = redis_sock_get(object, 1)) == NULL ||
303+
if ((redis_sock = redis_sock_get(getThis(), 1)) == NULL ||
307304
redis_sock->status < REDIS_SOCK_STATUS_CONNECTED)
308305
{
309306
return NULL;
@@ -544,7 +541,7 @@ PHP_METHOD(Redis, pconnect)
544541
PHP_REDIS_API int
545542
redis_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
546543
{
547-
zval *object, *context = NULL, *ele;
544+
zval *context = NULL, *ele;
548545
char *host = NULL, *persistent_id = NULL;
549546
zend_long port = -1, retry_interval = 0;
550547
size_t host_len, persistent_id_len;
@@ -558,14 +555,16 @@ redis_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
558555
persistent = 0;
559556
#endif
560557

561-
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(),
562-
"Os|lds!lda!", &object, redis_ce, &host,
563-
&host_len, &port, &timeout, &persistent_id,
564-
&persistent_id_len, &retry_interval,
565-
&read_timeout, &context) == FAILURE)
566-
{
567-
return FAILURE;
568-
}
558+
ZEND_PARSE_PARAMETERS_START(1, 7)
559+
Z_PARAM_STRING(host, host_len)
560+
Z_PARAM_OPTIONAL
561+
Z_PARAM_LONG(port)
562+
Z_PARAM_DOUBLE(timeout)
563+
Z_PARAM_STRING_OR_NULL(persistent_id, persistent_id_len)
564+
Z_PARAM_LONG(retry_interval)
565+
Z_PARAM_DOUBLE(read_timeout)
566+
Z_PARAM_ARRAY_OR_NULL(context)
567+
ZEND_PARSE_PARAMETERS_END_EX(return FAILURE);
569568

570569
/* Disregard persistent_id if we're not opening a persistent connection */
571570
if (!persistent) {
@@ -597,7 +596,7 @@ redis_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
597596
port = 6379;
598597
}
599598

600-
redis = PHPREDIS_ZVAL_GET_OBJECT(redis_object, object);
599+
redis = PHPREDIS_ZVAL_GET_OBJECT(redis_object, getThis());
601600

602601
/* if there is a redis sock already we have to remove it */
603602
if (redis->sock) {
@@ -1414,18 +1413,19 @@ generic_sort_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, int desc,
14141413
int alpha)
14151414
{
14161415
zend_string *key = NULL, *pattern = NULL, *store = NULL, *zpattern;
1417-
zval *object, *zele, *zget = NULL;
1416+
zval *zele, *zget = NULL;
14181417
zend_long offset = -1, count = -1;
14191418
RedisCmd *cmd;
14201419

1421-
/* Parse myriad of sort arguments */
1422-
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(),
1423-
"OS|S!z!llS", &object, redis_ce, &key,
1424-
&pattern, &zget, &offset, &count, &store)
1425-
== FAILURE)
1426-
{
1427-
return NULL;
1428-
}
1420+
ZEND_PARSE_PARAMETERS_START(1, 6)
1421+
Z_PARAM_STR(key)
1422+
Z_PARAM_OPTIONAL
1423+
Z_PARAM_STR_OR_NULL(pattern)
1424+
Z_PARAM_ZVAL_OR_NULL(zget)
1425+
Z_PARAM_LONG(offset)
1426+
Z_PARAM_LONG(count)
1427+
Z_PARAM_STR(store)
1428+
ZEND_PARSE_PARAMETERS_END_EX(return NULL);
14291429

14301430
/* Ensure we're sorting something, and we can get context */
14311431
if (ZSTR_LEN(key) == 0)
@@ -2110,19 +2110,16 @@ PHP_METHOD(Redis, multi)
21102110
RedisSock *redis_sock;
21112111
char *resp;
21122112
int resp_len;
2113-
zval *object;
21142113
zend_long multi_value = MULTI;
21152114

2116-
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(),
2117-
"O|l", &object, redis_ce, &multi_value)
2118-
== FAILURE)
2119-
{
2120-
RETURN_FALSE;
2121-
}
2115+
ZEND_PARSE_PARAMETERS_START(0, 1)
2116+
Z_PARAM_OPTIONAL
2117+
Z_PARAM_LONG(multi_value)
2118+
ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
21222119

21232120
/* if the flag is activated, send the command, the reply will be "QUEUED"
21242121
* or -ERR */
2125-
if ((redis_sock = redis_sock_get(object, 0)) == NULL) {
2122+
if ((redis_sock = redis_sock_get(getThis(), 0)) == NULL) {
21262123
RETURN_FALSE;
21272124
}
21282125

@@ -2171,14 +2168,12 @@ PHP_METHOD(Redis, discard)
21712168
{
21722169
int ret = FAILURE;
21732170
RedisSock *redis_sock;
2174-
zval *object;
21752171

2176-
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O",
2177-
&object, redis_ce) == FAILURE) {
2172+
if (zend_parse_parameters_none() == FAILURE) {
21782173
RETURN_FALSE;
21792174
}
21802175

2181-
if ((redis_sock = redis_sock_get(object, 0)) == NULL) {
2176+
if ((redis_sock = redis_sock_get(getThis(), 0)) == NULL) {
21822177
RETURN_FALSE;
21832178
}
21842179

@@ -2228,12 +2223,9 @@ PHP_METHOD(Redis, exec)
22282223
{
22292224
RedisSock *redis_sock;
22302225
int ret;
2231-
zval *object, z_ret;
2226+
zval z_ret;
22322227

2233-
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(),
2234-
"O", &object, redis_ce) == FAILURE ||
2235-
(redis_sock = redis_sock_get(object, 0)) == NULL
2236-
) {
2228+
if ((redis_sock = redis_sock_get(getThis(), 0)) == NULL) {
22372229
RETURN_FALSE;
22382230
}
22392231

@@ -2351,12 +2343,8 @@ redis_sock_read_multibulk_multi_reply_loop(INTERNAL_FUNCTION_PARAMETERS,
23512343
PHP_METHOD(Redis, pipeline)
23522344
{
23532345
RedisSock *redis_sock;
2354-
zval *object;
23552346

2356-
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(),
2357-
"O", &object, redis_ce) == FAILURE ||
2358-
(redis_sock = redis_sock_get(object, 0)) == NULL
2359-
) {
2347+
if ((redis_sock = redis_sock_get(getThis(), 0)) == NULL) {
23602348
RETURN_FALSE;
23612349
}
23622350

@@ -2673,18 +2661,10 @@ PHP_METHOD(Redis, _unpack) {
26732661

26742662
/* {{{ proto Redis::getLastError() */
26752663
PHP_METHOD(Redis, getLastError) {
2676-
zval *object;
26772664
RedisSock *redis_sock;
26782665

2679-
// Grab our object
2680-
if(zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O",
2681-
&object, redis_ce) == FAILURE)
2682-
{
2683-
RETURN_FALSE;
2684-
}
2685-
26862666
// Grab socket
2687-
if ((redis_sock = redis_sock_get_instance(object, 0)) == NULL) {
2667+
if ((redis_sock = redis_sock_get_instance(getThis(), 0)) == NULL) {
26882668
RETURN_FALSE;
26892669
}
26902670

@@ -2697,17 +2677,10 @@ PHP_METHOD(Redis, getLastError) {
26972677

26982678
/* {{{ proto Redis::clearLastError() */
26992679
PHP_METHOD(Redis, clearLastError) {
2700-
zval *object;
27012680
RedisSock *redis_sock;
27022681

2703-
// Grab our object
2704-
if(zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O",
2705-
&object, redis_ce) == FAILURE)
2706-
{
2707-
RETURN_FALSE;
2708-
}
27092682
// Grab socket
2710-
if ((redis_sock = redis_sock_get_instance(object, 0)) == NULL) {
2683+
if ((redis_sock = redis_sock_get_instance(getThis(), 0)) == NULL) {
27112684
RETURN_FALSE;
27122685
}
27132686

@@ -2720,16 +2693,10 @@ PHP_METHOD(Redis, clearLastError) {
27202693
* {{{ proto long Redis::getMode()
27212694
*/
27222695
PHP_METHOD(Redis, getMode) {
2723-
zval *object;
27242696
RedisSock *redis_sock;
27252697

2726-
/* Grab our object */
2727-
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &object, redis_ce) == FAILURE) {
2728-
RETURN_FALSE;
2729-
}
2730-
27312698
/* Grab socket */
2732-
if ((redis_sock = redis_sock_get_instance(object, 0)) == NULL) {
2699+
if ((redis_sock = redis_sock_get_instance(getThis(), 0)) == NULL) {
27332700
RETURN_FALSE;
27342701
}
27352702

@@ -2758,16 +2725,14 @@ PHP_METHOD(Redis, role) {
27582725

27592726
/* {{{ proto Redis::IsConnected */
27602727
PHP_METHOD(Redis, isConnected) {
2761-
zval *object;
27622728
RedisSock *redis_sock;
27632729

2764-
/* Grab our object */
2765-
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &object, redis_ce) == FAILURE) {
2730+
if (zend_parse_parameters_none() == FAILURE) {
27662731
RETURN_FALSE;
27672732
}
27682733

27692734
/* Grab socket */
2770-
if ((redis_sock = redis_sock_get_instance(object, 1)) == NULL) {
2735+
if ((redis_sock = redis_sock_get_instance(getThis(), 1)) == NULL) {
27712736
RETURN_FALSE;
27722737
}
27732738

@@ -3015,7 +2980,7 @@ PHP_REDIS_API void
30152980
generic_scan_cmd(INTERNAL_FUNCTION_PARAMETERS, REDIS_SCAN_TYPE type) {
30162981
zend_string *key = NULL, *pattern = NULL;
30172982
zend_string *match_type = NULL;
3018-
zval *object, *z_cursor;
2983+
zval *z_cursor;
30192984
RedisSock *redis_sock;
30202985
zend_bool pattern_free = 0;
30212986
zend_long count = 0;
@@ -3025,27 +2990,21 @@ generic_scan_cmd(INTERNAL_FUNCTION_PARAMETERS, REDIS_SCAN_TYPE type) {
30252990
uint64_t cursor;
30262991
RedisCmd *cmd;
30272992

3028-
/* Different prototype depending on if this is a key based scan */
3029-
if(type != TYPE_SCAN) {
3030-
// Requires a key
3031-
if(zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(),
3032-
"OS!z/|S!l", &object, redis_ce, &key,
3033-
&z_cursor, &pattern, &count)==FAILURE)
3034-
{
3035-
RETURN_FALSE;
2993+
ZEND_PARSE_PARAMETERS_START(1 + (type != TYPE_SCAN), 4)
2994+
if (type != TYPE_SCAN) {
2995+
Z_PARAM_STR_OR_NULL(key)
30362996
}
3037-
} else {
3038-
// Doesn't require a key
3039-
if(zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(),
3040-
"Oz/|S!lS!", &object, redis_ce, &z_cursor,
3041-
&pattern, &count, &match_type) == FAILURE)
3042-
{
3043-
RETURN_FALSE;
2997+
Z_PARAM_ZVAL_EX(z_cursor, 0, 1)
2998+
Z_PARAM_OPTIONAL
2999+
Z_PARAM_STR_OR_NULL(pattern)
3000+
Z_PARAM_LONG(count)
3001+
if (type == TYPE_SCAN) {
3002+
Z_PARAM_STR_OR_NULL(match_type)
30443003
}
3045-
}
3004+
ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
30463005

30473006
/* Grab our socket */
3048-
if ((redis_sock = redis_sock_get(object, 0)) == NULL) {
3007+
if ((redis_sock = redis_sock_get(getThis(), 0)) == NULL) {
30493008
RETURN_FALSE;
30503009
}
30513010

0 commit comments

Comments
 (0)