8000 WIP: php7 compatibility by yatsukhnenko · Pull Request #961 · phpredis/phpredis · GitHub
[go: up one dir, main page]

Skip to content

WIP: php7 compatibility #961

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 23, 2016
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
35 changes: 29 additions & 6 deletions common.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,13 @@ typedef smart_str smart_string;
#define smart_string_appendl(dest, src, len) smart_str_appendl(dest, src, len)

#define ZEND_HASH_FOREACH_VAL(ht, _val) do { \
zval **_pData; \
HashPosition _hpos; \
for (zend_hash_internal_pointer_reset_ex(ht, &_hpos); \
zend_hash_get_current_data_ex(ht, (void **) &_pData, &_hpos) == SUCCESS; \
(_val = zend_hash_get_current_data_ex(ht, &_hpos)) != NULL; \
zend_hash_move_forward_ex(ht, &_hpos) \
) { _val = *_pData;
)

#define ZEND_HASH_FOREACH_END() \
} \
} while(0)
#define ZEND_HASH_FOREACH_END() } while(0)

static zend_always_inline zval *
zend_hash_str_find(const HashTable *ht, const char *key, size_t len)
Expand Down Expand Up @@ -93,6 +90,32 @@ zend_hash_index_find_ptr(const HashTable *ht, zend_ulong h)
return NULL;
}

static int (*_zend_hash_get_current_data_ex)(HashTable *, void **, HashPosition *) = &zend_hash_get_current_data_ex;
#define zend_hash_get_current_data_ex(ht, pos) inline_zend_hash_get_current_data_ex(ht, pos)
static zend_always_inline zval *
inline_zend_hash_get_current_data_ex(HashTable *ht, HashPosition *pos)
{
zval **zv;
if (_zend_hash_get_current_data_ex(ht, (void **)&zv, pos) == SUCCESS) {
return *zv;
}
return NULL;
}

#undef zend_hash_next_index_insert
#define zend_hash_next_index_insert(ht, pData) \
_zend_hash_next_index_insert(ht, pData ZEND_FILE_LINE_CC)
static zend_always_inline zval *
_zend_hash_next_index_insert(HashTable *ht, zval *pData ZEND_FILE_LINE_DC)
{
if (_zend_hash_index_update_or_next_insert(ht, 0, &pData, sizeof(pData),
NULL, HASH_NEXT_INSERT ZEND_FILE_LINE_CC) == SUCCESS
) {
return pData;
}
return NULL;
}

#undef zend_get_parameters_array
#define zend_get_parameters_array(ht, param_count, argument_array) \
inline_zend_get_parameters_array(ht, param_count, argument_array TSRMLS_CC)
Expand Down
8 changes: 4 additions & 4 deletions redis_array_impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ void
ra_index_keys(zval *z_pairs, zval *z_redis TSRMLS_DC) {

/* Initialize key array */
zval *z_keys, **z_entry_pp;
zval *z_keys;
MAKE_STD_ZVAL(z_keys);
HashPosition pos;
#if PHP_VERSION_ID > 50300
Expand All @@ -592,7 +592,7 @@ ra_index_keys(zval *z_pairs, zval *z_redis TSRMLS_DC) {

/* Go through input array and add values to the key array */
zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(z_pairs), &pos);
while (zend_hash_get_current_data_ex(Z_ARRVAL_P(z_pairs), (void **)&z_entry_pp, &pos) == SUCCESS) {
while (zend_hash_get_current_data_ex(Z_ARRVAL_P(z_pairs), &pos) != NULL) {
char *key;
unsigned int key_len;
unsigned long num_key;
Expand All @@ -602,13 +602,13 @@ ra_index_keys(zval *z_pairs, zval *z_redis TSRMLS_DC) {
switch (zend_hash_get_current_key_ex(Z_ARRVAL_P(z_pairs), &key, &key_len, &num_key, 1, &pos)) {
case HASH_KEY_IS_STRING:
ZVAL_STRINGL(z_new, key, (int)key_len - 1, 0);
zend_hash_next_index_insert(Z_ARRVAL_P(z_keys), &z_new, sizeof(zval *), NULL);
zend_hash_next_index_insert(Z_ARRVAL_P(z_keys), z_new);
break;

case HASH_KEY_IS_LONG:
Z_TYPE_P(z_new) = IS_LONG;
Z_LVAL_P(z_new) = (long)num_key;
zend_hash_next_index_insert(Z_ARRVAL_P(z_keys), &z_new, sizeof(zval *), NULL);
zend_hash_next_index_insert(Z_ARRVAL_P(z_keys), z_new);
break;
}
zend_hash_move_forward_ex(Z_ARRVAL_P(z_pairs), &pos);
Expand Down
29 changes: 15 additions & 14 deletions redis_cluster.c
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ typedef struct clusterKeyValHT {
static int get_key_val_ht(redisCluster *c, HashTable *ht, HashPosition *ptr,
clusterKeyValHT *kv TSRMLS_DC)
{
zval **z_val;
zval *z_val;
unsigned int key_len;
ulong idx;

Expand All @@ -593,14 +593,14 @@ static int get_key_val_ht(redisCluster *c, HashTable *ht, HashPosition *ptr,
kv->slot = cluster_hash_key(kv->key, kv->key_len);

// Now grab our value
if(zend_hash_get_current_data_ex(ht, (void**)&z_val, ptr)==FAILURE) {
if ((z_val = zend_hash_get_current_data_ex(ht, ptr)) == NULL) {
zend_throw_exception(redis_cluster_exception_ce,
"Internal Zend HashTable error", 0 TSRMLS_CC);
return -1;
}

// Serialize our value if required
kv->val_free = redis_serialize(c->flags,*z_val,&(kv->val),&(kv->val_len)
kv->val_free = redis_serialize(c->flags,z_val,&(kv->val),&(kv->val_len)
TSRMLS_CC);

// Success
Expand All @@ -611,20 +611,20 @@ static int get_key_val_ht(redisCluster *c, HashTable *ht, HashPosition *ptr,
static int get_key_ht(redisCluster *c, HashTable *ht, HashPosition *ptr,
clusterKeyValHT *kv TSRMLS_DC)
{
zval **z_key;
zval *z_key;

if(zend_hash_get_current_data_ex(ht, (void**)&z_key, ptr)==FAILURE) {
if ((z_key = zend_hash_get_current_data_ex(ht, ptr)) == NULL) {
// Shouldn't happen, but check anyway
zend_throw_exception(redis_cluster_exception_ce,
"Internal Zend HashTable error", 0 TSRMLS_CC);
return -1;
}

// Always want to work with strings
convert_to_string(*z_key);
convert_to_string(z_key);

kv->key = Z_STRVAL_PP(z_key);
kv->key_len = Z_STRLEN_PP(z_key);
kv->key = Z_STRVAL_P(z_key);
kv->key_len = Z_STRLEN_P(z_key);
kv->key_free = redis_key_prefix(c->flags, &(kv->key), &(kv->key_len));

// Hash our key
Expand All @@ -645,7 +645,7 @@ static HashTable *method_args_to_ht(zval *z_args, int argc) {

/* Populate our return hash table with our arguments */
for (i = 0; i < argc; i++) {
zend_hash_next_index_insert(ht_ret, &z_args[i], sizeof(zval), NULL);
zend_hash_next_index_insert(ht_ret, &z_args[i]);
}

/* Return our hash table */
Expand All @@ -669,8 +669,8 @@ static int cluster_mkey_cmd(INTERNAL_FUNCTION_PARAMETERS, char *kw, int kw_len,
if (!argc) return -1;

/* Extract our arguments into an array */
z_args = emalloc(sizeof(zval)*argc);
if (zend_get_parameters_array(ht, ZEND_NUM_ARGS(), z_args) == FAILURE) {
z_args = ecalloc(argc, sizeof(zval));
if (zend_get_parameters_array(ht, argc, z_args) == FAILURE) {
efree(z_args);
return -1;
}
Expand All @@ -688,9 +688,6 @@ static int cluster_mkey_cmd(INTERNAL_FUNCTION_PARAMETERS, char *kw, int kw_len,
ht_free = 1;
}

/* We no longer need our array args */
efree(z_args);

/* MGET is readonly, DEL is not */
c->readonly = kw_len == 4 && CLUSTER_IS_ATOMIC(c);

Expand All @@ -701,6 +698,7 @@ static int cluster_mkey_cmd(INTERNAL_FUNCTION_PARAMETERS, char *kw, int kw_len,
// it's the first iteration every time, needlessly
zend_hash_internal_pointer_reset_ex(ht_arr, &ptr);
if(get_key_ht(c, ht_arr, &ptr, &kv TSRMLS_CC)<0) {
efree(z_args);
return -1;
}

Expand All @@ -722,6 +720,7 @@ static int cluster_mkey_cmd(INTERNAL_FUNCTION_PARAMETERS, char *kw, int kw_len,
zend_hash_destroy(ht_arr);
efree(ht_arr);
}
efree(z_args);
return -1;
}

Expand All @@ -736,6 +735,7 @@ static int cluster_mkey_cmd(INTERNAL_FUNCTION_PARAMETERS, char *kw, int kw_len,
zend_hash_destroy(ht_arr);
efree(ht_arr);
}
efree(z_args);
return -1;
}
}
Expand All @@ -752,6 +752,7 @@ static int cluster_mkey_cmd(INTERNAL_FUNCTION_PARAMETERS, char *kw, int kw_len,

zend_hash_move_forward_ex(ht_arr, &ptr);
}
efree(z_args);

// If we've got straggler(s) process them
if(mc.argc > 0) {
Expand Down
6 changes: 3 additions & 3 deletions redis_commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -1618,12 +1618,12 @@ int redis_hmset_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
char *mem, *val, kbuf[40];
int val_len, val_free;
unsigned int mem_len;
zval **z_val;
zval *z_val;

// Grab our key, and value for this element in our input
ktype = zend_hash_get_current_key_ex(ht_vals, &mem,
&mem_len, &idx, 0, &pos);
zend_hash_get_current_data_ex(ht_vals, (void**)&z_val, &pos);
z_val = zend_hash_get_current_data_ex(ht_vals, &pos);

// If the hash key is an integer, convert it to a string
if(ktype != HASH_KEY_IS_STRING) {
Expand All @@ -1635,7 +1635,7 @@ int redis_hmset_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
}

// Serialize value (if directed)
val_free = redis_serialize(redis_sock, *z_val, &val, &val_len TSRMLS_CC);
val_free = redis_serialize(redis_sock, z_val, &val, &val_len TSRMLS_CC);

// Append the key and value to our command
redis_cmd_append_sstr(&cmdstr, mem, mem_len);
Expand Down
0