Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 08e1064

Browse files
authored
Merge pull request #961 from yatsukhnenko/develop
WIP: php7 compatibility
2 parents 5b22204 + 377dc50 commit 08e1064

4 files changed

Lines changed: 51 additions & 27 deletions

File tree

common.h

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,13 @@ typedef smart_str smart_string;
1313
#define smart_string_appendl(dest, src, len) smart_str_appendl(dest, src, len)
1414

1515
#define ZEND_HASH_FOREACH_VAL(ht, _val) do { \
16-
zval **_pData; \
1716
HashPosition _hpos; \
1817
for (zend_hash_internal_pointer_reset_ex(ht, &_hpos); \
19-
zend_hash_get_current_data_ex(ht, (void **) &_pData, &_hpos) == SUCCESS; \
18+
(_val = zend_hash_get_current_data_ex(ht, &_hpos)) != NULL; \
2019
zend_hash_move_forward_ex(ht, &_hpos) \
21-
) { _val = *_pData;
20+
)
2221

23-
#define ZEND_HASH_FOREACH_END() \
24-
} \
25-
} while(0)
22+
#define ZEND_HASH_FOREACH_END() } while(0)
2623

2724
static zend_always_inline zval *
2825
zend_hash_str_find(const HashTable *ht, const char *key, size_t len)
@@ -93,6 +90,32 @@ zend_hash_index_find_ptr(const HashTable *ht, zend_ulong h)
9390
return NULL;
9491
}
9592

93+
static int (*_zend_hash_get_current_data_ex)(HashTable *, void **, HashPosition *) = &zend_hash_get_current_data_ex;
94+
#define zend_hash_get_current_data_ex(ht, pos) inline_zend_hash_get_current_data_ex(ht, pos)
95+
static zend_always_inline zval *
96+
inline_zend_hash_get_current_data_ex(HashTable *ht, HashPosition *pos)
97+
{
98+
zval **zv;
99+
if (_zend_hash_get_current_data_ex(ht, (void **)&zv, pos) == SUCCESS) {
100+
return *zv;
101+
}
102+
return NULL;
103+
}
104+
105+
#undef zend_hash_next_index_insert
106+
#define zend_hash_next_index_insert(ht, pData) \
107+
_zend_hash_next_index_insert(ht, pData ZEND_FILE_LINE_CC)
108+
static zend_always_inline zval *
109+
_zend_hash_next_index_insert(HashTable *ht, zval *pData ZEND_FILE_LINE_DC)
110+
{
111+
if (_zend_hash_index_update_or_next_insert(ht, 0, &pData, sizeof(pData),
112+
NULL, HASH_NEXT_INSERT ZEND_FILE_LINE_CC) == SUCCESS
113+
) {
114+
return pData;
115+
}
116+
return NULL;
117+
}
118+
96119
#undef zend_get_parameters_array
97120
#define zend_get_parameters_array(ht, param_count, argument_array) \
98121
inline_zend_get_parameters_array(ht, param_count, argument_array TSRMLS_CC)

redis_array_impl.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ void
581581
ra_index_keys(zval *z_pairs, zval *z_redis TSRMLS_DC) {
582582

583583
/* Initialize key array */
584-
zval *z_keys, **z_entry_pp;
584+
zval *z_keys;
585585
MAKE_STD_ZVAL(z_keys);
586586
HashPosition pos;
587587
#if PHP_VERSION_ID > 50300
@@ -592,7 +592,7 @@ ra_index_keys(zval *z_pairs, zval *z_redis TSRMLS_DC) {
592592

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

608608
case HASH_KEY_IS_LONG:
609609
Z_TYPE_P(z_new) = IS_LONG;
610610
Z_LVAL_P(z_new) = (long)num_key;
611-
zend_hash_next_index_insert(Z_ARRVAL_P(z_keys), &z_new, sizeof(zval *), NULL);
611+
zend_hash_next_index_insert(Z_ARRVAL_P(z_keys), z_new);
612612
break;
613613
}
614614
zend_hash_move_forward_ex(Z_ARRVAL_P(z_pairs), &pos);

redis_cluster.c

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ typedef struct clusterKeyValHT {
567567
static int get_key_val_ht(redisCluster *c, HashTable *ht, HashPosition *ptr,
568568
clusterKeyValHT *kv TSRMLS_DC)
569569
{
570-
zval **z_val;
570+
zval *z_val;
571571
unsigned int key_len;
572572
ulong idx;
573573

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

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

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

606606
// Success
@@ -611,20 +611,20 @@ static int get_key_val_ht(redisCluster *c, HashTable *ht, HashPosition *ptr,
611611
static int get_key_ht(redisCluster *c, HashTable *ht, HashPosition *ptr,
612612
clusterKeyValHT *kv TSRMLS_DC)
613613
{
614-
zval **z_key;
614+
zval *z_key;
615615

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

623623
// Always want to work with strings
624-
convert_to_string(*z_key);
624+
convert_to_string(z_key);
625625

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

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

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

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

671671
/* Extract our arguments into an array */
672-
z_args = emalloc(sizeof(zval)*argc);
673-
if (zend_get_parameters_array(ht, ZEND_NUM_ARGS(), z_args) == FAILURE) {
672+
z_args = ecalloc(argc, sizeof(zval));
673+
if (zend_get_parameters_array(ht, argc, z_args) == FAILURE) {
674674
efree(z_args);
675675
return -1;
676676
}
@@ -688,9 +688,6 @@ static int cluster_mkey_cmd(INTERNAL_FUNCTION_PARAMETERS, char *kw, int kw_len,
688688
ht_free = 1;
689689
}
690690

691-
/* We no longer need our array args */
692-
efree(z_args);
693-
694691
/* MGET is readonly, DEL is not */
695692
c->readonly = kw_len == 4 && CLUSTER_IS_ATOMIC(c);
696693

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

@@ -722,6 +720,7 @@ static int cluster_mkey_cmd(INTERNAL_FUNCTION_PARAMETERS, char *kw, int kw_len,
722720
zend_hash_destroy(ht_arr);
723721
efree(ht_arr);
724722
}
723+
efree(z_args);
725724
return -1;
726725
}
727726

@@ -736,6 +735,7 @@ static int cluster_mkey_cmd(INTERNAL_FUNCTION_PARAMETERS, char *kw, int kw_len,
736735
zend_hash_destroy(ht_arr);
737736
efree(ht_arr);
738737
}
738+
efree(z_args);
739739
return -1;
740740
}
741741
}
@@ -752,6 +752,7 @@ static int cluster_mkey_cmd(INTERNAL_FUNCTION_PARAMETERS, char *kw, int kw_len,
752752

753753
zend_hash_move_forward_ex(ht_arr, &ptr);
754754
}
755+
efree(z_args);
755756

756757
// If we've got straggler(s) process them
757758
if(mc.argc > 0) {

redis_commands.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1618,12 +1618,12 @@ int redis_hmset_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
16181618
char *mem, *val, kbuf[40];
16191619
int val_len, val_free;
16201620
unsigned int mem_len;
1621-
zval **z_val;
1621+
zval *z_val;
16221622

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

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

16371637
// Serialize value (if directed)
1638-
val_free = redis_serialize(redis_sock, *z_val, &val, &val_len TSRMLS_CC);
1638+
val_free = redis_serialize(redis_sock, z_val, &val, &val_len TSRMLS_CC);
16391639

16401640
// Append the key and value to our command
16411641
redis_cmd_append_sstr(&cmdstr, mem, mem_len);

0 commit comments

Comments
 (0)