Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/phpredis/phpredis.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common.h10
-rw-r--r--redis.c7
-rw-r--r--redis_array.c18
-rw-r--r--redis_array_impl.c38
4 files changed, 31 insertions, 42 deletions
diff --git a/common.h b/common.h
index 4322dedd..1b60da11 100644
--- a/common.h
+++ b/common.h
@@ -35,11 +35,12 @@ typedef struct {
#define ZEND_HASH_FOREACH_KEY_VAL(ht, _h, _key, _val) do { \
HashPosition _hpos; \
for (zend_hash_internal_pointer_reset_ex(ht, &_hpos); \
- (_val = zend_hash_get_current_data_ex(ht, &_hpos)) != NULL; \
+ zend_hash_has_more_elements_ex(ht, &_hpos) == SUCCESS; \
zend_hash_move_forward_ex(ht, &_hpos) \
) { \
zend_string _zstr = {0}; \
char *_str_index; uint _str_length; ulong _num_index; \
+ _val = zend_hash_get_current_data_ex(ht, &_hpos); \
switch (zend_hash_get_current_key_ex(ht, &_str_index, &_str_length, &_num_index, 0, &_hpos)) { \
case HASH_KEY_IS_STRING: \
_zstr.len = _str_length - 1; \
@@ -51,15 +52,16 @@ typedef struct {
_h = _num_index; \
break; \
default: \
- continue; \
+ /* noop */ break; \
}
#define ZEND_HASH_FOREACH_VAL(ht, _val) do { \
HashPosition _hpos; \
for (zend_hash_internal_pointer_reset_ex(ht, &_hpos); \
- (_val = zend_hash_get_current_data_ex(ht, &_hpos)) != NULL; \
+ zend_hash_has_more_elements_ex(ht, &_hpos) == SUCCESS; \
zend_hash_move_forward_ex(ht, &_hpos) \
- ) {
+ ) { \
+ _val = zend_hash_get_current_data_ex(ht, &_hpos); \
#define ZEND_HASH_FOREACH_END() \
} \
diff --git a/redis.c b/redis.c
index 082ec35b..e659aa99 100644
--- a/redis.c
+++ b/redis.c
@@ -1270,13 +1270,6 @@ PHP_METHOD(Redis, pconnect)
if (redis_connect(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1) == FAILURE) {
RETURN_FALSE;
} else {
- /* FIXME: should we remove whole `else` block? */
- /* reset multi/exec state if there is one. */
- RedisSock *redis_sock;
- if ((redis_sock = redis_sock_get(getThis() TSRMLS_CC, 0)) == NULL) {
- RETURN_FALSE;
- }
-
RETURN_TRUE;
}
}
diff --git a/redis_array.c b/redis_array.c
index d7da7490..311b34bc 100644
--- a/redis_array.c
+++ b/redis_array.c
@@ -814,25 +814,23 @@ PHP_METHOD(RedisArray, select)
#define HANDLE_MULTI_EXEC(ra, cmd) do { \
if (ra && ra->z_multi_exec) { \
int i, num_varargs;\
- zval ***varargs = NULL;\
- zval z_arg_array;\
+ zval ***varargs = NULL, *z_arg_array; \
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O*",\
&object, redis_array_ce, &varargs, &num_varargs) == FAILURE) {\
RETURN_FALSE;\
}\
/* copy all args into a zval hash table */\
- array_init(&z_arg_array);\
+ MAKE_STD_ZVAL(z_arg_array); \
+ array_init(z_arg_array);\
for(i = 0; i < num_varargs; ++i) {\
zval *z_tmp;\
- MAKE_STD_ZVAL(z_tmp);\
- *z_tmp = **varargs[i];\
- zval_copy_ctor(z_tmp);\
- INIT_PZVAL(z_tmp);\
- add_next_index_zval(&z_arg_array, z_tmp);\
+ MAKE_STD_ZVAL(z_tmp); \
+ ZVAL_ZVAL(z_tmp, *varargs[i], 1, 0); \
+ add_next_index_zval(z_arg_array, z_tmp); \
}\
/* call */\
- ra_forward_call(INTERNAL_FUNCTION_PARAM_PASSTHRU, ra, cmd, sizeof(cmd)-1, &z_arg_array, NULL);\
- zval_dtor(&z_arg_array);\
+ ra_forward_call(INTERNAL_FUNCTION_PARAM_PASSTHRU, ra, cmd, sizeof(cmd) - 1, z_arg_array, NULL); \
+ zval_ptr_dtor(&z_arg_array); \
if(varargs) {\
efree(varargs);\
}\
diff --git a/redis_array_impl.c b/redis_array_impl.c
index 56698157..9ccfffe1 100644
--- a/redis_array_impl.c
+++ b/redis_array_impl.c
@@ -583,9 +583,8 @@ ra_index_keys(zval *z_pairs, zval *z_redis TSRMLS_DC) {
zval zv, *z_new = &zv;
#if (PHP_MAJOR_VERSION < 7)
MAKE_STD_ZVAL(z_new);
-#else
- PHPREDIS_NOTUSED(z_val);
#endif
+ PHPREDIS_NOTUSED(z_val);
if (zkey) {
ZVAL_STRINGL(z_new, ZSTR_VAL(zkey), ZSTR_LEN(zkey));
@@ -695,46 +694,43 @@ ra_is_write_cmd(RedisArray *ra, const char *cmd, int cmd_len) {
static zend_bool
ra_get_key_type(zval *z_redis, const char *key, int key_len, zval *z_from, long *res TSRMLS_DC) {
- int i;
- zval z_fun_type, z_ret, z_arg[1];
- zval *z_data;
+ int i = 0;
+ zval z_fun, z_ret, z_arg, *z_data;
long success = 1;
/* Pipelined */
ra_index_multi(z_from, PIPELINE TSRMLS_CC);
/* prepare args */
- ZVAL_STRINGL(&z_arg[0], key, key_len);
+ ZVAL_STRINGL(&z_arg, key, key_len);
/* run TYPE */
- ZVAL_STRINGL(&z_fun_type, "TYPE", 4);
- call_user_function(&redis_ce->function_table, z_redis, &z_fun_type, &z_ret, 1, z_arg);
- zval_dtor(&z_fun_type);
+ ZVAL_NULL(&z_ret);
+ ZVAL_STRINGL(&z_fun, "TYPE", 4);
+ call_user_function(&redis_ce->function_table, z_redis, &z_fun, &z_ret, 1, &z_arg);
+ zval_dtor(&z_fun);
zval_dtor(&z_ret);
/* run TYPE */
- ZVAL_STRINGL(&z_fun_type, "TTL", 3);
- call_user_function(&redis_ce->function_table, z_redis, &z_fun_type, &z_ret, 1, z_arg);
- zval_dtor(&z_fun_type);
+ ZVAL_NULL(&z_ret);
+ ZVAL_STRINGL(&z_fun, "TTL", 3);
+ call_user_function(&redis_ce->function_table, z_redis, &z_fun, &z_ret, 1, &z_arg);
+ zval_dtor(&z_fun);
zval_dtor(&z_ret);
/* Get the result from the pipeline. */
ra_index_exec(z_from, &z_ret, 1 TSRMLS_CC);
- if(Z_TYPE(z_ret) == IS_ARRAY) {
- HashTable *retHash = Z_ARRVAL(z_ret);
- for(i = 0, zend_hash_internal_pointer_reset(retHash);
- zend_hash_has_more_elements(retHash) == SUCCESS;
- zend_hash_move_forward(retHash)) {
-
- if ((z_data = zend_hash_get_current_data(retHash)) == NULL || Z_TYPE_P(z_data) != IS_LONG) {
+ if (Z_TYPE(z_ret) == IS_ARRAY) {
+ ZEND_HASH_FOREACH_VAL(Z_ARRVAL(z_ret), z_data) {
+ if (z_data == NULL || Z_TYPE_P(z_data) != IS_LONG) {
success = 0;
break;
}
/* Get the result - Might change in the future to handle doubles as well */
res[i++] = Z_LVAL_P(z_data);
- }
+ } ZEND_HASH_FOREACH_END();
}
- zval_dtor(&z_arg[0]);
+ zval_dtor(&z_arg);
zval_dtor(&z_ret);
return success;
}