Skip to content

Commit

Permalink
php7 compatibility
Browse files Browse the repository at this point in the history
All tests passed. \o/
  • Loading branch information
yatsukhnenko committed Nov 12, 2016
1 parent f77c6fa commit ca4dc3b
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 38 deletions.
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ php:
- nightly
matrix:
allow_failures:
- php: 7.0
- php: 7.1
- php: nightly
before_install: phpize
install: ./configure CFLAGS=-Wall --prefix=/usr && sudo make install
Expand Down
32 changes: 19 additions & 13 deletions cluster_library.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,14 @@ static void
cluster_multibulk_resp_recursive(RedisSock *sock, size_t elements,
clusterReply **element, int *err TSRMLS_DC)
{
size_t idx = 0, sz;
int i;
size_t sz;
clusterReply *r;
long len;
char buf[1024];

while(elements-- > 0) {
element[idx] = ecalloc(1, sizeof(clusterReply));
r = element[idx];
for (i = 0; i < elements; i++) {
r = element[i] = ecalloc(1, sizeof(clusterReply));

// Bomb out, flag error condition on a communication failure
if(redis_read_reply_type(sock, &r->type, &len TSRMLS_CC)<0) {
Expand Down Expand Up @@ -158,7 +158,7 @@ cluster_multibulk_resp_recursive(RedisSock *sock, size_t elements,
}
break;
case TYPE_MULTIBULK:
r->element = ecalloc(r->len,r->len*sizeof(clusterReply*));
r->element = ecalloc(r->len,sizeof(clusterReply*));
r->elements = r->len;
cluster_multibulk_resp_recursive(sock, r->elements, r->element,
err TSRMLS_CC);
Expand All @@ -168,8 +168,6 @@ cluster_multibulk_resp_recursive(RedisSock *sock, size_t elements,
*err = 1;
return;
}

idx++;
}
}

Expand Down Expand Up @@ -2032,7 +2030,7 @@ PHP_REDIS_API void cluster_info_resp(INTERNAL_FUNCTION_PARAMETERS, redisCluster

// Return our array
if(CLUSTER_IS_ATOMIC(c)) {
RETVAL_ZVAL(z_result, 0, 1);
RETVAL_ZVAL(z_result, 1, 0);
} else {
add_next_index_zval(&c->multi_resp, z_result);
}
Expand Down Expand Up @@ -2341,7 +2339,10 @@ int mbulk_resp_loop(RedisSock *redis_sock, zval *z_result,
line = redis_sock_read(redis_sock, &line_len TSRMLS_CC);

if (line != NULL) {
zval *z = NULL;
zval zv, *z = &zv;
#if (PHP_MAJOR_VERSION < 7)
z = NULL;
#endif
if(redis_unserialize(redis_sock, line, line_len, &z TSRMLS_CC)==1) {
add_next_index_zval(z_result, z);
} else {
Expand Down Expand Up @@ -2382,7 +2383,10 @@ int mbulk_resp_loop_zipstr(RedisSock *redis_sock, zval *z_result,
key_len = line_len;
} else {
/* Attempt serialization */
zval *z = NULL;
zval zv, *z = &zv;
#if (PHP_MAJOR_VERSION < 7)
z = NULL;
#endif
if(redis_unserialize(redis_sock, line, line_len, &z TSRMLS_CC)==1) {
add_assoc_zval(z_result, key, z);
} else {
Expand Down Expand Up @@ -2417,12 +2421,11 @@ int mbulk_resp_loop_zipdbl(RedisSock *redis_sock, zval *z_result,
key = line;
key_len = line_len;
} else {
zval *z = NULL;
zval zv, *z = &zv;
if (redis_unserialize(redis_sock,key,key_len, &z TSRMLS_CC)) {
convert_to_string(z);
add_assoc_double_ex(z_result, Z_STRVAL_P(z), Z_STRLEN_P(z), atof(line));
zval_dtor(z);
efree(z);
} else {
add_assoc_double_ex(z_result, key, key_len, atof(line));
}
Expand Down Expand Up @@ -2450,7 +2453,10 @@ int mbulk_resp_loop_assoc(RedisSock *redis_sock, zval *z_result,
line = redis_sock_read(redis_sock, &line_len TSRMLS_CC);

if(line != NULL) {
zval *z = NULL;
zval zv, *z = &zv;
#if (PHP_MAJOR_VERSION < 7)
z = NULL;
#endif
if(redis_unserialize(redis_sock, line, line_len, &z TSRMLS_CC)==1) {
add_assoc_zval_ex(z_result,Z_STRVAL(z_keys[i]),
Z_STRLEN(z_keys[i]), z);
Expand Down
28 changes: 7 additions & 21 deletions library.c
Original file line number Diff line number Diff line change
Expand Up @@ -975,11 +975,9 @@ PHP_REDIS_API void redis_client_list_reply(INTERNAL_FUNCTION_PARAMETERS, RedisSo
RETURN_FALSE;
}

zval zv, *z_ret = &zv;
#if (PHP_MAJOR_VERSION < 7)
zval *z_ret;
MAKE_STD_ZVAL(z_ret);
#else
zval zv, *z_ret = &zv;
#endif

/* Parse it out */
Expand Down Expand Up @@ -1287,11 +1285,9 @@ redis_mbulk_reply_zipped(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
return -1;
}
numElems = atoi(inbuf+1);
zval zv, *z_multi_result = &zv;
#if (PHP_MAJOR_VERSION < 7)
zval *z_multi_result;
MAKE_STD_ZVAL(z_multi_result);
#else
zval zv, *z_multi_result = &zv;
#endif
array_init(z_multi_result); /* pre-allocate array for multi's results. */

Expand Down Expand Up @@ -1456,11 +1452,9 @@ PHP_REDIS_API void redis_debug_response(INTERNAL_FUNCTION_PARAMETERS, RedisSock
RETURN_FALSE;
}

zval zv, *z_result = &zv;
#if (PHP_MAJOR_VERSION < 7)
zval *z_result;
MAKE_STD_ZVAL(z_result);
#else
zval zv, *z_result = &zv;
#endif
array_init(z_result);

Expand Down Expand Up @@ -1783,11 +1777,9 @@ PHP_REDIS_API int redis_sock_read_multibulk_reply(INTERNAL_FUNCTION_PARAMETERS,
return -1;
}
numElems = atoi(inbuf+1);
zval zv, *z_multi_result = &zv;
#if (PHP_MAJOR_VERSION < 7)
zval *z_multi_result;
MAKE_STD_ZVAL(z_multi_result);
#else
zval zv, *z_multi_result = &zv;
#endif
array_init(z_multi_result); /* pre-allocate array for multi's results. */

Expand Down Expand Up @@ -1832,11 +1824,9 @@ PHP_REDIS_API int redis_mbulk_reply_raw(INTERNAL_FUNCTION_PARAMETERS, RedisSock
return -1;
}
numElems = atoi(inbuf+1);
zval zv, *z_multi_result = &zv;
#if (PHP_MAJOR_VERSION < 7)
zval *z_multi_result;
MAKE_STD_ZVAL(z_multi_result);
#else
zval zv, *z_multi_result = &zv;
#endif
array_init(z_multi_result); /* pre-allocate array for multi's results. */

Expand Down Expand Up @@ -1917,11 +1907,9 @@ PHP_REDIS_API int redis_mbulk_reply_assoc(INTERNAL_FUNCTION_PARAMETERS, RedisSoc
return -1;
}
numElems = atoi(inbuf+1);
zval zv, *z_multi_result = &zv;
#if (PHP_MAJOR_VERSION < 7)
zval *z_multi_result;
MAKE_STD_ZVAL(z_multi_result);
#else
zval zv, *z_multi_result = &zv;
#endif
array_init(z_multi_result); /* pre-allocate array for multi's results. */

Expand Down Expand Up @@ -2371,11 +2359,9 @@ redis_read_variant_reply(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
return -1;
}

zval zv, *z_ret = &zv;
#if (PHP_MAJOR_VERSION < 7)
zval *z_ret;
MAKE_STD_ZVAL(z_ret);
#else
zval zv, *z_ret = &zv;
#endif
/* Switch based on our top level reply type */
switch(reply_type) {
Expand Down
2 changes: 1 addition & 1 deletion php_redis.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#define PHP_REDIS_H

/* phpredis version */
#define PHP_REDIS_VERSION "2.2.8-rc1"
#define PHP_REDIS_VERSION "3.1.0-rc1"

PHP_METHOD(Redis, __construct);
PHP_METHOD(Redis, __destruct);
Expand Down
3 changes: 2 additions & 1 deletion redis_cluster.c
Original file line number Diff line number Diff line change
Expand Up @@ -2711,7 +2711,8 @@ PHP_METHOD(RedisCluster, info) {
redisCluster *c = GET_CONTEXT();
REDIS_REPLY_TYPE rtype;
char *cmd, *opt=NULL;
int cmd_len, opt_len;
int cmd_len;
size_t opt_len;
void *ctx = NULL;
zval *z_arg;
short slot;
Expand Down

0 comments on commit ca4dc3b

Please sign in to comment.