Skip to content

Commit fa2dc4e

Browse files
committed
WIP: php7 compatibility
RETVAL_STRING and RETVAL_STRINGL always duplicate value
1 parent 70a9cdc commit fa2dc4e

File tree

7 files changed

+28
-18
lines changed

7 files changed

+28
-18
lines changed

cluster_library.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1866,7 +1866,7 @@ PHP_REDIS_API void cluster_variant_resp(INTERNAL_FUNCTION_PARAMETERS, redisClust
18661866
RETVAL_TRUE;
18671867
break;
18681868
case TYPE_BULK:
1869-
RETVAL_STRINGL(r->str, r->len, 0);
1869+
RETVAL_STRINGL(r->str, r->len);
18701870
break;
18711871
case TYPE_MULTIBULK:
18721872
MAKE_STD_ZVAL(z_arr);

cluster_library.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@
116116
/* Helper to return a string value */
117117
#define CLUSTER_RETURN_STRING(c, str, len) \
118118
if(CLUSTER_IS_ATOMIC(c)) { \
119-
RETURN_STRINGL(str, len, 0); \
119+
RETURN_STRINGL(str, len); \
120120
} else { \
121121
add_next_index_stringl(c->multi_resp, str, len, 0); \
122122
} \

common.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,15 @@ inline_zend_get_parameters_array(int ht, int param_count, zval *argument_array T
167167

168168
typedef zend_rsrc_list_entry zend_resource;
169169

170+
#undef RETVAL_STRING
171+
#define RETVAL_STRING(s) ZVAL_STRING(return_value, s, 1)
172+
#undef RETURN_STRING
173+
#define RETURN_STRING(s) { RETVAL_STRING(s); return; }
174+
#undef RETVAL_STRINGL
175+
#define RETVAL_STRINGL(s, l) ZVAL_STRINGL(return_value, s, l, 1)
176+
#undef RETURN_STRINGL
177+
#define RETURN_STRINGL(s, l) { RETVAL_STRINGL(s, l); return; }
178+
170179
#else
171180
#include <ext/standard/php_smart_string.h>
172181
#endif

library.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1206,7 +1206,7 @@ PHP_REDIS_API void redis_long_response(INTERNAL_FUNCTION_PARAMETERS,
12061206
}
12071207
} else {
12081208
if(ret > LONG_MAX) { /* overflow */
1209-
RETURN_STRINGL(response+1, response_len-1, 1);
1209+
RETURN_STRINGL(response+1, response_len-1);
12101210
} else {
12111211
efree(response);
12121212
RETURN_LONG((long)ret);
@@ -1430,10 +1430,9 @@ PHP_REDIS_API void redis_string_response(INTERNAL_FUNCTION_PARAMETERS, RedisSock
14301430
if(redis_unserialize(redis_sock, response, response_len,
14311431
&return_value TSRMLS_CC) == 0)
14321432
{
1433-
RETURN_STRINGL(response, response_len, 0);
1434-
} else {
1435-
efree(response);
1433+
RETVAL_STRINGL(response, response_len);
14361434
}
1435+
efree(response);
14371436
}
14381437
}
14391438

@@ -1458,7 +1457,8 @@ redis_ping_response(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
14581457
IF_MULTI_OR_PIPELINE() {
14591458
add_next_index_stringl(z_tab, response, response_len, 0);
14601459
} else {
1461-
RETURN_STRINGL(response, response_len, 0);
1460+
RETVAL_STRINGL(response, response_len);
1461+
efree(response);
14621462
}
14631463
}
14641464

redis.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3397,7 +3397,7 @@ PHP_METHOD(Redis, getLastError) {
33973397

33983398
/* Return our last error or NULL if we don't have one */
33993399
if(redis_sock->err != NULL && redis_sock->err_len > 0) {
3400-
RETURN_STRINGL(redis_sock->err, redis_sock->err_len, 1);
3400+
RETURN_STRINGL(redis_sock->err, redis_sock->err_len);
34013401
} else {
34023402
RETURN_NULL();
34033403
}
@@ -3478,7 +3478,7 @@ PHP_METHOD(Redis, getHost) {
34783478
RedisSock *redis_sock;
34793479

34803480
if((redis_sock = redis_sock_get_connected(INTERNAL_FUNCTION_PARAM_PASSTHRU))) {
3481-
RETURN_STRING(redis_sock->host, 1);
3481+
RETURN_STRING(redis_sock->host);
34823482
} else {
34833483
RETURN_FALSE;
34843484
}
@@ -3536,7 +3536,7 @@ PHP_METHOD(Redis, getPersistentID) {
35363536

35373537
if((redis_sock = redis_sock_get_connected(INTERNAL_FUNCTION_PARAM_PASSTHRU))) {
35383538
if(redis_sock->persistent_id != NULL) {
3539-
RETURN_STRING(redis_sock->persistent_id, 1);
3539+
RETURN_STRING(redis_sock->persistent_id);
35403540
} else {
35413541
RETURN_NULL();
35423542
}
@@ -3551,7 +3551,7 @@ PHP_METHOD(Redis, getAuth) {
35513551

35523552
if((redis_sock = redis_sock_get_connected(INTERNAL_FUNCTION_PARAM_PASSTHRU))) {
35533553
if(redis_sock->auth != NULL) {
3554-
RETURN_STRING(redis_sock->auth, 1);
3554+
RETURN_STRING(redis_sock->auth);
35553555
} else {
35563556
RETURN_NULL();
35573557
}

redis_cluster.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1952,7 +1952,7 @@ PHP_METHOD(RedisCluster, getlasterror) {
19521952
redisCluster *c = GET_CONTEXT();
19531953

19541954
if(c->err != NULL && c->err_len > 0) {
1955-
RETURN_STRINGL(c->err, c->err_len, 1);
1955+
RETURN_STRINGL(c->err, c->err_len);
19561956
} else {
19571957
RETURN_NULL();
19581958
}
@@ -2043,7 +2043,7 @@ PHP_METHOD(RedisCluster, _redir) {
20432043

20442044
len = snprintf(buf, sizeof(buf), "%s:%d", c->redir_host, c->redir_port);
20452045
if(*c->redir_host && c->redir_host_len) {
2046-
RETURN_STRINGL(buf, len, 1);
2046+
RETURN_STRINGL(buf, len);
20472047
} else {
20482048
RETURN_NULL();
20492049
}

redis_commands.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3089,7 +3089,7 @@ void redis_getoption_handler(INTERNAL_FUNCTION_PARAMETERS,
30893089
RETURN_LONG(redis_sock->serializer);
30903090
case REDIS_OPT_PREFIX:
30913091
if(redis_sock->prefix) {
3092-
RETURN_STRINGL(redis_sock->prefix, redis_sock->prefix_len, 1);
3092+
RETURN_STRINGL(redis_sock->prefix, redis_sock->prefix_len);
30933093
}
30943094
RETURN_NULL();
30953095
case REDIS_OPT_READ_TIMEOUT:
@@ -3193,9 +3193,10 @@ void redis_prefix_handler(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock) {
31933193

31943194
if(redis_sock->prefix != NULL && redis_sock->prefix_len>0) {
31953195
redis_key_prefix(redis_sock, &key, &key_len);
3196-
RETURN_STRINGL(key, key_len, 0);
3196+
RETVAL_STRINGL(key, key_len);
3197+
efree(key);
31973198
} else {
3198-
RETURN_STRINGL(key, key_len, 1);
3199+
RETURN_STRINGL(key, key_len);
31993200
}
32003201
}
32013202

@@ -3212,7 +3213,7 @@ void redis_serialize_handler(INTERNAL_FUNCTION_PARAMETERS,
32123213

32133214
int val_free = redis_serialize(redis_sock, z_val, &val, &val_len TSRMLS_CC);
32143215

3215-
RETVAL_STRINGL(val, val_len, 1);
3216+
RETVAL_STRINGL(val, val_len);
32163217
if(val_free) STR_FREE(val);
32173218
}
32183219

@@ -3244,7 +3245,7 @@ void redis_unserialize_handler(INTERNAL_FUNCTION_PARAMETERS,
32443245
RETURN_ZVAL(z_ret, 0, 1);
32453246
} else {
32463247
// Just return the value that was passed to us
3247-
RETURN_STRINGL(value, value_len, 1);
3248+
RETURN_STRINGL(value, value_len);
32483249
}
32493250
}
32503251

0 commit comments

Comments
 (0)