summaryrefslogtreecommitdiff
path: root/ext/standard/array.c
diff options
context:
space:
mode:
Diffstat (limited to 'ext/standard/array.c')
-rw-r--r--ext/standard/array.c1234
1 files changed, 585 insertions, 649 deletions
diff --git a/ext/standard/array.c b/ext/standard/array.c
index 9892bd49ae..502d15ea3a 100644
--- a/ext/standard/array.c
+++ b/ext/standard/array.c
@@ -184,22 +184,16 @@ static int php_array_key_compare(const void *a, const void *b TSRMLS_DC) /* {{{
f = (Bucket *) a;
s = (Bucket *) b;
- if (f->nKeyLength == 0) {
- Z_TYPE(first) = IS_LONG;
- Z_LVAL(first) = f->h;
+ if (f->key == NULL) {
+ ZVAL_LONG(&first, f->h);
} else {
- Z_TYPE(first) = IS_STRING;
- Z_STRVAL(first) = (char*)f->arKey;
- Z_STRLEN(first) = f->nKeyLength - 1;
+ ZVAL_STR(&first, f->key);
}
- if (s->nKeyLength == 0) {
- Z_TYPE(second) = IS_LONG;
- Z_LVAL(second) = s->h;
+ if (s->key == 0) {
+ ZVAL_LONG(&second, s->h);
} else {
- Z_TYPE(second) = IS_STRING;
- Z_STRVAL(second) = (char*)s->arKey;
- Z_STRLEN(second) = s->nKeyLength - 1;
+ ZVAL_STR(&second, s->key);
}
if (ARRAYG(compare_func)(&result, &first, &second TSRMLS_CC) == FAILURE) {
@@ -277,7 +271,7 @@ PHP_FUNCTION(ksort)
static int php_count_recursive(zval *array, long mode TSRMLS_DC) /* {{{ */
{
long cnt = 0;
- zval **element;
+ zval *element;
if (Z_TYPE_P(array) == IS_ARRAY) {
if (Z_ARRVAL_P(array)->nApplyCount > 1) {
@@ -290,11 +284,11 @@ static int php_count_recursive(zval *array, long mode TSRMLS_DC) /* {{{ */
HashPosition pos;
for (zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(array), &pos);
- zend_hash_get_current_data_ex(Z_ARRVAL_P(array), (void **) &element, &pos) == SUCCESS;
+ (element = zend_hash_get_current_data_ex(Z_ARRVAL_P(array), &pos)) != NULL;
zend_hash_move_forward_ex(Z_ARRVAL_P(array), &pos)
) {
Z_ARRVAL_P(array)->nApplyCount++;
- cnt += php_count_recursive(*element, COUNT_RECURSIVE TSRMLS_CC);
+ cnt += php_count_recursive(element, COUNT_RECURSIVE TSRMLS_CC);
Z_ARRVAL_P(array)->nApplyCount--;
}
}
@@ -324,7 +318,7 @@ PHP_FUNCTION(count)
break;
case IS_OBJECT: {
#ifdef HAVE_SPL
- zval *retval;
+ zval retval;
#endif
/* first, we check if the handler is defined */
if (Z_OBJ_HT_P(array)->count_elements) {
@@ -333,21 +327,18 @@ PHP_FUNCTION(count)
return;
}
}
-//???
-#if 0
#ifdef HAVE_SPL
/* if not and the object implements Countable we call its count() method */
if (Z_OBJ_HT_P(array)->get_class_entry && instanceof_function(Z_OBJCE_P(array), spl_ce_Countable TSRMLS_CC)) {
- zend_call_method_with_0_params(&array, NULL, NULL, "count", &retval);
- if (retval) {
+ zend_call_method_with_0_params(array, NULL, NULL, "count", &retval);
+ if (Z_TYPE(retval) != IS_UNDEF) {
convert_to_long_ex(&retval);
- RETVAL_LONG(Z_LVAL_P(retval));
+ RETVAL_LONG(Z_LVAL(retval));
zval_ptr_dtor(&retval);
}
return;
}
#endif
-#endif
}
default:
RETURN_LONG(1);
@@ -373,8 +364,8 @@ static int php_array_data_compare(const void *a, const void *b TSRMLS_DC) /* {{{
f = (Bucket *) a;
s = (Bucket *) b;
- first = (zval *) f->xData;
- second = (zval *) s->xData;
+ first = &f->val;
+ second = &s->val;
if (ARRAYG(compare_func)(&result, first, second TSRMLS_CC) == FAILURE) {
return 0;
@@ -418,10 +409,10 @@ static int php_array_natural_general_compare(const void *a, const void *b, int f
f = (Bucket *) a;
s = (Bucket *) b;
- fval = (zval *) f->xData;
- sval = (zval *) s->xData;
- first = *fval;
- second = *sval;
+ fval = &f->val;
+ sval = &s->val;
+ ZVAL_COPY_VALUE(&first, fval);
+ ZVAL_COPY_VALUE(&second, sval);
if (Z_TYPE_P(fval) != IS_STRING) {
zval_copy_ctor(&first);
@@ -581,26 +572,26 @@ static int php_array_user_compare(const void *a, const void *b TSRMLS_DC) /* {{{
{
Bucket *f;
Bucket *s;
- zval **args[2];
- zval *retval_ptr = NULL;
+ zval args[2];
+ zval retval;
f = (Bucket *) a;
s = (Bucket *) b;
- args[0] = (zval **) &f->xData;
- args[1] = (zval **) &s->xData;
+ ZVAL_COPY_VALUE(&args[0], &f->val);
+ ZVAL_COPY_VALUE(&args[1], &s->val);
BG(user_compare_fci).param_count = 2;
BG(user_compare_fci).params = args;
- BG(user_compare_fci).retval_ptr_ptr = &retval_ptr;
+ BG(user_compare_fci).retval = &retval;
BG(user_compare_fci).no_separation = 0;
- if (zend_call_function(&BG(user_compare_fci), &BG(user_compare_fci_cache) TSRMLS_CC) == SUCCESS && retval_ptr) {
- long retval;
+ if (zend_call_function(&BG(user_compare_fci), &BG(user_compare_fci_cache) TSRMLS_CC) == SUCCESS && Z_TYPE(retval) != IS_UNDEF) {
+ long ret;
- convert_to_long_ex(&retval_ptr);
- retval = Z_LVAL_P(retval_ptr);
- zval_ptr_dtor(&retval_ptr);
- return retval < 0 ? -1 : retval > 0 ? 1 : 0;
+ convert_to_long_ex(&retval);
+ ret = Z_LVAL(retval);
+ zval_ptr_dtor(&retval);
+ return ret < 0 ? -1 : ret > 0 ? 1 : 0;
} else {
return 0;
}
@@ -657,7 +648,7 @@ PHP_FUNCTION(usort)
* comparison. The result of sorting in such case is undefined and the
* function returns FALSE.
*/
- Z_UNSET_ISREF_P(array);
+//??? Z_UNSET_ISREF_P(array);
refcount = Z_REFCOUNT_P(array);
if (zend_hash_sort(Z_ARRVAL_P(array), zend_qsort, php_array_user_compare, 1 TSRMLS_CC) == FAILURE) {
@@ -672,7 +663,7 @@ PHP_FUNCTION(usort)
}
if (Z_REFCOUNT_P(array) > 1) {
- Z_SET_ISREF_P(array);
+//??? Z_SET_ISREF_P(array);
}
PHP_ARRAY_CMP_FUNC_RESTORE();
@@ -700,7 +691,7 @@ PHP_FUNCTION(uasort)
* comparison. The result of sorting in such case is undefined and the
* function returns FALSE.
*/
- Z_UNSET_ISREF_P(array);
+//??? Z_UNSET_ISREF_P(array);
refcount = Z_REFCOUNT_P(array);
if (zend_hash_sort(Z_ARRVAL_P(array), zend_qsort, php_array_user_compare, 0 TSRMLS_CC) == FAILURE) {
@@ -715,7 +706,7 @@ PHP_FUNCTION(uasort)
}
if (Z_REFCOUNT_P(array) > 1) {
- Z_SET_ISREF_P(array);
+//??? Z_SET_ISREF_P(array);
}
PHP_ARRAY_CMP_FUNC_RESTORE();
@@ -726,50 +717,41 @@ static int php_array_user_key_compare(const void *a, const void *b TSRMLS_DC) /*
{
Bucket *f;
Bucket *s;
- zval *key1, *key2;
- zval **args[2];
- zval *retval_ptr = NULL;
+ zval args[2];
+ zval retval;
long result;
- ALLOC_INIT_ZVAL(key1);
- ALLOC_INIT_ZVAL(key2);
- args[0] = &key1;
- args[1] = &key2;
+ ZVAL_NULL(&args[0]);
+ ZVAL_NULL(&args[1]);
f = (Bucket *) a;
s = (Bucket *) b;
- if (f->nKeyLength == 0) {
- Z_LVAL_P(key1) = f->h;
- Z_TYPE_P(key1) = IS_LONG;
+ if (f->key == NULL) {
+ ZVAL_LONG(&args[0], f->h);
} else {
- Z_STRVAL_P(key1) = estrndup(f->arKey, f->nKeyLength - 1);
- Z_STRLEN_P(key1) = f->nKeyLength - 1;
- Z_TYPE_P(key1) = IS_STRING;
+ ZVAL_STR(&args[0], STR_COPY(f->key));
}
- if (s->nKeyLength == 0) {
- Z_LVAL_P(key2) = s->h;
- Z_TYPE_P(key2) = IS_LONG;
+ if (s->key == NULL) {
+ ZVAL_LONG(&args[1], s->h);
} else {
- Z_STRVAL_P(key2) = estrndup(s->arKey, s->nKeyLength - 1);
- Z_STRLEN_P(key2) = s->nKeyLength - 1;
- Z_TYPE_P(key2) = IS_STRING;
+ ZVAL_STR(&args[1], STR_COPY(s->key));
}
BG(user_compare_fci).param_count = 2;
BG(user_compare_fci).params = args;
- BG(user_compare_fci).retval_ptr_ptr = &retval_ptr;
+ BG(user_compare_fci).retval = &retval;
BG(user_compare_fci).no_separation = 0;
- if (zend_call_function(&BG(user_compare_fci), &BG(user_compare_fci_cache) TSRMLS_CC) == SUCCESS && retval_ptr) {
- convert_to_long_ex(&retval_ptr);
- result = Z_LVAL_P(retval_ptr);
- zval_ptr_dtor(&retval_ptr);
+ if (zend_call_function(&BG(user_compare_fci), &BG(user_compare_fci_cache) TSRMLS_CC) == SUCCESS && Z_TYPE(retval) != IS_UNDEF) {
+ convert_to_long_ex(&retval);
+ result = Z_LVAL(retval);
+ zval_ptr_dtor(&retval);
} else {
result = 0;
}
- zval_ptr_dtor(&key1);
- zval_ptr_dtor(&key2);
+ zval_ptr_dtor(&args[0]);
+ zval_ptr_dtor(&args[1]);
return result;
}
@@ -796,7 +778,7 @@ PHP_FUNCTION(uksort)
* comparison. The result of sorting in such case is undefined and the
* function returns FALSE.
*/
- Z_UNSET_ISREF_P(array);
+//??? Z_UNSET_ISREF_P(array);
refcount = Z_REFCOUNT_P(array);
if (zend_hash_sort(Z_ARRVAL_P(array), zend_qsort, php_array_user_key_compare, 0 TSRMLS_CC) == FAILURE) {
@@ -811,7 +793,7 @@ PHP_FUNCTION(uksort)
}
if (Z_REFCOUNT_P(array) > 1) {
- Z_SET_ISREF_P(array);
+//??? Z_SET_ISREF_P(array);
}
PHP_ARRAY_CMP_FUNC_RESTORE();
@@ -823,7 +805,7 @@ PHP_FUNCTION(uksort)
PHP_FUNCTION(end)
{
HashTable *array;
- zval **entry;
+ zval *entry;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "H", &array) == FAILURE) {
return;
@@ -832,11 +814,11 @@ PHP_FUNCTION(end)
zend_hash_internal_pointer_end(array);
if (return_value_used) {
- if (zend_hash_get_current_data(array, (void **) &entry) == FAILURE) {
+ if ((entry = zend_hash_get_current_data(array)) == NULL) {
RETURN_FALSE;
}
- RETURN_ZVAL_FAST(*entry);
+ RETURN_ZVAL_FAST(entry);
}
}
/* }}} */
@@ -846,7 +828,7 @@ PHP_FUNCTION(end)
PHP_FUNCTION(prev)
{
HashTable *array;
- zval **entry;
+ zval *entry;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "H", &array) == FAILURE) {
return;
@@ -855,11 +837,11 @@ PHP_FUNCTION(prev)
zend_hash_move_backwards(array);
if (return_value_used) {
- if (zend_hash_get_current_data(array, (void **) &entry) == FAILURE) {
+ if ((entry = zend_hash_get_current_data(array)) == NULL) {
RETURN_FALSE;
}
- RETURN_ZVAL_FAST(*entry);
+ RETURN_ZVAL_FAST(entry);
}
}
/* }}} */
@@ -869,7 +851,7 @@ PHP_FUNCTION(prev)
PHP_FUNCTION(next)
{
HashTable *array;
- zval **entry;
+ zval *entry;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "H", &array) == FAILURE) {
return;
@@ -878,11 +860,11 @@ PHP_FUNCTION(next)
zend_hash_move_forward(array);
if (return_value_used) {
- if (zend_hash_get_current_data(array, (void **) &entry) == FAILURE) {
+ if ((entry = zend_hash_get_current_data(array)) == NULL) {
RETURN_FALSE;
}
- RETURN_ZVAL_FAST(*entry);
+ RETURN_ZVAL_FAST(entry);
}
}
/* }}} */
@@ -892,7 +874,7 @@ PHP_FUNCTION(next)
PHP_FUNCTION(reset)
{
HashTable *array;
- zval **entry;
+ zval *entry;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "H", &array) == FAILURE) {
return;
@@ -901,11 +883,11 @@ PHP_FUNCTION(reset)
zend_hash_internal_pointer_reset(array);
if (return_value_used) {
- if (zend_hash_get_current_data(array, (void **) &entry) == FAILURE) {
+ if ((entry = zend_hash_get_current_data(array)) == NULL) {
RETURN_FALSE;
}
- RETURN_ZVAL_FAST(*entry);
+ RETURN_ZVAL_FAST(entry);
}
}
/* }}} */
@@ -915,17 +897,17 @@ PHP_FUNCTION(reset)
PHP_FUNCTION(current)
{
HashTable *array;
- zval **entry;
+ zval *entry;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "H", &array) == FAILURE) {
return;
}
- if (zend_hash_get_current_data(array, (void **) &entry) == FAILURE) {
+ if ((entry = zend_hash_get_current_data(array)) == NULL) {
RETURN_FALSE;
}
- RETURN_ZVAL_FAST(*entry);
+ RETURN_ZVAL_FAST(entry);
}
/* }}} */
@@ -948,7 +930,7 @@ PHP_FUNCTION(key)
PHP_FUNCTION(min)
{
int argc;
- zval ***args = NULL;
+ zval *args = NULL;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "+", &args, &argc) == FAILURE) {
return;
@@ -958,14 +940,14 @@ PHP_FUNCTION(min)
/* mixed min ( array $values ) */
if (argc == 1) {
- zval **result;
+ zval *result;
- if (Z_TYPE_PP(args[0]) != IS_ARRAY) {
+ if (Z_TYPE(args[0]) != IS_ARRAY) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "When only one parameter is given, it must be an array");
RETVAL_NULL();
} else {
- if (zend_hash_minmax(Z_ARRVAL_PP(args[0]), php_array_data_compare, 0, (void **) &result TSRMLS_CC) == SUCCESS) {
- RETVAL_ZVAL_FAST(*result);
+ if ((result = zend_hash_minmax(Z_ARRVAL(args[0]), php_array_data_compare, 0 TSRMLS_CC)) != NULL) {
+ RETVAL_ZVAL_FAST(result);
} else {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Array must contain at least one element");
RETVAL_FALSE;
@@ -973,19 +955,19 @@ PHP_FUNCTION(min)
}
} else {
/* mixed min ( mixed $value1 , mixed $value2 [, mixed $value3... ] ) */
- zval **min, result;
+ zval *min, result;
int i;
- min = args[0];
+ min = &args[0];
for (i = 1; i < argc; i++) {
- is_smaller_function(&result, *args[i], *min TSRMLS_CC);
+ is_smaller_function(&result, &args[i], min TSRMLS_CC);
if (Z_LVAL(result) == 1) {
- min = args[i];
+ min = &args[i];
}
}
- RETVAL_ZVAL_FAST(*min);
+ RETVAL_ZVAL_FAST(min);
}
if (args) {
@@ -998,7 +980,7 @@ PHP_FUNCTION(min)
Return the highest value in an array or a series of arguments */
PHP_FUNCTION(max)
{
- zval ***args = NULL;
+ zval *args = NULL;
int argc;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "+", &args, &argc) == FAILURE) {
@@ -1009,14 +991,14 @@ PHP_FUNCTION(max)
/* mixed max ( array $values ) */
if (argc == 1) {
- zval **result;
+ zval *result;
- if (Z_TYPE_PP(args[0]) != IS_ARRAY) {
+ if (Z_TYPE(args[0]) != IS_ARRAY) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "When only one parameter is given, it must be an array");
RETVAL_NULL();
} else {
- if (zend_hash_minmax(Z_ARRVAL_PP(args[0]), php_array_data_compare, 1, (void **) &result TSRMLS_CC) == SUCCESS) {
- RETVAL_ZVAL_FAST(*result);
+ if ((result = zend_hash_minmax(Z_ARRVAL(args[0]), php_array_data_compare, 1 TSRMLS_CC)) != NULL) {
+ RETVAL_ZVAL_FAST(result);
} else {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Array must contain at least one element");
RETVAL_FALSE;
@@ -1024,19 +1006,19 @@ PHP_FUNCTION(max)
}
} else {
/* mixed max ( mixed $value1 , mixed $value2 [, mixed $value3... ] ) */
- zval **max, result;
+ zval *max, result;
int i;
- max = args[0];
+ max = &args[0];
for (i = 1; i < argc; i++) {
- is_smaller_or_equal_function(&result, *args[i], *max TSRMLS_CC);
+ is_smaller_or_equal_function(&result, &args[i], max TSRMLS_CC);
if (Z_LVAL(result) == 0) {
- max = args[i];
+ max = &args[i];
}
}
- RETVAL_ZVAL_FAST(*max);
+ RETVAL_ZVAL_FAST(max);
}
if (args) {
@@ -1047,36 +1029,37 @@ PHP_FUNCTION(max)
static int php_array_walk(HashTable *target_hash, zval *userdata, int recursive TSRMLS_DC) /* {{{ */
{
- zval **args[3], /* Arguments to userland function */
- *retval_ptr = NULL, /* Return value - unused */
- *key=NULL; /* Entry key */
+ zval args[3], /* Arguments to userland function */
+ retval, /* Return value - unused */
+ *zv;
/* Set up known arguments */
- args[1] = &key;
- args[2] = &userdata;
+ ZVAL_UNDEF(&retval);
+ ZVAL_UNDEF(&args[1]);
if (userdata) {
- Z_ADDREF_P(userdata);
+ ZVAL_COPY(&args[2], userdata);
}
- BG(array_walk_fci).retval_ptr_ptr = &retval_ptr;
+ BG(array_walk_fci).retval = &retval;
BG(array_walk_fci).param_count = userdata ? 3 : 2;
BG(array_walk_fci).params = args;
BG(array_walk_fci).no_separation = 0;
/* Iterate through hash */
zend_hash_internal_pointer_reset(target_hash);
- while (!EG(exception) && zend_hash_get_current_data(target_hash, (void **)&args[0]) == SUCCESS) {
- if (recursive && Z_TYPE_PP(args[0]) == IS_ARRAY) {
+ while (!EG(exception) && (zv = zend_hash_get_current_data(target_hash)) != NULL) {
+ ZVAL_COPY_VALUE(&args[0], zv);
+ if (recursive && Z_TYPE(args[0]) == IS_ARRAY) {
HashTable *thash;
zend_fcall_info orig_array_walk_fci;
zend_fcall_info_cache orig_array_walk_fci_cache;
- SEPARATE_ZVAL_IF_NOT_REF(args[0]);
- thash = Z_ARRVAL_PP(args[0]);
+ SEPARATE_ZVAL_IF_NOT_REF(&args[0]);
+ thash = Z_ARRVAL(args[0]);
if (thash->nApplyCount > 1) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "recursion detected");
if (userdata) {
- zval_ptr_dtor(&userdata);
+ zval_ptr_dtor(userdata);
}
return 0;
}
@@ -1094,32 +1077,29 @@ static int php_array_walk(HashTable *target_hash, zval *userdata, int recursive
BG(array_walk_fci_cache) = orig_array_walk_fci_cache;
} else {
/* Allocate space for key */
- MAKE_STD_ZVAL(key);
- zend_hash_get_current_key_zval(target_hash, key);
+ zend_hash_get_current_key_zval(target_hash, &args[1]);
/* Call the userland function */
if (zend_call_function(&BG(array_walk_fci), &BG(array_walk_fci_cache) TSRMLS_CC) == SUCCESS) {
- if (retval_ptr) {
- zval_ptr_dtor(&retval_ptr);
- }
+ zval_ptr_dtor(&retval);
} else {
- if (key) {
- zval_ptr_dtor(&key);
- key = NULL;
+ if (Z_TYPE(args[1]) != IS_UNDEF) {
+ zval_ptr_dtor(&args[1]);
+ ZVAL_UNDEF(&args[1]);
}
break;
}
}
- if (key) {
- zval_ptr_dtor(&key);
- key = NULL;
+ if (Z_TYPE(args[1]) != IS_UNDEF) {
+ zval_ptr_dtor(&args[1]);
+ ZVAL_UNDEF(&args[1]);
}
zend_hash_move_forward(target_hash);
}
if (userdata) {
- zval_ptr_dtor(&userdata);
+ zval_ptr_dtor(userdata);
}
return 0;
}
@@ -1183,7 +1163,7 @@ static void php_search_array(INTERNAL_FUNCTION_PARAMETERS, int behavior) /* {{{
{
zval *value, /* value to check for */
*array, /* array to check in */
- **entry, /* pointer to array entry */
+ *entry, /* pointer to array entry */
res; /* comparison result */
HashPosition pos; /* hash iterator */
zend_bool strict = 0; /* strict comparison or not */
@@ -1198,8 +1178,8 @@ static void php_search_array(INTERNAL_FUNCTION_PARAMETERS, int behavior) /* {{{
}
zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(array), &pos);
- while (zend_hash_get_current_data_ex(Z_ARRVAL_P(array), (void **)&entry, &pos) == SUCCESS) {
- is_equal_func(&res, value, *entry TSRMLS_CC);
+ while ((entry = zend_hash_get_current_data_ex(Z_ARRVAL_P(array), &pos)) != NULL) {
+ is_equal_func(&res, value, entry TSRMLS_CC);
if (Z_LVAL(res)) {
if (behavior == 0) {
RETURN_TRUE;
@@ -1269,9 +1249,7 @@ static int php_valid_var_name(char *var_name, int var_name_len) /* {{{ */
PHPAPI int php_prefix_varname(zval *result, zval *prefix, char *var_name, int var_name_len, zend_bool add_underscore TSRMLS_DC) /* {{{ */
{
- Z_STRLEN_P(result) = Z_STRLEN_P(prefix) + (add_underscore ? 1 : 0) + var_name_len;
- Z_TYPE_P(result) = IS_STRING;
- Z_STRVAL_P(result) = emalloc(Z_STRLEN_P(result) + 1);
+ ZVAL_STR(result, STR_ALLOC(Z_STRLEN_P(prefix) + (add_underscore ? 1 : 0) + var_name_len, 0));
memcpy(Z_STRVAL_P(result), Z_STRVAL_P(prefix), Z_STRLEN_P(prefix));
if (add_underscore) {
@@ -1290,10 +1268,9 @@ PHP_FUNCTION(extract)
{
zval *var_array, *prefix = NULL;
long extract_type = EXTR_OVERWRITE;
- zval **entry, *data;
- char *var_name;
+ zval *entry, data;
+ zend_string *var_name;
ulong num_key;
- uint var_name_len;
int var_exists, key_type, count = 0;
int extract_refs = 0;
HashPosition pos;
@@ -1335,17 +1312,16 @@ PHP_FUNCTION(extract)
}
zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(var_array), &pos);
- while (zend_hash_get_current_data_ex(Z_ARRVAL_P(var_array), (void **)&entry, &pos) == SUCCESS) {
+ while ((entry = zend_hash_get_current_data_ex(Z_ARRVAL_P(var_array), &pos)) != NULL) {
zval final_name;
ZVAL_NULL(&final_name);
- key_type = zend_hash_get_current_key_ex(Z_ARRVAL_P(var_array), &var_name, &var_name_len, &num_key, 0, &pos);
+ key_type = zend_hash_get_current_key_ex(Z_ARRVAL_P(var_array), &var_name, &num_key, 0, &pos);
var_exists = 0;
if (key_type == HASH_KEY_IS_STRING) {
- var_name_len--;
- var_exists = zend_hash_exists(EG(active_symbol_table), var_name, var_name_len + 1);
+ var_exists = zend_hash_exists(EG(active_symbol_table), var_name);
} else if (key_type == HASH_KEY_IS_LONG && (extract_type == EXTR_PREFIX_ALL || extract_type == EXTR_PREFIX_INVALID)) {
zval num;
@@ -1365,69 +1341,66 @@ PHP_FUNCTION(extract)
case EXTR_OVERWRITE:
/* GLOBALS protection */
- if (var_exists && var_name_len == sizeof("GLOBALS")-1 && !strcmp(var_name, "GLOBALS")) {
+ if (var_exists && var_name->len == sizeof("GLOBALS")-1 && !strcmp(var_name->val, "GLOBALS")) {
break;
}
- if (var_exists && var_name_len == sizeof("this")-1 && !strcmp(var_name, "this") && EG(scope) && EG(scope)->name_length != 0) {
+ if (var_exists && var_name->len == sizeof("this")-1 && !strcmp(var_name->val, "this") && EG(scope) && EG(scope)->name->len != 0) {
break;
}
- ZVAL_STRINGL(&final_name, var_name, var_name_len, 1);
+ ZVAL_STR(&final_name, STR_COPY(var_name));
break;
case EXTR_PREFIX_IF_EXISTS:
if (var_exists) {
- php_prefix_varname(&final_name, prefix, var_name, var_name_len, 1 TSRMLS_CC);
+ php_prefix_varname(&final_name, prefix, var_name->val, var_name->len, 1 TSRMLS_CC);
}
break;
case EXTR_PREFIX_SAME:
- if (!var_exists && var_name_len != 0) {
- ZVAL_STRINGL(&final_name, var_name, var_name_len, 1);
+ if (!var_exists && var_name->len != 0) {
+ ZVAL_STR(&final_name, STR_COPY(var_name));
}
/* break omitted intentionally */
case EXTR_PREFIX_ALL:
- if (Z_TYPE(final_name) == IS_NULL && var_name_len != 0) {
- php_prefix_varname(&final_name, prefix, var_name, var_name_len, 1 TSRMLS_CC);
+ if (Z_TYPE(final_name) == IS_NULL && var_name->len != 0) {
+ php_prefix_varname(&final_name, prefix, var_name->val, var_name->len, 1 TSRMLS_CC);
}
break;
case EXTR_PREFIX_INVALID:
if (Z_TYPE(final_name) == IS_NULL) {
- if (!php_valid_var_name(var_name, var_name_len)) {
- php_prefix_varname(&final_name, prefix, var_name, var_name_len, 1 TSRMLS_CC);
+ if (!php_valid_var_name(var_name->val, var_name->len)) {
+ php_prefix_varname(&final_name, prefix, var_name->val, var_name->len, 1 TSRMLS_CC);
} else {
- ZVAL_STRINGL(&final_name, var_name, var_name_len, 1);
+ ZVAL_STR(&final_name, STR_COPY(var_name));
}
}
break;
default:
if (!var_exists) {
- ZVAL_STRINGL(&final_name, var_name, var_name_len, 1);
+ ZVAL_STR(&final_name, STR_COPY(var_name));
}
break;
}
if (Z_TYPE(final_name) != IS_NULL && php_valid_var_name(Z_STRVAL(final_name), Z_STRLEN(final_name))) {
if (extract_refs) {
- zval **orig_var;
+ zval *orig_var;
SEPARATE_ZVAL_TO_MAKE_IS_REF(entry);
zval_add_ref(entry);
- if (zend_hash_find(EG(active_symbol_table), Z_STRVAL(final_name), Z_STRLEN(final_name) + 1, (void **) &orig_var) == SUCCESS) {
+ if ((orig_var = zend_hash_find(EG(active_symbol_table), Z_STR(final_name))) != NULL) {
zval_ptr_dtor(orig_var);
- *orig_var = *entry;
+ ZVAL_COPY_VALUE(orig_var, entry);
} else {
- zend_hash_update(EG(active_symbol_table), Z_STRVAL(final_name), Z_STRLEN(final_name) + 1, (void **) entry, sizeof(zval *), NULL);
+ zend_hash_update(EG(active_symbol_table), Z_STR(final_name), entry);
}
} else {
- MAKE_STD_ZVAL(data);
- *data = **entry;
- zval_copy_ctor(data);
-
- ZEND_SET_SYMBOL_WITH_LENGTH(EG(active_symbol_table), Z_STRVAL(final_name), Z_STRLEN(final_name) + 1, data, 1, 0);
+ ZVAL_DUP(&data, entry);
+ ZEND_SET_SYMBOL_WITH_LENGTH(EG(active_symbol_table), Z_STRVAL(final_name), Z_STRLEN(final_name) + 1, &data, 1, 0);
}
count++;
}
@@ -1437,7 +1410,7 @@ PHP_FUNCTION(extract)
}
if (!extract_refs) {
- zval_ptr_dtor(&var_array);
+ zval_ptr_dtor(var_array);
}
RETURN_LONG(count);
@@ -1446,15 +1419,12 @@ PHP_FUNCTION(extract)
static void php_compact_var(HashTable *eg_active_symbol_table, zval *return_value, zval *entry TSRMLS_DC) /* {{{ */
{
- zval **value_ptr, *value, *data;
+ zval *value_ptr, data;
if (Z_TYPE_P(entry) == IS_STRING) {
- if (zend_hash_find(eg_active_symbol_table, Z_STRVAL_P(entry), Z_STRLEN_P(entry) + 1, (void **)&value_ptr) != FAILURE) {
- value = *value_ptr;
- ALLOC_ZVAL(data);
- MAKE_COPY_ZVAL(&value, data);
-
- zend_hash_update(Z_ARRVAL_P(return_value), Z_STRVAL_P(entry), Z_STRLEN_P(entry) + 1, &data, sizeof(zval *), NULL);
+ if ((value_ptr = zend_hash_find(eg_active_symbol_table, Z_STR_P(entry))) != NULL) {
+ ZVAL_DUP(&data, value_ptr);
+ zend_hash_update(Z_ARRVAL_P(return_value), Z_STR_P(entry), &data);
}
}
else if (Z_TYPE_P(entry) == IS_ARRAY) {
@@ -1468,10 +1438,8 @@ static void php_compact_var(HashTable *eg_active_symbol_table, zval *return_valu
Z_ARRVAL_P(entry)->nApplyCount++;
zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(entry), &pos);
- while (zend_hash_get_current_data_ex(Z_ARRVAL_P(entry), (void**)&value_ptr, &pos) == SUCCESS) {
- value = *value_ptr;
-
- php_compact_var(eg_active_symbol_table, return_value, value TSRMLS_CC);
+ while ((value_ptr = zend_hash_get_current_data_ex(Z_ARRVAL_P(entry), &pos)) != NULL) {
+ php_compact_var(eg_active_symbol_table, return_value, value_ptr TSRMLS_CC);
zend_hash_move_forward_ex(Z_ARRVAL_P(entry), &pos);
}
Z_ARRVAL_P(entry)->nApplyCount--;
@@ -1483,7 +1451,7 @@ static void php_compact_var(HashTable *eg_active_symbol_table, zval *return_valu
Creates a hash containing variables and their values */
PHP_FUNCTION(compact)
{
- zval ***args = NULL; /* function arguments array */
+ zval *args = NULL; /* function arguments array */
int num_args, i;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "+", &args, &num_args) == FAILURE) {
@@ -1497,14 +1465,14 @@ PHP_FUNCTION(compact)
/* compact() is probably most used with a single array of var_names
or multiple string names, rather than a combination of both.
So quickly guess a minimum result size based on that */
- if (ZEND_NUM_ARGS() == 1 && Z_TYPE_PP(args[0]) == IS_ARRAY) {
- array_init_size(return_value, zend_hash_num_elements(Z_ARRVAL_PP(args[0])));
+ if (ZEND_NUM_ARGS() == 1 && Z_TYPE(args[0]) == IS_ARRAY) {
+ array_init_size(return_value, zend_hash_num_elements(Z_ARRVAL(args[0])));
} else {
array_init_size(return_value, ZEND_NUM_ARGS());
}
for (i=0; i<ZEND_NUM_ARGS(); i++) {
- php_compact_var(EG(active_symbol_table), return_value, *args[i] TSRMLS_CC);
+ php_compact_var(EG(active_symbol_table), return_value, &args[i] TSRMLS_CC);
}
if (args) {
@@ -1537,12 +1505,12 @@ PHP_FUNCTION(array_fill)
}
num--;
- zend_hash_index_update(Z_ARRVAL_P(return_value), start_key, &val, sizeof(zval *), NULL);
- zval_add_ref(&val);
+ zend_hash_index_update(Z_ARRVAL_P(return_value), start_key, val);
+ zval_add_ref(val);
while (num--) {
- if (zend_hash_next_index_insert(Z_ARRVAL_P(return_value), &val, sizeof(zval *), NULL) == SUCCESS) {
- zval_add_ref(&val);
+ if (zend_hash_next_index_insert(Z_ARRVAL_P(return_value), val) != NULL) {
+ zval_add_ref(val);
} else {
zval_dtor(return_value);
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot add element to the array as the next element is already occupied");
@@ -1556,7 +1524,7 @@ PHP_FUNCTION(array_fill)
Create an array using the elements of the first parameter as keys each initialized to val */
PHP_FUNCTION(array_fill_keys)
{
- zval *keys, *val, **entry;
+ zval *keys, *val, *entry;
HashPosition pos;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "az", &keys, &val) == FAILURE) {
@@ -1567,25 +1535,24 @@ PHP_FUNCTION(array_fill_keys)
array_init_size(return_value, zend_hash_num_elements(Z_ARRVAL_P(keys)));
zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(keys), &pos);
- while (zend_hash_get_current_data_ex(Z_ARRVAL_P(keys), (void **)&entry, &pos) == SUCCESS) {
+ while ((entry = zend_hash_get_current_data_ex(Z_ARRVAL_P(keys), &pos)) != NULL) {
- if (Z_TYPE_PP(entry) == IS_LONG) {
- zval_add_ref(&val);
- zend_hash_index_update(Z_ARRVAL_P(return_value), Z_LVAL_PP(entry), &val, sizeof(zval *), NULL);
+ if (Z_TYPE_P(entry) == IS_LONG) {
+ zval_add_ref(val);
+ zend_hash_index_update(Z_ARRVAL_P(return_value), Z_LVAL_P(entry), val);
} else {
- zval key, *key_ptr = *entry;
+ zval key, *key_ptr = entry;
- if (Z_TYPE_PP(entry) != IS_STRING) {
- key = **entry;
- zval_copy_ctor(&key);
+ if (Z_TYPE_P(entry) != IS_STRING) {
+ ZVAL_DUP(&key, entry);
convert_to_string(&key);
key_ptr = &key;
}
- zval_add_ref(&val);
- zend_symtable_update(Z_ARRVAL_P(return_value), Z_STRVAL_P(key_ptr), Z_STRLEN_P(key_ptr) + 1, &val, sizeof(zval *), NULL);
+ zval_add_ref(val);
+ zend_symtable_update(Z_ARRVAL_P(return_value), Z_STR_P(key_ptr), val);
- if (key_ptr != *entry) {
+ if (key_ptr != entry) {
zval_dtor(&key);
}
}
@@ -1614,7 +1581,7 @@ PHP_FUNCTION(range)
is_step_double = 1;
}
- convert_to_double_ex(&zstep);
+ convert_to_double_ex(zstep);
step = Z_DVAL_P(zstep);
/* We only want positive step values. */
@@ -1765,7 +1732,7 @@ static void php_array_data_shuffle(zval *array TSRMLS_DC) /* {{{ */
if (hash->nNumUsed != hash->nNumOfElements) {
for (j = 0, idx = 0; idx < hash->nNumUsed; idx++) {
p = hash->arData + idx;
- if (!p->xData) continue;
+ if (Z_TYPE(p->val) == IS_UNDEF) continue;
if (j != idx) {
hash->arData[j] = *p;
}
@@ -1788,12 +1755,11 @@ static void php_array_data_shuffle(zval *array TSRMLS_DC) /* {{{ */
for (j = 0; j < n_elems; j++) {
p = hash->arData + j;
- if (p->nKeyLength && !IS_INTERNED(p->arKey)) {
- pefree((char*)p->arKey, hash->flags & HASH_FLAG_PERSISTENT);
+ if (p->key && !IS_INTERNED(p->key)) {
+ pefree((char*)p->key, hash->flags & HASH_FLAG_PERSISTENT);
}
p->h = j;
- p->nKeyLength = 0;
- p->arKey = NULL;
+ p->key = NULL;
}
hash->nNextFreeElement = n_elems;
if (!(hash->flags & HASH_FLAG_PACKED)) {
@@ -1819,7 +1785,7 @@ PHP_FUNCTION(shuffle)
}
/* }}} */
-PHPAPI HashTable* php_splice(HashTable *in_hash, int offset, int length, zval ***list, int list_count, HashTable **removed) /* {{{ */
+PHPAPI HashTable* php_splice(HashTable *in_hash, int offset, int length, zval *list, int list_count, HashTable *removed) /* {{{ */
{
HashTable *out_hash = NULL; /* Output hashtable */
int num_in, /* Number of entries in the input hashtable */
@@ -1858,17 +1824,17 @@ PHPAPI HashTable* php_splice(HashTable *in_hash, int offset, int length, zval **
/* Start at the beginning of the input hash and copy entries to output hash until offset is reached */
for (pos = 0, idx = 0; pos < offset && idx < in_hash->nNumUsed; idx++) {
p = in_hash->arData + idx;
- if (!p->xData) continue;
+ if (Z_TYPE(p->val) == IS_UNDEF) continue;
pos++;
/* Get entry and increase reference count */
- entry = (zval *)p->xData;
+ entry = &p->val;
Z_ADDREF_P(entry);
/* Update output hash depending on key type */
- if (p->nKeyLength == 0) {
- zend_hash_next_index_insert(out_hash, &entry, sizeof(zval *), NULL);
+ if (p->key == NULL) {
+ zend_hash_next_index_insert(out_hash, entry);
} else {
- zend_hash_quick_update(out_hash, p->arKey, p->nKeyLength, p->h, &entry, sizeof(zval *), NULL);
+ zend_hash_update(out_hash, p->key, entry);
}
}
@@ -1876,14 +1842,14 @@ PHPAPI HashTable* php_splice(HashTable *in_hash, int offset, int length, zval **
if (removed != NULL) {
for ( ; pos < offset + length && idx < in_hash->nNumUsed; idx++) {
p = in_hash->arData + idx;
- if (!p->xData) continue;
+ if (Z_TYPE(p->val) == IS_UNDEF) continue;
pos++;
- entry = (zval *)p->xData;
+ entry = &p->val;
Z_ADDREF_P(entry);
- if (p->nKeyLength == 0) {
- zend_hash_next_index_insert(*removed, &entry, sizeof(zval *), NULL);
+ if (p->key == NULL) {
+ zend_hash_next_index_insert(removed, entry);
} else {
- zend_hash_quick_update(*removed, p->arKey, p->nKeyLength, p->h, &entry, sizeof(zval *), NULL);
+ zend_hash_update(removed, p->key, entry);
}
}
} else { /* otherwise just skip those entries */
@@ -1894,22 +1860,22 @@ PHPAPI HashTable* php_splice(HashTable *in_hash, int offset, int length, zval **
if (list != NULL) {
/* ..for each one, create a new zval, copy entry into it and copy it into the output hash */
for (i = 0; i < list_count; i++) {
- entry = *list[i];
+ entry = &list[i];
Z_ADDREF_P(entry);
- zend_hash_next_index_insert(out_hash, &entry, sizeof(zval *), NULL);
+ zend_hash_next_index_insert(out_hash, entry);
}
}
/* Copy the remaining input hash entries to the output hash */
for ( ; idx < in_hash->nNumUsed ; idx++) {
p = in_hash->arData + idx;
- if (!p->xData) continue;
- entry = (zval *)p->xData;
+ if (Z_TYPE(p->val) == IS_UNDEF) continue;
+ entry = &p->val;
Z_ADDREF_P(entry);
- if (p->nKeyLength == 0) {
- zend_hash_next_index_insert(out_hash, &entry, sizeof(zval *), NULL);
+ if (p->key == NULL) {
+ zend_hash_next_index_insert(out_hash, entry);
} else {
- zend_hash_quick_update(out_hash, p->arKey, p->nKeyLength, p->h, &entry, sizeof(zval *), NULL);
+ zend_hash_update(out_hash, p->key, entry);
}
}
@@ -1938,7 +1904,7 @@ PHP_FUNCTION(array_push)
new_var = *args[i];
Z_ADDREF_P(new_var);
- if (zend_hash_next_index_insert(Z_ARRVAL_P(stack), &new_var, sizeof(zval *), NULL) == FAILURE) {
+ if (zend_hash_next_index_insert(Z_ARRVAL_P(stack), new_var) == NULL) {
Z_DELREF_P(new_var);
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot add element to the array as the next element is already occupied");
efree(args);
@@ -1956,9 +1922,8 @@ PHP_FUNCTION(array_push)
static void _phpi_pop(INTERNAL_FUNCTION_PARAMETERS, int off_the_end)
{
zval *stack, /* Input stack */
- **val; /* Value to be popped */
- char *key = NULL;
- uint key_len = 0;
+ *val; /* Value to be popped */
+ zend_string *key = NULL;
ulong index;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a", &stack) == FAILURE) {
@@ -1975,15 +1940,17 @@ static void _phpi_pop(INTERNAL_FUNCTION_PARAMETERS, int off_the_end)
} else {
zend_hash_internal_pointer_reset(Z_ARRVAL_P(stack));
}
- zend_hash_get_current_data(Z_ARRVAL_P(stack), (void **)&val);
- RETVAL_ZVAL_FAST(*val);
+ val = zend_hash_get_current_data(Z_ARRVAL_P(stack));
+ RETVAL_ZVAL_FAST(val);
/* Delete the first or last value */
- zend_hash_get_current_key_ex(Z_ARRVAL_P(stack), &key, &key_len, &index, 0, NULL);
- if (key && Z_ARRVAL_P(stack) == &EG(symbol_table)) {
- zend_delete_global_variable(key, key_len - 1 TSRMLS_CC);
+ zend_hash_get_current_key_ex(Z_ARRVAL_P(stack), &key, &index, 0, NULL);
+ if (key && Z_ARRVAL_P(stack) == &EG(symbol_table).ht) {
+ zend_delete_global_variable(key TSRMLS_CC);
+ } else if (key) {
+ zend_hash_del(Z_ARRVAL_P(stack), key);
} else {
- zend_hash_del_key_or_index(Z_ARRVAL_P(stack), key, key_len, index, (key) ? HASH_DEL_KEY : HASH_DEL_INDEX);
+ zend_hash_index_del(Z_ARRVAL_P(stack), index);
}
/* If we did a shift... re-index like it did before */
@@ -1995,8 +1962,8 @@ static void _phpi_pop(INTERNAL_FUNCTION_PARAMETERS, int off_the_end)
for (idx = 0; idx < Z_ARRVAL_P(stack)->nNumUsed; idx++) {
p = Z_ARRVAL_P(stack)->arData + idx;
- if (!p->xData) continue;
- if (p->nKeyLength == 0) {
+ if (Z_TYPE(p->val) == IS_UNDEF) continue;
+ if (p->key == NULL) {
if (p->h != k) {
p->h = k++;
should_rehash = 1;
@@ -2013,7 +1980,7 @@ static void _phpi_pop(INTERNAL_FUNCTION_PARAMETERS, int off_the_end)
zend_hash_rehash(Z_ARRVAL_P(stack));
}
}
- } else if (!key_len && index >= Z_ARRVAL_P(stack)->nNextFreeElement - 1) {
+ } else if (!key && index >= Z_ARRVAL_P(stack)->nNextFreeElement - 1) {
Z_ARRVAL_P(stack)->nNextFreeElement = Z_ARRVAL_P(stack)->nNextFreeElement - 1;
}
@@ -2041,7 +2008,7 @@ PHP_FUNCTION(array_shift)
Pushes elements onto the beginning of the array */
PHP_FUNCTION(array_unshift)
{
- zval ***args, /* Function arguments array */
+ zval *args, /* Function arguments array */
*stack; /* Input stack */
HashTable *new_hash; /* New hashtable for the stack */
HashTable old_hash;
@@ -2055,8 +2022,8 @@ PHP_FUNCTION(array_unshift)
* hashtable and replace it with new one */
new_hash = php_splice(Z_ARRVAL_P(stack), 0, 0, &args[0], argc, NULL);
old_hash = *Z_ARRVAL_P(stack);
- if (Z_ARRVAL_P(stack) == &EG(symbol_table)) {
- zend_reset_all_cv(&EG(symbol_table) TSRMLS_CC);
+ if (Z_ARRVAL_P(stack) == &EG(symbol_table).ht) {
+ zend_reset_all_cv(&EG(symbol_table).ht TSRMLS_CC);
}
*Z_ARRVAL_P(stack) = *new_hash;
FREE_HASHTABLE(new_hash);
@@ -2074,9 +2041,9 @@ PHP_FUNCTION(array_splice)
{
zval *array, /* Input array */
*repl_array = NULL, /* Replacement array */
- ***repl = NULL; /* Replacement elements */
+ *repl = NULL; /* Replacement elements */
HashTable *new_hash = NULL, /* Output array's hash */
- **rem_hash = NULL; /* Removed elements' hash */
+ *rem_hash = NULL; /* Removed elements' hash */
HashTable old_hash;
uint idx;
Bucket *p; /* Bucket used for traversing hash */
@@ -2102,11 +2069,11 @@ PHP_FUNCTION(array_splice)
/* Create the array of replacement elements */
repl_num = zend_hash_num_elements(Z_ARRVAL_P(repl_array));
- repl = (zval ***)safe_emalloc(repl_num, sizeof(zval **), 0);
+ repl = (zval *)safe_emalloc(repl_num, sizeof(zval), 0);
for (idx = 0, i = 0; idx < Z_ARRVAL_P(repl_array)->nNumUsed; idx++) {
p = Z_ARRVAL_P(repl_array)->arData + idx;
- if (!p->xData) continue;
- repl[i++] = (zval **)&p->xData;
+ if (Z_TYPE(p->val) == IS_UNDEF) continue;
+ ZVAL_COPY_VALUE(&repl[i++], &p->val);
}
}
@@ -2131,7 +2098,7 @@ PHP_FUNCTION(array_splice)
/* Initialize return value */
array_init_size(return_value, size > 0 ? size : 0);
- rem_hash = &Z_ARRVAL_P(return_value);
+ rem_hash = Z_ARRVAL_P(return_value);
}
/* Perform splice */
@@ -2139,8 +2106,8 @@ PHP_FUNCTION(array_splice)
/* Replace input array's hashtable with the new one */
old_hash = *Z_ARRVAL_P(array);
- if (Z_ARRVAL_P(array) == &EG(symbol_table)) {
- zend_reset_all_cv(&EG(symbol_table) TSRMLS_CC);
+ if (Z_ARRVAL_P(array) == &EG(symbol_table).ht) {
+ zend_reset_all_cv(&EG(symbol_table).ht TSRMLS_CC);
}
*Z_ARRVAL_P(array) = *new_hash;
FREE_HASHTABLE(new_hash);
@@ -2158,19 +2125,18 @@ PHP_FUNCTION(array_splice)
PHP_FUNCTION(array_slice)
{
zval *input, /* Input array */
- **z_length = NULL, /* How many elements to get */
- **entry; /* An array entry */
+ *z_length = NULL, /* How many elements to get */
+ *entry; /* An array entry */
long offset, /* Offset to get elements from */
length = 0;
zend_bool preserve_keys = 0; /* Whether to preserve keys while copying to the new array or not */
int num_in, /* Number of elements in the input array */
pos; /* Current position in the array */
- char *string_key;
- uint string_key_len;
+ zend_string *string_key;
ulong num_key;
HashPosition hpos;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "al|Zb", &input, &offset, &z_length, &preserve_keys) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "al|zb", &input, &offset, &z_length, &preserve_keys) == FAILURE) {
return;
}
@@ -2178,11 +2144,11 @@ PHP_FUNCTION(array_slice)
num_in = zend_hash_num_elements(Z_ARRVAL_P(input));
/* We want all entries from offset to the end if length is not passed or is null */
- if (ZEND_NUM_ARGS() < 3 || Z_TYPE_PP(z_length) == IS_NULL) {
+ if (ZEND_NUM_ARGS() < 3 || Z_TYPE_P(z_length) == IS_NULL) {
length = num_in;
} else {
convert_to_long_ex(z_length);
- length = Z_LVAL_PP(z_length);
+ length = Z_LVAL_P(z_length);
}
/* Clamp the offset.. */
@@ -2210,26 +2176,26 @@ PHP_FUNCTION(array_slice)
/* Start at the beginning and go until we hit offset */
pos = 0;
zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(input), &hpos);
- while (pos < offset && zend_hash_get_current_data_ex(Z_ARRVAL_P(input), (void **)&entry, &hpos) == SUCCESS) {
+ while (pos < offset && (entry = zend_hash_get_current_data_ex(Z_ARRVAL_P(input), &hpos)) != NULL) {
pos++;
zend_hash_move_forward_ex(Z_ARRVAL_P(input), &hpos);
}
/* Copy elements from input array to the one that's returned */
- while (pos < offset + length && zend_hash_get_current_data_ex(Z_ARRVAL_P(input), (void **)&entry, &hpos) == SUCCESS) {
+ while (pos < offset + length && (entry = zend_hash_get_current_data_ex(Z_ARRVAL_P(input), &hpos)) != NULL) {
zval_add_ref(entry);
- switch (zend_hash_get_current_key_ex(Z_ARRVAL_P(input), &string_key, &string_key_len, &num_key, 0, &hpos)) {
+ switch (zend_hash_get_current_key_ex(Z_ARRVAL_P(input), &string_key, &num_key, 0, &hpos)) {
case HASH_KEY_IS_STRING:
- zend_hash_update(Z_ARRVAL_P(return_value), string_key, string_key_len, entry, sizeof(zval *), NULL);
+ zend_hash_update(Z_ARRVAL_P(return_value), string_key, entry);
break;
case HASH_KEY_IS_LONG:
if (preserve_keys) {
- zend_hash_index_update(Z_ARRVAL_P(return_value), num_key, entry, sizeof(zval *), NULL);
+ zend_hash_index_update(Z_ARRVAL_P(return_value), num_key, entry);
} else {
- zend_hash_next_index_insert(Z_ARRVAL_P(return_value), entry, sizeof(zval *), NULL);
+ zend_hash_next_index_insert(Z_ARRVAL_P(return_value), entry);
}
break;
}
@@ -2241,47 +2207,45 @@ PHP_FUNCTION(array_slice)
PHPAPI int php_array_merge(HashTable *dest, HashTable *src, int recursive TSRMLS_DC) /* {{{ */
{
- zval **src_entry, **dest_entry;
- char *string_key;
- uint string_key_len;
+ zval *src_entry, *dest_entry;
+ zend_string *string_key;
ulong num_key;
HashPosition pos;
zend_hash_internal_pointer_reset_ex(src, &pos);
- while (zend_hash_get_current_data_ex(src, (void **)&src_entry, &pos) == SUCCESS) {
- switch (zend_hash_get_current_key_ex(src, &string_key, &string_key_len, &num_key, 0, &pos)) {
+ while ((src_entry = zend_hash_get_current_data_ex(src, &pos)) != NULL) {
+ switch (zend_hash_get_current_key_ex(src, &string_key, &num_key, 0, &pos)) {
case HASH_KEY_IS_STRING:
- if (recursive && zend_hash_find(dest, string_key, string_key_len, (void **)&dest_entry) == SUCCESS) {
- HashTable *thash = Z_TYPE_PP(dest_entry) == IS_ARRAY ? Z_ARRVAL_PP(dest_entry) : NULL;
- zval *src_zval;
+ if (recursive && (dest_entry = zend_hash_find(dest, string_key)) != NULL) {
+ HashTable *thash = Z_TYPE_P(dest_entry) == IS_ARRAY ? Z_ARRVAL_P(dest_entry) : NULL;
+ zval src_zval;
zval *tmp = NULL;
- if ((thash && thash->nApplyCount > 1) || (*src_entry == *dest_entry && Z_ISREF_PP(dest_entry) && (Z_REFCOUNT_PP(dest_entry) % 2))) {
+ if ((thash && thash->nApplyCount > 1) || (src_entry == dest_entry && Z_ISREF_P(dest_entry) && (Z_REFCOUNT_P(dest_entry) % 2))) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "recursion detected");
return 0;
}
SEPARATE_ZVAL(dest_entry);
- if (Z_TYPE_PP(dest_entry) == IS_NULL) {
+ if (Z_TYPE_P(dest_entry) == IS_NULL) {
convert_to_array_ex(dest_entry);
- add_next_index_null(*dest_entry);
+ add_next_index_null(dest_entry);
} else {
convert_to_array_ex(dest_entry);
}
- if (Z_TYPE_PP(src_entry) == IS_OBJECT) {
- ALLOC_ZVAL(src_zval);
- INIT_PZVAL_COPY(src_zval, *src_entry);
- zval_copy_ctor(src_zval);
- convert_to_array(src_zval);
- tmp = src_zval;
+ if (Z_TYPE_P(src_entry) == IS_OBJECT) {
+ ZVAL_DUP(&src_zval, src_entry);
+ zval_copy_ctor(&src_zval);
+ convert_to_array(&src_zval);
+ tmp = &src_zval;
} else {
- src_zval = *src_entry;
+ ZVAL_COPY_VALUE(&src_zval, src_entry);
}
- if (Z_TYPE_P(src_zval) == IS_ARRAY) {
+ if (Z_TYPE(src_zval) == IS_ARRAY) {
if (thash) {
thash->nApplyCount++;
}
- if (!php_array_merge(Z_ARRVAL_PP(dest_entry), Z_ARRVAL_P(src_zval), recursive TSRMLS_CC)) {
+ if (!php_array_merge(Z_ARRVAL_P(dest_entry), Z_ARRVAL(src_zval), recursive TSRMLS_CC)) {
if (thash) {
thash->nApplyCount--;
}
@@ -2291,21 +2255,21 @@ PHPAPI int php_array_merge(HashTable *dest, HashTable *src, int recursive TSRMLS
thash->nApplyCount--;
}
} else {
- Z_ADDREF_PP(src_entry);
- zend_hash_next_index_insert(Z_ARRVAL_PP(dest_entry), &src_zval, sizeof(zval *), NULL);
+ Z_ADDREF_P(src_entry);
+ zend_hash_next_index_insert(Z_ARRVAL_P(dest_entry), &src_zval);
}
if (tmp) {
- zval_ptr_dtor(&tmp);
+ zval_ptr_dtor(tmp);
}
} else {
- Z_ADDREF_PP(src_entry);
- zend_hash_update(dest, string_key, string_key_len, src_entry, sizeof(zval *), NULL);
+ Z_ADDREF_P(src_entry);
+ zend_hash_update(dest, string_key, src_entry);
}
break;
case HASH_KEY_IS_LONG:
- Z_ADDREF_PP(src_entry);
- zend_hash_next_index_insert(dest, src_entry, sizeof(zval *), NULL);
+ Z_ADDREF_P(src_entry);
+ zend_hash_next_index_insert(dest, src_entry);
break;
}
zend_hash_move_forward_ex(src, &pos);
@@ -2316,57 +2280,56 @@ PHPAPI int php_array_merge(HashTable *dest, HashTable *src, int recursive TSRMLS
PHPAPI int php_array_replace_recursive(HashTable *dest, HashTable *src TSRMLS_DC) /* {{{ */
{
- zval **src_entry, **dest_entry;
- char *string_key;
- uint string_key_len;
+ zval *src_entry, *dest_entry;
+ zend_string *string_key;
ulong num_key;
HashPosition pos;
for (zend_hash_internal_pointer_reset_ex(src, &pos);
- zend_hash_get_current_data_ex(src, (void **)&src_entry, &pos) == SUCCESS;
+ (src_entry = zend_hash_get_current_data_ex(src, &pos)) != NULL;
zend_hash_move_forward_ex(src, &pos)) {
- switch (zend_hash_get_current_key_ex(src, &string_key, &string_key_len, &num_key, 0, &pos)) {
+ switch (zend_hash_get_current_key_ex(src, &string_key, &num_key, 0, &pos)) {
case HASH_KEY_IS_STRING:
- if (Z_TYPE_PP(src_entry) != IS_ARRAY ||
- zend_hash_find(dest, string_key, string_key_len, (void **)&dest_entry) == FAILURE ||
- Z_TYPE_PP(dest_entry) != IS_ARRAY) {
+ if (Z_TYPE_P(src_entry) != IS_ARRAY ||
+ (dest_entry = zend_hash_find(dest, string_key)) == NULL ||
+ Z_TYPE_P(dest_entry) != IS_ARRAY) {
- Z_ADDREF_PP(src_entry);
- zend_hash_update(dest, string_key, string_key_len, src_entry, sizeof(zval *), NULL);
+ Z_ADDREF_P(src_entry);
+ zend_hash_update(dest, string_key, src_entry);
continue;
}
break;
case HASH_KEY_IS_LONG:
- if (Z_TYPE_PP(src_entry) != IS_ARRAY ||
- zend_hash_index_find(dest, num_key, (void **)&dest_entry) == FAILURE ||
- Z_TYPE_PP(dest_entry) != IS_ARRAY) {
+ if (Z_TYPE_P(src_entry) != IS_ARRAY ||
+ (dest_entry = zend_hash_index_find(dest, num_key)) == NULL ||
+ Z_TYPE_P(dest_entry) != IS_ARRAY) {
- Z_ADDREF_PP(src_entry);
- zend_hash_index_update(dest, num_key, src_entry, sizeof(zval *), NULL);
+ Z_ADDREF_P(src_entry);
+ zend_hash_index_update(dest, num_key, src_entry);
continue;
}
break;
}
- if (Z_ARRVAL_PP(dest_entry)->nApplyCount > 1 || Z_ARRVAL_PP(src_entry)->nApplyCount > 1 || (*src_entry == *dest_entry && Z_ISREF_PP(dest_entry) && (Z_REFCOUNT_PP(dest_entry) % 2))) {
+ if (Z_ARRVAL_P(dest_entry)->nApplyCount > 1 || Z_ARRVAL_P(src_entry)->nApplyCount > 1 || (src_entry == dest_entry && Z_ISREF_P(dest_entry) && (Z_REFCOUNT_P(dest_entry) % 2))) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "recursion detected");
return 0;
}
SEPARATE_ZVAL(dest_entry);
- Z_ARRVAL_PP(dest_entry)->nApplyCount++;
- Z_ARRVAL_PP(src_entry)->nApplyCount++;
+ Z_ARRVAL_P(dest_entry)->nApplyCount++;
+ Z_ARRVAL_P(src_entry)->nApplyCount++;
- if (!php_array_replace_recursive(Z_ARRVAL_PP(dest_entry), Z_ARRVAL_PP(src_entry) TSRMLS_CC)) {
- Z_ARRVAL_PP(dest_entry)->nApplyCount--;
- Z_ARRVAL_PP(src_entry)->nApplyCount--;
+ if (!php_array_replace_recursive(Z_ARRVAL_P(dest_entry), Z_ARRVAL_P(src_entry) TSRMLS_CC)) {
+ Z_ARRVAL_P(dest_entry)->nApplyCount--;
+ Z_ARRVAL_P(src_entry)->nApplyCount--;
return 0;
}
- Z_ARRVAL_PP(dest_entry)->nApplyCount--;
- Z_ARRVAL_PP(src_entry)->nApplyCount--;
+ Z_ARRVAL_P(dest_entry)->nApplyCount--;
+ Z_ARRVAL_P(src_entry)->nApplyCount--;
}
return 1;
@@ -2375,7 +2338,7 @@ PHPAPI int php_array_replace_recursive(HashTable *dest, HashTable *src TSRMLS_DC
static void php_array_merge_or_replace_wrapper(INTERNAL_FUNCTION_PARAMETERS, int recursive, int replace) /* {{{ */
{
- zval ***args = NULL;
+ zval *args = NULL;
int argc, i, init_size = 0;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "+", &args, &argc) == FAILURE) {
@@ -2383,12 +2346,12 @@ static void php_array_merge_or_replace_wrapper(INTERNAL_FUNCTION_PARAMETERS, int
}
for (i = 0; i < argc; i++) {
- if (Z_TYPE_PP(args[i]) != IS_ARRAY) {
+ if (Z_TYPE(args[i]) != IS_ARRAY) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Argument #%d is not an array", i + 1);
efree(args);
RETURN_NULL();
} else {
- int num = zend_hash_num_elements(Z_ARRVAL_PP(args[i]));
+ int num = zend_hash_num_elements(Z_ARRVAL(args[i]));
if (num > init_size) {
init_size = num;
@@ -2400,11 +2363,11 @@ static void php_array_merge_or_replace_wrapper(INTERNAL_FUNCTION_PARAMETERS, int
for (i = 0; i < argc; i++) {
if (!replace) {
- php_array_merge(Z_ARRVAL_P(return_value), Z_ARRVAL_PP(args[i]), recursive TSRMLS_CC);
+ php_array_merge(Z_ARRVAL_P(return_value), Z_ARRVAL(args[i]), recursive TSRMLS_CC);
} else if (recursive && i > 0) { /* First array will be copied directly instead */
- php_array_replace_recursive(Z_ARRVAL_P(return_value), Z_ARRVAL_PP(args[i]) TSRMLS_CC);
+ php_array_replace_recursive(Z_ARRVAL_P(return_value), Z_ARRVAL(args[i]) TSRMLS_CC);
} else {
- zend_hash_merge(Z_ARRVAL_P(return_value), Z_ARRVAL_PP(args[i]), (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *), 1);
+ zend_hash_merge(Z_ARRVAL_P(return_value), Z_ARRVAL(args[i]), zval_add_ref, 1);
}
}
@@ -2450,9 +2413,9 @@ PHP_FUNCTION(array_keys)
{
zval *input, /* Input array */
*search_value = NULL, /* Value to search for */
- **entry, /* An entry in the input array */
+ *entry, /* An entry in the input array */
res, /* Result of comparison */
- *new_val; /* New value */
+ new_val; /* New value */
int add_key; /* Flag to indicate whether a key should be added */
zend_bool strict = 0; /* do strict comparison */
HashPosition pos;
@@ -2476,16 +2439,15 @@ PHP_FUNCTION(array_keys)
/* Go through input array and add keys to the return array */
zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(input), &pos);
- while (zend_hash_get_current_data_ex(Z_ARRVAL_P(input), (void **)&entry, &pos) == SUCCESS) {
+ while ((entry = zend_hash_get_current_data_ex(Z_ARRVAL_P(input), &pos)) != NULL) {
if (search_value != NULL) {
- is_equal_func(&res, search_value, *entry TSRMLS_CC);
+ is_equal_func(&res, search_value, entry TSRMLS_CC);
add_key = zval_is_true(&res);
}
if (add_key) {
- MAKE_STD_ZVAL(new_val);
- zend_hash_get_current_key_zval_ex(Z_ARRVAL_P(input), new_val, &pos);
- zend_hash_next_index_insert(Z_ARRVAL_P(return_value), &new_val, sizeof(zval *), NULL);
+ zend_hash_get_current_key_zval_ex(Z_ARRVAL_P(input), &new_val, &pos);
+ zend_hash_next_index_insert(Z_ARRVAL_P(return_value), &new_val);
}
zend_hash_move_forward_ex(Z_ARRVAL_P(input), &pos);
@@ -2498,7 +2460,7 @@ PHP_FUNCTION(array_keys)
PHP_FUNCTION(array_values)
{
zval *input, /* Input array */
- **entry; /* An entry in the input array */
+ *entry; /* An entry in the input array */
HashPosition pos;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a", &input) == FAILURE) {
@@ -2510,9 +2472,9 @@ PHP_FUNCTION(array_values)
/* Go through input array and add values to the return array */
zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(input), &pos);
- while (zend_hash_get_current_data_ex(Z_ARRVAL_P(input), (void **)&entry, &pos) == SUCCESS) {
+ while ((entry = zend_hash_get_current_data_ex(Z_ARRVAL_P(input), &pos)) != NULL) {
zval_add_ref(entry);
- zend_hash_next_index_insert(Z_ARRVAL_P(return_value), entry, sizeof(zval *), NULL);
+ zend_hash_next_index_insert(Z_ARRVAL_P(return_value), entry);
zend_hash_move_forward_ex(Z_ARRVAL_P(input), &pos);
}
}
@@ -2522,9 +2484,9 @@ PHP_FUNCTION(array_values)
Return the value as key and the frequency of that value in input as value */
PHP_FUNCTION(array_count_values)
{
- zval *input, /* Input array */
- **entry, /* An entry in the input array */
- **tmp;
+ zval *input, /* Input array */
+ *entry, /* An entry in the input array */
+ *tmp;
HashTable *myht;
HashPosition pos;
@@ -2538,24 +2500,22 @@ PHP_FUNCTION(array_count_values)
/* Go through input array and add values to the return array */
myht = Z_ARRVAL_P(input);
zend_hash_internal_pointer_reset_ex(myht, &pos);
- while (zend_hash_get_current_data_ex(myht, (void **)&entry, &pos) == SUCCESS) {
- if (Z_TYPE_PP(entry) == IS_LONG) {
- if (zend_hash_index_find(Z_ARRVAL_P(return_value), Z_LVAL_PP(entry), (void **)&tmp) == FAILURE) {
- zval *data;
- MAKE_STD_ZVAL(data);
- ZVAL_LONG(data, 1);
- zend_hash_index_update(Z_ARRVAL_P(return_value), Z_LVAL_PP(entry), &data, sizeof(data), NULL);
+ while ((entry = zend_hash_get_current_data_ex(myht, &pos)) != NULL) {
+ if (Z_TYPE_P(entry) == IS_LONG) {
+ if ((tmp = zend_hash_index_find(Z_ARRVAL_P(return_value), Z_LVAL_P(entry))) == NULL) {
+ zval data;
+ ZVAL_LONG(&data, 1);
+ zend_hash_index_update(Z_ARRVAL_P(return_value), Z_LVAL_P(entry), &data);
} else {
- Z_LVAL_PP(tmp)++;
+ Z_LVAL_P(tmp)++;
}
- } else if (Z_TYPE_PP(entry) == IS_STRING) {
- if (zend_symtable_find(Z_ARRVAL_P(return_value), Z_STRVAL_PP(entry), Z_STRLEN_PP(entry) + 1, (void**)&tmp) == FAILURE) {
- zval *data;
- MAKE_STD_ZVAL(data);
- ZVAL_LONG(data, 1);
- zend_symtable_update(Z_ARRVAL_P(return_value), Z_STRVAL_PP(entry), Z_STRLEN_PP(entry) + 1, &data, sizeof(data), NULL);
+ } else if (Z_TYPE_P(entry) == IS_STRING) {
+ if ((tmp = zend_symtable_find(Z_ARRVAL_P(return_value), Z_STR_P(entry))) == NULL) {
+ zval data;
+ ZVAL_LONG(&data, 1);
+ zend_symtable_update(Z_ARRVAL_P(return_value), Z_STR_P(entry), &data);
} else {
- Z_LVAL_PP(tmp)++;
+ Z_LVAL_P(tmp)++;
}
} else {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Can only count STRING and INTEGER values!");
@@ -2570,9 +2530,9 @@ PHP_FUNCTION(array_count_values)
* Specialized conversion rules for array_column() function
*/
static inline
-zend_bool array_column_param_helper(zval **param,
+zend_bool array_column_param_helper(zval *param,
const char *name TSRMLS_DC) {
- switch (Z_TYPE_PP(param)) {
+ switch (Z_TYPE_P(param)) {
case IS_DOUBLE:
convert_to_long_ex(param);
/* fallthrough */
@@ -2596,11 +2556,11 @@ zend_bool array_column_param_helper(zval **param,
value_key and optionally indexed by the index_key */
PHP_FUNCTION(array_column)
{
- zval **zcolumn = NULL, **zkey = NULL, **data;
+ zval *zcolumn = NULL, *zkey = NULL, *data;
HashTable *arr_hash;
HashPosition pointer;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "hZ!|Z!", &arr_hash, &zcolumn, &zkey) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "hz!|z!", &arr_hash, &zcolumn, &zkey) == FAILURE) {
return;
}
@@ -2611,50 +2571,52 @@ PHP_FUNCTION(array_column)
array_init(return_value);
for (zend_hash_internal_pointer_reset_ex(arr_hash, &pointer);
- zend_hash_get_current_data_ex(arr_hash, (void**)&data, &pointer) == SUCCESS;
+ (data = zend_hash_get_current_data_ex(arr_hash, &pointer)) != NULL;
zend_hash_move_forward_ex(arr_hash, &pointer)) {
- zval **zcolval, **zkeyval = NULL;
+ zval *zcolval, *zkeyval = NULL;
HashTable *ht;
- if (Z_TYPE_PP(data) != IS_ARRAY) {
+ if (Z_TYPE_P(data) != IS_ARRAY) {
/* Skip elemens which are not sub-arrays */
continue;
}
- ht = Z_ARRVAL_PP(data);
+ ht = Z_ARRVAL_P(data);
if (!zcolumn) {
/* NULL column ID means use entire subarray as data */
zcolval = data;
/* Otherwise, skip if the value doesn't exist in our subarray */
- } else if ((Z_TYPE_PP(zcolumn) == IS_STRING) &&
- (zend_hash_find(ht, Z_STRVAL_PP(zcolumn), Z_STRLEN_PP(zcolumn) + 1, (void**)&zcolval) == FAILURE)) {
+ } else if ((Z_TYPE_P(zcolumn) == IS_STRING) &&
+ ((zcolval = zend_hash_find(ht, Z_STR_P(zcolumn))) == NULL)) {
continue;
- } else if ((Z_TYPE_PP(zcolumn) == IS_LONG) &&
- (zend_hash_index_find(ht, Z_LVAL_PP(zcolumn), (void**)&zcolval) == FAILURE)) {
+ } else if ((Z_TYPE_P(zcolumn) == IS_LONG) &&
+ ((zcolval = zend_hash_index_find(ht, Z_LVAL_P(zcolumn))) == NULL)) {
continue;
}
/* Failure will leave zkeyval alone which will land us on the final else block below
* which is to append the value as next_index
*/
- if (zkey && (Z_TYPE_PP(zkey) == IS_STRING)) {
- zend_hash_find(ht, Z_STRVAL_PP(zkey), Z_STRLEN_PP(zkey) + 1, (void**)&zkeyval);
- } else if (zkey && (Z_TYPE_PP(zkey) == IS_LONG)) {
- zend_hash_index_find(ht, Z_LVAL_PP(zkey), (void**)&zkeyval);
- }
-
- Z_ADDREF_PP(zcolval);
- if (zkeyval && Z_TYPE_PP(zkeyval) == IS_STRING) {
- add_assoc_zval(return_value, Z_STRVAL_PP(zkeyval), *zcolval);
- } else if (zkeyval && Z_TYPE_PP(zkeyval) == IS_LONG) {
- add_index_zval(return_value, Z_LVAL_PP(zkeyval), *zcolval);
- } else if (zkeyval && Z_TYPE_PP(zkeyval) == IS_OBJECT) {
+ if (zkey && (Z_TYPE_P(zkey) == IS_STRING)) {
+ zkeyval = zend_hash_find(ht, Z_STR_P(zkey));
+ } else if (zkey && (Z_TYPE_P(zkey) == IS_LONG)) {
+ zkeyval = zend_hash_index_find(ht, Z_LVAL_P(zkey));
+ }
+
+ Z_ADDREF_P(zcolval);
+ if (zkeyval && Z_TYPE_P(zkeyval) == IS_STRING) {
+//???
+ add_assoc_zval(return_value, Z_STRVAL_P(zkeyval), zcolval);
+ } else if (zkeyval && Z_TYPE_P(zkeyval) == IS_LONG) {
+ add_index_zval(return_value, Z_LVAL_P(zkeyval), zcolval);
+ } else if (zkeyval && Z_TYPE_P(zkeyval) == IS_OBJECT) {
SEPARATE_ZVAL(zkeyval);
- convert_to_string(*zkeyval);
- add_assoc_zval(return_value, Z_STRVAL_PP(zkeyval), *zcolval);
+ convert_to_string(zkeyval);
+//???
+ add_assoc_zval(return_value, Z_STRVAL_P(zkeyval), zcolval);
} else {
- add_next_index_zval(return_value, *zcolval);
+ add_next_index_zval(return_value, zcolval);
}
}
}
@@ -2665,9 +2627,8 @@ PHP_FUNCTION(array_column)
PHP_FUNCTION(array_reverse)
{
zval *input, /* Input array */
- **entry; /* An entry in the input array */
- char *string_key;
- uint string_key_len;
+ *entry; /* An entry in the input array */
+ zend_string *string_key;
ulong num_key;
zend_bool preserve_keys = 0; /* whether to preserve keys */
HashPosition pos;
@@ -2680,19 +2641,19 @@ PHP_FUNCTION(array_reverse)
array_init_size(return_value, zend_hash_num_elements(Z_ARRVAL_P(input)));
zend_hash_internal_pointer_end_ex(Z_ARRVAL_P(input), &pos);
- while (zend_hash_get_current_data_ex(Z_ARRVAL_P(input), (void **)&entry, &pos) == SUCCESS) {
+ while ((entry = zend_hash_get_current_data_ex(Z_ARRVAL_P(input), &pos)) != NULL) {
zval_add_ref(entry);
- switch (zend_hash_get_current_key_ex(Z_ARRVAL_P(input), &string_key, &string_key_len, &num_key, 0, &pos)) {
+ switch (zend_hash_get_current_key_ex(Z_ARRVAL_P(input), &string_key, &num_key, 0, &pos)) {
case HASH_KEY_IS_STRING:
- zend_hash_update(Z_ARRVAL_P(return_value), string_key, string_key_len, entry, sizeof(zval *), NULL);
+ zend_hash_update(Z_ARRVAL_P(return_value), string_key, entry);
break;
case HASH_KEY_IS_LONG:
if (preserve_keys) {
- zend_hash_index_update(Z_ARRVAL_P(return_value), num_key, entry, sizeof(zval *), NULL);
+ zend_hash_index_update(Z_ARRVAL_P(return_value), num_key, entry);
} else {
- zend_hash_next_index_insert(Z_ARRVAL_P(return_value), entry, sizeof(zval *), NULL);
+ zend_hash_next_index_insert(Z_ARRVAL_P(return_value), entry);
}
break;
}
@@ -2708,7 +2669,7 @@ PHP_FUNCTION(array_pad)
{
zval *input; /* Input array */
zval *pad_value; /* Padding value obviously */
- zval ***pads; /* Array to pass to splice */
+ zval *pads; /* Array to pass to splice */
HashTable *new_hash;/* Return value from splice */
HashTable old_hash;
long pad_size; /* Size to pad to */
@@ -2747,9 +2708,9 @@ PHP_FUNCTION(array_pad)
zval_dtor(return_value);
RETURN_FALSE;
}
- pads = (zval ***)safe_emalloc(num_pads, sizeof(zval **), 0);
+ pads = (zval *)safe_emalloc(num_pads, sizeof(zval), 0);
for (i = 0; i < num_pads; i++) {
- pads[i] = &pad_value;
+ ZVAL_COPY_VALUE(&pads[i], pad_value);
}
/* Pad on the right or on the left */
@@ -2761,8 +2722,8 @@ PHP_FUNCTION(array_pad)
/* Copy the result hash into return value */
old_hash = *Z_ARRVAL_P(return_value);
- if (Z_ARRVAL_P(return_value) == &EG(symbol_table)) {
- zend_reset_all_cv(&EG(symbol_table) TSRMLS_CC);
+ if (Z_ARRVAL_P(return_value) == &EG(symbol_table).ht) {
+ zend_reset_all_cv(&EG(symbol_table).ht TSRMLS_CC);
}
*Z_ARRVAL_P(return_value) = *new_hash;
FREE_HASHTABLE(new_hash);
@@ -2777,7 +2738,7 @@ PHP_FUNCTION(array_pad)
Return array with key <-> value flipped */
PHP_FUNCTION(array_flip)
{
- zval *array, **entry, *data;
+ zval *array, *entry, data;
HashPosition pos;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a", &array) == FAILURE) {
@@ -2787,14 +2748,13 @@ PHP_FUNCTION(array_flip)
array_init_size(return_value, zend_hash_num_elements(Z_ARRVAL_P(array)));
zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(array), &pos);
- while (zend_hash_get_current_data_ex(Z_ARRVAL_P(array), (void **)&entry, &pos) == SUCCESS) {
- MAKE_STD_ZVAL(data);
- zend_hash_get_current_key_zval_ex(Z_ARRVAL_P(array), data, &pos);
-
- if (Z_TYPE_PP(entry) == IS_LONG) {
- zend_hash_index_update(Z_ARRVAL_P(return_value), Z_LVAL_PP(entry), &data, sizeof(data), NULL);
- } else if (Z_TYPE_PP(entry) == IS_STRING) {
- zend_symtable_update(Z_ARRVAL_P(return_value), Z_STRVAL_PP(entry), Z_STRLEN_PP(entry) + 1, &data, sizeof(data), NULL);
+ while ((entry = zend_hash_get_current_data_ex(Z_ARRVAL_P(array), &pos)) != NULL) {
+ zend_hash_get_current_key_zval_ex(Z_ARRVAL_P(array), &data, &pos);
+
+ if (Z_TYPE_P(entry) == IS_LONG) {
+ zend_hash_index_update(Z_ARRVAL_P(return_value), Z_LVAL_P(entry), &data);
+ } else if (Z_TYPE_P(entry) == IS_STRING) {
+ zend_symtable_update(Z_ARRVAL_P(return_value), Z_STR_P(entry), &data);
} else {
zval_ptr_dtor(&data); /* will free also zval structure */
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Can only flip STRING and INTEGER values!");
@@ -2809,10 +2769,9 @@ PHP_FUNCTION(array_flip)
Retuns an array with all string keys lowercased [or uppercased] */
PHP_FUNCTION(array_change_key_case)
{
- zval *array, **entry;
- char *string_key;
- char *new_key;
- uint str_key_len;
+ zval *array, *entry;
+ zend_string *string_key;
+ zend_string *new_key;
ulong num_key;
long change_to_upper=0;
HashPosition pos;
@@ -2824,22 +2783,22 @@ PHP_FUNCTION(array_change_key_case)
array_init_size(return_value, zend_hash_num_elements(Z_ARRVAL_P(array)));
zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(array), &pos);
- while (zend_hash_get_current_data_ex(Z_ARRVAL_P(array), (void **)&entry, &pos) == SUCCESS) {
+ while ((entry = zend_hash_get_current_data_ex(Z_ARRVAL_P(array), &pos)) != NULL) {
zval_add_ref(entry);
- switch (zend_hash_get_current_key_ex(Z_ARRVAL_P(array), &string_key, &str_key_len, &num_key, 0, &pos)) {
+ switch (zend_hash_get_current_key_ex(Z_ARRVAL_P(array), &string_key, &num_key, 0, &pos)) {
case HASH_KEY_IS_LONG:
- zend_hash_index_update(Z_ARRVAL_P(return_value), num_key, entry, sizeof(entry), NULL);
+ zend_hash_index_update(Z_ARRVAL_P(return_value), num_key, entry);
break;
case HASH_KEY_IS_STRING:
- new_key = estrndup(string_key, str_key_len - 1);
+ new_key = STR_DUP(string_key, 0);
if (change_to_upper) {
- php_strtoupper(new_key, str_key_len - 1);
+ php_strtoupper(new_key->val, new_key->len);
} else {
- php_strtolower(new_key, str_key_len - 1);
+ php_strtolower(new_key->val, new_key->len);
}
- zend_hash_update(Z_ARRVAL_P(return_value), new_key, str_key_len, entry, sizeof(entry), NULL);
- efree(new_key);
+ zend_hash_update(Z_ARRVAL_P(return_value), new_key, entry);
+ STR_FREE(new_key);
break;
}
@@ -2852,7 +2811,7 @@ PHP_FUNCTION(array_change_key_case)
Removes duplicate values from array */
PHP_FUNCTION(array_unique)
{
- zval *array, *tmp;
+ zval *array;
uint idx;
Bucket *p;
struct bucketindex {
@@ -2870,7 +2829,7 @@ PHP_FUNCTION(array_unique)
php_set_compare_func(sort_type TSRMLS_CC);
array_init_size(return_value, zend_hash_num_elements(Z_ARRVAL_P(array)));
- zend_hash_copy(Z_ARRVAL_P(return_value), Z_ARRVAL_P(array), (copy_ctor_func_t) zval_add_ref, (void *)&tmp, sizeof(zval*));
+ zend_hash_copy(Z_ARRVAL_P(return_value), Z_ARRVAL_P(array), zval_add_ref);
if (Z_ARRVAL_P(array)->nNumOfElements <= 1) { /* nothing to do */
return;
@@ -2884,17 +2843,17 @@ PHP_FUNCTION(array_unique)
}
for (i = 0, idx = 0; idx < Z_ARRVAL_P(array)->nNumUsed; idx++) {
p = Z_ARRVAL_P(array)->arData + idx;
- if (!p->xData) continue;
+ if (Z_TYPE(p->val) == IS_UNDEF) continue;
arTmp[i].b = *p;
arTmp[i].i = i;
i++;
}
- arTmp[i].b.xData = NULL;
+ ZVAL_UNDEF(&arTmp[i].b.val);
zend_qsort((void *) arTmp, i, sizeof(struct bucketindex), php_array_data_compare TSRMLS_CC);
/* go through the sorted array and delete duplicates from the copy */
lastkept = arTmp;
- for (cmpdata = arTmp + 1; cmpdata->b.xData; cmpdata++) {
+ for (cmpdata = arTmp + 1; Z_TYPE(cmpdata->b.val) != IS_UNDEF; cmpdata++) {
if (php_array_data_compare(lastkept, cmpdata TSRMLS_CC)) {
lastkept = cmpdata;
} else {
@@ -2904,13 +2863,13 @@ PHP_FUNCTION(array_unique)
} else {
p = &cmpdata->b;
}
- if (p->nKeyLength == 0) {
+ if (p->key == NULL) {
zend_hash_index_del(Z_ARRVAL_P(return_value), p->h);
} else {
- if (Z_ARRVAL_P(return_value) == &EG(symbol_table)) {
- zend_delete_global_variable(p->arKey, p->nKeyLength - 1 TSRMLS_CC);
+ if (Z_ARRVAL_P(return_value) == &EG(symbol_table).ht) {
+ zend_delete_global_variable(p->key TSRMLS_CC);
} else {
- zend_hash_quick_del(Z_ARRVAL_P(return_value), p->arKey, p->nKeyLength, p->h);
+ zend_hash_del(Z_ARRVAL_P(return_value), p->key);
}
}
}
@@ -2919,14 +2878,14 @@ PHP_FUNCTION(array_unique)
}
/* }}} */
-static int zval_compare(zval **a, zval **b TSRMLS_DC) /* {{{ */
+static int zval_compare(zval *a, zval *b TSRMLS_DC) /* {{{ */
{
zval result;
zval *first;
zval *second;
- first = *((zval **) a);
- second = *((zval **) b);
+ first = a;
+ second = b;
if (string_compare_function(&result, first, second TSRMLS_CC) == FAILURE) {
return 0;
@@ -2954,26 +2913,26 @@ static int zval_compare(zval **a, zval **b TSRMLS_DC) /* {{{ */
}
/* }}} */
-static int zval_user_compare(zval **a, zval **b TSRMLS_DC) /* {{{ */
+static int zval_user_compare(zval *a, zval *b TSRMLS_DC) /* {{{ */
{
- zval **args[2];
- zval *retval_ptr = NULL;
+ zval args[2];
+ zval retval;
- args[0] = (zval **) a;
- args[1] = (zval **) b;
+ ZVAL_COPY_VALUE(&args[0], a);
+ ZVAL_COPY_VALUE(&args[1], b);
BG(user_compare_fci).param_count = 2;
BG(user_compare_fci).params = args;
- BG(user_compare_fci).retval_ptr_ptr = &retval_ptr;
+ BG(user_compare_fci).retval = &retval;
BG(user_compare_fci).no_separation = 0;
- if (zend_call_function(&BG(user_compare_fci), &BG(user_compare_fci_cache) TSRMLS_CC) == SUCCESS && retval_ptr) {
- long retval;
+ if (zend_call_function(&BG(user_compare_fci), &BG(user_compare_fci_cache) TSRMLS_CC) == SUCCESS && Z_TYPE(retval) != IS_UNDEF) {
+ long ret;
- convert_to_long_ex(&retval_ptr);
- retval = Z_LVAL_P(retval_ptr);
- zval_ptr_dtor(&retval_ptr);
- return retval < 0 ? -1 : retval > 0 ? 1 : 0;;
+ convert_to_long_ex(&retval);
+ ret = Z_LVAL(retval);
+ zval_ptr_dtor(&retval);
+ return ret < 0 ? -1 : ret > 0 ? 1 : 0;;
} else {
return 0;
}
@@ -2985,10 +2944,10 @@ static void php_array_intersect_key(INTERNAL_FUNCTION_PARAMETERS, int data_compa
uint idx;
Bucket *p;
int argc, i;
- zval ***args;
- int (*intersect_data_compare_func)(zval **, zval ** TSRMLS_DC) = NULL;
+ zval *args;
+ int (*intersect_data_compare_func)(zval *, zval * TSRMLS_DC) = NULL;
zend_bool ok;
- zval **data;
+ zval *data;
int req_args;
char *param_spec;
@@ -3020,7 +2979,7 @@ static void php_array_intersect_key(INTERNAL_FUNCTION_PARAMETERS, int data_compa
}
for (i = 0; i < argc; i++) {
- if (Z_TYPE_PP(args[i]) != IS_ARRAY) {
+ if (Z_TYPE(args[i]) != IS_ARRAY) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Argument #%d is not an array", i + 1);
RETVAL_NULL();
goto out;
@@ -3029,38 +2988,38 @@ static void php_array_intersect_key(INTERNAL_FUNCTION_PARAMETERS, int data_compa
array_init(return_value);
- for (idx = 0; idx < Z_ARRVAL_PP(args[0])->nNumUsed; idx++) {
- p = Z_ARRVAL_PP(args[0])->arData + idx;
- if (!p->xData) continue;
- if (p->nKeyLength == 0) {
+ for (idx = 0; idx < Z_ARRVAL(args[0])->nNumUsed; idx++) {
+ p = Z_ARRVAL(args[0])->arData + idx;
+ if (Z_TYPE(p->val) == IS_UNDEF) continue;
+ if (p->key == NULL) {
ok = 1;
for (i = 1; i < argc; i++) {
- if (zend_hash_index_find(Z_ARRVAL_PP(args[i]), p->h, (void**)&data) == FAILURE ||
+ if ((data = zend_hash_index_find(Z_ARRVAL(args[i]), p->h)) == NULL ||
(intersect_data_compare_func &&
- intersect_data_compare_func((zval**)&p->xData, data TSRMLS_CC) != 0)
+ intersect_data_compare_func(&p->val, data TSRMLS_CC) != 0)
) {
ok = 0;
break;
}
}
if (ok) {
- Z_ADDREF_P((zval*)p->xData);
- zend_hash_index_update(Z_ARRVAL_P(return_value), p->h, &p->xData, sizeof(zval*), NULL);
+ Z_ADDREF(p->val);
+ zend_hash_index_update(Z_ARRVAL_P(return_value), p->h, &p->val);
}
} else {
ok = 1;
for (i = 1; i < argc; i++) {
- if (zend_hash_quick_find(Z_ARRVAL_PP(args[i]), p->arKey, p->nKeyLength, p->h, (void**)&data) == FAILURE ||
+ if ((data = zend_hash_find(Z_ARRVAL(args[i]), p->key)) == NULL ||
(intersect_data_compare_func &&
- intersect_data_compare_func((zval**)&p->xData, data TSRMLS_CC) != 0)
+ intersect_data_compare_func(&p->val, data TSRMLS_CC) != 0)
) {
ok = 0;
break;
}
}
if (ok) {
- Z_ADDREF_P((zval*)p->xData);
- zend_hash_quick_update(Z_ARRVAL_P(return_value), p->arKey, p->nKeyLength, p->h, &p->xData, sizeof(zval*), NULL);
+ Z_ADDREF(p->val);
+ zend_hash_update(Z_ARRVAL_P(return_value), p->key, &p->val);
}
}
}
@@ -3071,7 +3030,7 @@ out:
static void php_array_intersect(INTERNAL_FUNCTION_PARAMETERS, int behavior, int data_compare_type, int key_compare_type) /* {{{ */
{
- zval ***args = NULL;
+ zval *args = NULL;
HashTable *hash;
int arr_argc, i, c = 0;
uint idx;
@@ -3188,12 +3147,12 @@ static void php_array_intersect(INTERNAL_FUNCTION_PARAMETERS, int behavior, int
}
for (i = 0; i < arr_argc; i++) {
- if (Z_TYPE_PP(args[i]) != IS_ARRAY) {
+ if (Z_TYPE(args[i]) != IS_ARRAY) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Argument #%d is not an array", i + 1);
arr_argc = i; /* only free up to i - 1 */
goto out;
}
- hash = Z_ARRVAL_PP(args[i]);
+ hash = Z_ARRVAL(args[i]);
list = (Bucket *) pemalloc((hash->nNumOfElements + 1) * sizeof(Bucket), hash->flags & HASH_FLAG_PERSISTENT);
if (!list) {
PHP_ARRAY_CMP_FUNC_RESTORE();
@@ -3207,10 +3166,10 @@ static void php_array_intersect(INTERNAL_FUNCTION_PARAMETERS, int behavior, int
ptrs[i] = list;
for (idx = 0; idx < hash->nNumUsed; idx++) {
p = hash->arData + idx;
- if (!p->xData) continue;
+ if (Z_TYPE(p->val) == IS_UNDEF) continue;
*list++ = *p;
}
- list->xData = NULL;
+ ZVAL_UNDEF(&list->val);
if (behavior == INTERSECT_NORMAL) {
zend_qsort((void *) lists[i], hash->nNumOfElements, sizeof(Bucket), intersect_data_compare_func TSRMLS_CC);
} else if (behavior & INTERSECT_ASSOC) { /* triggered also when INTERSECT_KEY */
@@ -3219,19 +3178,17 @@ static void php_array_intersect(INTERNAL_FUNCTION_PARAMETERS, int behavior, int
}
/* copy the argument array */
- RETVAL_ZVAL(*args[0], 1, 0);
- if (return_value->value.ht == &EG(symbol_table)) {
- HashTable *ht;
- zval *tmp;
+ RETVAL_ZVAL(&args[0], 1, 0);
+ if (Z_ARRVAL_P(return_value) == &EG(symbol_table).ht) {
+ HashTable *old_ht = Z_ARRVAL_P(return_value);
- ALLOC_HASHTABLE(ht);
- zend_hash_init(ht, zend_hash_num_elements(return_value->value.ht), NULL, ZVAL_PTR_DTOR, 0);
- zend_hash_copy(ht, return_value->value.ht, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *));
- return_value->value.ht = ht;
+ ZVAL_NEW_ARR(return_value);
+ zend_hash_init(Z_ARRVAL_P(return_value), zend_hash_num_elements(old_ht), NULL, ZVAL_PTR_DTOR, 0);
+ zend_hash_copy(Z_ARRVAL_P(return_value), old_ht, zval_add_ref);
}
/* go through the lists and look for common values */
- while (ptrs[0]->xData) {
+ while (Z_TYPE(ptrs[0]->val) != IS_UNDEF) {
if ((behavior & INTERSECT_ASSOC) /* triggered also when INTERSECT_KEY */
&&
key_compare_type == INTERSECT_COMP_KEY_USER) {
@@ -3242,14 +3199,14 @@ static void php_array_intersect(INTERNAL_FUNCTION_PARAMETERS, int behavior, int
for (i = 1; i < arr_argc; i++) {
if (behavior & INTERSECT_NORMAL) {
- while (ptrs[i]->xData && (0 < (c = intersect_data_compare_func(ptrs[0], ptrs[i] TSRMLS_CC)))) {
+ while (Z_TYPE(ptrs[i]->val) != IS_UNDEF && (0 < (c = intersect_data_compare_func(ptrs[0], ptrs[i] TSRMLS_CC)))) {
ptrs[i]++;
}
} else if (behavior & INTERSECT_ASSOC) { /* triggered also when INTERSECT_KEY */
- while (ptrs[i]->xData && (0 < (c = intersect_key_compare_func(ptrs[0], ptrs[i] TSRMLS_CC)))) {
+ while (Z_TYPE(ptrs[i]->val) != IS_UNDEF && (0 < (c = intersect_key_compare_func(ptrs[0], ptrs[i] TSRMLS_CC)))) {
ptrs[i]++;
}
- if ((!c && ptrs[i]->xData) && (behavior == INTERSECT_ASSOC)) { /* only when INTERSECT_ASSOC */
+ if ((!c && Z_TYPE(ptrs[i]->val) != IS_UNDEF) && (behavior == INTERSECT_ASSOC)) { /* only when INTERSECT_ASSOC */
/* this means that ptrs[i] is not NULL so we can compare
* and "c==0" is from last operation
* in this branch of code we enter only when INTERSECT_ASSOC
@@ -3271,19 +3228,19 @@ static void php_array_intersect(INTERNAL_FUNCTION_PARAMETERS, int behavior, int
}
}
}
- if (!ptrs[i]->xData) {
+ if (Z_TYPE(ptrs[i]->val) == IS_UNDEF) {
/* delete any values corresponding to remains of ptrs[0] */
/* and exit because they do not present in at least one of */
/* the other arguments */
for (;;) {
p = ptrs[0]++;
- if (!p->xData) {
+ if (Z_TYPE(p->val) == IS_UNDEF) {
goto out;
}
- if (p->nKeyLength == 0) {
+ if (p->key == NULL) {
zend_hash_index_del(Z_ARRVAL_P(return_value), p->h);
} else {
- zend_hash_quick_del(Z_ARRVAL_P(return_value), p->arKey, p->nKeyLength, p->h);
+ zend_hash_del(Z_ARRVAL_P(return_value), p->key);
}
}
}
@@ -3296,12 +3253,12 @@ static void php_array_intersect(INTERNAL_FUNCTION_PARAMETERS, int behavior, int
/* with value < value of ptrs[i] */
for (;;) {
p = ptrs[0];
- if (p->nKeyLength == 0) {
+ if (p->key == NULL) {
zend_hash_index_del(Z_ARRVAL_P(return_value), p->h);
} else {
- zend_hash_quick_del(Z_ARRVAL_P(return_value), p->arKey, p->nKeyLength, p->h);
+ zend_hash_del(Z_ARRVAL_P(return_value), p->key);
}
- if (!(++ptrs[0])->xData) {
+ if (Z_TYPE((++ptrs[0])->val) == IS_UNDEF) {
goto out;
}
if (behavior == INTERSECT_NORMAL) {
@@ -3317,7 +3274,7 @@ static void php_array_intersect(INTERNAL_FUNCTION_PARAMETERS, int behavior, int
/* ptrs[0] is present in all the arguments */
/* Skip all entries with same value as ptrs[0] */
for (;;) {
- if (!(++ptrs[0])->xData) {
+ if (Z_TYPE((++ptrs[0])->val) == IS_UNDEF) {
goto out;
}
if (behavior == INTERSECT_NORMAL) {
@@ -3333,7 +3290,7 @@ static void php_array_intersect(INTERNAL_FUNCTION_PARAMETERS, int behavior, int
}
out:
for (i = 0; i < arr_argc; i++) {
- hash = Z_ARRVAL_PP(args[i]);
+ hash = Z_ARRVAL(args[i]);
pefree(lists[i], hash->flags & HASH_FLAG_PERSISTENT);
}
@@ -3414,10 +3371,10 @@ static void php_array_diff_key(INTERNAL_FUNCTION_PARAMETERS, int data_compare_ty
uint idx;
Bucket *p;
int argc, i;
- zval ***args;
- int (*diff_data_compare_func)(zval **, zval ** TSRMLS_DC) = NULL;
+ zval *args;
+ int (*diff_data_compare_func)(zval *, zval * TSRMLS_DC) = NULL;
zend_bool ok;
- zval **data;
+ zval *data;
/* Get the argument count */
argc = ZEND_NUM_ARGS();
@@ -3444,7 +3401,7 @@ static void php_array_diff_key(INTERNAL_FUNCTION_PARAMETERS, int data_compare_ty
}
for (i = 0; i < argc; i++) {
- if (Z_TYPE_PP(args[i]) != IS_ARRAY) {
+ if (Z_TYPE(args[i]) != IS_ARRAY) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Argument #%d is not an array", i + 1);
RETVAL_NULL();
goto out;
@@ -3453,38 +3410,38 @@ static void php_array_diff_key(INTERNAL_FUNCTION_PARAMETERS, int data_compare_ty
array_init(return_value);
- for (idx = 0; idx < Z_ARRVAL_PP(args[0])->nNumUsed; idx++) {
- p = Z_ARRVAL_PP(args[0])->arData + idx;
- if (!p->xData) continue;
- if (p->nKeyLength == 0) {
+ for (idx = 0; idx < Z_ARRVAL(args[0])->nNumUsed; idx++) {
+ p = Z_ARRVAL(args[0])->arData + idx;
+ if (Z_TYPE(p->val) == IS_UNDEF) continue;
+ if (p->key == NULL) {
ok = 1;
for (i = 1; i < argc; i++) {
- if (zend_hash_index_find(Z_ARRVAL_PP(args[i]), p->h, (void**)&data) == SUCCESS &&
+ if ((data = zend_hash_index_find(Z_ARRVAL(args[i]), p->h)) != NULL &&
(!diff_data_compare_func ||
- diff_data_compare_func((zval**)&p->xData, data TSRMLS_CC) == 0)
+ diff_data_compare_func(&p->val, data TSRMLS_CC) == 0)
) {
ok = 0;
break;
}
}
if (ok) {
- Z_ADDREF_P((zval*)p->xData);
- zend_hash_index_update(Z_ARRVAL_P(return_value), p->h, &p->xData, sizeof(zval*), NULL);
+ Z_ADDREF(p->val);
+ zend_hash_index_update(Z_ARRVAL_P(return_value), p->h, &p->val);
}
} else {
ok = 1;
for (i = 1; i < argc; i++) {
- if (zend_hash_quick_find(Z_ARRVAL_PP(args[i]), p->arKey, p->nKeyLength, p->h, (void**)&data) == SUCCESS &&
+ if ((data = zend_hash_find(Z_ARRVAL(args[i]), p->key)) != NULL &&
(!diff_data_compare_func ||
- diff_data_compare_func((zval**)&p->xData, data TSRMLS_CC) == 0)
+ diff_data_compare_func(&p->val, data TSRMLS_CC) == 0)
) {
ok = 0;
break;
}
}
if (ok) {
- Z_ADDREF_P((zval*)p->xData);
- zend_hash_quick_update(Z_ARRVAL_P(return_value), p->arKey, p->nKeyLength, p->h, &p->xData, sizeof(zval*), NULL);
+ Z_ADDREF(p->val);
+ zend_hash_update(Z_ARRVAL_P(return_value), p->key, &p->val);
}
}
}
@@ -3495,7 +3452,7 @@ out:
static void php_array_diff(INTERNAL_FUNCTION_PARAMETERS, int behavior, int data_compare_type, int key_compare_type) /* {{{ */
{
- zval ***args = NULL;
+ zval *args = NULL;
HashTable *hash;
int arr_argc, i, c;
uint idx;
@@ -3611,12 +3568,12 @@ static void php_array_diff(INTERNAL_FUNCTION_PARAMETERS, int behavior, int data_
}
for (i = 0; i < arr_argc; i++) {
- if (Z_TYPE_PP(args[i]) != IS_ARRAY) {
+ if (Z_TYPE(args[i]) != IS_ARRAY) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Argument #%d is not an array", i + 1);
arr_argc = i; /* only free up to i - 1 */
goto out;
}
- hash = Z_ARRVAL_PP(args[i]);
+ hash = Z_ARRVAL(args[i]);
list = (Bucket *) pemalloc((hash->nNumOfElements + 1) * sizeof(Bucket), hash->flags & HASH_FLAG_PERSISTENT);
if (!list) {
PHP_ARRAY_CMP_FUNC_RESTORE();
@@ -3630,10 +3587,10 @@ static void php_array_diff(INTERNAL_FUNCTION_PARAMETERS, int behavior, int data_
ptrs[i] = list;
for (idx = 0; idx < hash->nNumUsed; idx++) {
p = hash->arData + idx;
- if (!p->xData) continue;
+ if (Z_TYPE(p->val) == IS_UNDEF) continue;
*list++ = *p;
}
- list->xData = NULL;
+ ZVAL_UNDEF(&list->val);
if (behavior == DIFF_NORMAL) {
zend_qsort((void *) lists[i], hash->nNumOfElements, sizeof(Bucket), diff_data_compare_func TSRMLS_CC);
} else if (behavior & DIFF_ASSOC) { /* triggered also when DIFF_KEY */
@@ -3642,19 +3599,17 @@ static void php_array_diff(INTERNAL_FUNCTION_PARAMETERS, int behavior, int data_
}
/* copy the argument array */
- RETVAL_ZVAL(*args[0], 1, 0);
- if (return_value->value.ht == &EG(symbol_table)) {
- HashTable *ht;
- zval *tmp;
+ RETVAL_ZVAL(&args[0], 1, 0);
+ if (Z_ARRVAL_P(return_value) == &EG(symbol_table).ht) {
+ HashTable *old_ht = Z_ARRVAL_P(return_value);
- ALLOC_HASHTABLE(ht);
- zend_hash_init(ht, zend_hash_num_elements(return_value->value.ht), NULL, ZVAL_PTR_DTOR, 0);
- zend_hash_copy(ht, return_value->value.ht, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *));
- return_value->value.ht = ht;
+ ZVAL_NEW_ARR(return_value);
+ zend_hash_init(Z_ARRVAL_P(return_value), zend_hash_num_elements(old_ht), NULL, ZVAL_PTR_DTOR, 0);
+ zend_hash_copy(Z_ARRVAL_P(return_value), old_ht, zval_add_ref);
}
/* go through the lists and look for values of ptr[0] that are not in the others */
- while (ptrs[0]->xData) {
+ while (Z_TYPE(ptrs[0]->val) != IS_UNDEF) {
if ((behavior & DIFF_ASSOC) /* triggered also when DIFF_KEY */
&&
key_compare_type == DIFF_COMP_KEY_USER
@@ -3666,24 +3621,24 @@ static void php_array_diff(INTERNAL_FUNCTION_PARAMETERS, int behavior, int data_
for (i = 1; i < arr_argc; i++) {
Bucket *ptr = ptrs[i];
if (behavior == DIFF_NORMAL) {
- while (ptrs[i]->xData && (0 < (c = diff_data_compare_func(ptrs[0], ptrs[i] TSRMLS_CC)))) {
+ while (Z_TYPE(ptrs[i]->val) != IS_UNDEF && (0 < (c = diff_data_compare_func(ptrs[0], ptrs[i] TSRMLS_CC)))) {
ptrs[i]++;
}
} else if (behavior & DIFF_ASSOC) { /* triggered also when DIFF_KEY */
- while (ptr->xData && (0 != (c = diff_key_compare_func(ptrs[0], ptr TSRMLS_CC)))) {
+ while (Z_TYPE(ptr->val) != IS_UNDEF && (0 != (c = diff_key_compare_func(ptrs[0], ptr TSRMLS_CC)))) {
ptr++;
}
}
if (!c) {
if (behavior == DIFF_NORMAL) {
- if (ptrs[i]->xData) {
+ if (Z_TYPE(ptrs[i]->val) != IS_UNDEF) {
ptrs[i]++;
}
break;
} else if (behavior == DIFF_ASSOC) { /* only when DIFF_ASSOC */
/* In this branch is execute only when DIFF_ASSOC. If behavior == DIFF_KEY
* data comparison is not needed - skipped. */
- if (ptr->xData) {
+ if (Z_TYPE(ptr->val) != IS_UNDEF) {
if (data_compare_type == DIFF_COMP_DATA_USER) {
BG(user_compare_fci) = *fci_data;
BG(user_compare_fci_cache) = *fci_data_cache;
@@ -3715,12 +3670,12 @@ static void php_array_diff(INTERNAL_FUNCTION_PARAMETERS, int behavior, int data_
/* delete all entries with value as ptrs[0] */
for (;;) {
p = ptrs[0];
- if (p->nKeyLength == 0) {
+ if (p->key == NULL) {
zend_hash_index_del(Z_ARRVAL_P(return_value), p->h);
} else {
- zend_hash_quick_del(Z_ARRVAL_P(return_value), p->arKey, p->nKeyLength, p->h);
+ zend_hash_del(Z_ARRVAL_P(return_value), p->key);
}
- if (!(++ptrs[0])->xData) {
+ if (Z_TYPE((++ptrs[0])->val) == IS_UNDEF) {
goto out;
}
if (behavior == DIFF_NORMAL) {
@@ -3736,7 +3691,7 @@ static void php_array_diff(INTERNAL_FUNCTION_PARAMETERS, int behavior, int data_
/* ptrs[0] in none of the other arguments */
/* skip all entries with value as ptrs[0] */
for (;;) {
- if (!(++ptrs[0])->xData) {
+ if (Z_TYPE((++ptrs[0])->val) == IS_UNDEF) {
goto out;
}
if (behavior == DIFF_NORMAL) {
@@ -3752,7 +3707,7 @@ static void php_array_diff(INTERNAL_FUNCTION_PARAMETERS, int behavior, int data_
}
out:
for (i = 0; i < arr_argc; i++) {
- hash = Z_ARRVAL_PP(args[i]);
+ hash = Z_ARRVAL(args[i]);
pefree(lists[i], hash->flags & HASH_FLAG_PERSISTENT);
}
@@ -3844,13 +3799,13 @@ PHPAPI int php_multisort_compare(const void *a, const void *b TSRMLS_DC) /* {{{
do {
php_set_compare_func(ARRAYG(multisort_flags)[MULTISORT_TYPE][r] TSRMLS_CC);
- ARRAYG(compare_func)(&temp, (zval *)ab[r].xData, (zval *)bb[r].xData TSRMLS_CC);
+ ARRAYG(compare_func)(&temp, &ab[r].val, &bb[r].val TSRMLS_CC);
result = ARRAYG(multisort_flags)[MULTISORT_ORDER][r] * Z_LVAL(temp);
if (result != 0) {
return result;
}
r++;
- } while (ab[r].xData != NULL);
+ } while (Z_TYPE(ab[r].val) != IS_UNDEF);
return result;
}
@@ -3867,8 +3822,8 @@ PHPAPI int php_multisort_compare(const void *a, const void *b TSRMLS_DC) /* {{{
Sort multiple arrays at once similar to how ORDER BY clause works in SQL */
PHP_FUNCTION(array_multisort)
{
- zval*** args;
- zval*** arrays;
+ zval* args;
+ zval** arrays;
Bucket** indirect;
uint idx;
Bucket* p;
@@ -3886,7 +3841,7 @@ PHP_FUNCTION(array_multisort)
}
/* Allocate space for storing pointers to input arrays and sort flags. */
- arrays = (zval ***)ecalloc(argc, sizeof(zval **));
+ arrays = (zval **)ecalloc(argc, sizeof(zval *));
for (i = 0; i < MULTISORT_LAST; i++) {
parse_state[i] = 0;
ARRAYG(multisort_flags)[i] = (int *)ecalloc(argc, sizeof(int));
@@ -3898,7 +3853,7 @@ PHP_FUNCTION(array_multisort)
* accordingly. There can't be two sort flags of the same type after an
* array, and the very first argument has to be an array. */
for (i = 0; i < argc; i++) {
- if (Z_TYPE_PP(args[i]) == IS_ARRAY) {
+ if (Z_TYPE(args[i]) == IS_ARRAY) {
/* We see the next array, so we update the sort flags of
* the previous array and reset the sort flags. */
if (i > 0) {
@@ -3907,20 +3862,20 @@ PHP_FUNCTION(array_multisort)
sort_order = PHP_SORT_ASC;
sort_type = PHP_SORT_REGULAR;
}
- arrays[num_arrays++] = args[i];
+ arrays[num_arrays++] = &args[i];
/* Next one may be an array or a list of sort flags. */
for (k = 0; k < MULTISORT_LAST; k++) {
parse_state[k] = 1;
}
- } else if (Z_TYPE_PP(args[i]) == IS_LONG) {
- switch (Z_LVAL_PP(args[i]) & ~PHP_SORT_FLAG_CASE) {
+ } else if (Z_TYPE(args[i]) == IS_LONG) {
+ switch (Z_LVAL(args[i]) & ~PHP_SORT_FLAG_CASE) {
case PHP_SORT_ASC:
case PHP_SORT_DESC:
/* flag allowed here */
if (parse_state[MULTISORT_ORDER] == 1) {
/* Save the flag and make sure then next arg is not the current flag. */
- sort_order = Z_LVAL_PP(args[i]) == PHP_SORT_DESC ? -1 : 1;
+ sort_order = Z_LVAL(args[i]) == PHP_SORT_DESC ? -1 : 1;
parse_state[MULTISORT_ORDER] = 0;
} else {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Argument #%d is expected to be an array or sorting flag that has not already been specified", i + 1);
@@ -3938,7 +3893,7 @@ PHP_FUNCTION(array_multisort)
/* flag allowed here */
if (parse_state[MULTISORT_TYPE] == 1) {
/* Save the flag and make sure then next arg is not the current flag. */
- sort_type = Z_LVAL_PP(args[i]);
+ sort_type = Z_LVAL(args[i]);
parse_state[MULTISORT_TYPE] = 0;
} else {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Argument #%d is expected to be an array or sorting flag that has not already been specified", i + 1);
@@ -3962,9 +3917,9 @@ PHP_FUNCTION(array_multisort)
ARRAYG(multisort_flags)[MULTISORT_TYPE][num_arrays - 1] = sort_type;
/* Make sure the arrays are of the same size. */
- array_size = zend_hash_num_elements(Z_ARRVAL_PP(arrays[0]));
+ array_size = zend_hash_num_elements(Z_ARRVAL_P(arrays[0]));
for (i = 0; i < num_arrays; i++) {
- if (zend_hash_num_elements(Z_ARRVAL_PP(arrays[i])) != array_size) {
+ if (zend_hash_num_elements(Z_ARRVAL_P(arrays[i])) != array_size) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Array sizes are inconsistent");
MULTISORT_ABORT;
}
@@ -3990,15 +3945,15 @@ PHP_FUNCTION(array_multisort)
}
for (i = 0; i < num_arrays; i++) {
k = 0;
- for (idx = 0; idx < Z_ARRVAL_PP(arrays[i])->nNumUsed; idx++) {
- p = Z_ARRVAL_PP(arrays[i])->arData + idx;
- if (!p->xData) continue;
+ for (idx = 0; idx < Z_ARRVAL_P(arrays[i])->nNumUsed; idx++) {
+ p = Z_ARRVAL_P(arrays[i])->arData + idx;
+ if (Z_TYPE(p->val) == IS_UNDEF) continue;
indirect[k][i] = *p;
k++;
}
}
for (k = 0; k < array_size; k++) {
- indirect[k][num_arrays].xData = NULL;
+ ZVAL_UNDEF(&indirect[k][num_arrays].val);
}
/* Do the actual sort magic - bada-bim, bada-boom. */
@@ -4007,13 +3962,13 @@ PHP_FUNCTION(array_multisort)
/* Restructure the arrays based on sorted indirect - this is mostly taken from zend_hash_sort() function. */
HANDLE_BLOCK_INTERRUPTIONS();
for (i = 0; i < num_arrays; i++) {
- hash = Z_ARRVAL_PP(arrays[i]);
+ hash = Z_ARRVAL_P(arrays[i]);
hash->nNumUsed = array_size;
hash->nInternalPointer = 0;
for (n = 0, k = 0; k < array_size; k++) {
hash->arData[k] = indirect[k][i];
- if (hash->arData[k].nKeyLength == 0)
+ if (hash->arData[k].key == NULL)
hash->arData[k].h = n++;
}
@@ -4045,8 +4000,7 @@ PHP_FUNCTION(array_rand)
zval *input;
long randval, num_req = 1;
int num_avail, key_type;
- char *string_key;
- uint string_key_len;
+ zend_string *string_key;
ulong num_key;
HashPosition pos;
@@ -4070,7 +4024,7 @@ PHP_FUNCTION(array_rand)
/* We can't use zend_hash_index_find() because the array may have string keys or gaps. */
zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(input), &pos);
- while (num_req && (key_type = zend_hash_get_current_key_ex(Z_ARRVAL_P(input), &string_key, &string_key_len, &num_key, 0, &pos)) != HASH_KEY_NON_EXISTENT) {
+ while (num_req && (key_type = zend_hash_get_current_key_ex(Z_ARRVAL_P(input), &string_key, &num_key, 0, &pos)) != HASH_KEY_NON_EXISTENT) {
randval = php_rand(TSRMLS_C);
@@ -4078,14 +4032,14 @@ PHP_FUNCTION(array_rand)
/* If we are returning a single result, just do it. */
if (Z_TYPE_P(return_value) != IS_ARRAY) {
if (key_type == HASH_KEY_IS_STRING) {
- RETURN_STRINGL(string_key, string_key_len - 1, 1);
+ RETURN_STR(STR_COPY(string_key));
} else {
RETURN_LONG(num_key);
}
} else {
/* Append the result to the return value. */
if (key_type == HASH_KEY_IS_STRING) {
- add_next_index_stringl(return_value, string_key, string_key_len - 1, 1);
+ add_next_index_str(return_value, string_key);
} else {
add_next_index_long(return_value, num_key);
}
@@ -4103,7 +4057,7 @@ PHP_FUNCTION(array_rand)
PHP_FUNCTION(array_sum)
{
zval *input,
- **entry,
+ *entry,
entry_n;
HashPosition pos;
@@ -4114,14 +4068,13 @@ PHP_FUNCTION(array_sum)
ZVAL_LONG(return_value, 0);
for (zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(input), &pos);
- zend_hash_get_current_data_ex(Z_ARRVAL_P(input), (void **)&entry, &pos) == SUCCESS;
+ (entry = zend_hash_get_current_data_ex(Z_ARRVAL_P(input), &pos)) != NULL;
zend_hash_move_forward_ex(Z_ARRVAL_P(input), &pos)
) {
- if (Z_TYPE_PP(entry) == IS_ARRAY || Z_TYPE_PP(entry) == IS_OBJECT) {
+ if (Z_TYPE_P(entry) == IS_ARRAY || Z_TYPE_P(entry) == IS_OBJECT) {
continue;
}
- entry_n = **entry;
- zval_copy_ctor(&entry_n);
+ ZVAL_DUP(&entry_n, entry);
convert_scalar_to_number(&entry_n TSRMLS_CC);
fast_add_function(return_value, return_value, &entry_n TSRMLS_CC);
}
@@ -4133,7 +4086,7 @@ PHP_FUNCTION(array_sum)
PHP_FUNCTION(array_product)
{
zval *input,
- **entry,
+ *entry,
entry_n;
HashPosition pos;
double dval;
@@ -4148,14 +4101,13 @@ PHP_FUNCTION(array_product)
}
for (zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(input), &pos);
- zend_hash_get_current_data_ex(Z_ARRVAL_P(input), (void **)&entry, &pos) == SUCCESS;
+ (entry = zend_hash_get_current_data_ex(Z_ARRVAL_P(input), &pos)) != NULL;
zend_hash_move_forward_ex(Z_ARRVAL_P(input), &pos)
) {
- if (Z_TYPE_PP(entry) == IS_ARRAY || Z_TYPE_PP(entry) == IS_OBJECT) {
+ if (Z_TYPE_P(entry) == IS_ARRAY || Z_TYPE_P(entry) == IS_OBJECT) {
continue;
}
- entry_n = **entry;
- zval_copy_ctor(&entry_n);
+ ZVAL_DUP(&entry_n, entry);
convert_scalar_to_number(&entry_n TSRMLS_CC);
if (Z_TYPE(entry_n) == IS_LONG && Z_TYPE_P(return_value) == IS_LONG) {
@@ -4177,10 +4129,10 @@ PHP_FUNCTION(array_product)
PHP_FUNCTION(array_reduce)
{
zval *input;
- zval **args[2];
- zval **operand;
- zval *result = NULL;
- zval *retval;
+ zval args[2];
+ zval *operand;
+ zval result;
+ zval retval;
zend_fcall_info fci;
zend_fcall_info_cache fci_cache = empty_fcall_info_cache;
zval *initial = NULL;
@@ -4191,12 +4143,11 @@ PHP_FUNCTION(array_reduce)
return;
}
+
if (ZEND_NUM_ARGS() > 2) {
- ALLOC_ZVAL(result);
- MAKE_COPY_ZVAL(&initial, result);
+ ZVAL_DUP(&result, initial);
} else {
- MAKE_STD_ZVAL(result);
- ZVAL_NULL(result);
+ ZVAL_NULL(&result);
}
/* (zval **)input points to an element of argument stack
@@ -4205,38 +4156,29 @@ PHP_FUNCTION(array_reduce)
htbl = Z_ARRVAL_P(input);
if (zend_hash_num_elements(htbl) == 0) {
- if (result) {
- RETVAL_ZVAL(result, 1, 1);
- }
- return;
+ RETURN_ZVAL(&result, 1, 1);
}
- fci.retval_ptr_ptr = &retval;
+ fci.retval = &retval;
fci.param_count = 2;
fci.no_separation = 0;
zend_hash_internal_pointer_reset_ex(htbl, &pos);
- while (zend_hash_get_current_data_ex(htbl, (void **)&operand, &pos) == SUCCESS) {
-
- if (result) {
- args[0] = &result;
- args[1] = operand;
- fci.params = args;
-
- if (zend_call_function(&fci, &fci_cache TSRMLS_CC) == SUCCESS && retval) {
- zval_ptr_dtor(&result);
- result = retval;
- } else {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "An error occurred while invoking the reduction callback");
- return;
- }
+ while ((operand = zend_hash_get_current_data_ex(htbl, &pos)) != NULL) {
+ ZVAL_COPY_VALUE(&args[0], &result);
+ ZVAL_COPY_VALUE(&args[1], operand);
+ fci.params = args;
+
+ if (zend_call_function(&fci, &fci_cache TSRMLS_CC) == SUCCESS && Z_TYPE(retval) != IS_UNDEF) {
+ zval_ptr_dtor(&result);
+ ZVAL_COPY_VALUE(&result, &retval);
} else {
- result = *operand;
- zval_add_ref(&result);
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "An error occurred while invoking the reduction callback");
+ return;
}
zend_hash_move_forward_ex(htbl, &pos);
}
- RETVAL_ZVAL(result, 1, 1);
+ RETVAL_ZVAL(&result, 1, 1);
}
/* }}} */
@@ -4245,16 +4187,15 @@ PHP_FUNCTION(array_reduce)
PHP_FUNCTION(array_filter)
{
zval *array;
- zval **operand;
- zval **args[2];
- zval *retval = NULL;
- zval *key = NULL;
+ zval *operand;
+ zval args[2];
+ zval retval;
+//??? zval *key = NULL;
zend_bool have_callback = 0;
long use_type = 0;
- char *string_key;
+ zend_string *string_key;
zend_fcall_info fci = empty_fcall_info;
zend_fcall_info_cache fci_cache = empty_fcall_info_cache;
- uint string_key_len;
ulong num_key;
HashPosition pos;
@@ -4270,52 +4211,50 @@ PHP_FUNCTION(array_filter)
if (ZEND_NUM_ARGS() > 1) {
have_callback = 1;
fci.no_separation = 0;
- fci.retval_ptr_ptr = &retval;
+ fci.retval = &retval;
if (use_type == ARRAY_FILTER_USE_BOTH) {
fci.param_count = 2;
- args[1] = &key;
+//??? args[1] = &key;
} else {
fci.param_count = 1;
if (use_type == ARRAY_FILTER_USE_KEY) {
- args[0] = &key;
+//??? args[0] = &key;
}
}
}
for (zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(array), &pos);
- zend_hash_get_current_data_ex(Z_ARRVAL_P(array), (void **)&operand, &pos) == SUCCESS;
+ (operand = zend_hash_get_current_data_ex(Z_ARRVAL_P(array), &pos)) != NULL;
zend_hash_move_forward_ex(Z_ARRVAL_P(array), &pos)
) {
- int key_type = zend_hash_get_current_key_ex(Z_ARRVAL_P(array), &string_key, &string_key_len, &num_key, 0, &pos);
+ int key_type = zend_hash_get_current_key_ex(Z_ARRVAL_P(array), &string_key, &num_key, 0, &pos);
if (have_callback) {
if (use_type) {
- MAKE_STD_ZVAL(key);
/* Set up the key */
switch (key_type) {
case HASH_KEY_IS_LONG:
- Z_TYPE_P(key) = IS_LONG;
- Z_LVAL_P(key) = num_key;
+ ZVAL_LONG(&args[0], num_key);
break;
case HASH_KEY_IS_STRING:
- ZVAL_STRINGL(key, string_key, string_key_len - 1, 1);
+ ZVAL_STR(&args[0], STR_COPY(string_key));
break;
}
}
if (use_type != ARRAY_FILTER_USE_KEY) {
- args[0] = operand;
+ ZVAL_COPY_VALUE(&args[0], operand);
}
fci.params = args;
- if (zend_call_function(&fci, &fci_cache TSRMLS_CC) == SUCCESS && retval) {
- int retval_true = zend_is_true(retval TSRMLS_CC);
+ if (zend_call_function(&fci, &fci_cache TSRMLS_CC) == SUCCESS && Z_TYPE(retval) != IS_UNDEF) {
+ int retval_true = zend_is_true(&retval TSRMLS_CC);
zval_ptr_dtor(&retval);
if (use_type) {
- zval_ptr_dtor(&key);
+ zval_ptr_dtor(&args[0]);
}
if (!retval_true) {
continue;
@@ -4324,18 +4263,18 @@ PHP_FUNCTION(array_filter)
php_error_docref(NULL TSRMLS_CC, E_WARNING, "An error occurred while invoking the filter callback");
return;
}
- } else if (!zend_is_true(*operand TSRMLS_CC)) {
+ } else if (!zend_is_true(operand TSRMLS_CC)) {
continue;
}
zval_add_ref(operand);
switch (key_type) {
case HASH_KEY_IS_STRING:
- zend_hash_update(Z_ARRVAL_P(return_value), string_key, string_key_len, operand, sizeof(zval *), NULL);
+ zend_hash_update(Z_ARRVAL_P(return_value), string_key, operand);
break;
case HASH_KEY_IS_LONG:
- zend_hash_index_update(Z_ARRVAL_P(return_value), num_key, operand, sizeof(zval *), NULL);
+ zend_hash_index_update(Z_ARRVAL_P(return_value), num_key, operand);
break;
}
}
@@ -4346,10 +4285,10 @@ PHP_FUNCTION(array_filter)
Applies the callback to the elements in given arrays. */
PHP_FUNCTION(array_map)
{
- zval ***arrays = NULL;
+ zval *arrays = NULL;
int n_arrays = 0;
- zval ***params;
- zval *result, *null;
+ zval *params;
+ zval result;
HashPosition *array_pos;
zval **args;
zend_fcall_info fci = empty_fcall_info;
@@ -4368,7 +4307,7 @@ PHP_FUNCTION(array_map)
array_pos = (HashPosition *)safe_emalloc(n_arrays, sizeof(HashPosition), 0);
for (i = 0; i < n_arrays; i++) {
- if (Z_TYPE_PP(arrays[i]) != IS_ARRAY) {
+ if (Z_TYPE(arrays[i]) != IS_ARRAY) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Argument #%d should be an array", i + 2);
efree(arrays);
efree(args);
@@ -4376,13 +4315,13 @@ PHP_FUNCTION(array_map)
efree(array_pos);
return;
}
- SEPARATE_ZVAL_IF_NOT_REF(arrays[i]);
- args[i] = *arrays[i];
- array_len[i] = zend_hash_num_elements(Z_ARRVAL_PP(arrays[i]));
+ SEPARATE_ZVAL_IF_NOT_REF(&arrays[i]);
+ args[i] = &arrays[i];
+ array_len[i] = zend_hash_num_elements(Z_ARRVAL(arrays[i]));
if (array_len[i] > maxlen) {
maxlen = array_len[i];
}
- zend_hash_internal_pointer_reset_ex(Z_ARRVAL_PP(arrays[i]), &array_pos[i]);
+ zend_hash_internal_pointer_reset_ex(Z_ARRVAL(arrays[i]), &array_pos[i]);
}
efree(arrays);
@@ -4397,76 +4336,73 @@ PHP_FUNCTION(array_map)
}
array_init_size(return_value, maxlen);
- params = (zval ***)safe_emalloc(n_arrays, sizeof(zval **), 0);
- MAKE_STD_ZVAL(null);
- ZVAL_NULL(null);
+ params = (zval *)safe_emalloc(n_arrays, sizeof(zval), 0);
/* We iterate through all the arrays at once. */
for (k = 0; k < maxlen; k++) {
- uint str_key_len;
ulong num_key;
- char *str_key;
+ zend_string *str_key;
int key_type = 0;
/* If no callback, the result will be an array, consisting of current
* entries from all arrays. */
if (!ZEND_FCI_INITIALIZED(fci)) {
- MAKE_STD_ZVAL(result);
- array_init_size(result, n_arrays);
+ array_init_size(&result, n_arrays);
}
for (i = 0; i < n_arrays; i++) {
/* If this array still has elements, add the current one to the
* parameter list, otherwise use null value. */
if (k < array_len[i]) {
- zend_hash_get_current_data_ex(Z_ARRVAL_P(args[i]), (void **)&params[i], &array_pos[i]);
+ zval *zv = zend_hash_get_current_data_ex(Z_ARRVAL_P(args[i]), &array_pos[i]);
+
+ ZVAL_COPY_VALUE(&params[i], zv);
/* It is safe to store only last value of key type, because
* this loop will run just once if there is only 1 array. */
if (n_arrays == 1) {
- key_type = zend_hash_get_current_key_ex(Z_ARRVAL_P(args[0]), &str_key, &str_key_len, &num_key, 0, &array_pos[i]);
+ key_type = zend_hash_get_current_key_ex(Z_ARRVAL_P(args[0]), &str_key, &num_key, 0, &array_pos[i]);
}
zend_hash_move_forward_ex(Z_ARRVAL_P(args[i]), &array_pos[i]);
} else {
- params[i] = &null;
+ ZVAL_NULL(&params[i]);
}
if (!ZEND_FCI_INITIALIZED(fci)) {
- zval_add_ref(params[i]);
- add_next_index_zval(result, *params[i]);
+ zval_add_ref(&params[i]);
+ add_next_index_zval(&result, &params[i]);
}
}
if (ZEND_FCI_INITIALIZED(fci)) {
- fci.retval_ptr_ptr = &result;
+ fci.retval = &result;
fci.param_count = n_arrays;
fci.params = params;
fci.no_separation = 0;
- if (zend_call_function(&fci, &fci_cache TSRMLS_CC) != SUCCESS || !result) {
+ if (zend_call_function(&fci, &fci_cache TSRMLS_CC) != SUCCESS || Z_TYPE(result) == IS_UNDEF) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "An error occurred while invoking the map callback");
efree(array_len);
efree(args);
efree(array_pos);
zval_dtor(return_value);
- zval_ptr_dtor(&null);
efree(params);
RETURN_NULL();
}
}
if (n_arrays > 1) {
- add_next_index_zval(return_value, result);
+ add_next_index_zval(return_value, &result);
} else {
if (key_type == HASH_KEY_IS_STRING) {
- add_assoc_zval_ex(return_value, str_key, str_key_len, result);
+//???
+ add_assoc_zval_ex(return_value, str_key->val, str_key->len, &result);
} else {
- add_index_zval(return_value, num_key, result);
+ add_index_zval(return_value, num_key, &result);
}
}
}
- zval_ptr_dtor(&null);
efree(params);
efree(array_len);
efree(array_pos);
@@ -4487,7 +4423,7 @@ PHP_FUNCTION(array_key_exists)
switch (Z_TYPE_P(key)) {
case IS_STRING:
- if (zend_symtable_exists(array, Z_STRVAL_P(key), Z_STRLEN_P(key) + 1)) {
+ if (zend_symtable_exists(array, Z_STR_P(key))) {
RETURN_TRUE;
}
RETURN_FALSE;
@@ -4497,7 +4433,7 @@ PHP_FUNCTION(array_key_exists)
}
RETURN_FALSE;
case IS_NULL:
- if (zend_hash_exists(array, "", 1)) {
+ if (zend_hash_exists(array, STR_EMPTY_ALLOC())) {
RETURN_TRUE;
}
RETURN_FALSE;
@@ -4515,13 +4451,12 @@ PHP_FUNCTION(array_chunk)
{
int argc = ZEND_NUM_ARGS(), key_type, num_in;
long size, current = 0;
- char *str_key;
- uint str_key_len;
+ zend_string *str_key;
ulong num_key;
zend_bool preserve_keys = 0;
zval *input = NULL;
- zval *chunk = NULL;
- zval **entry;
+ zval chunk;
+ zval *entry;
HashPosition pos;
if (zend_parse_parameters(argc TSRMLS_CC, "al|b", &input, &size, &preserve_keys) == FAILURE) {
@@ -4541,44 +4476,45 @@ PHP_FUNCTION(array_chunk)
array_init_size(return_value, ((num_in - 1) / size) + 1);
+ ZVAL_UNDEF(&chunk);
zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(input), &pos);
- while (zend_hash_get_current_data_ex(Z_ARRVAL_P(input), (void**)&entry, &pos) == SUCCESS) {
+ while ((entry = zend_hash_get_current_data_ex(Z_ARRVAL_P(input), &pos)) != NULL) {
/* If new chunk, create and initialize it. */
- if (!chunk) {
- MAKE_STD_ZVAL(chunk);
- array_init_size(chunk, size);
+ if (Z_TYPE(chunk) == IS_UNDEF) {
+ array_init_size(&chunk, size);
}
/* Add entry to the chunk, preserving keys if necessary. */
zval_add_ref(entry);
if (preserve_keys) {
- key_type = zend_hash_get_current_key_ex(Z_ARRVAL_P(input), &str_key, &str_key_len, &num_key, 0, &pos);
+ key_type = zend_hash_get_current_key_ex(Z_ARRVAL_P(input), &str_key, &num_key, 0, &pos);
switch (key_type) {
case HASH_KEY_IS_STRING:
- add_assoc_zval_ex(chunk, str_key, str_key_len, *entry);
+//???
+ add_assoc_zval_ex(&chunk, str_key->val, str_key->len, entry);
break;
default:
- add_index_zval(chunk, num_key, *entry);
+ add_index_zval(&chunk, num_key, entry);
break;
}
} else {
- add_next_index_zval(chunk, *entry);
+ add_next_index_zval(&chunk, entry);
}
/* If reached the chunk size, add it to the result array, and reset the
* pointer. */
if (!(++current % size)) {
- add_next_index_zval(return_value, chunk);
- chunk = NULL;
+ add_next_index_zval(return_value, &chunk);
+ ZVAL_UNDEF(&chunk);
}
zend_hash_move_forward_ex(Z_ARRVAL_P(input), &pos);
}
/* Add the final chunk if there is one. */
- if (chunk) {
- add_next_index_zval(return_value, chunk);
+ if (Z_TYPE(chunk) != IS_UNDEF) {
+ add_next_index_zval(return_value, &chunk);
}
}
/* }}} */
@@ -4589,7 +4525,7 @@ PHP_FUNCTION(array_combine)
{
zval *values, *keys;
HashPosition pos_values, pos_keys;
- zval **entry_keys, **entry_values;
+ zval *entry_keys, *entry_values;
int num_keys, num_values;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "aa", &keys, &values) == FAILURE) {
@@ -4612,26 +4548,26 @@ PHP_FUNCTION(array_combine)
zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(keys), &pos_keys);
zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(values), &pos_values);
- while (zend_hash_get_current_data_ex(Z_ARRVAL_P(keys), (void **)&entry_keys, &pos_keys) == SUCCESS &&
- zend_hash_get_current_data_ex(Z_ARRVAL_P(values), (void **)&entry_values, &pos_values) == SUCCESS
+ while ((entry_keys = zend_hash_get_current_data_ex(Z_ARRVAL_P(keys), &pos_keys)) != NULL &&
+ (entry_values = zend_hash_get_current_data_ex(Z_ARRVAL_P(values), &pos_values)) != NULL
) {
- if (Z_TYPE_PP(entry_keys) == IS_LONG) {
+ if (Z_TYPE_P(entry_keys) == IS_LONG) {
zval_add_ref(entry_values);
- add_index_zval(return_value, Z_LVAL_PP(entry_keys), *entry_values);
+ add_index_zval(return_value, Z_LVAL_P(entry_keys), entry_values);
} else {
- zval key, *key_ptr = *entry_keys;
+ zval key, *key_ptr = entry_keys;
- if (Z_TYPE_PP(entry_keys) != IS_STRING) {
- key = **entry_keys;
- zval_copy_ctor(&key);
+ if (Z_TYPE_P(entry_keys) != IS_STRING) {
+ ZVAL_DUP(&key, entry_keys);
convert_to_string(&key);
key_ptr = &key;
}
zval_add_ref(entry_values);
- add_assoc_zval_ex(return_value, Z_STRVAL_P(key_ptr), Z_STRLEN_P(key_ptr) + 1, *entry_values);
+//???
+ add_assoc_zval_ex(return_value, Z_STRVAL_P(key_ptr), Z_STRLEN_P(key_ptr), entry_values);
- if (key_ptr != *entry_keys) {
+ if (key_ptr != entry_keys) {
zval_dtor(&key);
}
}