Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cluster_library.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ static zend_always_inline zend_bool cluster_is_ask(const char *p, size_t len) {
mc.kw_len = keyword_len; \

static zend_always_inline zend_bool cluster_caching_enabled(void) {
return INI_INT("redis.clusters.cache_slots") == 1;
return zend_ini_long_literal("redis.clusters.cache_slots") == 1;
}

/* Cluster redirection enum */
Expand Down
2 changes: 1 addition & 1 deletion common.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include <zend_smart_str.h>
#include <zend_smart_string.h>

#define PHPREDIS_GET_OBJECT(class_entry, o) (class_entry *)((char *)o - XtOffsetOf(class_entry, std))
#define PHPREDIS_GET_OBJECT(class_entry, o) (class_entry *)((char *)o - offsetof(class_entry, std))
#define PHPREDIS_ZVAL_GET_OBJECT(class_entry, z) PHPREDIS_GET_OBJECT(class_entry, Z_OBJ_P(z))

/* We'll fallthrough if we want to */
Expand Down
22 changes: 12 additions & 10 deletions library.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ redis_sock_get_connection_pool(RedisSock *redis_sock)
zend_string *persistent_id;

/* Generate our unique pool id depending on configuration */
persistent_id = redis_pool_spprintf(redis_sock, INI_STR("redis.pconnect.pool_pattern"));
persistent_id = redis_pool_spprintf(redis_sock, zend_ini_string_literal("redis.pconnect.pool_pattern"));

/* Return early if we can find the pool */
if ((le = zend_hash_find_ptr(&EG(persistent_list), persistent_id))) {
Expand Down Expand Up @@ -938,7 +938,7 @@ static void append_auth_hash(smart_str *dst, zend_string *user, zend_string *pas

/* A printf like function to generate our connection pool hash value. */
PHP_REDIS_API zend_string *
redis_pool_spprintf(RedisSock *redis_sock, char *fmt, ...) {
redis_pool_spprintf(RedisSock *redis_sock, const char *fmt, ...) {
smart_str str = {0};

smart_str_alloc(&str, 128, 0);
Expand Down Expand Up @@ -3047,7 +3047,7 @@ static php_socket_t redis_stream_fd_for_select(php_stream *stream) {
}

static int redis_detect_dirty_config(void) {
int val = INI_INT("redis.pconnect.pool_detect_dirty");
int val = zend_ini_long_literal("redis.pconnect.pool_detect_dirty");

if (val >= 0 && val <= 2)
return val;
Expand All @@ -3058,7 +3058,7 @@ static int redis_detect_dirty_config(void) {
}

static int redis_pool_poll_timeout(void) {
int val = INI_INT("redis.pconnect.pool_poll_timeout");
int val = zend_ini_long_literal("redis.pconnect.pool_poll_timeout");
if (val >= 0)
return val;

Expand Down Expand Up @@ -3152,7 +3152,7 @@ redis_sock_check_liveness(RedisSock *redis_sock)
goto failure;

redis_sock->status = REDIS_SOCK_STATUS_CONNECTED;
if (!INI_INT("redis.pconnect.echo_check_liveness")) {
if (!zend_ini_long_literal("redis.pconnect.echo_check_liveness")) {
return SUCCESS;
}

Expand Down Expand Up @@ -3283,7 +3283,7 @@ PHP_REDIS_API int redis_sock_connect(RedisSock *redis_sock)
}

if (redis_sock->persistent) {
if (INI_INT("redis.pconnect.pooling_enabled")) {
if (zend_ini_long_literal("redis.pconnect.pooling_enabled")) {
p = redis_sock_get_connection_pool(redis_sock);
if (zend_llist_count(&p->list) > 0) {
redis_sock->stream = *(php_stream **)zend_llist_get_last(&p->list);
Expand All @@ -3296,7 +3296,7 @@ PHP_REDIS_API int redis_sock_connect(RedisSock *redis_sock)
p->nb_active--;
}

int limit = INI_INT("redis.pconnect.connection_limit");
int limit = zend_ini_long_literal("redis.pconnect.connection_limit");
if (limit > 0 && p->nb_active >= limit) {
redis_sock_set_err(redis_sock, ZEND_STRL("Connection limit reached"));
return FAILURE;
Expand Down Expand Up @@ -3423,7 +3423,7 @@ redis_sock_disconnect(RedisSock *redis_sock, int force, int is_reset_mode)
} else if (redis_sock->stream) {
if (redis_sock->persistent) {
ConnectionPool *p = NULL;
if (INI_INT("redis.pconnect.pooling_enabled")) {
if (zend_ini_long_literal("redis.pconnect.pooling_enabled")) {
p = redis_sock_get_connection_pool(redis_sock);
}
if (force || !redis_sock_is_atomic(redis_sock)) {
Expand Down Expand Up @@ -4365,7 +4365,8 @@ redis_serialize(RedisSock *redis_sock, zval *z, char **val, size_t *val_len)
return 1;
#endif
break;
EMPTY_SWITCH_DEFAULT_CASE()
default:
ZEND_UNREACHABLE();
}

return 0;
Expand Down Expand Up @@ -4432,7 +4433,8 @@ redis_unserialize(RedisSock* redis_sock, const char *val, int val_len,
ret = !php_json_decode(z_ret, (char *)val, val_len, 1, PHP_JSON_PARSER_DEFAULT_DEPTH);
#endif
break;
EMPTY_SWITCH_DEFAULT_CASE()
default:
ZEND_UNREACHABLE();
}

return ret;
Expand Down
2 changes: 1 addition & 1 deletion library.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ void redis_free_reply_callbacks(RedisSock *redis_sock);
PHP_REDIS_API int redis_extract_auth_info(zval *ztest, zend_string **user, zend_string **pass);
PHP_REDIS_API void redis_with_metadata(zval *zdst, zval *zsrc, zend_long length);

PHP_REDIS_API zend_string *redis_pool_spprintf(RedisSock *redis_sock, char *fmt, ...);
PHP_REDIS_API zend_string *redis_pool_spprintf(RedisSock *redis_sock, const char *fmt, ...);

PHP_REDIS_API char *redis_sock_read(RedisSock *redis_sock, int *buf_len);
PHP_REDIS_API int redis_sock_gets(RedisSock *redis_sock, char *buf, int buf_size, size_t* line_len);
Expand Down
21 changes: 21 additions & 0 deletions php_compat.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef PHP_REDIS_COMPAT_H
#define PHP_REDIS_COMPAT_H

#include <stddef.h>

#include "php.h"
#include <ext/hash/php_hash.h>

Expand All @@ -11,6 +13,25 @@
#include <ext/random/php_random.h>
#endif

#ifndef ZEND_UNREACHABLE
#define ZEND_UNREACHABLE() do { ZEND_ASSERT(0); ZEND_ASSUME(0); } while (0)
#endif

#if PHP_VERSION_ID < 80600

#define zend_ini_bool_literal(name) \
zend_ini_parse_bool(zend_ini_str((name), sizeof("" name) - 1, 0))
#define zend_ini_long_literal(name) \
zend_ini_long((name), sizeof("" name) - 1, 0)
#define zend_ini_double_literal(name) \
zend_ini_double((name), sizeof("" name) - 1, 0)
#define zend_ini_str_literal(name) \
zend_ini_str((name), sizeof("" name) - 1, 0)
#define zend_ini_string_literal(name) \
zend_ini_string((name), sizeof("" name) - 1, 0)

#endif

#if PHP_VERSION_ID < 80000

static zend_always_inline zend_string *
Expand Down
2 changes: 1 addition & 1 deletion redis.c
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ static void redis_random_hex_bytes(char *dst, size_t dstsize) {
static void redis_init_object_handlers(void) {
memcpy(&redis_object_handlers, zend_get_std_object_handlers(),
sizeof(redis_object_handlers));
redis_object_handlers.offset = XtOffsetOf(redis_object, std);
redis_object_handlers.offset = offsetof(redis_object, std);
redis_object_handlers.free_obj = free_redis_object;
redis_object_handlers.clone_obj = NULL;
}
Expand Down
2 changes: 1 addition & 1 deletion redis_array.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ redis_array_init_object_handlers(void)
{
memcpy(&redis_array_object_handlers, zend_get_std_object_handlers(),
sizeof(redis_array_object_handlers));
redis_array_object_handlers.offset = XtOffsetOf(redis_array_object, std);
redis_array_object_handlers.offset = offsetof(redis_array_object, std);
redis_array_object_handlers.free_obj = free_redis_array_object;
redis_array_object_handlers.clone_obj = NULL;
}
Expand Down
33 changes: 16 additions & 17 deletions redis_array_impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ ra_find_name(const char *name) {
const char *ini_names, *p, *next;
/* php_printf("Loading redis array with name=[%s]\n", name); */

ini_names = INI_STR("redis.arrays.names");
ini_names = zend_ini_string_literal("redis.arrays.names");
for(p = ini_names; p;) {
next = strchr(p, ',');
if(next) {
Expand Down Expand Up @@ -168,7 +168,7 @@ RedisArray *ra_load_array(const char *name) {
double d_connect_timeout = 0, read_timeout = 0.0;
HashTable *hHosts = NULL, *hPrev = NULL;
size_t name_len = strlen(name);
char *iptr;
const char *iptr;

/* find entry */
if(!ra_find_name(name))
Expand All @@ -179,7 +179,7 @@ RedisArray *ra_load_array(const char *name) {

/* find hosts */
array_init(&z_params_hosts);
if ((iptr = INI_STR("redis.arrays.hosts")) != NULL) {
if ((iptr = zend_ini_string_literal("redis.arrays.hosts")) != NULL) {
sapi_module.treat_data(PARSE_STRING, estrdup(iptr), &z_params_hosts);
if ((z_data = zend_hash_str_find(Z_ARRVAL(z_params_hosts), name, name_len)) != NULL) {
hHosts = Z_ARRVAL_P(z_data);
Expand All @@ -188,7 +188,7 @@ RedisArray *ra_load_array(const char *name) {

/* find previous hosts */
array_init(&z_params_prev);
if ((iptr = INI_STR("redis.arrays.previous")) != NULL) {
if ((iptr = zend_ini_string_literal("redis.arrays.previous")) != NULL) {
sapi_module.treat_data(PARSE_STRING, estrdup(iptr), &z_params_prev);
if ((z_data = zend_hash_str_find(Z_ARRVAL(z_params_prev), name, name_len)) != NULL) {
if (Z_TYPE_P(z_data) == IS_ARRAY) {
Expand All @@ -198,87 +198,87 @@ RedisArray *ra_load_array(const char *name) {
}

/* find function */
if ((iptr = INI_STR("redis.arrays.functions")) != NULL) {
if ((iptr = zend_ini_string_literal("redis.arrays.functions")) != NULL) {
array_init(&z_tmp);
sapi_module.treat_data(PARSE_STRING, estrdup(iptr), &z_tmp);
redis_conf_zval(Z_ARRVAL(z_tmp), name, name_len, &z_fun, 1, 0);
zval_ptr_dtor_nogc(&z_tmp);
}

/* find distributor */
if ((iptr = INI_STR("redis.arrays.distributor")) != NULL) {
if ((iptr = zend_ini_string_literal("redis.arrays.distributor")) != NULL) {
array_init(&z_tmp);
sapi_module.treat_data(PARSE_STRING, estrdup(iptr), &z_tmp);
redis_conf_zval(Z_ARRVAL(z_tmp), name, name_len, &z_dist, 1, 0);
zval_ptr_dtor_nogc(&z_tmp);
}

/* find hash algorithm */
if ((iptr = INI_STR("redis.arrays.algorithm")) != NULL) {
if ((iptr = zend_ini_string_literal("redis.arrays.algorithm")) != NULL) {
array_init(&z_tmp);
sapi_module.treat_data(PARSE_STRING, estrdup(iptr), &z_tmp);
redis_conf_string(Z_ARRVAL(z_tmp), name, name_len, &algorithm);
zval_ptr_dtor_nogc(&z_tmp);
}

/* find index option */
if ((iptr = INI_STR("redis.arrays.index")) != NULL) {
if ((iptr = zend_ini_string_literal("redis.arrays.index")) != NULL) {
array_init(&z_tmp);
sapi_module.treat_data(PARSE_STRING, estrdup(iptr), &z_tmp);
redis_conf_zend_bool(Z_ARRVAL(z_tmp), name, name_len, &b_index);
zval_ptr_dtor_nogc(&z_tmp);
}

/* find autorehash option */
if ((iptr = INI_STR("redis.arrays.autorehash")) != NULL) {
if ((iptr = zend_ini_string_literal("redis.arrays.autorehash")) != NULL) {
array_init(&z_tmp);
sapi_module.treat_data(PARSE_STRING, estrdup(iptr), &z_tmp);
redis_conf_zend_bool(Z_ARRVAL(z_tmp), name, name_len, &b_autorehash);
zval_ptr_dtor_nogc(&z_tmp);
}

/* find retry interval option */
if ((iptr = INI_STR("redis.arrays.retryinterval")) != NULL) {
if ((iptr = zend_ini_string_literal("redis.arrays.retryinterval")) != NULL) {
array_init(&z_tmp);
sapi_module.treat_data(PARSE_STRING, estrdup(iptr), &z_tmp);
redis_conf_long(Z_ARRVAL(z_tmp), name, name_len, &l_retry_interval);
zval_ptr_dtor_nogc(&z_tmp);
}

/* find pconnect option */
if ((iptr = INI_STR("redis.arrays.pconnect")) != NULL) {
if ((iptr = zend_ini_string_literal("redis.arrays.pconnect")) != NULL) {
array_init(&z_tmp);
sapi_module.treat_data(PARSE_STRING, estrdup(iptr), &z_tmp);
redis_conf_zend_bool(Z_ARRVAL(z_tmp), name, name_len, &b_pconnect);
zval_ptr_dtor_nogc(&z_tmp);
}

/* find lazy connect option */
if ((iptr = INI_STR("redis.arrays.lazyconnect")) != NULL) {
if ((iptr = zend_ini_string_literal("redis.arrays.lazyconnect")) != NULL) {
array_init(&z_tmp);
sapi_module.treat_data(PARSE_STRING, estrdup(iptr), &z_tmp);
redis_conf_zend_bool(Z_ARRVAL(z_tmp), name, name_len, &b_lazy_connect);
zval_ptr_dtor_nogc(&z_tmp);
}

/* find connect timeout option */
if ((iptr = INI_STR("redis.arrays.connecttimeout")) != NULL) {
if ((iptr = zend_ini_string_literal("redis.arrays.connecttimeout")) != NULL) {
array_init(&z_tmp);
sapi_module.treat_data(PARSE_STRING, estrdup(iptr), &z_tmp);
redis_conf_double(Z_ARRVAL(z_tmp), name, name_len, &d_connect_timeout);
zval_ptr_dtor_nogc(&z_tmp);
}

/* find read timeout option */
if ((iptr = INI_STR("redis.arrays.readtimeout")) != NULL) {
if ((iptr = zend_ini_string_literal("redis.arrays.readtimeout")) != NULL) {
array_init(&z_tmp);
sapi_module.treat_data(PARSE_STRING, estrdup(iptr), &z_tmp);
redis_conf_double(Z_ARRVAL(z_tmp), name, name_len, &read_timeout);
zval_ptr_dtor_nogc(&z_tmp);
}

/* find consistent option */
if ((iptr = INI_STR("redis.arrays.consistent")) != NULL) {
if ((iptr = zend_ini_string_literal("redis.arrays.consistent")) != NULL) {
array_init(&z_tmp);
sapi_module.treat_data(PARSE_STRING, estrdup(iptr), &z_tmp);
if ((z_data = zend_hash_str_find(Z_ARRVAL(z_tmp), name, name_len)) != NULL) {
Expand All @@ -289,7 +289,7 @@ RedisArray *ra_load_array(const char *name) {
}

/* find auth option */
if ((iptr = INI_STR("redis.arrays.auth")) != NULL) {
if ((iptr = zend_ini_string_literal("redis.arrays.auth")) != NULL) {
array_init(&z_tmp);
sapi_module.treat_data(PARSE_STRING, estrdup(iptr), &z_tmp);
redis_conf_auth(Z_ARRVAL(z_tmp), name, name_len, &user, &pass);
Expand Down Expand Up @@ -1225,4 +1225,3 @@ ra_rehash(RedisArray *ra, zend_fcall_info *z_cb, zend_fcall_info_cache *z_cb_cac
ra_rehash_server(ra, &ra->prev->redis[i], ra->prev->hosts[i], ra->index, z_cb, z_cb_cache);
}
}

14 changes: 7 additions & 7 deletions redis_cluster.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ redis_cluster_init_object_handlers(void)
{
memcpy(&RedisCluster_handlers, zend_get_std_object_handlers(),
sizeof(RedisCluster_handlers));
RedisCluster_handlers.offset = XtOffsetOf(redisCluster, std);
RedisCluster_handlers.offset = offsetof(redisCluster, std);
RedisCluster_handlers.free_obj = free_cluster_context;
RedisCluster_handlers.clone_obj = NULL;
}
Expand Down Expand Up @@ -300,12 +300,12 @@ void redis_cluster_load(redisCluster *c, char *name, int name_len) {
zend_string *user = NULL, *pass = NULL;
double timeout = 0, read_timeout = 0;
int persistent = 0;
char *iptr;
const char *iptr;
HashTable *ht_seeds = NULL;

/* Seeds */
array_init(&z_seeds);
if ((iptr = INI_STR("redis.clusters.seeds")) != NULL) {
if ((iptr = zend_ini_string_literal("redis.clusters.seeds")) != NULL) {
sapi_module.treat_data(PARSE_STRING, estrdup(iptr), &z_seeds);
}
if ((z_value = zend_hash_str_find(Z_ARRVAL(z_seeds), name, name_len)) != NULL) {
Expand All @@ -317,30 +317,30 @@ void redis_cluster_load(redisCluster *c, char *name, int name_len) {
}

/* Connection timeout */
if ((iptr = INI_STR("redis.clusters.timeout")) != NULL) {
if ((iptr = zend_ini_string_literal("redis.clusters.timeout")) != NULL) {
array_init(&z_tmp);
sapi_module.treat_data(PARSE_STRING, estrdup(iptr), &z_tmp);
redis_conf_double(Z_ARRVAL(z_tmp), name, name_len, &timeout);
zval_ptr_dtor_nogc(&z_tmp);
}

/* Read timeout */
if ((iptr = INI_STR("redis.clusters.read_timeout")) != NULL) {
if ((iptr = zend_ini_string_literal("redis.clusters.read_timeout")) != NULL) {
array_init(&z_tmp);
sapi_module.treat_data(PARSE_STRING, estrdup(iptr), &z_tmp);
redis_conf_double(Z_ARRVAL(z_tmp), name, name_len, &read_timeout);
zval_ptr_dtor_nogc(&z_tmp);
}

/* Persistent connections */
if ((iptr = INI_STR("redis.clusters.persistent")) != NULL) {
if ((iptr = zend_ini_string_literal("redis.clusters.persistent")) != NULL) {
array_init(&z_tmp);
sapi_module.treat_data(PARSE_STRING, estrdup(iptr), &z_tmp);
redis_conf_bool(Z_ARRVAL(z_tmp), name, name_len, &persistent);
zval_ptr_dtor_nogc(&z_tmp);
}

if ((iptr = INI_STR("redis.clusters.auth"))) {
if ((iptr = zend_ini_string_literal("redis.clusters.auth"))) {
array_init(&z_tmp);
sapi_module.treat_data(PARSE_STRING, estrdup(iptr), &z_tmp);
redis_conf_auth(Z_ARRVAL(z_tmp), name, name_len, &user, &pass);
Expand Down
Loading
Loading