WIP: php7 compatibility

zend_list_insert + add_assoc_string + add_assoc_zval
This commit is contained in:
Pavlo Yatsukhnenko
2016-10-27 12:43:57 +03:00
parent bff08f7afb
commit 8cfebfd98b
5 changed files with 29 additions and 16 deletions
+3 -3
View File
@@ -2384,7 +2384,7 @@ int mbulk_resp_loop_zipstr(RedisSock *redis_sock, zval *z_result,
if(redis_unserialize(redis_sock, line, line_len, &z TSRMLS_CC)==1) {
add_assoc_zval(z_result, key, z);
} else {
add_assoc_stringl_ex(z_result, key, 1+key_len, line, line_len);
add_assoc_stringl_ex(z_result, key, key_len, line, line_len);
}
efree(line);
efree(key);
@@ -2451,10 +2451,10 @@ int mbulk_resp_loop_assoc(RedisSock *redis_sock, zval *z_result,
zval *z = NULL;
if(redis_unserialize(redis_sock, line, line_len, &z TSRMLS_CC)==1) {
add_assoc_zval_ex(z_result,Z_STRVAL_P(z_keys[i]),
1+Z_STRLEN_P(z_keys[i]), z);
Z_STRLEN_P(z_keys[i]), z);
} else {
add_assoc_stringl_ex(z_result, Z_STRVAL_P(z_keys[i]),
1+Z_STRLEN_P(z_keys[i]), line, line_len);
Z_STRLEN_P(z_keys[i]), line, line_len);
}
efree(line);
} else {
+11 -1
View File
@@ -222,8 +222,18 @@ inline_call_user_function(HashTable *function_table, zval *object, zval *functio
#define _IS_BOOL IS_BOOL
#define ZEND_SAME_FAKE_TYPE(faketype, realtype) ((faketype) == (realtype))
#undef add_assoc_string
#define add_assoc_string(__arg, __key, __str) add_assoc_string_ex(__arg, __key, strlen(__key), __str)
static int (*_add_assoc_string_ex)(zval *, const char *, uint, char *, int) = &add_assoc_string_ex;
#define add_assoc_string_ex(_arg, _key, _key_len, _str) _add_assoc_string_ex(_arg, _key, _key_len + 1, _str, 1)
static int (*_add_assoc_stringl_ex)(zval *, const char *, uint, char *, uint, int) = &add_assoc_stringl_ex;
#define add_assoc_stringl_ex(_arg, _key, _key_len, _str, _length) _add_assoc_stringl_ex(_arg, _key, _key_len, _str, _length, 1)
#define add_assoc_stringl_ex(_arg, _key, _key_len, _str, _length) _add_assoc_stringl_ex(_arg, _key, _key_len + 1, _str, _length, 1)
#undef add_assoc_zval
#define add_assoc_zval(__arg, __key, __value) add_assoc_zval_ex(__arg, __key, strlen(__key), __value)
static int (*_add_assoc_zval_ex)(zval *, const char *, uint, zval *) = &add_assoc_zval_ex;
#define add_assoc_zval_ex(_arg, _key, _key_len, _value) _add_assoc_zval_ex(_arg, _key, _key_len + 1, _value);
#else
#include <ext/standard/php_smart_string.h>
+9 -9
View File
@@ -971,10 +971,10 @@ PHP_REDIS_API zval *redis_parse_info_response(char *response) {
if(is_numeric == 1) {
add_assoc_long(z_ret, key, atol(value));
efree(value);
} else {
add_assoc_string(z_ret, key, value, 0);
add_assoc_string(z_ret, key, value);
}
efree(value);
efree(key);
}
@@ -1061,10 +1061,10 @@ PHP_REDIS_API zval* redis_parse_client_list_response(char *response) {
/* Add as a long or string, depending */
if(is_numeric == 1) {
add_assoc_long(z_sub_result, key, atol(value));
efree(value);
} else {
add_assoc_string(z_sub_result, key, value, 0);
add_assoc_string(z_sub_result, key, value);
}
efree(value);
// If we hit a '\n', then we can add this user to our list
if(*p == '\n') {
/* Add our user */
@@ -1262,7 +1262,7 @@ static void array_zip_values_and_scores(RedisSock *redis_sock, zval *z_tab,
MAKE_STD_ZVAL(z);
*z = *z_value_p;
zval_copy_ctor(z);
add_assoc_zval_ex(z_ret, hkey, 1+hkey_len, z);
add_assoc_zval_ex(z_ret, hkey, hkey_len, z);
}
}
@@ -1496,7 +1496,7 @@ PHP_REDIS_API void redis_debug_response(INTERNAL_FUNCTION_PARAMETERS, RedisSock
if(is_numeric) {
add_assoc_long(z_result, p, atol(p2));
} else {
add_assoc_string(z_result, p, p2, 1);
add_assoc_string(z_result, p, p2);
}
p = p3;
@@ -1609,7 +1609,7 @@ PHP_REDIS_API int redis_sock_connect(RedisSock *redis_sock TSRMLS_DC)
}
redis_sock->stream = php_stream_xport_create(host, host_len,
ENFORCE_SAFE_MODE, STREAM_XPORT_CLIENT | STREAM_XPORT_CONNECT,
0, STREAM_XPORT_CLIENT | STREAM_XPORT_CONNECT,
persistent_id, tv_ptr, NULL, &errstr, &err);
if (persistent_id) {
@@ -1925,9 +1925,9 @@ PHP_REDIS_API int redis_mbulk_reply_assoc(INTERNAL_FUNCTION_PARAMETERS, RedisSoc
if(response != NULL) {
zval *z = NULL;
if(redis_unserialize(redis_sock, response, response_len, &z TSRMLS_CC) == 1) {
add_assoc_zval_ex(z_multi_result, Z_STRVAL_P(z_keys[i]), 1+Z_STRLEN_P(z_keys[i]), z);
add_assoc_zval_ex(z_multi_result, Z_STRVAL_P(z_keys[i]), Z_STRLEN_P(z_keys[i]), z);
} else {
add_assoc_stringl_ex(z_multi_result, Z_STRVAL_P(z_keys[i]), 1+Z_STRLEN_P(z_keys[i]), response, response_len);
add_assoc_stringl_ex(z_multi_result, Z_STRVAL_P(z_keys[i]), Z_STRLEN_P(z_keys[i]), response, response_len);
}
efree(response);
} else {
+1 -1
View File
@@ -1057,7 +1057,7 @@ PHP_METHOD(RedisArray, mset)
zval_copy_ctor(z_tmp);
INIT_PZVAL(z_tmp);
add_assoc_zval_ex(z_argarray, keys[i], key_lens[i] + 1, z_tmp); /* +1 to count the \0 here */
add_assoc_zval_ex(z_argarray, keys[i], key_lens[i], z_tmp);
found++;
}
+5 -2
View File
@@ -32,7 +32,7 @@ extern zend_class_entry *redis_ce;
RedisArray*
ra_load_hosts(RedisArray *ra, HashTable *hosts, long retry_interval, zend_bool b_lazy_connect TSRMLS_DC)
{
int i = 0, host_len, id;
int i = 0, host_len;
char *host, *p;
short port;
zval *zpData, z_cons, z_ret, *redis_inst;
@@ -89,14 +89,16 @@ ra_load_hosts(RedisArray *ra, HashTable *hosts, long retry_interval, zend_bool b
}
/* attach */
#if (PHP_MAJOR_VERSION < 7)
int id;
#if PHP_VERSION_ID >= 50400
id = zend_list_insert(redis_sock, le_redis_sock TSRMLS_CC);
#else
id = zend_list_insert(redis_sock, le_redis_sock);
#endif
#if (PHP_MAJOR_VERSION < 7)
add_property_resource(&ra->redis[i], "socket", id);
#else
zval *id = zend_list_insert(redis_sock, le_redis_sock TSRMLS_CC);
add_property_resource(&ra->redis[i], "socket", Z_RES_P(id));
#endif
@@ -1162,6 +1164,7 @@ static void zval_rehash_callback(zend_fcall_info *z_cb, zend_fcall_info_cache *z
zval *z_ret = NULL, z_args[2];
zval *z_host = &z_args[0], *z_count = &z_args[1];
INIT_ZVAL(z_args[0]);
ZVAL_STRING(z_host, hostname);
ZVAL_LONG(z_count, count);