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

Skip to content

Commit 6d104fc

Browse files
authored
Merge pull request #1018 from yatsukhnenko/develop
refactoring
2 parents efb0030 + eab9327 commit 6d104fc

4 files changed

Lines changed: 29 additions & 35 deletions

File tree

cluster_library.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2150,8 +2150,7 @@ PHP_REDIS_API void cluster_mbulk_mget_resp(INTERNAL_FUNCTION_PARAMETERS,
21502150
// If this is the tail of our multi command, we can set our returns
21512151
if(mctx->last) {
21522152
if(CLUSTER_IS_ATOMIC(c)) {
2153-
*return_value = *(mctx->z_multi);
2154-
efree(mctx->z_multi);
2153+
RETVAL_ZVAL(mctx->z_multi, 0, 1);
21552154
} else {
21562155
add_next_index_zval(&c->multi_resp, mctx->z_multi);
21572156
}
@@ -2186,8 +2185,7 @@ PHP_REDIS_API void cluster_msetnx_resp(INTERNAL_FUNCTION_PARAMETERS, redisCluste
21862185
// Set return value if it's our last response
21872186
if(mctx->last) {
21882187
if(CLUSTER_IS_ATOMIC(c)) {
2189-
*return_value = *(mctx->z_multi);
2190-
efree(mctx->z_multi);
2188+
RETVAL_ZVAL(mctx->z_multi, 0, 1);
21912189
} else {
21922190
add_next_index_zval(&c->multi_resp, mctx->z_multi);
21932191
}
@@ -2237,18 +2235,23 @@ PHP_REDIS_API void cluster_mset_resp(INTERNAL_FUNCTION_PARAMETERS, redisCluster
22372235
if(c->reply_type != TYPE_LINE) {
22382236
php_error_docref(0 TSRMLS_CC, E_ERROR,
22392237
"Invalid reply type returned for MSET command");
2240-
ZVAL_FALSE(return_value);
2238+
zval_dtor(mctx->z_multi);
22412239
efree(mctx->z_multi);
22422240
efree(mctx);
2243-
return;
2241+
RETURN_FALSE;
22442242
}
22452243

22462244
// Set our return if it's the last call
22472245
if(mctx->last) {
2246+
#if (PHP_MAJOR_VERSION < 7)
2247+
zend_bool bval = Z_LVAL_P(mctx->z_multi);
2248+
#else
2249+
zend_bool bval = (Z_TYPE_P(mctx->z_multi) == IS_TRUE);
2250+
#endif
22482251
if(CLUSTER_IS_ATOMIC(c)) {
2249-
ZVAL_BOOL(return_value, Z_LVAL_P(mctx->z_multi));
2252+
ZVAL_BOOL(return_value, bval);
22502253
} else {
2251-
add_next_index_bool(&c->multi_resp, Z_LVAL_P(mctx->z_multi));
2254+
add_next_index_bool(&c->multi_resp, bval);
22522255
}
22532256
efree(mctx->z_multi);
22542257
}

library.c

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,11 +1003,9 @@ redis_parse_client_list_response(char *response, zval *z_ret)
10031003
array_init(z_ret);
10041004

10051005
/* Allocate memory for one user (there should be at least one, namely us!) */
1006+
zval zv, *z_sub_result = &zv;
10061007
#if (PHP_MAJOR_VERSION < 7)
1007-
zval *z_sub_result;
10081008
ALLOC_INIT_ZVAL(z_sub_result);
1009-
#else
1010-
zval zv, *z_sub_result = &zv;
10111009
#endif
10121010
array_init(z_sub_result);
10131011

@@ -1244,7 +1242,7 @@ static void array_zip_values_and_scores(RedisSock *redis_sock, zval *z_tab,
12441242
} else if (decode == SCORE_DECODE_DOUBLE) {
12451243
add_assoc_double_ex(z_ret, hkey, hkey_len, atof(hval));
12461244
} else {
1247-
zval zv, *z = &zv;
1245+
zval zv0, *z = &zv0;
12481246
#if (PHP_MAJOR_VERSION < 7)
12491247
MAKE_STD_ZVAL(z);
12501248
#endif
@@ -1702,12 +1700,8 @@ PHP_REDIS_API void redis_send_discard(INTERNAL_FUNCTION_PARAMETERS,
17021700
RETURN_FALSE;
17031701
}
17041702

1705-
if(response_len == 3 && strncmp(response, "+OK", 3) == 0) {
1706-
efree(response);
1707-
RETURN_TRUE;
1708-
}
1703+
RETVAL_BOOL(response_len == 3 && strncmp(response, "+OK", 3) == 0);
17091704
efree(response);
1710-
RETURN_FALSE;
17111705
}
17121706

17131707
/**
@@ -1915,7 +1909,7 @@ PHP_REDIS_API int redis_mbulk_reply_assoc(INTERNAL_FUNCTION_PARAMETERS, RedisSoc
19151909
for(i = 0; i < numElems; ++i) {
19161910
response = redis_sock_read(redis_sock, &response_len TSRMLS_CC);
19171911
if(response != NULL) {
1918-
zval zv, *z = &zv;
1912+
zval zv0, *z = &zv0;
19191913
#if (PHP_MAJOR_VERSION < 7)
19201914
z = NULL;
19211915
#endif
@@ -2386,6 +2380,9 @@ redis_read_variant_reply(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
23862380
}
23872381
break;
23882382
default:
2383+
#if (PHP_MAJOR_VERSION < 7)
2384+
efree(z_ret);
2385+
#endif
23892386
// Protocol error
23902387
zend_throw_exception_ex(redis_exception_ce, 0 TSRMLS_CC,
23912388
"protocol error, got '%c' as reply-type byte\n", reply_type);

redis.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3257,7 +3257,7 @@ PHP_METHOD(Redis, script) {
32573257

32583258
/* {{{ proto DUMP key */
32593259
PHP_METHOD(Redis, dump) {
3260-
REDIS_PROCESS_KW_CMD("DUMP", redis_key_cmd, redis_ping_response);
3260+
REDIS_PROCESS_KW_CMD("DUMP", redis_key_cmd, redis_string_response);
32613261
}
32623262
/* }}} */
32633263

redis_array.c

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,6 +1085,8 @@ PHP_METHOD(RedisArray, mset)
10851085
} ZEND_HASH_FOREACH_END();
10861086

10871087

1088+
/* prepare call */
1089+
ZVAL_STRINGL(&z_fun, "MSET", 4);
10881090
/* calls */
10891091
for(n = 0; n < ra->count; ++n) { /* for each node */
10901092
int found = 0;
@@ -1093,11 +1095,9 @@ PHP_METHOD(RedisArray, mset)
10931095
array_init(&z_argarray);
10941096
for(i = 0; i < argc; ++i) {
10951097
if(pos[i] != n) continue;
1098+
zval zv, *z_tmp = &zv;
10961099
#if (PHP_MAJOR_VERSION < 7)
1097-
zval *z_tmp;
10981100
MAKE_STD_ZVAL(z_tmp);
1099-
#else
1100-
zval zv, *z_tmp = &zv;
11011101
#endif
11021102
ZVAL_ZVAL(z_tmp, argv[i], 1, 0);
11031103
add_assoc_zval_ex(&z_argarray, keys[i], key_lens[i], z_tmp);
@@ -1110,25 +1110,21 @@ PHP_METHOD(RedisArray, mset)
11101110
continue; /* don't run empty MSETs */
11111111
}
11121112

1113-
/* prepare call */
1114-
ZVAL_STRINGL(&z_fun, "MSET", 4);
11151113
if(ra->index) { /* add MULTI */
11161114
ra_index_multi(&ra->redis[n], MULTI TSRMLS_CC);
11171115
}
11181116

11191117
/* call */
11201118
call_user_function(&redis_ce->function_table, &ra->redis[n], &z_fun, &z_ret, 1, &z_argarray);
1119+
zval_dtor(&z_ret);
11211120

11221121
if(ra->index) {
11231122
ra_index_keys(&z_argarray, &ra->redis[n] TSRMLS_CC); /* use SADD to add keys to node index */
11241123
ra_index_exec(&ra->redis[n], NULL, 0 TSRMLS_CC); /* run EXEC */
11251124
}
1126-
1127-
zval_dtor(&z_fun);
1128-
zval_dtor(&z_ret);
1129-
11301125
zval_dtor(&z_argarray);
11311126
}
1127+
zval_dtor(&z_fun);
11321128

11331129
/* Free any keys that we needed to allocate memory for, because they weren't strings */
11341130
for(i = 0; i < argc; i++) {
@@ -1162,7 +1158,9 @@ PHP_METHOD(RedisArray, del)
11621158

11631159
/* get all args in z_args */
11641160
z_args = emalloc(argc * sizeof(zval));
1165-
if (zend_get_parameters_array(ht, argc, z_args) == FAILURE) {
1161+
if (zend_get_parameters_array(ht, argc, z_args) == FAILURE ||
1162+
redis_array_get(getThis(), &ra TSRMLS_CC) < 0
1163+
) {
11661164
efree(z_args);
11671165
RETURN_FALSE;
11681166
}
@@ -1188,12 +1186,6 @@ PHP_METHOD(RedisArray, del)
11881186
free_zkeys = 1;
11891187
}
11901188

1191-
1192-
if (redis_array_get(getThis(), &ra TSRMLS_CC) < 0) {
1193-
efree(z_args);
1194-
RETURN_FALSE;
1195-
}
1196-
11971189
/* prepare call */
11981190
ZVAL_STRINGL(&z_fun, "DEL", 3);
11991191

@@ -1211,6 +1203,8 @@ PHP_METHOD(RedisArray, del)
12111203
ZEND_HASH_FOREACH_VAL(h_keys, data) {
12121204
if (Z_TYPE_P(data) != IS_STRING) {
12131205
php_error_docref(NULL TSRMLS_CC, E_ERROR, "DEL: all keys must be string.");
1206+
if (free_zkeys) zval_dtor(&z_keys);
1207+
efree(z_args);
12141208
efree(argv);
12151209
efree(pos);
12161210
RETURN_FALSE;

0 commit comments

Comments
 (0)