mirror of
https://github.com/php-win-ext/phpredis.git
synced 2026-03-24 00:52:16 +01:00
WIP: php7 compatibility
This commit is contained in:
@@ -1936,7 +1936,7 @@ PHP_REDIS_API void cluster_variant_resp(INTERNAL_FUNCTION_PARAMETERS, redisClust
|
||||
PHP_REDIS_API void cluster_gen_mbulk_resp(INTERNAL_FUNCTION_PARAMETERS,
|
||||
redisCluster *c, mbulk_cb cb, void *ctx)
|
||||
{
|
||||
zval *z_result;
|
||||
zval zv, *z_result = &zv;
|
||||
|
||||
/* Return FALSE if we didn't get a multi-bulk response */
|
||||
if (c->reply_type != TYPE_MULTIBULK) {
|
||||
@@ -1944,7 +1944,9 @@ PHP_REDIS_API void cluster_gen_mbulk_resp(INTERNAL_FUNCTION_PARAMETERS,
|
||||
}
|
||||
|
||||
/* Allocate our array */
|
||||
#if (PHP_MAJOR_VERSION < 7)
|
||||
MAKE_STD_ZVAL(z_result);
|
||||
#endif
|
||||
array_init(z_result);
|
||||
|
||||
/* Consume replies as long as there are more than zero */
|
||||
@@ -1954,16 +1956,14 @@ PHP_REDIS_API void cluster_gen_mbulk_resp(INTERNAL_FUNCTION_PARAMETERS,
|
||||
|
||||
/* Call our specified callback */
|
||||
if (cb(c->cmd_sock, z_result, c->reply_len, ctx TSRMLS_CC)==FAILURE) {
|
||||
zval_dtor(z_result);
|
||||
FREE_ZVAL(z_result);
|
||||
zval_ptr_dtor(z_result);
|
||||
CLUSTER_RETURN_FALSE(c);
|
||||
}
|
||||
}
|
||||
|
||||
// Success, make this array our return value
|
||||
if(CLUSTER_IS_ATOMIC(c)) {
|
||||
*return_value = *z_result;
|
||||
efree(z_result);
|
||||
RETVAL_ZVAL(z_result, 0, 1);
|
||||
} else {
|
||||
add_next_index_zval(c->multi_resp, z_result);
|
||||
}
|
||||
|
||||
@@ -218,6 +218,8 @@ PHP_METHOD(RedisArray, __construct)
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
ZVAL_NULL(&z_fun);
|
||||
ZVAL_NULL(&z_dist);
|
||||
/* extract options */
|
||||
if(z_opts) {
|
||||
zval *z_retry_interval_p;
|
||||
@@ -234,16 +236,12 @@ PHP_METHOD(RedisArray, __construct)
|
||||
}
|
||||
|
||||
/* extract function name. */
|
||||
if ((zpData = zend_hash_str_find(hOpts, "function", sizeof("function") - 1)) == NULL) {
|
||||
ZVAL_NULL(&z_fun);
|
||||
} else {
|
||||
if ((zpData = zend_hash_str_find(hOpts, "function", sizeof("function") - 1)) != NULL) {
|
||||
ZVAL_ZVAL(&z_fun, zpData, 1, 0);
|
||||
}
|
||||
|
||||
/* extract function name. */
|
||||
if ((zpData = zend_hash_str_find(hOpts, "distributor", sizeof("distributor") - 1)) == NULL) {
|
||||
ZVAL_NULL(&z_dist);
|
||||
} else {
|
||||
if ((zpData = zend_hash_str_find(hOpts, "distributor", sizeof("distributor") - 1)) != NULL) {
|
||||
ZVAL_ZVAL(&z_dist, zpData, 1, 0);
|
||||
}
|
||||
|
||||
@@ -1124,7 +1122,7 @@ PHP_METHOD(RedisArray, mset)
|
||||
/* DEL will distribute the call to several nodes and regroup the values. */
|
||||
PHP_METHOD(RedisArray, del)
|
||||
{
|
||||
zval *object, *z_keys, z_fun, *z_argarray, *data, *z_ret, *z_tmp, *z_args;
|
||||
zval *object, z_keys, z_fun, *data, z_ret, *z_tmp, *z_args;
|
||||
int i, n;
|
||||
RedisArray *ra;
|
||||
int *pos, argc = ZEND_NUM_ARGS(), *argc_each;
|
||||
@@ -1145,25 +1143,28 @@ PHP_METHOD(RedisArray, del)
|
||||
|
||||
/* if single array arg, point z_keys to it. */
|
||||
if (argc == 1 && Z_TYPE(z_args[0]) == IS_ARRAY) {
|
||||
z_keys = &z_args[0];
|
||||
z_keys = z_args[0];
|
||||
} else {
|
||||
/* copy all elements to z_keys */
|
||||
MAKE_STD_ZVAL(z_keys);
|
||||
array_init(z_keys);
|
||||
free_zkeys = 1;
|
||||
array_init(&z_keys);
|
||||
for (i = 0; i < argc; ++i) {
|
||||
zval *z_arg = &z_args[i];
|
||||
#if (PHP_MAJOR_VERSION < 7)
|
||||
MAKE_STD_ZVAL(z_tmp);
|
||||
*z_tmp = z_args[i];
|
||||
zval_copy_ctor(z_tmp);
|
||||
INIT_PZVAL(z_tmp);
|
||||
|
||||
#else
|
||||
zval zv;
|
||||
z_tmp = &zv;
|
||||
#endif
|
||||
ZVAL_ZVAL(z_tmp, z_arg, 1, 0);
|
||||
/* add copy to z_keys */
|
||||
add_next_index_zval(z_keys, z_tmp);
|
||||
add_next_index_zval(&z_keys, z_tmp);
|
||||
}
|
||||
free_zkeys = 1;
|
||||
}
|
||||
|
||||
|
||||
if (redis_array_get(getThis(), &ra TSRMLS_CC) < 0) {
|
||||
efree(z_args);
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
@@ -1171,7 +1172,7 @@ PHP_METHOD(RedisArray, del)
|
||||
ZVAL_STRINGL(&z_fun, "DEL", 3);
|
||||
|
||||
/* init data structures */
|
||||
h_keys = Z_ARRVAL_P(z_keys);
|
||||
h_keys = Z_ARRVAL(z_keys);
|
||||
argc = zend_hash_num_elements(h_keys);
|
||||
argv = emalloc(argc * sizeof(zval*));
|
||||
pos = emalloc(argc * sizeof(int));
|
||||
@@ -1184,6 +1185,7 @@ PHP_METHOD(RedisArray, del)
|
||||
ZEND_HASH_FOREACH_VAL(h_keys, data) {
|
||||
if (Z_TYPE_P(data) != IS_STRING) {
|
||||
php_error_docref(NULL TSRMLS_CC, E_ERROR, "DEL: all keys must be string.");
|
||||
efree(argv);
|
||||
efree(pos);
|
||||
RETURN_FALSE;
|
||||
}
|
||||
@@ -1199,25 +1201,26 @@ PHP_METHOD(RedisArray, del)
|
||||
for(n = 0; n < ra->count; ++n) { /* for each node */
|
||||
|
||||
int found = 0;
|
||||
zval z_argarray;
|
||||
|
||||
/* copy args */
|
||||
MAKE_STD_ZVAL(z_argarray);
|
||||
array_init(z_argarray);
|
||||
array_init(&z_argarray);
|
||||
for(i = 0; i < argc; ++i) {
|
||||
if(pos[i] != n) continue;
|
||||
|
||||
#if (PHP_MAJOR_VERSION < 7)
|
||||
MAKE_STD_ZVAL(z_tmp);
|
||||
*z_tmp = *argv[i];
|
||||
zval_copy_ctor(z_tmp);
|
||||
INIT_PZVAL(z_tmp);
|
||||
|
||||
add_next_index_zval(z_argarray, z_tmp);
|
||||
#else
|
||||
zval zv;
|
||||
z_tmp = &zv;
|
||||
#endif
|
||||
ZVAL_ZVAL(z_tmp, argv[i], 1, 0);
|
||||
add_next_index_zval(&z_argarray, z_tmp);
|
||||
found++;
|
||||
}
|
||||
|
||||
if(!found) { /* don't run empty DELs */
|
||||
zval_dtor(z_argarray);
|
||||
efree(z_argarray);
|
||||
zval_dtor(&z_argarray);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -1227,22 +1230,19 @@ PHP_METHOD(RedisArray, del)
|
||||
}
|
||||
|
||||
/* call */
|
||||
MAKE_STD_ZVAL(z_ret);
|
||||
call_user_function(&redis_ce->function_table, redis_inst, &z_fun, z_ret, 1, z_argarray);
|
||||
call_user_function(&redis_ce->function_table, redis_inst, &z_fun, &z_ret, 1, &z_argarray);
|
||||
|
||||
if(ra->index) {
|
||||
ra_index_del(z_argarray, redis_inst TSRMLS_CC); /* use SREM to remove keys from node index */
|
||||
ra_index_del(&z_argarray, redis_inst TSRMLS_CC); /* use SREM to remove keys from node index */
|
||||
ra_index_exec(redis_inst, z_tmp, 0 TSRMLS_CC); /* run EXEC */
|
||||
total += Z_LVAL_P(z_tmp); /* increment total from multi/exec block */
|
||||
} else {
|
||||
total += Z_LVAL_P(z_ret); /* increment total from single command */
|
||||
total += Z_LVAL(z_ret); /* increment total from single command */
|
||||
}
|
||||
|
||||
zval_dtor(z_ret);
|
||||
efree(z_ret);
|
||||
zval_dtor(&z_ret);
|
||||
|
||||
zval_dtor(z_argarray);
|
||||
efree(z_argarray);
|
||||
zval_dtor(&z_argarray);
|
||||
}
|
||||
|
||||
/* cleanup */
|
||||
@@ -1252,8 +1252,7 @@ PHP_METHOD(RedisArray, del)
|
||||
efree(argc_each);
|
||||
|
||||
if(free_zkeys) {
|
||||
zval_dtor(z_keys);
|
||||
efree(z_keys);
|
||||
zval_dtor(&z_keys);
|
||||
}
|
||||
|
||||
efree(z_args);
|
||||
|
||||
@@ -340,7 +340,13 @@ create_cluster_context(zend_class_entry *class_type TSRMLS_DC) {
|
||||
}
|
||||
|
||||
/* Free redisCluster context */
|
||||
void free_cluster_context(void *object TSRMLS_DC) {
|
||||
void
|
||||
#if (PHP_MAJOR_VERSION < 7)
|
||||
free_cluster_context(void *object TSRMLS_DC)
|
||||
#else
|
||||
free_cluster_context(zend_object *object)
|
||||
#endif
|
||||
{
|
||||
redisCluster *cluster;
|
||||
|
||||
// Grab context
|
||||
@@ -385,7 +391,6 @@ void redis_cluster_init(redisCluster *c, HashTable *ht_seeds, double timeout,
|
||||
zend_throw_exception(redis_cluster_exception_ce,
|
||||
"Must pass seeds", 0 TSRMLS_CC);
|
||||
}
|
||||
|
||||
/* Set our timeout and read_timeout which we'll pass through to the
|
||||
* socket type operations */
|
||||
c->timeout = timeout;
|
||||
@@ -919,10 +924,9 @@ static int cluster_mset_cmd(INTERNAL_FUNCTION_PARAMETERS, char *kw, int kw_len,
|
||||
|
||||
/* {{{ proto array RedisCluster::del(string key1, string key2, ... keyN) */
|
||||
PHP_METHOD(RedisCluster, del) {
|
||||
zval *z_ret;
|
||||
zval *z_ret = emalloc(sizeof(zval));
|
||||
|
||||
// Initialize a LONG value to zero for our return
|
||||
MAKE_STD_ZVAL(z_ret);
|
||||
ZVAL_LONG(z_ret, 0);
|
||||
|
||||
// Parse args, process
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
((redisCluster*)zend_object_store_get_object(getThis() TSRMLS_CC))
|
||||
#else
|
||||
#define GET_CONTEXT() \
|
||||
((redisCluster *)((char *)getThis() - XtOffsetOf(redisCluster, std)))
|
||||
((redisCluster *)((char *)Z_OBJ_P(getThis()) - XtOffsetOf(redisCluster, std)))
|
||||
#endif
|
||||
|
||||
/* Command building/processing is identical for every command */
|
||||
@@ -106,15 +106,18 @@
|
||||
/* For the creation of RedisCluster specific exceptions */
|
||||
PHP_REDIS_API zend_class_entry *rediscluster_get_exception_base(int root TSRMLS_DC);
|
||||
|
||||
/* Create cluster context */
|
||||
#if (PHP_MAJOR_VERSION < 7)
|
||||
/* Create cluster context */
|
||||
zend_object_value create_cluster_context(zend_class_entry *class_type TSRMLS_DC);
|
||||
#else
|
||||
zend_object *create_cluster_context(zend_class_entry *class_type TSRMLS_DC);
|
||||
#endif
|
||||
|
||||
/* Free cluster context struct */
|
||||
void free_cluster_context(void *object TSRMLS_DC);
|
||||
#else
|
||||
/* Create cluster context */
|
||||
zend_object *create_cluster_context(zend_class_entry *class_type TSRMLS_DC);
|
||||
/* Free cluster context struct */
|
||||
void free_cluster_context(zend_object *object);
|
||||
#endif
|
||||
|
||||
|
||||
/* Inittialize our class with PHP */
|
||||
void init_rediscluster(TSRMLS_D);
|
||||
|
||||
@@ -189,7 +189,7 @@ redis_pool_get_sock(redis_pool *pool, const char *key TSRMLS_DC) {
|
||||
PS_OPEN_FUNC(redis)
|
||||
{
|
||||
php_url *url;
|
||||
zval *params, *param;
|
||||
zval params, *param;
|
||||
int i, j, path_len;
|
||||
|
||||
redis_pool *pool = redis_pool_new(TSRMLS_C);
|
||||
@@ -236,37 +236,36 @@ PS_OPEN_FUNC(redis)
|
||||
|
||||
/* parse parameters */
|
||||
if (url->query != NULL) {
|
||||
MAKE_STD_ZVAL(params);
|
||||
array_init(params);
|
||||
array_init(¶ms);
|
||||
|
||||
sapi_module.treat_data(PARSE_STRING, estrdup(url->query), params TSRMLS_CC);
|
||||
sapi_module.treat_data(PARSE_STRING, estrdup(url->query), ¶ms TSRMLS_CC);
|
||||
|
||||
if ((param = zend_hash_str_find(Z_ARRVAL_P(params), "weight", sizeof("weight") - 1)) != NULL) {
|
||||
if ((param = zend_hash_str_find(Z_ARRVAL(params), "weight", sizeof("weight") - 1)) != NULL) {
|
||||
weight = zval_get_long(param);
|
||||
}
|
||||
if ((param = zend_hash_str_find(Z_ARRVAL_P(params), "timeout", sizeof("timeout") - 1)) != NULL) {
|
||||
if ((param = zend_hash_str_find(Z_ARRVAL(params), "timeout", sizeof("timeout") - 1)) != NULL) {
|
||||
timeout = atof(Z_STRVAL_P(param));
|
||||
}
|
||||
if ((param = zend_hash_str_find(Z_ARRVAL_P(params), "persistent", sizeof("persistent") - 1)) != NULL) {
|
||||
if ((param = zend_hash_str_find(Z_ARRVAL(params), "persistent", sizeof("persistent") - 1)) != NULL) {
|
||||
persistent = (atol(Z_STRVAL_P(param)) == 1 ? 1 : 0);
|
||||
}
|
||||
if ((param = zend_hash_str_find(Z_ARRVAL_P(params), "persistent_id", sizeof("persistent_id") - 1)) != NULL) {
|
||||
if ((param = zend_hash_str_find(Z_ARRVAL(params), "persistent_id", sizeof("persistent_id") - 1)) != NULL) {
|
||||
persistent_id = estrndup(Z_STRVAL_P(param), Z_STRLEN_P(param));
|
||||
}
|
||||
if ((param = zend_hash_str_find(Z_ARRVAL_P(params), "prefix", sizeof("prefix") - 1)) != NULL) {
|
||||
if ((param = zend_hash_str_find(Z_ARRVAL(params), "prefix", sizeof("prefix") - 1)) != NULL) {
|
||||
prefix = estrndup(Z_STRVAL_P(param), Z_STRLEN_P(param));
|
||||
}
|
||||
if ((param = zend_hash_str_find(Z_ARRVAL_P(params), "auth", sizeof("auth") - 1)) != NULL) {
|
||||
if ((param = zend_hash_str_find(Z_ARRVAL(params), "auth", sizeof("auth") - 1)) != NULL) {
|
||||
auth = estrndup(Z_STRVAL_P(param), Z_STRLEN_P(param));
|
||||
}
|
||||
if ((param = zend_hash_str_find(Z_ARRVAL_P(params), "database", sizeof("database") - 1)) != NULL) {
|
||||
if ((param = zend_hash_str_find(Z_ARRVAL(params), "database", sizeof("database") - 1)) != NULL) {
|
||||
database = zval_get_long(param);
|
||||
}
|
||||
if ((param = zend_hash_str_find(Z_ARRVAL_P(params), "retry_interval", sizeof("retry_interval") - 1)) != NULL) {
|
||||
if ((param = zend_hash_str_find(Z_ARRVAL(params), "retry_interval", sizeof("retry_interval") - 1)) != NULL) {
|
||||
retry_interval = zval_get_long(param);
|
||||
}
|
||||
|
||||
zval_ptr_dtor(¶ms);
|
||||
zval_dtor(¶ms);
|
||||
}
|
||||
|
||||
if ((url->path == NULL && url->host == NULL) || weight <= 0 || timeout <= 0) {
|
||||
@@ -545,7 +544,7 @@ static char *cluster_session_key(redisCluster *c, const char *key, int keylen,
|
||||
|
||||
PS_OPEN_FUNC(rediscluster) {
|
||||
redisCluster *c;
|
||||
zval *z_conf, *z_val;
|
||||
zval z_conf, *z_val;
|
||||
HashTable *ht_conf, *ht_seeds;
|
||||
double timeout = 0, read_timeout = 0;
|
||||
int persistent = 0;
|
||||
@@ -553,22 +552,20 @@ PS_OPEN_FUNC(rediscluster) {
|
||||
char *prefix;
|
||||
|
||||
/* Parse configuration for session handler */
|
||||
MAKE_STD_ZVAL(z_conf);
|
||||
array_init(z_conf);
|
||||
sapi_module.treat_data(PARSE_STRING, estrdup(save_path), z_conf TSRMLS_CC);
|
||||
array_init(&z_conf);
|
||||
sapi_module.treat_data(PARSE_STRING, estrdup(save_path), &z_conf TSRMLS_CC);
|
||||
|
||||
/* Sanity check that we're able to parse and have a seeds array */
|
||||
if (Z_TYPE_P(z_conf) != IS_ARRAY ||
|
||||
(z_val = zend_hash_str_find(Z_ARRVAL_P(z_conf), "seed", sizeof("seed") - 1)) == NULL ||
|
||||
if (Z_TYPE(z_conf) != IS_ARRAY ||
|
||||
(z_val = zend_hash_str_find(Z_ARRVAL(z_conf), "seed", sizeof("seed") - 1)) == NULL ||
|
||||
Z_TYPE_P(z_val) != IS_ARRAY)
|
||||
{
|
||||
zval_dtor(z_conf);
|
||||
efree(z_conf);
|
||||
zval_dtor(&z_conf);
|
||||
return FAILURE;
|
||||
}
|
||||
|
||||
/* Grab a copy of our config hash table and keep seeds array */
|
||||
ht_conf = Z_ARRVAL_P(z_conf);
|
||||
ht_conf = Z_ARRVAL(z_conf);
|
||||
ht_seeds = Z_ARRVAL_P(z_val);
|
||||
|
||||
/* Grab timeouts if they were specified */
|
||||
@@ -582,8 +579,7 @@ PS_OPEN_FUNC(rediscluster) {
|
||||
if (timeout < 0 || read_timeout < 0) {
|
||||
php_error_docref(NULL TSRMLS_CC, E_WARNING,
|
||||
"Can't set negative timeout values in session configuration");
|
||||
zval_dtor(z_conf);
|
||||
efree(z_conf);
|
||||
zval_dtor(&z_conf);
|
||||
return FAILURE;
|
||||
}
|
||||
|
||||
@@ -623,8 +619,7 @@ PS_OPEN_FUNC(rediscluster) {
|
||||
}
|
||||
|
||||
/* Cleanup */
|
||||
zval_dtor(z_conf);
|
||||
efree(z_conf);
|
||||
zval_dtor(&z_conf);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user