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:
authorPavlo Yatsukhnenko <yatsukhnenko@gmail.com>2020-03-09 14:36:27 +0300
committerPavlo Yatsukhnenko <yatsukhnenko@gmail.com>2020-03-09 14:36:27 +0300
commitd5dadaf63552360e3e663cdcffd706b859c3ea83 (patch)
tree057bb3b636fa96be42c8e370a35d4c6dc4fd389d
parent92f8dde1c996d4e1c3d79226b888119307612c40 (diff)
Add PHPREDIS_GET_OBJECT and PHPREDIS_ZVAL_GET_OBJECT macros
-rw-r--r--common.h3
-rw-r--r--redis.c6
-rw-r--r--redis_array.c8
-rw-r--r--redis_array_impl.c2
-rw-r--r--redis_cluster.c2
-rw-r--r--redis_cluster.h3
-rw-r--r--redis_sentinel.c2
-rw-r--r--sentinel_library.c2
8 files changed, 14 insertions, 14 deletions
diff --git a/common.h b/common.h
index 80381a6c..f9aed17a 100644
--- a/common.h
+++ b/common.h
@@ -13,7 +13,8 @@
#include <ext/standard/php_smart_string.h>
#define PHPREDIS_ZVAL_IS_STRICT_FALSE(z) (Z_TYPE_P(z) == IS_FALSE)
-#define PHPREDIS_GET_OBJECT(class_entry, z) (class_entry *)((char *)Z_OBJ_P(z) - XtOffsetOf(class_entry, std))
+#define PHPREDIS_GET_OBJECT(class_entry, o) (class_entry *)((char *)o - XtOffsetOf(class_entry, std))
+#define PHPREDIS_ZVAL_GET_OBJECT(class_entry, z) PHPREDIS_GET_OBJECT(class_entry, Z_OBJ_P(z))
/* NULL check so Eclipse doesn't go crazy */
#ifndef NULL
diff --git a/redis.c b/redis.c
index 1a19c6a5..ff0bd029 100644
--- a/redis.c
+++ b/redis.c
@@ -567,7 +567,7 @@ static void cluster_cache_dtor(zend_resource *rsrc) {
void
free_redis_object(zend_object *object)
{
- redis_object *redis = (redis_object *)((char *)(object) - XtOffsetOf(redis_object, std));
+ redis_object *redis = PHPREDIS_GET_OBJECT(redis_object, object);
zend_object_std_dtor(&redis->std);
if (redis->sock) {
@@ -600,7 +600,7 @@ redis_sock_get_instance(zval *id, int no_throw)
redis_object *redis;
if (Z_TYPE_P(id) == IS_OBJECT) {
- redis = PHPREDIS_GET_OBJECT(redis_object, id);
+ redis = PHPREDIS_ZVAL_GET_OBJECT(redis_object, id);
if (redis->sock) {
return redis->sock;
}
@@ -1012,7 +1012,7 @@ redis_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
port = 6379;
}
- redis = PHPREDIS_GET_OBJECT(redis_object, object);
+ redis = PHPREDIS_ZVAL_GET_OBJECT(redis_object, object);
/* if there is a redis sock already we have to remove it */
if (redis->sock) {
redis_sock_disconnect(redis->sock, 0);
diff --git a/redis_array.c b/redis_array.c
index ca448616..f5ada276 100644
--- a/redis_array.c
+++ b/redis_array.c
@@ -178,7 +178,7 @@ zend_object_handlers redis_array_object_handlers;
void
free_redis_array_object(zend_object *object)
{
- redis_array_object *obj = (redis_array_object *)((char *)(object) - XtOffsetOf(redis_array_object, std));
+ redis_array_object *obj = PHPREDIS_GET_OBJECT(redis_array_object, object);
if (obj->ra) {
if (obj->ra->prev) redis_array_free(obj->ra->prev);
@@ -214,7 +214,7 @@ redis_array_get(zval *id)
redis_array_object *obj;
if (Z_TYPE_P(id) == IS_OBJECT) {
- obj = PHPREDIS_GET_OBJECT(redis_array_object, id);
+ obj = PHPREDIS_ZVAL_GET_OBJECT(redis_array_object, id);
return obj->ra;
}
return NULL;
@@ -224,7 +224,7 @@ PHP_REDIS_API int
ra_call_user_function(HashTable *function_table, zval *object, zval *function_name, zval *retval_ptr, uint32_t param_count, zval params[])
{
if (object) {
- redis_object *redis = PHPREDIS_GET_OBJECT(redis_object, object);
+ redis_object *redis = PHPREDIS_ZVAL_GET_OBJECT(redis_object, object);
if (redis->sock->auth &&
redis->sock->status != REDIS_SOCK_STATUS_CONNECTED &&
redis_sock_server_open(redis->sock) == SUCCESS
@@ -366,7 +366,7 @@ PHP_METHOD(RedisArray, __construct)
ra->auto_rehash = b_autorehash;
ra->connect_timeout = d_connect_timeout;
if(ra->prev) ra->prev->auto_rehash = b_autorehash;
- obj = PHPREDIS_GET_OBJECT(redis_array_object, getThis());
+ obj = PHPREDIS_ZVAL_GET_OBJECT(redis_array_object, getThis());
obj->ra = ra;
}
}
diff --git a/redis_array_impl.c b/redis_array_impl.c
index f76bac2a..646b08a2 100644
--- a/redis_array_impl.c
+++ b/redis_array_impl.c
@@ -67,7 +67,7 @@ ra_load_hosts(RedisArray *ra, HashTable *hosts, zend_string *auth, long retry_in
call_user_function(&redis_ce->function_table, &ra->redis[i], &z_cons, &z_ret, 0, NULL);
zval_dtor(&z_ret);
- redis = PHPREDIS_GET_OBJECT(redis_object, &ra->redis[i]);
+ redis = PHPREDIS_ZVAL_GET_OBJECT(redis_object, &ra->redis[i]);
/* create socket */
redis->sock = redis_sock_create(host, host_len, port, ra->connect_timeout, ra->read_timeout, ra->pconnect, NULL, retry_interval);
diff --git a/redis_cluster.c b/redis_cluster.c
index 1029b9df..1ee7e444 100644
--- a/redis_cluster.c
+++ b/redis_cluster.c
@@ -334,7 +334,7 @@ zend_object * create_cluster_context(zend_class_entry *class_type) {
/* Free redisCluster context */
void free_cluster_context(zend_object *object) {
- redisCluster *cluster = (redisCluster*)((char*)(object) - XtOffsetOf(redisCluster, std));
+ redisCluster *cluster = PHPREDIS_GET_OBJECT(redisCluster, object);
cluster_free(cluster, 0);
zend_object_std_dtor(&cluster->std);
diff --git a/redis_cluster.h b/redis_cluster.h
index 414c489d..68a0273c 100644
--- a/redis_cluster.h
+++ b/redis_cluster.h
@@ -10,8 +10,7 @@
#define REDIS_CLUSTER_MOD (REDIS_CLUSTER_SLOTS-1)
/* Get attached object context */
-#define GET_CONTEXT() \
- ((redisCluster *)((char *)Z_OBJ_P(getThis()) - XtOffsetOf(redisCluster, std)))
+#define GET_CONTEXT() PHPREDIS_ZVAL_GET_OBJECT(redisCluster, getThis())
/* Command building/processing is identical for every command */
#define CLUSTER_BUILD_CMD(name, c, cmd, cmd_len, slot) \
diff --git a/redis_sentinel.c b/redis_sentinel.c
index f4729d78..9fa5414d 100644
--- a/redis_sentinel.c
+++ b/redis_sentinel.c
@@ -93,7 +93,7 @@ PHP_METHOD(RedisSentinel, __construct)
}
}
- obj = PHPREDIS_GET_OBJECT(redis_sentinel_object, getThis());
+ obj = PHPREDIS_ZVAL_GET_OBJECT(redis_sentinel_object, getThis());
obj->sock = redis_sock_create(ZSTR_VAL(host), ZSTR_LEN(host), port,
timeout, read_timeout, persistent, persistent_id, retry_interval);
}
diff --git a/sentinel_library.c b/sentinel_library.c
index bd81e8d8..48198546 100644
--- a/sentinel_library.c
+++ b/sentinel_library.c
@@ -5,7 +5,7 @@ static zend_object_handlers redis_sentinel_object_handlers;
static void
free_redis_sentinel_object(zend_object *object)
{
- redis_sentinel_object *obj = (redis_sentinel_object *)((char *)(object) - XtOffsetOf(redis_sentinel_object, std));
+ redis_sentinel_object *obj = PHPREDIS_GET_OBJECT(redis_sentinel_object, object);
if (obj->sock) {
redis_sock_disconnect(obj->sock, 0);