mirror of
https://github.com/php/php-src.git
synced 2024-11-27 03:44:07 +08:00
Use ZEND_FETCH_FOREACH_* macros to iterate over HashTables instead of zend_hash_move_forward() and family.
This commit is contained in:
parent
ea2e1bb1eb
commit
7652a977a8
69
Zend/zend.c
69
Zend/zend.c
@ -142,12 +142,10 @@ static void print_hash(zend_write_func_t write_func, HashTable *ht, int indent,
|
|||||||
}
|
}
|
||||||
ZEND_PUTS_EX("(\n");
|
ZEND_PUTS_EX("(\n");
|
||||||
indent += PRINT_ZVAL_INDENT;
|
indent += PRINT_ZVAL_INDENT;
|
||||||
zend_hash_internal_pointer_reset_ex(ht, &iterator);
|
ZEND_HASH_FOREACH_KEY_VAL(ht, num_key, string_key, tmp) {
|
||||||
while ((tmp = zend_hash_get_current_data_ex(ht, &iterator)) != NULL) {
|
|
||||||
if (Z_TYPE_P(tmp) == IS_INDIRECT) {
|
if (Z_TYPE_P(tmp) == IS_INDIRECT) {
|
||||||
tmp = Z_INDIRECT_P(tmp);
|
tmp = Z_INDIRECT_P(tmp);
|
||||||
if (Z_TYPE_P(tmp) == IS_UNDEF) {
|
if (Z_TYPE_P(tmp) == IS_UNDEF) {
|
||||||
zend_hash_move_forward_ex(ht, &iterator);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -155,40 +153,34 @@ static void print_hash(zend_write_func_t write_func, HashTable *ht, int indent,
|
|||||||
ZEND_PUTS_EX(" ");
|
ZEND_PUTS_EX(" ");
|
||||||
}
|
}
|
||||||
ZEND_PUTS_EX("[");
|
ZEND_PUTS_EX("[");
|
||||||
switch (zend_hash_get_current_key_ex(ht, &string_key, &num_key, 0, &iterator)) {
|
if (string_key) {
|
||||||
case HASH_KEY_IS_STRING:
|
if (is_object) {
|
||||||
if (is_object) {
|
const char *prop_name, *class_name;
|
||||||
const char *prop_name, *class_name;
|
int prop_len;
|
||||||
int prop_len;
|
int mangled = zend_unmangle_property_name_ex(string_key->val, string_key->len, &class_name, &prop_name, &prop_len);
|
||||||
int mangled = zend_unmangle_property_name_ex(string_key->val, string_key->len, &class_name, &prop_name, &prop_len);
|
|
||||||
|
|
||||||
ZEND_WRITE_EX(prop_name, prop_len);
|
ZEND_WRITE_EX(prop_name, prop_len);
|
||||||
if (class_name && mangled == SUCCESS) {
|
if (class_name && mangled == SUCCESS) {
|
||||||
if (class_name[0]=='*') {
|
if (class_name[0]=='*') {
|
||||||
ZEND_PUTS_EX(":protected");
|
ZEND_PUTS_EX(":protected");
|
||||||
} else {
|
} else {
|
||||||
ZEND_PUTS_EX(":");
|
ZEND_PUTS_EX(":");
|
||||||
ZEND_PUTS_EX(class_name);
|
ZEND_PUTS_EX(class_name);
|
||||||
ZEND_PUTS_EX(":private");
|
ZEND_PUTS_EX(":private");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
ZEND_WRITE_EX(string_key->val, string_key->len);
|
|
||||||
}
|
}
|
||||||
break;
|
} else {
|
||||||
case HASH_KEY_IS_LONG:
|
ZEND_WRITE_EX(string_key->val, string_key->len);
|
||||||
{
|
}
|
||||||
char key[25];
|
} else {
|
||||||
snprintf(key, sizeof(key), "%ld", num_key);
|
char key[25];
|
||||||
ZEND_PUTS_EX(key);
|
snprintf(key, sizeof(key), "%ld", num_key);
|
||||||
}
|
ZEND_PUTS_EX(key);
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
ZEND_PUTS_EX("] => ");
|
ZEND_PUTS_EX("] => ");
|
||||||
zend_print_zval_r_ex(write_func, tmp, indent+PRINT_ZVAL_INDENT TSRMLS_CC);
|
zend_print_zval_r_ex(write_func, tmp, indent+PRINT_ZVAL_INDENT TSRMLS_CC);
|
||||||
ZEND_PUTS_EX("\n");
|
ZEND_PUTS_EX("\n");
|
||||||
zend_hash_move_forward_ex(ht, &iterator);
|
} ZEND_HASH_FOREACH_END();
|
||||||
}
|
|
||||||
indent -= PRINT_ZVAL_INDENT;
|
indent -= PRINT_ZVAL_INDENT;
|
||||||
for (i = 0; i < indent; i++) {
|
for (i = 0; i < indent; i++) {
|
||||||
ZEND_PUTS_EX(" ");
|
ZEND_PUTS_EX(" ");
|
||||||
@ -205,24 +197,19 @@ static void print_flat_hash(HashTable *ht TSRMLS_DC) /* {{{ */
|
|||||||
ulong num_key;
|
ulong num_key;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
zend_hash_internal_pointer_reset_ex(ht, &iterator);
|
ZEND_HASH_FOREACH_KEY_VAL(ht, num_key, string_key, tmp) {
|
||||||
while ((tmp = zend_hash_get_current_data_ex(ht, &iterator)) != NULL) {
|
|
||||||
if (i++ > 0) {
|
if (i++ > 0) {
|
||||||
ZEND_PUTS(",");
|
ZEND_PUTS(",");
|
||||||
}
|
}
|
||||||
ZEND_PUTS("[");
|
ZEND_PUTS("[");
|
||||||
switch (zend_hash_get_current_key_ex(ht, &string_key, &num_key, 0, &iterator)) {
|
if (string_key) {
|
||||||
case HASH_KEY_IS_STRING:
|
ZEND_WRITE(string_key->val, string_key->len);
|
||||||
ZEND_WRITE(string_key->val, string_key->len);
|
} else {
|
||||||
break;
|
zend_printf("%ld", num_key);
|
||||||
case HASH_KEY_IS_LONG:
|
|
||||||
zend_printf("%ld", num_key);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
ZEND_PUTS("] => ");
|
ZEND_PUTS("] => ");
|
||||||
zend_print_flat_zval_r(tmp TSRMLS_CC);
|
zend_print_flat_zval_r(tmp TSRMLS_CC);
|
||||||
zend_hash_move_forward_ex(ht, &iterator);
|
} ZEND_HASH_FOREACH_END();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
|
@ -1119,13 +1119,10 @@ static int zval_update_class_constant(zval *pp, int is_static, int offset TSRMLS
|
|||||||
|
|
||||||
if ((*scope)->parent) {
|
if ((*scope)->parent) {
|
||||||
zend_class_entry *ce = *scope;
|
zend_class_entry *ce = *scope;
|
||||||
HashPosition pos;
|
|
||||||
zend_property_info *prop_info;
|
zend_property_info *prop_info;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
for (zend_hash_internal_pointer_reset_ex(&ce->properties_info, &pos);
|
ZEND_HASH_FOREACH_PTR(&ce->properties_info, prop_info) {
|
||||||
(prop_info = zend_hash_get_current_data_ptr_ex(&ce->properties_info, &pos)) != NULL;
|
|
||||||
zend_hash_move_forward_ex(&ce->properties_info, &pos)) {
|
|
||||||
if (is_static == ((prop_info->flags & ZEND_ACC_STATIC) != 0) &&
|
if (is_static == ((prop_info->flags & ZEND_ACC_STATIC) != 0) &&
|
||||||
offset == prop_info->offset) {
|
offset == prop_info->offset) {
|
||||||
int ret;
|
int ret;
|
||||||
@ -1135,7 +1132,7 @@ static int zval_update_class_constant(zval *pp, int is_static, int offset TSRMLS
|
|||||||
*scope = old_scope;
|
*scope = old_scope;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
} ZEND_HASH_FOREACH_END();
|
||||||
ce = ce->parent;
|
ce = ce->parent;
|
||||||
} while (ce);
|
} while (ce);
|
||||||
|
|
||||||
@ -1223,17 +1220,12 @@ ZEND_API void object_properties_init_ex(zend_object *object, HashTable *properti
|
|||||||
{
|
{
|
||||||
object->properties = properties;
|
object->properties = properties;
|
||||||
if (object->ce->default_properties_count) {
|
if (object->ce->default_properties_count) {
|
||||||
HashPosition pos;
|
|
||||||
zval *prop, tmp;
|
zval *prop, tmp;
|
||||||
zend_string *key;
|
zend_string *key;
|
||||||
ulong num_key;
|
ulong num_key;
|
||||||
zend_property_info *property_info;
|
zend_property_info *property_info;
|
||||||
|
|
||||||
for (zend_hash_internal_pointer_reset_ex(properties, &pos);
|
ZEND_HASH_FOREACH_KEY_VAL(properties, num_key, key, prop) {
|
||||||
(prop = zend_hash_get_current_data_ex(properties, &pos)) != NULL &&
|
|
||||||
zend_hash_get_current_key_ex(properties, &key, &num_key, 0, &pos) == HASH_KEY_IS_STRING;
|
|
||||||
zend_hash_move_forward_ex(properties, &pos)) {
|
|
||||||
|
|
||||||
ZVAL_STR(&tmp, key);
|
ZVAL_STR(&tmp, key);
|
||||||
property_info = zend_get_property_info(object->ce, &tmp, 1 TSRMLS_CC);
|
property_info = zend_get_property_info(object->ce, &tmp, 1 TSRMLS_CC);
|
||||||
if (property_info &&
|
if (property_info &&
|
||||||
@ -1242,24 +1234,19 @@ ZEND_API void object_properties_init_ex(zend_object *object, HashTable *properti
|
|||||||
ZVAL_COPY_VALUE(&object->properties_table[property_info->offset], prop);
|
ZVAL_COPY_VALUE(&object->properties_table[property_info->offset], prop);
|
||||||
ZVAL_INDIRECT(prop, &object->properties_table[property_info->offset]);
|
ZVAL_INDIRECT(prop, &object->properties_table[property_info->offset]);
|
||||||
}
|
}
|
||||||
}
|
} ZEND_HASH_FOREACH_END();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
ZEND_API void object_properties_load(zend_object *object, HashTable *properties TSRMLS_DC) /* {{{ */
|
ZEND_API void object_properties_load(zend_object *object, HashTable *properties TSRMLS_DC) /* {{{ */
|
||||||
{
|
{
|
||||||
HashPosition pos;
|
|
||||||
zval *prop, tmp;
|
zval *prop, tmp;
|
||||||
zend_string *key;
|
zend_string *key;
|
||||||
ulong num_key;
|
ulong num_key;
|
||||||
zend_property_info *property_info;
|
zend_property_info *property_info;
|
||||||
|
|
||||||
for (zend_hash_internal_pointer_reset_ex(properties, &pos);
|
ZEND_HASH_FOREACH_KEY_VAL(properties, num_key, key, prop) {
|
||||||
(prop = zend_hash_get_current_data_ex(properties, &pos)) != NULL &&
|
|
||||||
zend_hash_get_current_key_ex(properties, &key, &num_key, 0, &pos) == HASH_KEY_IS_STRING;
|
|
||||||
zend_hash_move_forward_ex(properties, &pos)) {
|
|
||||||
|
|
||||||
ZVAL_STR(&tmp, key);
|
ZVAL_STR(&tmp, key);
|
||||||
property_info = zend_get_property_info(object->ce, &tmp, 1 TSRMLS_CC);
|
property_info = zend_get_property_info(object->ce, &tmp, 1 TSRMLS_CC);
|
||||||
if (property_info &&
|
if (property_info &&
|
||||||
@ -1279,7 +1266,7 @@ ZEND_API void object_properties_load(zend_object *object, HashTable *properties
|
|||||||
prop = zend_hash_update(object->properties, key, prop);
|
prop = zend_hash_update(object->properties, key, prop);
|
||||||
zval_add_ref(prop);
|
zval_add_ref(prop);
|
||||||
}
|
}
|
||||||
}
|
} ZEND_HASH_FOREACH_END();
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
@ -1892,7 +1879,6 @@ try_again:
|
|||||||
|
|
||||||
ZEND_API void zend_collect_module_handlers(TSRMLS_D) /* {{{ */
|
ZEND_API void zend_collect_module_handlers(TSRMLS_D) /* {{{ */
|
||||||
{
|
{
|
||||||
HashPosition pos;
|
|
||||||
zend_module_entry *module;
|
zend_module_entry *module;
|
||||||
int startup_count = 0;
|
int startup_count = 0;
|
||||||
int shutdown_count = 0;
|
int shutdown_count = 0;
|
||||||
@ -1901,9 +1887,7 @@ ZEND_API void zend_collect_module_handlers(TSRMLS_D) /* {{{ */
|
|||||||
int class_count = 0;
|
int class_count = 0;
|
||||||
|
|
||||||
/* Collect extensions with request startup/shutdown handlers */
|
/* Collect extensions with request startup/shutdown handlers */
|
||||||
for (zend_hash_internal_pointer_reset_ex(&module_registry, &pos);
|
ZEND_HASH_FOREACH_PTR(&module_registry, module) {
|
||||||
(module = zend_hash_get_current_data_ptr_ex(&module_registry, &pos)) != NULL;
|
|
||||||
zend_hash_move_forward_ex(&module_registry, &pos)) {
|
|
||||||
if (module->request_startup_func) {
|
if (module->request_startup_func) {
|
||||||
startup_count++;
|
startup_count++;
|
||||||
}
|
}
|
||||||
@ -1913,7 +1897,7 @@ ZEND_API void zend_collect_module_handlers(TSRMLS_D) /* {{{ */
|
|||||||
if (module->post_deactivate_func) {
|
if (module->post_deactivate_func) {
|
||||||
post_deactivate_count++;
|
post_deactivate_count++;
|
||||||
}
|
}
|
||||||
}
|
} ZEND_HASH_FOREACH_END();
|
||||||
module_request_startup_handlers = (zend_module_entry**)malloc(
|
module_request_startup_handlers = (zend_module_entry**)malloc(
|
||||||
sizeof(zend_module_entry*) *
|
sizeof(zend_module_entry*) *
|
||||||
(startup_count + 1 +
|
(startup_count + 1 +
|
||||||
@ -1926,9 +1910,7 @@ ZEND_API void zend_collect_module_handlers(TSRMLS_D) /* {{{ */
|
|||||||
module_post_deactivate_handlers[post_deactivate_count] = NULL;
|
module_post_deactivate_handlers[post_deactivate_count] = NULL;
|
||||||
startup_count = 0;
|
startup_count = 0;
|
||||||
|
|
||||||
for (zend_hash_internal_pointer_reset_ex(&module_registry, &pos);
|
ZEND_HASH_FOREACH_PTR(&module_registry, module) {
|
||||||
(module = zend_hash_get_current_data_ptr_ex(&module_registry, &pos)) != NULL;
|
|
||||||
zend_hash_move_forward_ex(&module_registry, &pos)) {
|
|
||||||
if (module->request_startup_func) {
|
if (module->request_startup_func) {
|
||||||
module_request_startup_handlers[startup_count++] = module;
|
module_request_startup_handlers[startup_count++] = module;
|
||||||
}
|
}
|
||||||
@ -1938,17 +1920,15 @@ ZEND_API void zend_collect_module_handlers(TSRMLS_D) /* {{{ */
|
|||||||
if (module->post_deactivate_func) {
|
if (module->post_deactivate_func) {
|
||||||
module_post_deactivate_handlers[--post_deactivate_count] = module;
|
module_post_deactivate_handlers[--post_deactivate_count] = module;
|
||||||
}
|
}
|
||||||
}
|
} ZEND_HASH_FOREACH_END();
|
||||||
|
|
||||||
/* Collect internal classes with static members */
|
/* Collect internal classes with static members */
|
||||||
for (zend_hash_internal_pointer_reset_ex(CG(class_table), &pos);
|
ZEND_HASH_FOREACH_PTR(CG(class_table), ce) {
|
||||||
(ce = zend_hash_get_current_data_ptr_ex(CG(class_table), &pos)) != NULL;
|
|
||||||
zend_hash_move_forward_ex(CG(class_table), &pos)) {
|
|
||||||
if (ce->type == ZEND_INTERNAL_CLASS &&
|
if (ce->type == ZEND_INTERNAL_CLASS &&
|
||||||
ce->default_static_members_count > 0) {
|
ce->default_static_members_count > 0) {
|
||||||
class_count++;
|
class_count++;
|
||||||
}
|
}
|
||||||
}
|
} ZEND_HASH_FOREACH_END();
|
||||||
|
|
||||||
class_cleanup_handlers = (zend_class_entry**)malloc(
|
class_cleanup_handlers = (zend_class_entry**)malloc(
|
||||||
sizeof(zend_class_entry*) *
|
sizeof(zend_class_entry*) *
|
||||||
@ -1956,14 +1936,12 @@ ZEND_API void zend_collect_module_handlers(TSRMLS_D) /* {{{ */
|
|||||||
class_cleanup_handlers[class_count] = NULL;
|
class_cleanup_handlers[class_count] = NULL;
|
||||||
|
|
||||||
if (class_count) {
|
if (class_count) {
|
||||||
for (zend_hash_internal_pointer_reset_ex(CG(class_table), &pos);
|
ZEND_HASH_FOREACH_PTR(CG(class_table), ce) {
|
||||||
(ce = zend_hash_get_current_data_ptr_ex(CG(class_table), &pos)) != NULL;
|
|
||||||
zend_hash_move_forward_ex(CG(class_table), &pos)) {
|
|
||||||
if (ce->type == ZEND_INTERNAL_CLASS &&
|
if (ce->type == ZEND_INTERNAL_CLASS &&
|
||||||
ce->default_static_members_count > 0) {
|
ce->default_static_members_count > 0) {
|
||||||
class_cleanup_handlers[--class_count] = ce;
|
class_cleanup_handlers[--class_count] = ce;
|
||||||
}
|
}
|
||||||
}
|
} ZEND_HASH_FOREACH_END();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
@ -3407,7 +3385,6 @@ ZEND_API void zend_fcall_info_args_restore(zend_fcall_info *fci, int param_count
|
|||||||
|
|
||||||
ZEND_API int zend_fcall_info_args(zend_fcall_info *fci, zval *args TSRMLS_DC) /* {{{ */
|
ZEND_API int zend_fcall_info_args(zend_fcall_info *fci, zval *args TSRMLS_DC) /* {{{ */
|
||||||
{
|
{
|
||||||
HashPosition pos;
|
|
||||||
zval *arg, *params;
|
zval *arg, *params;
|
||||||
|
|
||||||
zend_fcall_info_args_clear(fci, !args);
|
zend_fcall_info_args_clear(fci, !args);
|
||||||
@ -3423,12 +3400,10 @@ ZEND_API int zend_fcall_info_args(zend_fcall_info *fci, zval *args TSRMLS_DC) /*
|
|||||||
fci->param_count = zend_hash_num_elements(Z_ARRVAL_P(args));
|
fci->param_count = zend_hash_num_elements(Z_ARRVAL_P(args));
|
||||||
fci->params = params = (zval *) erealloc(fci->params, fci->param_count * sizeof(zval));
|
fci->params = params = (zval *) erealloc(fci->params, fci->param_count * sizeof(zval));
|
||||||
|
|
||||||
zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(args), &pos);
|
ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(args), arg) {
|
||||||
while ((arg = zend_hash_get_current_data_ex(Z_ARRVAL_P(args), &pos)) != NULL) {
|
|
||||||
ZVAL_COPY(params, arg);
|
ZVAL_COPY(params, arg);
|
||||||
params++;
|
params++;
|
||||||
zend_hash_move_forward_ex(Z_ARRVAL_P(args), &pos);
|
} ZEND_HASH_FOREACH_END();
|
||||||
}
|
|
||||||
|
|
||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
@ -4026,6 +4001,8 @@ ZEND_API zend_string *zend_resolve_method_name(zend_class_entry *ce, zend_functi
|
|||||||
zend_function *func;
|
zend_function *func;
|
||||||
HashPosition iterator;
|
HashPosition iterator;
|
||||||
HashTable *function_table;
|
HashTable *function_table;
|
||||||
|
zend_string *name;
|
||||||
|
ulong idx;
|
||||||
|
|
||||||
if (f->common.type != ZEND_USER_FUNCTION ||
|
if (f->common.type != ZEND_USER_FUNCTION ||
|
||||||
*(f->op_array.refcount) < 2 ||
|
*(f->op_array.refcount) < 2 ||
|
||||||
@ -4035,13 +4012,9 @@ ZEND_API zend_string *zend_resolve_method_name(zend_class_entry *ce, zend_functi
|
|||||||
}
|
}
|
||||||
|
|
||||||
function_table = &ce->function_table;
|
function_table = &ce->function_table;
|
||||||
zend_hash_internal_pointer_reset_ex(function_table, &iterator);
|
ZEND_HASH_FOREACH_KEY_PTR(function_table, idx, name, func) {
|
||||||
while ((func = zend_hash_get_current_data_ptr_ex(function_table, &iterator)) != NULL) {
|
|
||||||
if (func == f) {
|
if (func == f) {
|
||||||
zend_string *name;
|
if (!name) {
|
||||||
ulong idx;
|
|
||||||
|
|
||||||
if (zend_hash_get_current_key_ex(function_table, &name, &idx, 0, &iterator) != HASH_KEY_IS_STRING) {
|
|
||||||
return f->common.function_name;
|
return f->common.function_name;
|
||||||
}
|
}
|
||||||
if (name->len == f->common.function_name->len &&
|
if (name->len == f->common.function_name->len &&
|
||||||
@ -4050,8 +4023,7 @@ ZEND_API zend_string *zend_resolve_method_name(zend_class_entry *ce, zend_functi
|
|||||||
}
|
}
|
||||||
return zend_find_alias_name(f->common.scope, name);
|
return zend_find_alias_name(f->common.scope, name);
|
||||||
}
|
}
|
||||||
zend_hash_move_forward_ex(function_table, &iterator);
|
} ZEND_HASH_FOREACH_END();
|
||||||
}
|
|
||||||
return f->common.function_name;
|
return f->common.function_name;
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
@ -903,16 +903,12 @@ ZEND_FUNCTION(is_a)
|
|||||||
/* {{{ add_class_vars */
|
/* {{{ add_class_vars */
|
||||||
static void add_class_vars(zend_class_entry *ce, int statics, zval *return_value TSRMLS_DC)
|
static void add_class_vars(zend_class_entry *ce, int statics, zval *return_value TSRMLS_DC)
|
||||||
{
|
{
|
||||||
HashPosition pos;
|
|
||||||
zend_property_info *prop_info;
|
zend_property_info *prop_info;
|
||||||
zval *prop, prop_copy;
|
zval *prop, prop_copy;
|
||||||
zend_string *key;
|
zend_string *key;
|
||||||
ulong num_index;
|
ulong num_index;
|
||||||
|
|
||||||
zend_hash_internal_pointer_reset_ex(&ce->properties_info, &pos);
|
ZEND_HASH_FOREACH_KEY_PTR(&ce->properties_info, num_index, key, prop_info) {
|
||||||
while ((prop_info = zend_hash_get_current_data_ptr_ex(&ce->properties_info, &pos)) != NULL) {
|
|
||||||
zend_hash_get_current_key_ex(&ce->properties_info, &key, &num_index, 0, &pos);
|
|
||||||
zend_hash_move_forward_ex(&ce->properties_info, &pos);
|
|
||||||
if (((prop_info->flags & ZEND_ACC_SHADOW) &&
|
if (((prop_info->flags & ZEND_ACC_SHADOW) &&
|
||||||
prop_info->ce != EG(scope)) ||
|
prop_info->ce != EG(scope)) ||
|
||||||
((prop_info->flags & ZEND_ACC_PROTECTED) &&
|
((prop_info->flags & ZEND_ACC_PROTECTED) &&
|
||||||
@ -944,7 +940,7 @@ static void add_class_vars(zend_class_entry *ce, int statics, zval *return_value
|
|||||||
}
|
}
|
||||||
|
|
||||||
zend_hash_update(Z_ARRVAL_P(return_value), key, &prop_copy);
|
zend_hash_update(Z_ARRVAL_P(return_value), key, &prop_copy);
|
||||||
}
|
} ZEND_HASH_FOREACH_END();
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
@ -980,7 +976,6 @@ ZEND_FUNCTION(get_object_vars)
|
|||||||
zval *obj;
|
zval *obj;
|
||||||
zval *value;
|
zval *value;
|
||||||
HashTable *properties;
|
HashTable *properties;
|
||||||
HashPosition pos;
|
|
||||||
zend_string *key;
|
zend_string *key;
|
||||||
const char *prop_name, *class_name;
|
const char *prop_name, *class_name;
|
||||||
uint prop_len;
|
uint prop_len;
|
||||||
@ -1005,17 +1000,8 @@ ZEND_FUNCTION(get_object_vars)
|
|||||||
|
|
||||||
array_init(return_value);
|
array_init(return_value);
|
||||||
|
|
||||||
zend_hash_internal_pointer_reset_ex(properties, &pos);
|
ZEND_HASH_FOREACH_KEY_VAL_IND(properties, num_index, key, value) {
|
||||||
|
if (key) {
|
||||||
while ((value = zend_hash_get_current_data_ex(properties, &pos)) != NULL) {
|
|
||||||
if (Z_TYPE_P(value) == IS_INDIRECT) {
|
|
||||||
value = Z_INDIRECT_P(value);
|
|
||||||
if (Z_TYPE_P(value) == IS_UNDEF) {
|
|
||||||
zend_hash_move_forward_ex(properties, &pos);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (zend_hash_get_current_key_ex(properties, &key, &num_index, 0, &pos) == HASH_KEY_IS_STRING) {
|
|
||||||
if (zend_check_property_access(zobj, key TSRMLS_CC) == SUCCESS) {
|
if (zend_check_property_access(zobj, key TSRMLS_CC) == SUCCESS) {
|
||||||
/* Not separating references */
|
/* Not separating references */
|
||||||
if (Z_REFCOUNTED_P(value)) Z_ADDREF_P(value);
|
if (Z_REFCOUNTED_P(value)) Z_ADDREF_P(value);
|
||||||
@ -1027,8 +1013,7 @@ ZEND_FUNCTION(get_object_vars)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
zend_hash_move_forward_ex(properties, &pos);
|
} ZEND_HASH_FOREACH_END();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
@ -1047,8 +1032,9 @@ ZEND_FUNCTION(get_class_methods)
|
|||||||
zval *klass;
|
zval *klass;
|
||||||
zval method_name;
|
zval method_name;
|
||||||
zend_class_entry *ce = NULL;
|
zend_class_entry *ce = NULL;
|
||||||
HashPosition pos;
|
|
||||||
zend_function *mptr;
|
zend_function *mptr;
|
||||||
|
zend_string *key;
|
||||||
|
ulong num_index;
|
||||||
|
|
||||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &klass) == FAILURE) {
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &klass) == FAILURE) {
|
||||||
return;
|
return;
|
||||||
@ -1069,21 +1055,19 @@ ZEND_FUNCTION(get_class_methods)
|
|||||||
}
|
}
|
||||||
|
|
||||||
array_init(return_value);
|
array_init(return_value);
|
||||||
zend_hash_internal_pointer_reset_ex(&ce->function_table, &pos);
|
|
||||||
|
|
||||||
while ((mptr = zend_hash_get_current_data_ptr_ex(&ce->function_table, &pos)) != NULL) {
|
ZEND_HASH_FOREACH_KEY_PTR(&ce->function_table, num_index, key, mptr) {
|
||||||
|
|
||||||
if ((mptr->common.fn_flags & ZEND_ACC_PUBLIC)
|
if ((mptr->common.fn_flags & ZEND_ACC_PUBLIC)
|
||||||
|| (EG(scope) &&
|
|| (EG(scope) &&
|
||||||
(((mptr->common.fn_flags & ZEND_ACC_PROTECTED) &&
|
(((mptr->common.fn_flags & ZEND_ACC_PROTECTED) &&
|
||||||
zend_check_protected(mptr->common.scope, EG(scope)))
|
zend_check_protected(mptr->common.scope, EG(scope)))
|
||||||
|| ((mptr->common.fn_flags & ZEND_ACC_PRIVATE) &&
|
|| ((mptr->common.fn_flags & ZEND_ACC_PRIVATE) &&
|
||||||
EG(scope) == mptr->common.scope)))) {
|
EG(scope) == mptr->common.scope)))) {
|
||||||
zend_string *key;
|
|
||||||
ulong num_index;
|
|
||||||
uint len = mptr->common.function_name->len;
|
uint len = mptr->common.function_name->len;
|
||||||
|
|
||||||
/* Do not display old-style inherited constructors */
|
/* Do not display old-style inherited constructors */
|
||||||
if (zend_hash_get_current_key_ex(&ce->function_table, &key, &num_index, 0, &pos) != HASH_KEY_IS_STRING) {
|
if (!key) {
|
||||||
// TODO: we have to duplicate it, becaise it may be stored in opcache SHM ???
|
// TODO: we have to duplicate it, becaise it may be stored in opcache SHM ???
|
||||||
ZVAL_STR(&method_name, STR_DUP(mptr->common.function_name, 0));
|
ZVAL_STR(&method_name, STR_DUP(mptr->common.function_name, 0));
|
||||||
zend_hash_next_index_insert(Z_ARRVAL_P(return_value), &method_name);
|
zend_hash_next_index_insert(Z_ARRVAL_P(return_value), &method_name);
|
||||||
@ -1104,8 +1088,7 @@ ZEND_FUNCTION(get_class_methods)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
zend_hash_move_forward_ex(&ce->function_table, &pos);
|
} ZEND_HASH_FOREACH_END();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
@ -1443,17 +1426,18 @@ ZEND_FUNCTION(crash)
|
|||||||
ZEND_FUNCTION(get_included_files)
|
ZEND_FUNCTION(get_included_files)
|
||||||
{
|
{
|
||||||
zend_string *entry;
|
zend_string *entry;
|
||||||
|
ulong num_idx;
|
||||||
|
|
||||||
if (zend_parse_parameters_none() == FAILURE) {
|
if (zend_parse_parameters_none() == FAILURE) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
array_init(return_value);
|
array_init(return_value);
|
||||||
zend_hash_internal_pointer_reset(&EG(included_files));
|
ZEND_HASH_FOREACH_KEY(&EG(included_files), num_idx, entry) {
|
||||||
while (zend_hash_get_current_key(&EG(included_files), &entry, NULL, 0) == HASH_KEY_IS_STRING) {
|
if (entry) {
|
||||||
add_next_index_str(return_value, STR_COPY(entry));
|
add_next_index_str(return_value, STR_COPY(entry));
|
||||||
zend_hash_move_forward(&EG(included_files));
|
}
|
||||||
}
|
} ZEND_HASH_FOREACH_END();
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
@ -1928,7 +1912,6 @@ ZEND_FUNCTION(get_defined_constants)
|
|||||||
array_init(return_value);
|
array_init(return_value);
|
||||||
|
|
||||||
if (categorize) {
|
if (categorize) {
|
||||||
HashPosition pos;
|
|
||||||
zend_constant *val;
|
zend_constant *val;
|
||||||
int module_number;
|
int module_number;
|
||||||
zval *modules;
|
zval *modules;
|
||||||
@ -1940,28 +1923,25 @@ ZEND_FUNCTION(get_defined_constants)
|
|||||||
module_names = emalloc((zend_hash_num_elements(&module_registry) + 2) * sizeof(char *));
|
module_names = emalloc((zend_hash_num_elements(&module_registry) + 2) * sizeof(char *));
|
||||||
|
|
||||||
module_names[0] = "internal";
|
module_names[0] = "internal";
|
||||||
zend_hash_internal_pointer_reset_ex(&module_registry, &pos);
|
ZEND_HASH_FOREACH_PTR(&module_registry, module) {
|
||||||
while ((module = zend_hash_get_current_data_ptr_ex(&module_registry, &pos)) != NULL) {
|
|
||||||
module_names[module->module_number] = (char *)module->name;
|
module_names[module->module_number] = (char *)module->name;
|
||||||
i++;
|
i++;
|
||||||
zend_hash_move_forward_ex(&module_registry, &pos);
|
} ZEND_HASH_FOREACH_END();
|
||||||
}
|
|
||||||
module_names[i] = "user";
|
module_names[i] = "user";
|
||||||
|
|
||||||
zend_hash_internal_pointer_reset_ex(EG(zend_constants), &pos);
|
ZEND_HASH_FOREACH_PTR(EG(zend_constants), val) {
|
||||||
while ((val = zend_hash_get_current_data_ptr_ex(EG(zend_constants), &pos)) != NULL) {
|
|
||||||
zval const_val;
|
zval const_val;
|
||||||
|
|
||||||
if (!val->name) {
|
if (!val->name) {
|
||||||
/* skip special constants */
|
/* skip special constants */
|
||||||
goto next_constant;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (val->module_number == PHP_USER_CONSTANT) {
|
if (val->module_number == PHP_USER_CONSTANT) {
|
||||||
module_number = i;
|
module_number = i;
|
||||||
} else if (val->module_number > i || val->module_number < 0) {
|
} else if (val->module_number > i || val->module_number < 0) {
|
||||||
/* should not happen */
|
/* should not happen */
|
||||||
goto next_constant;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
module_number = val->module_number;
|
module_number = val->module_number;
|
||||||
}
|
}
|
||||||
@ -1974,9 +1954,8 @@ ZEND_FUNCTION(get_defined_constants)
|
|||||||
ZVAL_DUP_DEREF(&const_val, &val->value);
|
ZVAL_DUP_DEREF(&const_val, &val->value);
|
||||||
|
|
||||||
zend_hash_update(Z_ARRVAL(modules[module_number]), val->name, &const_val);
|
zend_hash_update(Z_ARRVAL(modules[module_number]), val->name, &const_val);
|
||||||
next_constant:
|
} ZEND_HASH_FOREACH_END();
|
||||||
zend_hash_move_forward_ex(EG(zend_constants), &pos);
|
|
||||||
}
|
|
||||||
efree(module_names);
|
efree(module_names);
|
||||||
efree(modules);
|
efree(modules);
|
||||||
} else {
|
} else {
|
||||||
@ -2009,17 +1988,14 @@ static void debug_backtrace_get_args(zval *curpos, zval *arg_array TSRMLS_DC)
|
|||||||
void debug_print_backtrace_args(zval *arg_array TSRMLS_DC)
|
void debug_print_backtrace_args(zval *arg_array TSRMLS_DC)
|
||||||
{
|
{
|
||||||
zval *tmp;
|
zval *tmp;
|
||||||
HashPosition iterator;
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(arg_array), &iterator);
|
ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(arg_array), tmp) {
|
||||||
while ((tmp = zend_hash_get_current_data_ex(Z_ARRVAL_P(arg_array), &iterator)) != NULL) {
|
|
||||||
if (i++) {
|
if (i++) {
|
||||||
ZEND_PUTS(", ");
|
ZEND_PUTS(", ");
|
||||||
}
|
}
|
||||||
zend_print_flat_zval_r(tmp TSRMLS_CC);
|
zend_print_flat_zval_r(tmp TSRMLS_CC);
|
||||||
zend_hash_move_forward_ex(Z_ARRVAL_P(arg_array), &iterator);
|
} ZEND_HASH_FOREACH_END();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* {{{ proto void debug_print_backtrace([int options[, int limit]]) */
|
/* {{{ proto void debug_print_backtrace([int options[, int limit]]) */
|
||||||
@ -2402,8 +2378,8 @@ ZEND_FUNCTION(get_extension_funcs)
|
|||||||
zend_string *lcname;
|
zend_string *lcname;
|
||||||
int extension_name_len, array;
|
int extension_name_len, array;
|
||||||
zend_module_entry *module;
|
zend_module_entry *module;
|
||||||
HashPosition iterator;
|
|
||||||
zend_function *zif;
|
zend_function *zif;
|
||||||
|
|
||||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &extension_name, &extension_name_len) == FAILURE) {
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &extension_name, &extension_name_len) == FAILURE) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -2419,7 +2395,6 @@ ZEND_FUNCTION(get_extension_funcs)
|
|||||||
RETURN_FALSE;
|
RETURN_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
zend_hash_internal_pointer_reset_ex(CG(function_table), &iterator);
|
|
||||||
if (module->functions) {
|
if (module->functions) {
|
||||||
/* avoid BC break, if functions list is empty, will return an empty array */
|
/* avoid BC break, if functions list is empty, will return an empty array */
|
||||||
array_init(return_value);
|
array_init(return_value);
|
||||||
@ -2427,7 +2402,8 @@ ZEND_FUNCTION(get_extension_funcs)
|
|||||||
} else {
|
} else {
|
||||||
array = 0;
|
array = 0;
|
||||||
}
|
}
|
||||||
while ((zif = zend_hash_get_current_data_ptr_ex(CG(function_table), &iterator)) != NULL) {
|
|
||||||
|
ZEND_HASH_FOREACH_PTR(CG(function_table), zif) {
|
||||||
if (zif->common.type == ZEND_INTERNAL_FUNCTION
|
if (zif->common.type == ZEND_INTERNAL_FUNCTION
|
||||||
&& zif->internal_function.module == module) {
|
&& zif->internal_function.module == module) {
|
||||||
if (!array) {
|
if (!array) {
|
||||||
@ -2437,8 +2413,7 @@ ZEND_FUNCTION(get_extension_funcs)
|
|||||||
// TODO: we have to duplicate it, becaise it may be stored in opcache SHM ???
|
// TODO: we have to duplicate it, becaise it may be stored in opcache SHM ???
|
||||||
add_next_index_str(return_value, STR_DUP(zif->common.function_name, 0));
|
add_next_index_str(return_value, STR_DUP(zif->common.function_name, 0));
|
||||||
}
|
}
|
||||||
zend_hash_move_forward_ex(CG(function_table), &iterator);
|
} ZEND_HASH_FOREACH_END();
|
||||||
}
|
|
||||||
|
|
||||||
if (!array) {
|
if (!array) {
|
||||||
RETURN_FALSE;
|
RETURN_FALSE;
|
||||||
|
@ -3847,9 +3847,7 @@ ZEND_API void zend_do_inheritance(zend_class_entry *ce, zend_class_entry *parent
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (zend_hash_internal_pointer_reset(&ce->properties_info);
|
ZEND_HASH_FOREACH_PTR(&ce->properties_info, property_info) {
|
||||||
(property_info = zend_hash_get_current_data_ptr(&ce->properties_info)) != NULL;
|
|
||||||
zend_hash_move_forward(&ce->properties_info)) {
|
|
||||||
if (property_info->ce == ce) {
|
if (property_info->ce == ce) {
|
||||||
if (property_info->flags & ZEND_ACC_STATIC) {
|
if (property_info->flags & ZEND_ACC_STATIC) {
|
||||||
property_info->offset += parent_ce->default_static_members_count;
|
property_info->offset += parent_ce->default_static_members_count;
|
||||||
@ -3857,7 +3855,7 @@ ZEND_API void zend_do_inheritance(zend_class_entry *ce, zend_class_entry *parent
|
|||||||
property_info->offset += parent_ce->default_properties_count;
|
property_info->offset += parent_ce->default_properties_count;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} ZEND_HASH_FOREACH_END();
|
||||||
|
|
||||||
zend_hash_merge_ex(&ce->properties_info, &parent_ce->properties_info, (ce->type & ZEND_INTERNAL_CLASS ? zend_duplicate_property_info_internal_zval : zend_duplicate_property_info_zval), (merge_checker_func_t) do_inherit_property_access_check, ce);
|
zend_hash_merge_ex(&ce->properties_info, &parent_ce->properties_info, (ce->type & ZEND_INTERNAL_CLASS ? zend_duplicate_property_info_internal_zval : zend_duplicate_property_info_zval), (merge_checker_func_t) do_inherit_property_access_check, ce);
|
||||||
|
|
||||||
@ -4430,9 +4428,7 @@ static void zend_do_traits_property_binding(zend_class_entry *ce TSRMLS_DC) /* {
|
|||||||
* - if compatible, then strict notice
|
* - if compatible, then strict notice
|
||||||
*/
|
*/
|
||||||
for (i = 0; i < ce->num_traits; i++) {
|
for (i = 0; i < ce->num_traits; i++) {
|
||||||
for (zend_hash_internal_pointer_reset(&ce->traits[i]->properties_info);
|
ZEND_HASH_FOREACH_PTR(&ce->traits[i]->properties_info, property_info) {
|
||||||
(property_info = zend_hash_get_current_data_ptr(&ce->traits[i]->properties_info)) != NULL;
|
|
||||||
zend_hash_move_forward(&ce->traits[i]->properties_info)) {
|
|
||||||
/* first get the unmangeld name if necessary,
|
/* first get the unmangeld name if necessary,
|
||||||
* then check whether the property is already there
|
* then check whether the property is already there
|
||||||
*/
|
*/
|
||||||
@ -4507,7 +4503,7 @@ static void zend_do_traits_property_binding(zend_class_entry *ce TSRMLS_DC) /* {
|
|||||||
prop_value, flags,
|
prop_value, flags,
|
||||||
doc_comment TSRMLS_CC);
|
doc_comment TSRMLS_CC);
|
||||||
STR_RELEASE(prop_name);
|
STR_RELEASE(prop_name);
|
||||||
}
|
} ZEND_HASH_FOREACH_END();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
100
Zend/zend_hash.h
100
Zend/zend_hash.h
@ -533,6 +533,106 @@ static inline void *zend_hash_get_current_data_ptr_ex(HashTable *ht, HashPositio
|
|||||||
#define zend_hash_get_current_data_ptr(ht) \
|
#define zend_hash_get_current_data_ptr(ht) \
|
||||||
zend_hash_get_current_data_ptr_ex(ht, &(ht)->nInternalPointer)
|
zend_hash_get_current_data_ptr_ex(ht, &(ht)->nInternalPointer)
|
||||||
|
|
||||||
|
#define ZEND_HASH_FOREACH_VAL(_ht, _val) do { \
|
||||||
|
uint _idx; \
|
||||||
|
Bucket *_p; \
|
||||||
|
for (_idx = 0; _idx < (_ht)->nNumUsed; _idx++) { \
|
||||||
|
_p = (_ht)->arData + _idx; \
|
||||||
|
if (Z_TYPE(_p->val) == IS_UNDEF) continue; \
|
||||||
|
_val = &_p->val;
|
||||||
|
|
||||||
|
#define ZEND_HASH_FOREACH_VAL_IND(_ht, _val) do { \
|
||||||
|
uint _idx; \
|
||||||
|
Bucket *_p; \
|
||||||
|
zval *_z; \
|
||||||
|
for (_idx = 0; _idx < (_ht)->nNumUsed; _idx++) { \
|
||||||
|
_p = (_ht)->arData + _idx; \
|
||||||
|
_z = &_p->val; \
|
||||||
|
if (Z_TYPE_P(_z) == IS_INDIRECT) { \
|
||||||
|
_z = Z_INDIRECT_P(_z); \
|
||||||
|
} \
|
||||||
|
if (Z_TYPE_P(_z) == IS_UNDEF) continue; \
|
||||||
|
_val = _z;
|
||||||
|
|
||||||
|
#define ZEND_HASH_FOREACH_PTR(_ht, _ptr) do { \
|
||||||
|
uint _idx; \
|
||||||
|
Bucket *_p; \
|
||||||
|
for (_idx = 0; _idx < (_ht)->nNumUsed; _idx++) { \
|
||||||
|
_p = (_ht)->arData + _idx; \
|
||||||
|
if (Z_TYPE(_p->val) == IS_UNDEF) continue; \
|
||||||
|
_ptr = Z_PTR(_p->val);
|
||||||
|
|
||||||
|
#define ZEND_HASH_FOREACH_KEY(_ht, _h, _key) do { \
|
||||||
|
uint _idx; \
|
||||||
|
Bucket *_p; \
|
||||||
|
for (_idx = 0; _idx < (_ht)->nNumUsed; _idx++) { \
|
||||||
|
_p = (_ht)->arData + _idx; \
|
||||||
|
if (Z_TYPE(_p->val) == IS_UNDEF) continue; \
|
||||||
|
_h = _p->h; \
|
||||||
|
_key = _p->key; \
|
||||||
|
|
||||||
|
#define ZEND_HASH_FOREACH_KEY_VAL(_ht, _h, _key, _val) do { \
|
||||||
|
uint _idx; \
|
||||||
|
Bucket *_p; \
|
||||||
|
for (_idx = 0; _idx < (_ht)->nNumUsed; _idx++) { \
|
||||||
|
_p = (_ht)->arData + _idx; \
|
||||||
|
if (Z_TYPE(_p->val) == IS_UNDEF) continue; \
|
||||||
|
_h = _p->h; \
|
||||||
|
_key = _p->key; \
|
||||||
|
_val = &_p->val;
|
||||||
|
|
||||||
|
#define ZEND_HASH_FOREACH_KEY_VAL(_ht, _h, _key, _val) do { \
|
||||||
|
uint _idx; \
|
||||||
|
Bucket *_p; \
|
||||||
|
for (_idx = 0; _idx < (_ht)->nNumUsed; _idx++) { \
|
||||||
|
_p = (_ht)->arData + _idx; \
|
||||||
|
if (Z_TYPE(_p->val) == IS_UNDEF) continue; \
|
||||||
|
_h = _p->h; \
|
||||||
|
_key = _p->key; \
|
||||||
|
_val = &_p->val;
|
||||||
|
|
||||||
|
#define ZEND_HASH_FOREACH_KEY_VAL_IND(_ht, _h, _key, _val) do { \
|
||||||
|
uint _idx; \
|
||||||
|
Bucket *_p; \
|
||||||
|
zval *_z; \
|
||||||
|
for (_idx = 0; _idx < (_ht)->nNumUsed; _idx++) { \
|
||||||
|
_p = (_ht)->arData + _idx; \
|
||||||
|
_z = &_p->val; \
|
||||||
|
if (Z_TYPE_P(_z) == IS_INDIRECT) { \
|
||||||
|
_z = Z_INDIRECT_P(_z); \
|
||||||
|
} \
|
||||||
|
if (Z_TYPE_P(_z) == IS_UNDEF) continue; \
|
||||||
|
_h = _p->h; \
|
||||||
|
_key = _p->key; \
|
||||||
|
_val = _z;
|
||||||
|
|
||||||
|
#define ZEND_HASH_FOREACH_KEY_PTR(_ht, _h, _key, _ptr) do { \
|
||||||
|
uint _idx; \
|
||||||
|
Bucket *_p; \
|
||||||
|
for (_idx = 0; _idx < (_ht)->nNumUsed; _idx++) { \
|
||||||
|
_p = (_ht)->arData + _idx; \
|
||||||
|
if (Z_TYPE(_p->val) == IS_UNDEF) continue; \
|
||||||
|
_h = _p->h; \
|
||||||
|
_key = _p->key; \
|
||||||
|
_ptr = Z_PTR(_p->val);
|
||||||
|
|
||||||
|
|
||||||
|
#define ZEND_HASH_REVERSE_FOREACH_KEY_VAL(_ht, _h, _key, _val) do { \
|
||||||
|
uint _idx; \
|
||||||
|
Bucket *_p; \
|
||||||
|
for (_idx = (_ht)->nNumUsed; _idx > 0; _idx--) { \
|
||||||
|
_p = (_ht)->arData + _idx - 1; \
|
||||||
|
if (Z_TYPE(_p->val) == IS_UNDEF) continue; \
|
||||||
|
_h = _p->h; \
|
||||||
|
_key = _p->key; \
|
||||||
|
_val = &_p->val;
|
||||||
|
|
||||||
|
#define ZEND_HASH_FOREACH_END() \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* ZEND_HASH_H */
|
#endif /* ZEND_HASH_H */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -315,15 +315,12 @@ ZEND_API int zend_register_list_destructors_ex(rsrc_dtor_func_t ld, rsrc_dtor_fu
|
|||||||
ZEND_API int zend_fetch_list_dtor_id(const char *type_name)
|
ZEND_API int zend_fetch_list_dtor_id(const char *type_name)
|
||||||
{
|
{
|
||||||
zend_rsrc_list_dtors_entry *lde;
|
zend_rsrc_list_dtors_entry *lde;
|
||||||
HashPosition pos;
|
|
||||||
|
|
||||||
zend_hash_internal_pointer_reset_ex(&list_destructors, &pos);
|
ZEND_HASH_FOREACH_PTR(&list_destructors, lde) {
|
||||||
while ((lde = zend_hash_get_current_data_ptr_ex(&list_destructors, &pos)) != NULL) {
|
|
||||||
if (lde->type_name && (strcmp(type_name, lde->type_name) == 0)) {
|
if (lde->type_name && (strcmp(type_name, lde->type_name) == 0)) {
|
||||||
return lde->resource_id;
|
return lde->resource_id;
|
||||||
}
|
}
|
||||||
zend_hash_move_forward_ex(&list_destructors, &pos);
|
} ZEND_HASH_FOREACH_END();
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -71,16 +71,13 @@
|
|||||||
ZEND_API void rebuild_object_properties(zend_object *zobj) /* {{{ */
|
ZEND_API void rebuild_object_properties(zend_object *zobj) /* {{{ */
|
||||||
{
|
{
|
||||||
if (!zobj->properties) {
|
if (!zobj->properties) {
|
||||||
HashPosition pos;
|
|
||||||
zend_property_info *prop_info;
|
zend_property_info *prop_info;
|
||||||
zend_class_entry *ce = zobj->ce;
|
zend_class_entry *ce = zobj->ce;
|
||||||
|
|
||||||
ALLOC_HASHTABLE(zobj->properties);
|
ALLOC_HASHTABLE(zobj->properties);
|
||||||
zend_hash_init(zobj->properties, 0, NULL, ZVAL_PTR_DTOR, 0);
|
zend_hash_init(zobj->properties, 0, NULL, ZVAL_PTR_DTOR, 0);
|
||||||
if (ce->default_properties_count) {
|
if (ce->default_properties_count) {
|
||||||
for (zend_hash_internal_pointer_reset_ex(&ce->properties_info, &pos);
|
ZEND_HASH_FOREACH_PTR(&ce->properties_info, prop_info) {
|
||||||
(prop_info = zend_hash_get_current_data_ptr_ex(&ce->properties_info, &pos)) != NULL;
|
|
||||||
zend_hash_move_forward_ex(&ce->properties_info, &pos)) {
|
|
||||||
if (/*prop_info->ce == ce &&*/
|
if (/*prop_info->ce == ce &&*/
|
||||||
(prop_info->flags & ZEND_ACC_STATIC) == 0 &&
|
(prop_info->flags & ZEND_ACC_STATIC) == 0 &&
|
||||||
prop_info->offset >= 0 &&
|
prop_info->offset >= 0 &&
|
||||||
@ -90,12 +87,10 @@ ZEND_API void rebuild_object_properties(zend_object *zobj) /* {{{ */
|
|||||||
ZVAL_INDIRECT(&zv, &zobj->properties_table[prop_info->offset]);
|
ZVAL_INDIRECT(&zv, &zobj->properties_table[prop_info->offset]);
|
||||||
zend_hash_add(zobj->properties, prop_info->name, &zv);
|
zend_hash_add(zobj->properties, prop_info->name, &zv);
|
||||||
}
|
}
|
||||||
}
|
} ZEND_HASH_FOREACH_END();
|
||||||
while (ce->parent && ce->parent->default_properties_count) {
|
while (ce->parent && ce->parent->default_properties_count) {
|
||||||
ce = ce->parent;
|
ce = ce->parent;
|
||||||
for (zend_hash_internal_pointer_reset_ex(&ce->properties_info, &pos);
|
ZEND_HASH_FOREACH_PTR(&ce->properties_info, prop_info) {
|
||||||
(prop_info = zend_hash_get_current_data_ptr_ex(&ce->properties_info, &pos)) != NULL;
|
|
||||||
zend_hash_move_forward_ex(&ce->properties_info, &pos)) {
|
|
||||||
if (prop_info->ce == ce &&
|
if (prop_info->ce == ce &&
|
||||||
(prop_info->flags & ZEND_ACC_STATIC) == 0 &&
|
(prop_info->flags & ZEND_ACC_STATIC) == 0 &&
|
||||||
(prop_info->flags & ZEND_ACC_PRIVATE) != 0 &&
|
(prop_info->flags & ZEND_ACC_PRIVATE) != 0 &&
|
||||||
@ -106,7 +101,7 @@ ZEND_API void rebuild_object_properties(zend_object *zobj) /* {{{ */
|
|||||||
ZVAL_INDIRECT(&zv, &zobj->properties_table[prop_info->offset]);
|
ZVAL_INDIRECT(&zv, &zobj->properties_table[prop_info->offset]);
|
||||||
zend_hash_add(zobj->properties, prop_info->name, &zv);
|
zend_hash_add(zobj->properties, prop_info->name, &zv);
|
||||||
}
|
}
|
||||||
}
|
} ZEND_HASH_FOREACH_END();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -148,7 +148,6 @@ ZEND_API void zend_objects_clone_members(zend_object *new_object, zend_object *o
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (old_object->properties) {
|
if (old_object->properties) {
|
||||||
HashPosition pos;
|
|
||||||
zval *prop, new_prop;
|
zval *prop, new_prop;
|
||||||
ulong num_key;
|
ulong num_key;
|
||||||
zend_string *key;
|
zend_string *key;
|
||||||
@ -158,24 +157,19 @@ ZEND_API void zend_objects_clone_members(zend_object *new_object, zend_object *o
|
|||||||
zend_hash_init(new_object->properties, 0, NULL, ZVAL_PTR_DTOR, 0);
|
zend_hash_init(new_object->properties, 0, NULL, ZVAL_PTR_DTOR, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (zend_hash_internal_pointer_reset_ex(old_object->properties, &pos);
|
ZEND_HASH_FOREACH_KEY_VAL(old_object->properties, num_key, key, prop) {
|
||||||
(prop = zend_hash_get_current_data_ex(old_object->properties, &pos)) != NULL;
|
|
||||||
zend_hash_move_forward_ex(old_object->properties, &pos)) {
|
|
||||||
if (Z_TYPE_P(prop) == IS_INDIRECT) {
|
if (Z_TYPE_P(prop) == IS_INDIRECT) {
|
||||||
ZVAL_INDIRECT(&new_prop, new_object->properties_table + (Z_INDIRECT_P(prop) - old_object->properties_table));
|
ZVAL_INDIRECT(&new_prop, new_object->properties_table + (Z_INDIRECT_P(prop) - old_object->properties_table));
|
||||||
} else {
|
} else {
|
||||||
ZVAL_COPY_VALUE(&new_prop, prop);
|
ZVAL_COPY_VALUE(&new_prop, prop);
|
||||||
zval_add_ref(&new_prop);
|
zval_add_ref(&new_prop);
|
||||||
}
|
}
|
||||||
switch (zend_hash_get_current_key_ex(old_object->properties, &key, &num_key, 0, &pos)) {
|
if (key) {
|
||||||
case HASH_KEY_IS_STRING:
|
zend_hash_update(new_object->properties, key, &new_prop);
|
||||||
zend_hash_update(new_object->properties, key, &new_prop);
|
} else {
|
||||||
break;
|
zend_hash_index_update(new_object->properties, num_key, &new_prop);
|
||||||
case HASH_KEY_IS_LONG:
|
|
||||||
zend_hash_index_update(new_object->properties, num_key, &new_prop);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
} ZEND_HASH_FOREACH_END();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (old_object->ce->clone) {
|
if (old_object->ce->clone) {
|
||||||
|
@ -1250,14 +1250,12 @@ static zend_string *php_replace_in_subject(zval *regex, zval *replace, zval *sub
|
|||||||
/* Duplicate subject string for repeated replacement */
|
/* Duplicate subject string for repeated replacement */
|
||||||
subject_value = STR_INIT(Z_STRVAL_P(subject), Z_STRLEN_P(subject), 0);
|
subject_value = STR_INIT(Z_STRVAL_P(subject), Z_STRLEN_P(subject), 0);
|
||||||
|
|
||||||
zend_hash_internal_pointer_reset(Z_ARRVAL_P(regex));
|
|
||||||
|
|
||||||
replace_value = replace;
|
replace_value = replace;
|
||||||
if (Z_TYPE_P(replace) == IS_ARRAY && !is_callable_replace)
|
if (Z_TYPE_P(replace) == IS_ARRAY && !is_callable_replace)
|
||||||
zend_hash_internal_pointer_reset(Z_ARRVAL_P(replace));
|
zend_hash_internal_pointer_reset(Z_ARRVAL_P(replace));
|
||||||
|
|
||||||
/* For each entry in the regex array, get the entry */
|
/* For each entry in the regex array, get the entry */
|
||||||
while ((regex_entry = zend_hash_get_current_data(Z_ARRVAL_P(regex))) != NULL) {
|
ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(regex), regex_entry) {
|
||||||
/* Make sure we're dealing with strings. */
|
/* Make sure we're dealing with strings. */
|
||||||
convert_to_string_ex(regex_entry);
|
convert_to_string_ex(regex_entry);
|
||||||
|
|
||||||
@ -1293,8 +1291,7 @@ static zend_string *php_replace_in_subject(zval *regex, zval *replace, zval *sub
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
zend_hash_move_forward(Z_ARRVAL_P(regex));
|
} ZEND_HASH_FOREACH_END();
|
||||||
}
|
|
||||||
|
|
||||||
zval_ptr_dtor(&tmp_subject);
|
zval_ptr_dtor(&tmp_subject);
|
||||||
return subject_value;
|
return subject_value;
|
||||||
@ -1365,32 +1362,24 @@ static void preg_replace_impl(INTERNAL_FUNCTION_PARAMETERS, int is_callable_repl
|
|||||||
/* if subject is an array */
|
/* if subject is an array */
|
||||||
if (Z_TYPE_P(subject) == IS_ARRAY) {
|
if (Z_TYPE_P(subject) == IS_ARRAY) {
|
||||||
array_init(return_value);
|
array_init(return_value);
|
||||||
zend_hash_internal_pointer_reset(Z_ARRVAL_P(subject));
|
|
||||||
|
|
||||||
/* For each subject entry, convert it to string, then perform replacement
|
/* For each subject entry, convert it to string, then perform replacement
|
||||||
and add the result to the return_value array. */
|
and add the result to the return_value array. */
|
||||||
while ((subject_entry = zend_hash_get_current_data(Z_ARRVAL_P(subject))) != NULL) {
|
ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(subject), num_key, string_key, subject_entry) {
|
||||||
old_replace_count = replace_count;
|
old_replace_count = replace_count;
|
||||||
if ((result = php_replace_in_subject(regex, replace, subject_entry, limit_val, is_callable_replace, &replace_count TSRMLS_CC)) != NULL) {
|
if ((result = php_replace_in_subject(regex, replace, subject_entry, limit_val, is_callable_replace, &replace_count TSRMLS_CC)) != NULL) {
|
||||||
if (!is_filter || replace_count > old_replace_count) {
|
if (!is_filter || replace_count > old_replace_count) {
|
||||||
/* Add to return array */
|
/* Add to return array */
|
||||||
switch(zend_hash_get_current_key(Z_ARRVAL_P(subject), &string_key, &num_key, 0))
|
if (string_key) {
|
||||||
{
|
|
||||||
case HASH_KEY_IS_STRING:
|
|
||||||
add_assoc_str_ex(return_value, string_key->val, string_key->len, result);
|
add_assoc_str_ex(return_value, string_key->val, string_key->len, result);
|
||||||
break;
|
} else {
|
||||||
|
|
||||||
case HASH_KEY_IS_LONG:
|
|
||||||
add_index_str(return_value, num_key, result);
|
add_index_str(return_value, num_key, result);
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
STR_FREE(result);
|
STR_FREE(result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} ZEND_HASH_FOREACH_END();
|
||||||
zend_hash_move_forward(Z_ARRVAL_P(subject));
|
|
||||||
}
|
|
||||||
} else { /* if subject is not an array */
|
} else { /* if subject is not an array */
|
||||||
old_replace_count = replace_count;
|
old_replace_count = replace_count;
|
||||||
if ((result = php_replace_in_subject(regex, replace, subject, limit_val, is_callable_replace, &replace_count TSRMLS_CC)) != NULL) {
|
if ((result = php_replace_in_subject(regex, replace, subject, limit_val, is_callable_replace, &replace_count TSRMLS_CC)) != NULL) {
|
||||||
@ -1781,8 +1770,7 @@ PHPAPI void php_pcre_grep_impl(pcre_cache_entry *pce, zval *input, zval *return
|
|||||||
PCRE_G(error_code) = PHP_PCRE_NO_ERROR;
|
PCRE_G(error_code) = PHP_PCRE_NO_ERROR;
|
||||||
|
|
||||||
/* Go through the input array */
|
/* Go through the input array */
|
||||||
zend_hash_internal_pointer_reset(Z_ARRVAL_P(input));
|
ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(input), num_key, string_key, entry) {
|
||||||
while ((entry = zend_hash_get_current_data(Z_ARRVAL_P(input))) != NULL) {
|
|
||||||
zval subject, *ref_entry = entry;
|
zval subject, *ref_entry = entry;
|
||||||
|
|
||||||
if (Z_ISREF_P(entry)) {
|
if (Z_ISREF_P(entry)) {
|
||||||
@ -1818,15 +1806,10 @@ PHPAPI void php_pcre_grep_impl(pcre_cache_entry *pce, zval *input, zval *return
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Add to return array */
|
/* Add to return array */
|
||||||
switch (zend_hash_get_current_key(Z_ARRVAL_P(input), &string_key, &num_key, 0))
|
if (string_key) {
|
||||||
{
|
zend_hash_update(Z_ARRVAL_P(return_value), string_key, ref_entry);
|
||||||
case HASH_KEY_IS_STRING:
|
} else {
|
||||||
zend_hash_update(Z_ARRVAL_P(return_value), string_key, ref_entry);
|
zend_hash_index_update(Z_ARRVAL_P(return_value), num_key, ref_entry);
|
||||||
break;
|
|
||||||
|
|
||||||
case HASH_KEY_IS_LONG:
|
|
||||||
zend_hash_index_update(Z_ARRVAL_P(return_value), num_key, ref_entry);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1834,9 +1817,8 @@ PHPAPI void php_pcre_grep_impl(pcre_cache_entry *pce, zval *input, zval *return
|
|||||||
zval_dtor(&subject);
|
zval_dtor(&subject);
|
||||||
}
|
}
|
||||||
|
|
||||||
zend_hash_move_forward(Z_ARRVAL_P(input));
|
} ZEND_HASH_FOREACH_END();
|
||||||
}
|
|
||||||
zend_hash_internal_pointer_reset(Z_ARRVAL_P(input));
|
|
||||||
/* Clean up */
|
/* Clean up */
|
||||||
efree(offsets);
|
efree(offsets);
|
||||||
}
|
}
|
||||||
|
@ -281,17 +281,12 @@ static int php_count_recursive(zval *array, long mode TSRMLS_DC) /* {{{ */
|
|||||||
|
|
||||||
cnt = zend_hash_num_elements(Z_ARRVAL_P(array));
|
cnt = zend_hash_num_elements(Z_ARRVAL_P(array));
|
||||||
if (mode == COUNT_RECURSIVE) {
|
if (mode == COUNT_RECURSIVE) {
|
||||||
HashPosition pos;
|
ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(array), element) {
|
||||||
|
|
||||||
for (zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(array), &pos);
|
|
||||||
(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++;
|
Z_ARRVAL_P(array)->nApplyCount++;
|
||||||
ZVAL_DEREF(element);
|
ZVAL_DEREF(element);
|
||||||
cnt += php_count_recursive(element, COUNT_RECURSIVE TSRMLS_CC);
|
cnt += php_count_recursive(element, COUNT_RECURSIVE TSRMLS_CC);
|
||||||
Z_ARRVAL_P(array)->nApplyCount--;
|
Z_ARRVAL_P(array)->nApplyCount--;
|
||||||
}
|
} ZEND_HASH_FOREACH_END();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1218,7 +1213,8 @@ static void php_search_array(INTERNAL_FUNCTION_PARAMETERS, int behavior) /* {{{
|
|||||||
*array, /* array to check in */
|
*array, /* array to check in */
|
||||||
*entry, /* pointer to array entry */
|
*entry, /* pointer to array entry */
|
||||||
res; /* comparison result */
|
res; /* comparison result */
|
||||||
HashPosition pos; /* hash iterator */
|
ulong num_idx;
|
||||||
|
zend_string *str_idx;
|
||||||
zend_bool strict = 0; /* strict comparison or not */
|
zend_bool strict = 0; /* strict comparison or not */
|
||||||
int (*is_equal_func)(zval *, zval *, zval * TSRMLS_DC) = is_equal_function;
|
int (*is_equal_func)(zval *, zval *, zval * TSRMLS_DC) = is_equal_function;
|
||||||
|
|
||||||
@ -1230,19 +1226,21 @@ static void php_search_array(INTERNAL_FUNCTION_PARAMETERS, int behavior) /* {{{
|
|||||||
is_equal_func = is_identical_function;
|
is_equal_func = is_identical_function;
|
||||||
}
|
}
|
||||||
|
|
||||||
zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(array), &pos);
|
ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(array), num_idx, str_idx, entry) {
|
||||||
while ((entry = zend_hash_get_current_data_ex(Z_ARRVAL_P(array), &pos)) != NULL) {
|
|
||||||
is_equal_func(&res, value, entry TSRMLS_CC);
|
is_equal_func(&res, value, entry TSRMLS_CC);
|
||||||
if (Z_LVAL(res)) {
|
if (Z_LVAL(res)) {
|
||||||
if (behavior == 0) {
|
if (behavior == 0) {
|
||||||
RETURN_TRUE;
|
RETURN_TRUE;
|
||||||
} else {
|
} else {
|
||||||
zend_hash_get_current_key_zval_ex(Z_ARRVAL_P(array), return_value, &pos);
|
if (str_idx) {
|
||||||
|
RETVAL_STR(STR_COPY(str_idx));
|
||||||
|
} else {
|
||||||
|
RETVAL_LONG(num_idx);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
zend_hash_move_forward_ex(Z_ARRVAL_P(array), &pos);
|
} ZEND_HASH_FOREACH_END();
|
||||||
}
|
|
||||||
|
|
||||||
RETURN_FALSE;
|
RETURN_FALSE;
|
||||||
}
|
}
|
||||||
@ -1324,9 +1322,8 @@ PHP_FUNCTION(extract)
|
|||||||
zval *entry, data;
|
zval *entry, data;
|
||||||
zend_string *var_name;
|
zend_string *var_name;
|
||||||
ulong num_key;
|
ulong num_key;
|
||||||
int var_exists, key_type, count = 0;
|
int var_exists, count = 0;
|
||||||
int extract_refs = 0;
|
int extract_refs = 0;
|
||||||
HashPosition pos;
|
|
||||||
|
|
||||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|lz/", &var_array, &extract_type, &prefix) == FAILURE) {
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|lz/", &var_array, &extract_type, &prefix) == FAILURE) {
|
||||||
return;
|
return;
|
||||||
@ -1364,26 +1361,15 @@ PHP_FUNCTION(extract)
|
|||||||
SEPARATE_ARG_IF_REF(var_array);
|
SEPARATE_ARG_IF_REF(var_array);
|
||||||
}
|
}
|
||||||
|
|
||||||
zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(var_array), &pos);
|
ZEND_HASH_FOREACH_KEY_VAL_IND(Z_ARRVAL_P(var_array), num_key, var_name, entry) {
|
||||||
while ((entry = zend_hash_get_current_data_ex(Z_ARRVAL_P(var_array), &pos)) != NULL) {
|
|
||||||
zval final_name;
|
zval final_name;
|
||||||
|
|
||||||
if (Z_TYPE_P(entry) == IS_INDIRECT) {
|
|
||||||
entry = Z_INDIRECT_P(entry);
|
|
||||||
if (Z_TYPE_P(entry) == IS_UNDEF) {
|
|
||||||
zend_hash_move_forward_ex(Z_ARRVAL_P(var_array), &pos);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ZVAL_NULL(&final_name);
|
ZVAL_NULL(&final_name);
|
||||||
|
|
||||||
key_type = zend_hash_get_current_key_ex(Z_ARRVAL_P(var_array), &var_name, &num_key, 0, &pos);
|
|
||||||
var_exists = 0;
|
var_exists = 0;
|
||||||
|
|
||||||
if (key_type == HASH_KEY_IS_STRING) {
|
if (var_name) {
|
||||||
var_exists = zend_hash_exists_ind(&EG(active_symbol_table)->ht, var_name);
|
var_exists = zend_hash_exists_ind(&EG(active_symbol_table)->ht, var_name);
|
||||||
} else if (key_type == HASH_KEY_IS_LONG && (extract_type == EXTR_PREFIX_ALL || extract_type == EXTR_PREFIX_INVALID)) {
|
} else if (extract_type == EXTR_PREFIX_ALL || extract_type == EXTR_PREFIX_INVALID) {
|
||||||
zval num;
|
zval num;
|
||||||
|
|
||||||
ZVAL_LONG(&num, num_key);
|
ZVAL_LONG(&num, num_key);
|
||||||
@ -1391,7 +1377,6 @@ PHP_FUNCTION(extract)
|
|||||||
php_prefix_varname(&final_name, prefix, Z_STRVAL(num), Z_STRLEN(num), 1 TSRMLS_CC);
|
php_prefix_varname(&final_name, prefix, Z_STRVAL(num), Z_STRLEN(num), 1 TSRMLS_CC);
|
||||||
zval_dtor(&num);
|
zval_dtor(&num);
|
||||||
} else {
|
} else {
|
||||||
zend_hash_move_forward_ex(Z_ARRVAL_P(var_array), &pos);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1469,9 +1454,7 @@ PHP_FUNCTION(extract)
|
|||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
zval_dtor(&final_name);
|
zval_dtor(&final_name);
|
||||||
|
} ZEND_HASH_FOREACH_END();
|
||||||
zend_hash_move_forward_ex(Z_ARRVAL_P(var_array), &pos);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!extract_refs) {
|
if (!extract_refs) {
|
||||||
zval_ptr_dtor(var_array);
|
zval_ptr_dtor(var_array);
|
||||||
@ -1492,8 +1475,6 @@ static void php_compact_var(HashTable *eg_active_symbol_table, zval *return_valu
|
|||||||
zend_hash_update(Z_ARRVAL_P(return_value), Z_STR_P(entry), &data);
|
zend_hash_update(Z_ARRVAL_P(return_value), Z_STR_P(entry), &data);
|
||||||
}
|
}
|
||||||
} else if (Z_TYPE_P(entry) == IS_ARRAY) {
|
} else if (Z_TYPE_P(entry) == IS_ARRAY) {
|
||||||
HashPosition pos;
|
|
||||||
|
|
||||||
if ((Z_ARRVAL_P(entry)->nApplyCount > 1)) {
|
if ((Z_ARRVAL_P(entry)->nApplyCount > 1)) {
|
||||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "recursion detected");
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "recursion detected");
|
||||||
return;
|
return;
|
||||||
@ -1501,18 +1482,9 @@ static void php_compact_var(HashTable *eg_active_symbol_table, zval *return_valu
|
|||||||
|
|
||||||
Z_ARRVAL_P(entry)->nApplyCount++;
|
Z_ARRVAL_P(entry)->nApplyCount++;
|
||||||
|
|
||||||
zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(entry), &pos);
|
ZEND_HASH_FOREACH_VAL_IND(Z_ARRVAL_P(entry), value_ptr) {
|
||||||
while ((value_ptr = zend_hash_get_current_data_ex(Z_ARRVAL_P(entry), &pos)) != NULL) {
|
|
||||||
if (Z_TYPE_P(value_ptr) == IS_INDIRECT) {
|
|
||||||
value_ptr = Z_INDIRECT_P(value_ptr);
|
|
||||||
if (Z_TYPE_P(value_ptr) == IS_UNDEF) {
|
|
||||||
zend_hash_move_forward_ex(Z_ARRVAL_P(entry), &pos);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
php_compact_var(eg_active_symbol_table, return_value, value_ptr TSRMLS_CC);
|
php_compact_var(eg_active_symbol_table, return_value, value_ptr TSRMLS_CC);
|
||||||
zend_hash_move_forward_ex(Z_ARRVAL_P(entry), &pos);
|
} ZEND_HASH_FOREACH_END();
|
||||||
}
|
|
||||||
Z_ARRVAL_P(entry)->nApplyCount--;
|
Z_ARRVAL_P(entry)->nApplyCount--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1592,7 +1564,6 @@ PHP_FUNCTION(array_fill)
|
|||||||
PHP_FUNCTION(array_fill_keys)
|
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) {
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "az", &keys, &val) == FAILURE) {
|
||||||
return;
|
return;
|
||||||
@ -1601,8 +1572,7 @@ PHP_FUNCTION(array_fill_keys)
|
|||||||
/* Initialize return array */
|
/* Initialize return array */
|
||||||
array_init_size(return_value, zend_hash_num_elements(Z_ARRVAL_P(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);
|
ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(keys), entry) {
|
||||||
while ((entry = zend_hash_get_current_data_ex(Z_ARRVAL_P(keys), &pos)) != NULL) {
|
|
||||||
ZVAL_DEREF(entry);
|
ZVAL_DEREF(entry);
|
||||||
if (Z_TYPE_P(entry) == IS_LONG) {
|
if (Z_TYPE_P(entry) == IS_LONG) {
|
||||||
zval_add_ref(val);
|
zval_add_ref(val);
|
||||||
@ -1623,9 +1593,7 @@ PHP_FUNCTION(array_fill_keys)
|
|||||||
zval_dtor(&key);
|
zval_dtor(&key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} ZEND_HASH_FOREACH_END();
|
||||||
zend_hash_move_forward_ex(Z_ARRVAL_P(keys), &pos);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
@ -2285,87 +2253,80 @@ PHPAPI int php_array_merge(HashTable *dest, HashTable *src, int recursive TSRMLS
|
|||||||
zval *src_entry, *dest_entry;
|
zval *src_entry, *dest_entry;
|
||||||
zend_string *string_key;
|
zend_string *string_key;
|
||||||
ulong num_key;
|
ulong num_key;
|
||||||
HashPosition pos;
|
|
||||||
|
|
||||||
zend_hash_internal_pointer_reset_ex(src, &pos);
|
ZEND_HASH_FOREACH_KEY_VAL(src, num_key, string_key, src_entry) {
|
||||||
while ((src_entry = zend_hash_get_current_data_ex(src, &pos)) != NULL) {
|
if (string_key) {
|
||||||
switch (zend_hash_get_current_key_ex(src, &string_key, &num_key, 0, &pos)) {
|
if (recursive && (dest_entry = zend_hash_find(dest, string_key)) != NULL) {
|
||||||
case HASH_KEY_IS_STRING:
|
zval *src_zval = src_entry;
|
||||||
if (recursive && (dest_entry = zend_hash_find(dest, string_key)) != NULL) {
|
zval *dest_zval = dest_entry;
|
||||||
zval *src_zval = src_entry;
|
HashTable *thash;
|
||||||
zval *dest_zval = dest_entry;
|
zval tmp;
|
||||||
HashTable *thash;
|
|
||||||
zval tmp;
|
|
||||||
|
|
||||||
ZVAL_DEREF(src_zval);
|
ZVAL_DEREF(src_zval);
|
||||||
ZVAL_DEREF(dest_zval);
|
ZVAL_DEREF(dest_zval);
|
||||||
thash = Z_TYPE_P(dest_zval) == IS_ARRAY ? Z_ARRVAL_P(dest_zval) : NULL;
|
thash = Z_TYPE_P(dest_zval) == IS_ARRAY ? Z_ARRVAL_P(dest_zval) : NULL;
|
||||||
if ((thash && thash->nApplyCount > 1) || (src_entry == dest_entry && Z_ISREF_P(dest_entry) && (Z_REFCOUNT_P(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");
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "recursion detected");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Z_ISREF_P(dest_entry)) {
|
if (Z_ISREF_P(dest_entry)) {
|
||||||
if (Z_REFCOUNT_P(dest_entry) == 1) {
|
if (Z_REFCOUNT_P(dest_entry) == 1) {
|
||||||
ZVAL_UNREF(dest_entry);
|
ZVAL_UNREF(dest_entry);
|
||||||
} else {
|
|
||||||
Z_DELREF_P(dest_entry);
|
|
||||||
ZVAL_DUP(dest_entry, dest_zval);
|
|
||||||
}
|
|
||||||
dest_zval = dest_entry;
|
|
||||||
} else {
|
} else {
|
||||||
SEPARATE_ZVAL(dest_zval);
|
Z_DELREF_P(dest_entry);
|
||||||
|
ZVAL_DUP(dest_entry, dest_zval);
|
||||||
}
|
}
|
||||||
|
dest_zval = dest_entry;
|
||||||
|
} else {
|
||||||
|
SEPARATE_ZVAL(dest_zval);
|
||||||
|
}
|
||||||
|
|
||||||
if (Z_TYPE_P(dest_zval) == IS_NULL) {
|
if (Z_TYPE_P(dest_zval) == IS_NULL) {
|
||||||
convert_to_array_ex(dest_zval);
|
convert_to_array_ex(dest_zval);
|
||||||
add_next_index_null(dest_zval);
|
add_next_index_null(dest_zval);
|
||||||
} else {
|
} else {
|
||||||
convert_to_array_ex(dest_zval);
|
convert_to_array_ex(dest_zval);
|
||||||
|
}
|
||||||
|
ZVAL_UNDEF(&tmp);
|
||||||
|
if (Z_TYPE_P(src_zval) == IS_OBJECT) {
|
||||||
|
ZVAL_DUP(&tmp, src_zval);
|
||||||
|
convert_to_array(&tmp);
|
||||||
|
src_zval = &tmp;
|
||||||
|
}
|
||||||
|
if (Z_TYPE_P(src_zval) == IS_ARRAY) {
|
||||||
|
if (thash) {
|
||||||
|
thash->nApplyCount++;
|
||||||
}
|
}
|
||||||
ZVAL_UNDEF(&tmp);
|
if (!php_array_merge(Z_ARRVAL_P(dest_zval), Z_ARRVAL_P(src_zval), recursive TSRMLS_CC)) {
|
||||||
if (Z_TYPE_P(src_zval) == IS_OBJECT) {
|
|
||||||
ZVAL_DUP(&tmp, src_zval);
|
|
||||||
convert_to_array(&tmp);
|
|
||||||
src_zval = &tmp;
|
|
||||||
}
|
|
||||||
if (Z_TYPE_P(src_zval) == IS_ARRAY) {
|
|
||||||
if (thash) {
|
|
||||||
thash->nApplyCount++;
|
|
||||||
}
|
|
||||||
if (!php_array_merge(Z_ARRVAL_P(dest_zval), Z_ARRVAL_P(src_zval), recursive TSRMLS_CC)) {
|
|
||||||
if (thash) {
|
|
||||||
thash->nApplyCount--;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
if (thash) {
|
if (thash) {
|
||||||
thash->nApplyCount--;
|
thash->nApplyCount--;
|
||||||
}
|
}
|
||||||
} else {
|
return 0;
|
||||||
if (Z_REFCOUNTED_P(src_entry)) {
|
}
|
||||||
Z_ADDREF_P(src_entry);
|
if (thash) {
|
||||||
}
|
thash->nApplyCount--;
|
||||||
zend_hash_next_index_insert(Z_ARRVAL_P(dest_zval), src_zval);
|
|
||||||
}
|
}
|
||||||
zval_ptr_dtor(&tmp);
|
|
||||||
} else {
|
} else {
|
||||||
if (Z_REFCOUNTED_P(src_entry)) {
|
if (Z_REFCOUNTED_P(src_entry)) {
|
||||||
Z_ADDREF_P(src_entry);
|
Z_ADDREF_P(src_entry);
|
||||||
}
|
}
|
||||||
zend_hash_update(dest, string_key, src_entry);
|
zend_hash_next_index_insert(Z_ARRVAL_P(dest_zval), src_zval);
|
||||||
}
|
}
|
||||||
break;
|
zval_ptr_dtor(&tmp);
|
||||||
|
} else {
|
||||||
case HASH_KEY_IS_LONG:
|
|
||||||
if (Z_REFCOUNTED_P(src_entry)) {
|
if (Z_REFCOUNTED_P(src_entry)) {
|
||||||
Z_ADDREF_P(src_entry);
|
Z_ADDREF_P(src_entry);
|
||||||
}
|
}
|
||||||
zend_hash_next_index_insert(dest, src_entry);
|
zend_hash_update(dest, string_key, src_entry);
|
||||||
break;
|
}
|
||||||
|
} else {
|
||||||
|
if (Z_REFCOUNTED_P(src_entry)) {
|
||||||
|
Z_ADDREF_P(src_entry);
|
||||||
|
}
|
||||||
|
zend_hash_next_index_insert(dest, src_entry);
|
||||||
}
|
}
|
||||||
zend_hash_move_forward_ex(src, &pos);
|
} ZEND_HASH_FOREACH_END();
|
||||||
}
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
@ -2375,44 +2336,36 @@ PHPAPI int php_array_replace_recursive(HashTable *dest, HashTable *src TSRMLS_DC
|
|||||||
zval *src_entry, *dest_entry, *src_zval, *dest_zval;
|
zval *src_entry, *dest_entry, *src_zval, *dest_zval;
|
||||||
zend_string *string_key;
|
zend_string *string_key;
|
||||||
ulong num_key;
|
ulong num_key;
|
||||||
HashPosition pos;
|
|
||||||
|
|
||||||
for (zend_hash_internal_pointer_reset_ex(src, &pos);
|
|
||||||
(src_entry = zend_hash_get_current_data_ex(src, &pos)) != NULL;
|
|
||||||
zend_hash_move_forward_ex(src, &pos)) {
|
|
||||||
|
|
||||||
|
ZEND_HASH_FOREACH_KEY_VAL(src, num_key, string_key, src_entry) {
|
||||||
src_zval = src_entry;
|
src_zval = src_entry;
|
||||||
ZVAL_DEREF(src_zval);
|
ZVAL_DEREF(src_zval);
|
||||||
switch (zend_hash_get_current_key_ex(src, &string_key, &num_key, 0, &pos)) {
|
if (string_key) {
|
||||||
case HASH_KEY_IS_STRING:
|
if (Z_TYPE_P(src_zval) != IS_ARRAY ||
|
||||||
if (Z_TYPE_P(src_zval) != IS_ARRAY ||
|
(dest_entry = zend_hash_find(dest, string_key)) == NULL ||
|
||||||
(dest_entry = zend_hash_find(dest, string_key)) == NULL ||
|
(Z_TYPE_P(dest_entry) != IS_ARRAY &&
|
||||||
(Z_TYPE_P(dest_entry) != IS_ARRAY &&
|
(!Z_ISREF_P(dest_entry) || Z_TYPE_P(Z_REFVAL_P(dest_entry)) != IS_ARRAY))) {
|
||||||
(!Z_ISREF_P(dest_entry) || Z_TYPE_P(Z_REFVAL_P(dest_entry)) != IS_ARRAY))) {
|
|
||||||
|
|
||||||
if (Z_REFCOUNTED_P(src_entry)) {
|
if (Z_REFCOUNTED_P(src_entry)) {
|
||||||
Z_ADDREF_P(src_entry);
|
Z_ADDREF_P(src_entry);
|
||||||
}
|
|
||||||
zend_hash_update(dest, string_key, src_entry);
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
break;
|
zend_hash_update(dest, string_key, src_entry);
|
||||||
|
|
||||||
case HASH_KEY_IS_LONG:
|
continue;
|
||||||
if (Z_TYPE_P(src_zval) != IS_ARRAY ||
|
}
|
||||||
(dest_entry = zend_hash_index_find(dest, num_key)) == NULL ||
|
} else {
|
||||||
(Z_TYPE_P(dest_entry) != IS_ARRAY &&
|
if (Z_TYPE_P(src_zval) != IS_ARRAY ||
|
||||||
(!Z_ISREF_P(dest_entry) || Z_TYPE_P(Z_REFVAL_P(dest_entry)) != IS_ARRAY))) {
|
(dest_entry = zend_hash_index_find(dest, num_key)) == NULL ||
|
||||||
|
(Z_TYPE_P(dest_entry) != IS_ARRAY &&
|
||||||
|
(!Z_ISREF_P(dest_entry) || Z_TYPE_P(Z_REFVAL_P(dest_entry)) != IS_ARRAY))) {
|
||||||
|
|
||||||
if (Z_REFCOUNTED_P(src_entry)) {
|
if (Z_REFCOUNTED_P(src_entry)) {
|
||||||
Z_ADDREF_P(src_entry);
|
Z_ADDREF_P(src_entry);
|
||||||
}
|
|
||||||
zend_hash_index_update(dest, num_key, src_entry);
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
break;
|
zend_hash_index_update(dest, num_key, src_entry);
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dest_zval = dest_entry;
|
dest_zval = dest_entry;
|
||||||
@ -2435,7 +2388,7 @@ PHPAPI int php_array_replace_recursive(HashTable *dest, HashTable *src TSRMLS_DC
|
|||||||
}
|
}
|
||||||
Z_ARRVAL_P(dest_zval)->nApplyCount--;
|
Z_ARRVAL_P(dest_zval)->nApplyCount--;
|
||||||
Z_ARRVAL_P(src_zval)->nApplyCount--;
|
Z_ARRVAL_P(src_zval)->nApplyCount--;
|
||||||
}
|
} ZEND_HASH_FOREACH_END();
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -2526,7 +2479,8 @@ PHP_FUNCTION(array_keys)
|
|||||||
new_val; /* New value */
|
new_val; /* New value */
|
||||||
int add_key; /* Flag to indicate whether a key should be added */
|
int add_key; /* Flag to indicate whether a key should be added */
|
||||||
zend_bool strict = 0; /* do strict comparison */
|
zend_bool strict = 0; /* do strict comparison */
|
||||||
HashPosition pos;
|
ulong num_idx;
|
||||||
|
zend_string *str_idx;
|
||||||
int (*is_equal_func)(zval *, zval *, zval * TSRMLS_DC) = is_equal_function;
|
int (*is_equal_func)(zval *, zval *, zval * TSRMLS_DC) = is_equal_function;
|
||||||
|
|
||||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|zb", &input, &search_value, &strict) == FAILURE) {
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|zb", &input, &search_value, &strict) == FAILURE) {
|
||||||
@ -2546,20 +2500,21 @@ PHP_FUNCTION(array_keys)
|
|||||||
add_key = 1;
|
add_key = 1;
|
||||||
|
|
||||||
/* Go through input array and add keys to the return array */
|
/* Go through input array and add keys to the return array */
|
||||||
zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(input), &pos);
|
ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(input), num_idx, str_idx, entry) {
|
||||||
while ((entry = zend_hash_get_current_data_ex(Z_ARRVAL_P(input), &pos)) != NULL) {
|
|
||||||
if (search_value != 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);
|
add_key = zval_is_true(&res);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (add_key) {
|
if (add_key) {
|
||||||
zend_hash_get_current_key_zval_ex(Z_ARRVAL_P(input), &new_val, &pos);
|
if (str_idx) {
|
||||||
|
ZVAL_STR(&new_val, STR_COPY(str_idx));
|
||||||
|
} else {
|
||||||
|
ZVAL_LONG(&new_val, num_idx);
|
||||||
|
}
|
||||||
zend_hash_next_index_insert(Z_ARRVAL_P(return_value), &new_val);
|
zend_hash_next_index_insert(Z_ARRVAL_P(return_value), &new_val);
|
||||||
}
|
}
|
||||||
|
} ZEND_HASH_FOREACH_END();
|
||||||
zend_hash_move_forward_ex(Z_ARRVAL_P(input), &pos);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
@ -2569,7 +2524,6 @@ PHP_FUNCTION(array_values)
|
|||||||
{
|
{
|
||||||
zval *input, /* Input array */
|
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) {
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a", &input) == FAILURE) {
|
||||||
return;
|
return;
|
||||||
@ -2579,12 +2533,10 @@ PHP_FUNCTION(array_values)
|
|||||||
array_init_size(return_value, zend_hash_num_elements(Z_ARRVAL_P(input)));
|
array_init_size(return_value, zend_hash_num_elements(Z_ARRVAL_P(input)));
|
||||||
|
|
||||||
/* Go through input array and add values to the return array */
|
/* Go through input array and add values to the return array */
|
||||||
zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(input), &pos);
|
ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(input), entry) {
|
||||||
while ((entry = zend_hash_get_current_data_ex(Z_ARRVAL_P(input), &pos)) != NULL) {
|
|
||||||
zval_add_ref(entry);
|
zval_add_ref(entry);
|
||||||
zend_hash_next_index_insert(Z_ARRVAL_P(return_value), entry);
|
zend_hash_next_index_insert(Z_ARRVAL_P(return_value), entry);
|
||||||
zend_hash_move_forward_ex(Z_ARRVAL_P(input), &pos);
|
} ZEND_HASH_FOREACH_END();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
@ -2596,7 +2548,6 @@ PHP_FUNCTION(array_count_values)
|
|||||||
*entry, /* An entry in the input array */
|
*entry, /* An entry in the input array */
|
||||||
*tmp;
|
*tmp;
|
||||||
HashTable *myht;
|
HashTable *myht;
|
||||||
HashPosition pos;
|
|
||||||
|
|
||||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a", &input) == FAILURE) {
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a", &input) == FAILURE) {
|
||||||
return;
|
return;
|
||||||
@ -2607,8 +2558,7 @@ PHP_FUNCTION(array_count_values)
|
|||||||
|
|
||||||
/* Go through input array and add values to the return array */
|
/* Go through input array and add values to the return array */
|
||||||
myht = Z_ARRVAL_P(input);
|
myht = Z_ARRVAL_P(input);
|
||||||
zend_hash_internal_pointer_reset_ex(myht, &pos);
|
ZEND_HASH_FOREACH_VAL(myht, entry) {
|
||||||
while ((entry = zend_hash_get_current_data_ex(myht, &pos)) != NULL) {
|
|
||||||
if (Z_TYPE_P(entry) == IS_LONG) {
|
if (Z_TYPE_P(entry) == IS_LONG) {
|
||||||
if ((tmp = zend_hash_index_find(Z_ARRVAL_P(return_value), Z_LVAL_P(entry))) == NULL) {
|
if ((tmp = zend_hash_index_find(Z_ARRVAL_P(return_value), Z_LVAL_P(entry))) == NULL) {
|
||||||
zval data;
|
zval data;
|
||||||
@ -2628,9 +2578,7 @@ PHP_FUNCTION(array_count_values)
|
|||||||
} else {
|
} else {
|
||||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Can only count STRING and INTEGER values!");
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Can only count STRING and INTEGER values!");
|
||||||
}
|
}
|
||||||
|
} ZEND_HASH_FOREACH_END();
|
||||||
zend_hash_move_forward_ex(myht, &pos);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
@ -2666,7 +2614,6 @@ PHP_FUNCTION(array_column)
|
|||||||
{
|
{
|
||||||
zval *zcolumn = NULL, *zkey = NULL, *data;
|
zval *zcolumn = NULL, *zkey = NULL, *data;
|
||||||
HashTable *arr_hash;
|
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;
|
return;
|
||||||
@ -2678,9 +2625,7 @@ PHP_FUNCTION(array_column)
|
|||||||
}
|
}
|
||||||
|
|
||||||
array_init(return_value);
|
array_init(return_value);
|
||||||
for (zend_hash_internal_pointer_reset_ex(arr_hash, &pointer);
|
ZEND_HASH_FOREACH_VAL(arr_hash, data) {
|
||||||
(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;
|
HashTable *ht;
|
||||||
|
|
||||||
@ -2726,7 +2671,7 @@ PHP_FUNCTION(array_column)
|
|||||||
} else {
|
} else {
|
||||||
add_next_index_zval(return_value, zcolval);
|
add_next_index_zval(return_value, zcolval);
|
||||||
}
|
}
|
||||||
}
|
} ZEND_HASH_FOREACH_END();
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
@ -2739,7 +2684,6 @@ PHP_FUNCTION(array_reverse)
|
|||||||
zend_string *string_key;
|
zend_string *string_key;
|
||||||
ulong num_key;
|
ulong num_key;
|
||||||
zend_bool preserve_keys = 0; /* whether to preserve keys */
|
zend_bool preserve_keys = 0; /* whether to preserve keys */
|
||||||
HashPosition pos;
|
|
||||||
|
|
||||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|b", &input, &preserve_keys) == FAILURE) {
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|b", &input, &preserve_keys) == FAILURE) {
|
||||||
return;
|
return;
|
||||||
@ -2748,26 +2692,19 @@ PHP_FUNCTION(array_reverse)
|
|||||||
/* Initialize return array */
|
/* Initialize return array */
|
||||||
array_init_size(return_value, zend_hash_num_elements(Z_ARRVAL_P(input)));
|
array_init_size(return_value, zend_hash_num_elements(Z_ARRVAL_P(input)));
|
||||||
|
|
||||||
zend_hash_internal_pointer_end_ex(Z_ARRVAL_P(input), &pos);
|
ZEND_HASH_REVERSE_FOREACH_KEY_VAL(Z_ARRVAL_P(input), num_key, string_key, entry) {
|
||||||
while ((entry = zend_hash_get_current_data_ex(Z_ARRVAL_P(input), &pos)) != NULL) {
|
|
||||||
zval_add_ref(entry);
|
zval_add_ref(entry);
|
||||||
|
|
||||||
switch (zend_hash_get_current_key_ex(Z_ARRVAL_P(input), &string_key, &num_key, 0, &pos)) {
|
if (string_key) {
|
||||||
case HASH_KEY_IS_STRING:
|
zend_hash_update(Z_ARRVAL_P(return_value), string_key, entry);
|
||||||
zend_hash_update(Z_ARRVAL_P(return_value), string_key, entry);
|
} else {
|
||||||
break;
|
if (preserve_keys) {
|
||||||
|
zend_hash_index_update(Z_ARRVAL_P(return_value), num_key, entry);
|
||||||
case HASH_KEY_IS_LONG:
|
} else {
|
||||||
if (preserve_keys) {
|
zend_hash_next_index_insert(Z_ARRVAL_P(return_value), entry);
|
||||||
zend_hash_index_update(Z_ARRVAL_P(return_value), num_key, entry);
|
}
|
||||||
} else {
|
|
||||||
zend_hash_next_index_insert(Z_ARRVAL_P(return_value), entry);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
} ZEND_HASH_FOREACH_END();
|
||||||
zend_hash_move_backwards_ex(Z_ARRVAL_P(input), &pos);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
@ -2844,7 +2781,8 @@ PHP_FUNCTION(array_pad)
|
|||||||
PHP_FUNCTION(array_flip)
|
PHP_FUNCTION(array_flip)
|
||||||
{
|
{
|
||||||
zval *array, *entry, data;
|
zval *array, *entry, data;
|
||||||
HashPosition pos;
|
ulong num_idx;
|
||||||
|
zend_string *str_idx;
|
||||||
|
|
||||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a", &array) == FAILURE) {
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a", &array) == FAILURE) {
|
||||||
return;
|
return;
|
||||||
@ -2852,21 +2790,25 @@ PHP_FUNCTION(array_flip)
|
|||||||
|
|
||||||
array_init_size(return_value, zend_hash_num_elements(Z_ARRVAL_P(array)));
|
array_init_size(return_value, zend_hash_num_elements(Z_ARRVAL_P(array)));
|
||||||
|
|
||||||
zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(array), &pos);
|
ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(array), num_idx, str_idx, entry) {
|
||||||
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) {
|
if (Z_TYPE_P(entry) == IS_LONG) {
|
||||||
|
if (str_idx) {
|
||||||
|
ZVAL_STR(&data, STR_COPY(str_idx));
|
||||||
|
} else {
|
||||||
|
ZVAL_LONG(&data, num_idx);
|
||||||
|
}
|
||||||
zend_hash_index_update(Z_ARRVAL_P(return_value), Z_LVAL_P(entry), &data);
|
zend_hash_index_update(Z_ARRVAL_P(return_value), Z_LVAL_P(entry), &data);
|
||||||
} else if (Z_TYPE_P(entry) == IS_STRING) {
|
} else if (Z_TYPE_P(entry) == IS_STRING) {
|
||||||
|
if (str_idx) {
|
||||||
|
ZVAL_STR(&data, STR_COPY(str_idx));
|
||||||
|
} else {
|
||||||
|
ZVAL_LONG(&data, num_idx);
|
||||||
|
}
|
||||||
zend_symtable_update(Z_ARRVAL_P(return_value), Z_STR_P(entry), &data);
|
zend_symtable_update(Z_ARRVAL_P(return_value), Z_STR_P(entry), &data);
|
||||||
} else {
|
} 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!");
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Can only flip STRING and INTEGER values!");
|
||||||
}
|
}
|
||||||
|
} ZEND_HASH_FOREACH_END();
|
||||||
zend_hash_move_forward_ex(Z_ARRVAL_P(array), &pos);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
@ -2879,7 +2821,6 @@ PHP_FUNCTION(array_change_key_case)
|
|||||||
zend_string *new_key;
|
zend_string *new_key;
|
||||||
ulong num_key;
|
ulong num_key;
|
||||||
long change_to_upper=0;
|
long change_to_upper=0;
|
||||||
HashPosition pos;
|
|
||||||
|
|
||||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|l", &array, &change_to_upper) == FAILURE) {
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|l", &array, &change_to_upper) == FAILURE) {
|
||||||
return;
|
return;
|
||||||
@ -2887,28 +2828,22 @@ PHP_FUNCTION(array_change_key_case)
|
|||||||
|
|
||||||
array_init_size(return_value, zend_hash_num_elements(Z_ARRVAL_P(array)));
|
array_init_size(return_value, zend_hash_num_elements(Z_ARRVAL_P(array)));
|
||||||
|
|
||||||
zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(array), &pos);
|
ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(array), num_key, string_key, entry) {
|
||||||
while ((entry = zend_hash_get_current_data_ex(Z_ARRVAL_P(array), &pos)) != NULL) {
|
|
||||||
zval_add_ref(entry);
|
zval_add_ref(entry);
|
||||||
|
|
||||||
switch (zend_hash_get_current_key_ex(Z_ARRVAL_P(array), &string_key, &num_key, 0, &pos)) {
|
if (!string_key) {
|
||||||
case HASH_KEY_IS_LONG:
|
zend_hash_index_update(Z_ARRVAL_P(return_value), num_key, entry);
|
||||||
zend_hash_index_update(Z_ARRVAL_P(return_value), num_key, entry);
|
} else {
|
||||||
break;
|
new_key = STR_INIT(string_key->val, string_key->len, 0);
|
||||||
case HASH_KEY_IS_STRING:
|
if (change_to_upper) {
|
||||||
new_key = STR_INIT(string_key->val, string_key->len, 0);
|
php_strtoupper(new_key->val, new_key->len);
|
||||||
if (change_to_upper) {
|
} else {
|
||||||
php_strtoupper(new_key->val, new_key->len);
|
php_strtolower(new_key->val, new_key->len);
|
||||||
} else {
|
}
|
||||||
php_strtolower(new_key->val, new_key->len);
|
zend_hash_update(Z_ARRVAL_P(return_value), new_key, entry);
|
||||||
}
|
STR_RELEASE(new_key);
|
||||||
zend_hash_update(Z_ARRVAL_P(return_value), new_key, entry);
|
|
||||||
STR_RELEASE(new_key);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
} ZEND_HASH_FOREACH_END();
|
||||||
zend_hash_move_forward_ex(Z_ARRVAL_P(array), &pos);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
@ -4116,10 +4051,9 @@ PHP_FUNCTION(array_rand)
|
|||||||
{
|
{
|
||||||
zval *input;
|
zval *input;
|
||||||
long randval, num_req = 1;
|
long randval, num_req = 1;
|
||||||
int num_avail, key_type;
|
int num_avail;
|
||||||
zend_string *string_key;
|
zend_string *string_key;
|
||||||
ulong num_key;
|
ulong num_key;
|
||||||
HashPosition pos;
|
|
||||||
|
|
||||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|l", &input, &num_req) == FAILURE) {
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|l", &input, &num_req) == FAILURE) {
|
||||||
return;
|
return;
|
||||||
@ -4140,22 +4074,24 @@ PHP_FUNCTION(array_rand)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* We can't use zend_hash_index_find() because the array may have string keys or gaps. */
|
/* 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);
|
ZEND_HASH_FOREACH_KEY(Z_ARRVAL_P(input), num_key, string_key) {
|
||||||
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) {
|
if (!num_req) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
randval = php_rand(TSRMLS_C);
|
randval = php_rand(TSRMLS_C);
|
||||||
|
|
||||||
if ((double) (randval / (PHP_RAND_MAX + 1.0)) < (double) num_req / (double) num_avail) {
|
if ((double) (randval / (PHP_RAND_MAX + 1.0)) < (double) num_req / (double) num_avail) {
|
||||||
/* If we are returning a single result, just do it. */
|
/* If we are returning a single result, just do it. */
|
||||||
if (Z_TYPE_P(return_value) != IS_ARRAY) {
|
if (Z_TYPE_P(return_value) != IS_ARRAY) {
|
||||||
if (key_type == HASH_KEY_IS_STRING) {
|
if (string_key) {
|
||||||
RETURN_STR(STR_COPY(string_key));
|
RETURN_STR(STR_COPY(string_key));
|
||||||
} else {
|
} else {
|
||||||
RETURN_LONG(num_key);
|
RETURN_LONG(num_key);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* Append the result to the return value. */
|
/* Append the result to the return value. */
|
||||||
if (key_type == HASH_KEY_IS_STRING) {
|
if (string_key) {
|
||||||
add_next_index_str(return_value, STR_COPY(string_key));
|
add_next_index_str(return_value, STR_COPY(string_key));
|
||||||
} else {
|
} else {
|
||||||
add_next_index_long(return_value, num_key);
|
add_next_index_long(return_value, num_key);
|
||||||
@ -4164,8 +4100,7 @@ PHP_FUNCTION(array_rand)
|
|||||||
num_req--;
|
num_req--;
|
||||||
}
|
}
|
||||||
num_avail--;
|
num_avail--;
|
||||||
zend_hash_move_forward_ex(Z_ARRVAL_P(input), &pos);
|
} ZEND_HASH_FOREACH_END();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
@ -4176,7 +4111,6 @@ PHP_FUNCTION(array_sum)
|
|||||||
zval *input,
|
zval *input,
|
||||||
*entry,
|
*entry,
|
||||||
entry_n;
|
entry_n;
|
||||||
HashPosition pos;
|
|
||||||
|
|
||||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a", &input) == FAILURE) {
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a", &input) == FAILURE) {
|
||||||
return;
|
return;
|
||||||
@ -4184,17 +4118,14 @@ PHP_FUNCTION(array_sum)
|
|||||||
|
|
||||||
ZVAL_LONG(return_value, 0);
|
ZVAL_LONG(return_value, 0);
|
||||||
|
|
||||||
for (zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(input), &pos);
|
ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(input), entry) {
|
||||||
(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_P(entry) == IS_ARRAY || Z_TYPE_P(entry) == IS_OBJECT) {
|
if (Z_TYPE_P(entry) == IS_ARRAY || Z_TYPE_P(entry) == IS_OBJECT) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
ZVAL_DUP(&entry_n, entry);
|
ZVAL_DUP(&entry_n, entry);
|
||||||
convert_scalar_to_number(&entry_n TSRMLS_CC);
|
convert_scalar_to_number(&entry_n TSRMLS_CC);
|
||||||
fast_add_function(return_value, return_value, &entry_n TSRMLS_CC);
|
fast_add_function(return_value, return_value, &entry_n TSRMLS_CC);
|
||||||
}
|
} ZEND_HASH_FOREACH_END();
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
@ -4205,7 +4136,6 @@ PHP_FUNCTION(array_product)
|
|||||||
zval *input,
|
zval *input,
|
||||||
*entry,
|
*entry,
|
||||||
entry_n;
|
entry_n;
|
||||||
HashPosition pos;
|
|
||||||
double dval;
|
double dval;
|
||||||
|
|
||||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a", &input) == FAILURE) {
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a", &input) == FAILURE) {
|
||||||
@ -4217,10 +4147,7 @@ PHP_FUNCTION(array_product)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(input), &pos);
|
ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(input), entry) {
|
||||||
(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_P(entry) == IS_ARRAY || Z_TYPE_P(entry) == IS_OBJECT) {
|
if (Z_TYPE_P(entry) == IS_ARRAY || Z_TYPE_P(entry) == IS_OBJECT) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -4237,7 +4164,7 @@ PHP_FUNCTION(array_product)
|
|||||||
convert_to_double(return_value);
|
convert_to_double(return_value);
|
||||||
convert_to_double(&entry_n);
|
convert_to_double(&entry_n);
|
||||||
Z_DVAL_P(return_value) *= Z_DVAL(entry_n);
|
Z_DVAL_P(return_value) *= Z_DVAL(entry_n);
|
||||||
}
|
} ZEND_HASH_FOREACH_END();
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
@ -4253,7 +4180,6 @@ PHP_FUNCTION(array_reduce)
|
|||||||
zend_fcall_info fci;
|
zend_fcall_info fci;
|
||||||
zend_fcall_info_cache fci_cache = empty_fcall_info_cache;
|
zend_fcall_info_cache fci_cache = empty_fcall_info_cache;
|
||||||
zval *initial = NULL;
|
zval *initial = NULL;
|
||||||
HashPosition pos;
|
|
||||||
HashTable *htbl;
|
HashTable *htbl;
|
||||||
|
|
||||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "af|z", &input, &fci, &fci_cache, &initial) == FAILURE) {
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "af|z", &input, &fci, &fci_cache, &initial) == FAILURE) {
|
||||||
@ -4280,8 +4206,7 @@ PHP_FUNCTION(array_reduce)
|
|||||||
fci.param_count = 2;
|
fci.param_count = 2;
|
||||||
fci.no_separation = 0;
|
fci.no_separation = 0;
|
||||||
|
|
||||||
zend_hash_internal_pointer_reset_ex(htbl, &pos);
|
ZEND_HASH_FOREACH_VAL(htbl, operand) {
|
||||||
while ((operand = zend_hash_get_current_data_ex(htbl, &pos)) != NULL) {
|
|
||||||
ZVAL_COPY_VALUE(&args[0], &result);
|
ZVAL_COPY_VALUE(&args[0], &result);
|
||||||
ZVAL_COPY_VALUE(&args[1], operand);
|
ZVAL_COPY_VALUE(&args[1], operand);
|
||||||
fci.params = args;
|
fci.params = args;
|
||||||
@ -4293,8 +4218,8 @@ PHP_FUNCTION(array_reduce)
|
|||||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "An error occurred while invoking the reduction callback");
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "An error occurred while invoking the reduction callback");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
zend_hash_move_forward_ex(htbl, &pos);
|
} ZEND_HASH_FOREACH_END();
|
||||||
}
|
|
||||||
RETVAL_ZVAL(&result, 1, 1);
|
RETVAL_ZVAL(&result, 1, 1);
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
@ -4313,7 +4238,6 @@ PHP_FUNCTION(array_filter)
|
|||||||
zend_fcall_info fci = empty_fcall_info;
|
zend_fcall_info fci = empty_fcall_info;
|
||||||
zend_fcall_info_cache fci_cache = empty_fcall_info_cache;
|
zend_fcall_info_cache fci_cache = empty_fcall_info_cache;
|
||||||
ulong num_key;
|
ulong num_key;
|
||||||
HashPosition pos;
|
|
||||||
|
|
||||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|fl", &array, &fci, &fci_cache, &use_type) == FAILURE) {
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|fl", &array, &fci, &fci_cache, &use_type) == FAILURE) {
|
||||||
return;
|
return;
|
||||||
@ -4331,32 +4255,23 @@ PHP_FUNCTION(array_filter)
|
|||||||
fci.param_count = 1;
|
fci.param_count = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(array), &pos);
|
ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(array), num_key, string_key, operand) {
|
||||||
(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, &num_key, 0, &pos);
|
|
||||||
|
|
||||||
if (have_callback) {
|
if (have_callback) {
|
||||||
if (use_type) {
|
if (use_type) {
|
||||||
/* Set up the key */
|
/* Set up the key */
|
||||||
switch (key_type) {
|
if (!string_key) {
|
||||||
case HASH_KEY_IS_LONG:
|
if (use_type == ARRAY_FILTER_USE_BOTH) {
|
||||||
if (use_type == ARRAY_FILTER_USE_BOTH) {
|
fci.param_count = 2;
|
||||||
fci.param_count = 2;
|
ZVAL_LONG(&args[1], num_key);
|
||||||
ZVAL_LONG(&args[1], num_key);
|
} else if (use_type == ARRAY_FILTER_USE_KEY) {
|
||||||
} else if (use_type == ARRAY_FILTER_USE_KEY) {
|
ZVAL_LONG(&args[0], num_key);
|
||||||
ZVAL_LONG(&args[0], num_key);
|
}
|
||||||
}
|
} else {
|
||||||
break;
|
if (use_type == ARRAY_FILTER_USE_BOTH) {
|
||||||
|
ZVAL_STR(&args[1], STR_COPY(string_key));
|
||||||
case HASH_KEY_IS_STRING:
|
} else if (use_type == ARRAY_FILTER_USE_KEY) {
|
||||||
if (use_type == ARRAY_FILTER_USE_BOTH) {
|
ZVAL_STR(&args[0], STR_COPY(string_key));
|
||||||
ZVAL_STR(&args[1], STR_COPY(string_key));
|
}
|
||||||
} else if (use_type == ARRAY_FILTER_USE_KEY) {
|
|
||||||
ZVAL_STR(&args[0], STR_COPY(string_key));
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (use_type != ARRAY_FILTER_USE_KEY) {
|
if (use_type != ARRAY_FILTER_USE_KEY) {
|
||||||
@ -4392,16 +4307,12 @@ PHP_FUNCTION(array_filter)
|
|||||||
}
|
}
|
||||||
|
|
||||||
zval_add_ref(operand);
|
zval_add_ref(operand);
|
||||||
switch (key_type) {
|
if (string_key) {
|
||||||
case HASH_KEY_IS_STRING:
|
zend_hash_update(Z_ARRVAL_P(return_value), string_key, operand);
|
||||||
zend_hash_update(Z_ARRVAL_P(return_value), string_key, operand);
|
} else {
|
||||||
break;
|
zend_hash_index_update(Z_ARRVAL_P(return_value), num_key, operand);
|
||||||
|
|
||||||
case HASH_KEY_IS_LONG:
|
|
||||||
zend_hash_index_update(Z_ARRVAL_P(return_value), num_key, operand);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
} ZEND_HASH_FOREACH_END();
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
@ -4584,7 +4495,6 @@ PHP_FUNCTION(array_chunk)
|
|||||||
zval *input = NULL;
|
zval *input = NULL;
|
||||||
zval chunk;
|
zval chunk;
|
||||||
zval *entry;
|
zval *entry;
|
||||||
HashPosition pos;
|
|
||||||
|
|
||||||
if (zend_parse_parameters(argc TSRMLS_CC, "al|b", &input, &size, &preserve_keys) == FAILURE) {
|
if (zend_parse_parameters(argc TSRMLS_CC, "al|b", &input, &size, &preserve_keys) == FAILURE) {
|
||||||
return;
|
return;
|
||||||
@ -4604,8 +4514,8 @@ PHP_FUNCTION(array_chunk)
|
|||||||
array_init_size(return_value, ((num_in - 1) / size) + 1);
|
array_init_size(return_value, ((num_in - 1) / size) + 1);
|
||||||
|
|
||||||
ZVAL_UNDEF(&chunk);
|
ZVAL_UNDEF(&chunk);
|
||||||
zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(input), &pos);
|
|
||||||
while ((entry = zend_hash_get_current_data_ex(Z_ARRVAL_P(input), &pos)) != NULL) {
|
ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(input), num_key, str_key, entry) {
|
||||||
/* If new chunk, create and initialize it. */
|
/* If new chunk, create and initialize it. */
|
||||||
if (Z_TYPE(chunk) == IS_UNDEF) {
|
if (Z_TYPE(chunk) == IS_UNDEF) {
|
||||||
array_init_size(&chunk, size);
|
array_init_size(&chunk, size);
|
||||||
@ -4615,14 +4525,10 @@ PHP_FUNCTION(array_chunk)
|
|||||||
zval_add_ref(entry);
|
zval_add_ref(entry);
|
||||||
|
|
||||||
if (preserve_keys) {
|
if (preserve_keys) {
|
||||||
key_type = zend_hash_get_current_key_ex(Z_ARRVAL_P(input), &str_key, &num_key, 0, &pos);
|
if (str_key) {
|
||||||
switch (key_type) {
|
zend_hash_update(Z_ARRVAL(chunk), str_key, entry);
|
||||||
case HASH_KEY_IS_STRING:
|
} else {
|
||||||
zend_hash_update(Z_ARRVAL(chunk), str_key, entry);
|
add_index_zval(&chunk, num_key, entry);
|
||||||
break;
|
|
||||||
default:
|
|
||||||
add_index_zval(&chunk, num_key, entry);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
add_next_index_zval(&chunk, entry);
|
add_next_index_zval(&chunk, entry);
|
||||||
@ -4634,9 +4540,7 @@ PHP_FUNCTION(array_chunk)
|
|||||||
add_next_index_zval(return_value, &chunk);
|
add_next_index_zval(return_value, &chunk);
|
||||||
ZVAL_UNDEF(&chunk);
|
ZVAL_UNDEF(&chunk);
|
||||||
}
|
}
|
||||||
|
} ZEND_HASH_FOREACH_END();
|
||||||
zend_hash_move_forward_ex(Z_ARRVAL_P(input), &pos);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Add the final chunk if there is one. */
|
/* Add the final chunk if there is one. */
|
||||||
if (Z_TYPE(chunk) != IS_UNDEF) {
|
if (Z_TYPE(chunk) != IS_UNDEF) {
|
||||||
|
@ -4281,11 +4281,8 @@ PHP_FUNCTION(getopt)
|
|||||||
* and a trailing NULL */
|
* and a trailing NULL */
|
||||||
argv = (char **) safe_emalloc(sizeof(char *), (argc + 1), 0);
|
argv = (char **) safe_emalloc(sizeof(char *), (argc + 1), 0);
|
||||||
|
|
||||||
/* Reset the array indexes. */
|
|
||||||
zend_hash_internal_pointer_reset(Z_ARRVAL_P(args));
|
|
||||||
|
|
||||||
/* Iterate over the hash to construct the argv array. */
|
/* Iterate over the hash to construct the argv array. */
|
||||||
while ((entry = zend_hash_get_current_data(Z_ARRVAL_P(args))) != NULL) {
|
ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(args), entry) {
|
||||||
zval arg, *arg_ptr = entry;
|
zval arg, *arg_ptr = entry;
|
||||||
|
|
||||||
if (Z_TYPE_P(entry) != IS_STRING) {
|
if (Z_TYPE_P(entry) != IS_STRING) {
|
||||||
@ -4299,9 +4296,7 @@ PHP_FUNCTION(getopt)
|
|||||||
if (arg_ptr != entry) {
|
if (arg_ptr != entry) {
|
||||||
zval_dtor(&arg);
|
zval_dtor(&arg);
|
||||||
}
|
}
|
||||||
|
} ZEND_HASH_FOREACH_END();
|
||||||
zend_hash_move_forward(Z_ARRVAL_P(args));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* The C Standard requires argv[argc] to be NULL - this might
|
/* The C Standard requires argv[argc] to be NULL - this might
|
||||||
* keep some getopt implementations happy. */
|
* keep some getopt implementations happy. */
|
||||||
@ -4327,11 +4322,8 @@ PHP_FUNCTION(getopt)
|
|||||||
|
|
||||||
memset(opts, 0, count * sizeof(opt_struct));
|
memset(opts, 0, count * sizeof(opt_struct));
|
||||||
|
|
||||||
/* Reset the array indexes. */
|
|
||||||
zend_hash_internal_pointer_reset(Z_ARRVAL_P(p_longopts));
|
|
||||||
|
|
||||||
/* Iterate over the hash to construct the argv array. */
|
/* Iterate over the hash to construct the argv array. */
|
||||||
while ((entry = zend_hash_get_current_data(Z_ARRVAL_P(p_longopts))) != NULL) {
|
ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(p_longopts), entry) {
|
||||||
zval arg, *arg_ptr = entry;
|
zval arg, *arg_ptr = entry;
|
||||||
|
|
||||||
if (Z_TYPE_P(entry) != IS_STRING) {
|
if (Z_TYPE_P(entry) != IS_STRING) {
|
||||||
@ -4357,9 +4349,7 @@ PHP_FUNCTION(getopt)
|
|||||||
if (arg_ptr != entry) {
|
if (arg_ptr != entry) {
|
||||||
zval_dtor(&arg);
|
zval_dtor(&arg);
|
||||||
}
|
}
|
||||||
|
} ZEND_HASH_FOREACH_END();
|
||||||
zend_hash_move_forward(Z_ARRVAL_P(p_longopts));
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
opts = (opt_struct*) erealloc(opts, sizeof(opt_struct) * (len + 1));
|
opts = (opt_struct*) erealloc(opts, sizeof(opt_struct) * (len + 1));
|
||||||
orig_opts = opts;
|
orig_opts = opts;
|
||||||
@ -4877,13 +4867,10 @@ PHP_FUNCTION(call_user_method_array)
|
|||||||
num_elems = zend_hash_num_elements(params_ar);
|
num_elems = zend_hash_num_elements(params_ar);
|
||||||
method_args = (zval *) safe_emalloc(sizeof(zval), num_elems, 0);
|
method_args = (zval *) safe_emalloc(sizeof(zval), num_elems, 0);
|
||||||
|
|
||||||
for (zend_hash_internal_pointer_reset(params_ar);
|
ZEND_HASH_FOREACH_VAL(params_ar, zv) {
|
||||||
(zv = zend_hash_get_current_data(params_ar)) != NULL;
|
|
||||||
zend_hash_move_forward(params_ar)
|
|
||||||
) {
|
|
||||||
ZVAL_COPY_VALUE(&method_args[element], zv);
|
ZVAL_COPY_VALUE(&method_args[element], zv);
|
||||||
element++;
|
element++;
|
||||||
}
|
} ZEND_HASH_FOREACH_END();
|
||||||
|
|
||||||
if (call_user_function_ex(EG(function_table), object, callback, &retval, num_elems, method_args, 0, NULL TSRMLS_CC) == SUCCESS) {
|
if (call_user_function_ex(EG(function_table), object, callback, &retval, num_elems, method_args, 0, NULL TSRMLS_CC) == SUCCESS) {
|
||||||
if (Z_TYPE(retval) != IS_UNDEF) {
|
if (Z_TYPE(retval) != IS_UNDEF) {
|
||||||
|
@ -647,10 +647,8 @@ PHP_FUNCTION(file_put_contents)
|
|||||||
if (zend_hash_num_elements(Z_ARRVAL_P(data))) {
|
if (zend_hash_num_elements(Z_ARRVAL_P(data))) {
|
||||||
int bytes_written;
|
int bytes_written;
|
||||||
zval *tmp;
|
zval *tmp;
|
||||||
HashPosition pos;
|
|
||||||
|
|
||||||
zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(data), &pos);
|
ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(data), tmp) {
|
||||||
while ((tmp = zend_hash_get_current_data_ex(Z_ARRVAL_P(data), &pos)) != NULL) {
|
|
||||||
if (Z_TYPE_P(tmp) != IS_STRING) {
|
if (Z_TYPE_P(tmp) != IS_STRING) {
|
||||||
SEPARATE_ZVAL(tmp);
|
SEPARATE_ZVAL(tmp);
|
||||||
convert_to_string(tmp);
|
convert_to_string(tmp);
|
||||||
@ -668,8 +666,7 @@ PHP_FUNCTION(file_put_contents)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
zend_hash_move_forward_ex(Z_ARRVAL_P(data), &pos);
|
} ZEND_HASH_FOREACH_END();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -1882,11 +1879,9 @@ PHPAPI int php_fputcsv(php_stream *stream, zval *fields, char delimiter, char en
|
|||||||
int count, i = 0, ret;
|
int count, i = 0, ret;
|
||||||
zval *field_tmp = NULL, field;
|
zval *field_tmp = NULL, field;
|
||||||
smart_str csvline = {0};
|
smart_str csvline = {0};
|
||||||
HashPosition pos;
|
|
||||||
|
|
||||||
count = zend_hash_num_elements(Z_ARRVAL_P(fields));
|
count = zend_hash_num_elements(Z_ARRVAL_P(fields));
|
||||||
zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(fields), &pos);
|
ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(fields), field_tmp) {
|
||||||
while ((field_tmp = zend_hash_get_current_data_ex(Z_ARRVAL_P(fields), &pos)) != NULL) {
|
|
||||||
ZVAL_COPY_VALUE(&field, field_tmp);
|
ZVAL_COPY_VALUE(&field, field_tmp);
|
||||||
|
|
||||||
if (Z_TYPE(field) != IS_STRING) {
|
if (Z_TYPE(field) != IS_STRING) {
|
||||||
@ -1927,12 +1922,10 @@ PHPAPI int php_fputcsv(php_stream *stream, zval *fields, char delimiter, char en
|
|||||||
if (++i != count) {
|
if (++i != count) {
|
||||||
smart_str_appendl(&csvline, &delimiter, 1);
|
smart_str_appendl(&csvline, &delimiter, 1);
|
||||||
}
|
}
|
||||||
zend_hash_move_forward_ex(Z_ARRVAL_P(fields), &pos);
|
|
||||||
|
|
||||||
if (Z_TYPE_P(field_tmp) != IS_STRING) {
|
if (Z_TYPE_P(field_tmp) != IS_STRING) {
|
||||||
zval_dtor(&field);
|
zval_dtor(&field);
|
||||||
}
|
}
|
||||||
}
|
} ZEND_HASH_FOREACH_END();
|
||||||
|
|
||||||
smart_str_appendc(&csvline, '\n');
|
smart_str_appendc(&csvline, '\n');
|
||||||
smart_str_0(&csvline);
|
smart_str_0(&csvline);
|
||||||
|
@ -258,17 +258,14 @@ static php_stream_filter *strfilter_strip_tags_create(const char *filtername, zv
|
|||||||
|
|
||||||
if (filterparams != NULL) {
|
if (filterparams != NULL) {
|
||||||
if (Z_TYPE_P(filterparams) == IS_ARRAY) {
|
if (Z_TYPE_P(filterparams) == IS_ARRAY) {
|
||||||
HashPosition pos;
|
|
||||||
zval *tmp;
|
zval *tmp;
|
||||||
|
|
||||||
zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(filterparams), &pos);
|
ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(filterparams), tmp) {
|
||||||
while ((tmp = zend_hash_get_current_data_ex(Z_ARRVAL_P(filterparams), &pos)) != NULL) {
|
|
||||||
convert_to_string_ex(tmp);
|
convert_to_string_ex(tmp);
|
||||||
smart_str_appendc(&tags_ss, '<');
|
smart_str_appendc(&tags_ss, '<');
|
||||||
smart_str_appendl(&tags_ss, Z_STRVAL_P(tmp), Z_STRLEN_P(tmp));
|
smart_str_appendl(&tags_ss, Z_STRVAL_P(tmp), Z_STRLEN_P(tmp));
|
||||||
smart_str_appendc(&tags_ss, '>');
|
smart_str_appendc(&tags_ss, '>');
|
||||||
zend_hash_move_forward_ex(Z_ARRVAL_P(filterparams), &pos);
|
} ZEND_HASH_FOREACH_END();
|
||||||
}
|
|
||||||
smart_str_0(&tags_ss);
|
smart_str_0(&tags_ss);
|
||||||
} else {
|
} else {
|
||||||
/* FIXME: convert_to_* may clutter zvals and lead it into segfault ? */
|
/* FIXME: convert_to_* may clutter zvals and lead it into segfault ? */
|
||||||
|
@ -404,12 +404,10 @@ php_formatted_print(int param_count, int use_array, int format_offset TSRMLS_DC)
|
|||||||
newargs = (zval *)safe_emalloc(argc, sizeof(zval), 0);
|
newargs = (zval *)safe_emalloc(argc, sizeof(zval), 0);
|
||||||
ZVAL_COPY_VALUE(&newargs[0], z_format);
|
ZVAL_COPY_VALUE(&newargs[0], z_format);
|
||||||
|
|
||||||
for (zend_hash_internal_pointer_reset(Z_ARRVAL_P(array));
|
ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(array), zv) {
|
||||||
(zv = zend_hash_get_current_data(Z_ARRVAL_P(array))) != NULL;
|
|
||||||
zend_hash_move_forward(Z_ARRVAL_P(array))) {
|
|
||||||
ZVAL_COPY_VALUE(&newargs[i], zv);
|
ZVAL_COPY_VALUE(&newargs[i], zv);
|
||||||
i++;
|
i++;
|
||||||
}
|
} ZEND_HASH_FOREACH_END();
|
||||||
args = newargs;
|
args = newargs;
|
||||||
format_offset = 0;
|
format_offset = 0;
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ PHPAPI int php_url_encode_hash_ex(HashTable *ht, smart_str *formstr,
|
|||||||
{
|
{
|
||||||
zend_string *key = NULL;
|
zend_string *key = NULL;
|
||||||
char *newprefix, *p, *prop_name;
|
char *newprefix, *p, *prop_name;
|
||||||
int arg_sep_len, key_type, newprefix_len, prop_len;
|
int arg_sep_len, newprefix_len, prop_len;
|
||||||
ulong idx;
|
ulong idx;
|
||||||
zval *zdata = NULL, copyzval;
|
zval *zdata = NULL, copyzval;
|
||||||
|
|
||||||
@ -54,10 +54,7 @@ PHPAPI int php_url_encode_hash_ex(HashTable *ht, smart_str *formstr,
|
|||||||
}
|
}
|
||||||
arg_sep_len = strlen(arg_sep);
|
arg_sep_len = strlen(arg_sep);
|
||||||
|
|
||||||
for (zend_hash_internal_pointer_reset(ht);
|
ZEND_HASH_FOREACH_KEY_VAL_IND(ht, idx, key, zdata) {
|
||||||
(key_type = zend_hash_get_current_key(ht, &key, &idx, 0)) != HASH_KEY_NON_EXISTENT;
|
|
||||||
zend_hash_move_forward(ht)
|
|
||||||
) {
|
|
||||||
/* handling for private & protected object properties */
|
/* handling for private & protected object properties */
|
||||||
if (key) {
|
if (key) {
|
||||||
if (key->val[0] == '\0' && type != NULL) {
|
if (key->val[0] == '\0' && type != NULL) {
|
||||||
@ -78,18 +75,8 @@ PHPAPI int php_url_encode_hash_ex(HashTable *ht, smart_str *formstr,
|
|||||||
prop_len = 0;
|
prop_len = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((zdata = zend_hash_get_current_data(ht)) == NULL) {
|
|
||||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Error traversing form data array");
|
|
||||||
return FAILURE;
|
|
||||||
}
|
|
||||||
if (Z_TYPE_P(zdata) == IS_INDIRECT) {
|
|
||||||
zdata = Z_INDIRECT_P(zdata);
|
|
||||||
if (Z_TYPE_P(zdata) == IS_UNDEF) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (Z_TYPE_P(zdata) == IS_ARRAY || Z_TYPE_P(zdata) == IS_OBJECT) {
|
if (Z_TYPE_P(zdata) == IS_ARRAY || Z_TYPE_P(zdata) == IS_OBJECT) {
|
||||||
if (key_type == HASH_KEY_IS_STRING) {
|
if (key) {
|
||||||
zend_string *ekey;
|
zend_string *ekey;
|
||||||
if (enc_type == PHP_QUERY_RFC3986) {
|
if (enc_type == PHP_QUERY_RFC3986) {
|
||||||
ekey = php_raw_url_encode(prop_name, prop_len);
|
ekey = php_raw_url_encode(prop_name, prop_len);
|
||||||
@ -160,7 +147,7 @@ PHPAPI int php_url_encode_hash_ex(HashTable *ht, smart_str *formstr,
|
|||||||
}
|
}
|
||||||
/* Simple key=value */
|
/* Simple key=value */
|
||||||
smart_str_appendl(formstr, key_prefix, key_prefix_len);
|
smart_str_appendl(formstr, key_prefix, key_prefix_len);
|
||||||
if (key_type == HASH_KEY_IS_STRING) {
|
if (key) {
|
||||||
zend_string *ekey;
|
zend_string *ekey;
|
||||||
if (enc_type == PHP_QUERY_RFC3986) {
|
if (enc_type == PHP_QUERY_RFC3986) {
|
||||||
ekey = php_raw_url_encode(prop_name, prop_len);
|
ekey = php_raw_url_encode(prop_name, prop_len);
|
||||||
@ -230,7 +217,7 @@ PHPAPI int php_url_encode_hash_ex(HashTable *ht, smart_str *formstr,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} ZEND_HASH_FOREACH_END();
|
||||||
|
|
||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -237,12 +237,9 @@ php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper,
|
|||||||
char *s, *p;
|
char *s, *p;
|
||||||
|
|
||||||
if (Z_TYPE_P(tmpzval) == IS_ARRAY) {
|
if (Z_TYPE_P(tmpzval) == IS_ARRAY) {
|
||||||
HashPosition pos;
|
|
||||||
zval *tmpheader = NULL;
|
zval *tmpheader = NULL;
|
||||||
|
|
||||||
for (zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(tmpzval), &pos);
|
ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(tmpzval), tmpheader) {
|
||||||
NULL != (tmpheader = zend_hash_get_current_data_ex(Z_ARRVAL_P(tmpzval), &pos));
|
|
||||||
zend_hash_move_forward_ex(Z_ARRVAL_P(tmpzval), &pos)) {
|
|
||||||
if (Z_TYPE_P(tmpheader) == IS_STRING) {
|
if (Z_TYPE_P(tmpheader) == IS_STRING) {
|
||||||
s = Z_STRVAL_P(tmpheader);
|
s = Z_STRVAL_P(tmpheader);
|
||||||
do {
|
do {
|
||||||
@ -266,7 +263,7 @@ php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper,
|
|||||||
while (*s == '\r' || *s == '\n') s++;
|
while (*s == '\r' || *s == '\n') s++;
|
||||||
} while (*s != 0);
|
} while (*s != 0);
|
||||||
}
|
}
|
||||||
}
|
} ZEND_HASH_FOREACH_END();
|
||||||
} else if (Z_TYPE_P(tmpzval) == IS_STRING && Z_STRLEN_P(tmpzval)) {
|
} else if (Z_TYPE_P(tmpzval) == IS_STRING && Z_STRLEN_P(tmpzval)) {
|
||||||
s = Z_STRVAL_P(tmpzval);
|
s = Z_STRVAL_P(tmpzval);
|
||||||
do {
|
do {
|
||||||
@ -423,19 +420,15 @@ finish:
|
|||||||
tmp = NULL;
|
tmp = NULL;
|
||||||
|
|
||||||
if (Z_TYPE_P(tmpzval) == IS_ARRAY) {
|
if (Z_TYPE_P(tmpzval) == IS_ARRAY) {
|
||||||
HashPosition pos;
|
|
||||||
zval *tmpheader = NULL;
|
zval *tmpheader = NULL;
|
||||||
smart_str tmpstr = {0};
|
smart_str tmpstr = {0};
|
||||||
|
|
||||||
for (zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(tmpzval), &pos);
|
ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(tmpzval), tmpheader) {
|
||||||
NULL != (tmpheader = zend_hash_get_current_data_ex(Z_ARRVAL_P(tmpzval), &pos));
|
|
||||||
zend_hash_move_forward_ex(Z_ARRVAL_P(tmpzval), &pos)
|
|
||||||
) {
|
|
||||||
if (Z_TYPE_P(tmpheader) == IS_STRING) {
|
if (Z_TYPE_P(tmpheader) == IS_STRING) {
|
||||||
smart_str_appendl(&tmpstr, Z_STRVAL_P(tmpheader), Z_STRLEN_P(tmpheader));
|
smart_str_appendl(&tmpstr, Z_STRVAL_P(tmpheader), Z_STRLEN_P(tmpheader));
|
||||||
smart_str_appendl(&tmpstr, "\r\n", sizeof("\r\n") - 1);
|
smart_str_appendl(&tmpstr, "\r\n", sizeof("\r\n") - 1);
|
||||||
}
|
}
|
||||||
}
|
} ZEND_HASH_FOREACH_END();
|
||||||
smart_str_0(&tmpstr);
|
smart_str_0(&tmpstr);
|
||||||
/* Remove newlines and spaces from start and end. there's at least one extra \r\n at the end that needs to go. */
|
/* Remove newlines and spaces from start and end. there's at least one extra \r\n at the end that needs to go. */
|
||||||
if (tmpstr.s) {
|
if (tmpstr.s) {
|
||||||
|
@ -85,7 +85,6 @@ static php_process_env_t _php_array_to_envp(zval *environment, int is_persistent
|
|||||||
uint cnt, l, sizeenv=0, el_len;
|
uint cnt, l, sizeenv=0, el_len;
|
||||||
ulong num_key;
|
ulong num_key;
|
||||||
HashTable *target_hash;
|
HashTable *target_hash;
|
||||||
HashPosition pos;
|
|
||||||
|
|
||||||
memset(&env, 0, sizeof(env));
|
memset(&env, 0, sizeof(env));
|
||||||
|
|
||||||
@ -109,10 +108,7 @@ static php_process_env_t _php_array_to_envp(zval *environment, int is_persistent
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* first, we have to get the size of all the elements in the hash */
|
/* first, we have to get the size of all the elements in the hash */
|
||||||
for (zend_hash_internal_pointer_reset_ex(target_hash, &pos);
|
ZEND_HASH_FOREACH_KEY_VAL(target_hash, num_key, string_key, element) {
|
||||||
(element = zend_hash_get_current_data_ex(target_hash, &pos)) != NULL;
|
|
||||||
zend_hash_move_forward_ex(target_hash, &pos)) {
|
|
||||||
|
|
||||||
convert_to_string_ex(element);
|
convert_to_string_ex(element);
|
||||||
el_len = Z_STRLEN_P(element);
|
el_len = Z_STRLEN_P(element);
|
||||||
if (el_len == 0) {
|
if (el_len == 0) {
|
||||||
@ -121,25 +117,20 @@ static php_process_env_t _php_array_to_envp(zval *environment, int is_persistent
|
|||||||
|
|
||||||
sizeenv += el_len+1;
|
sizeenv += el_len+1;
|
||||||
|
|
||||||
switch (zend_hash_get_current_key_ex(target_hash, &string_key, &num_key, 0, &pos)) {
|
if (string_key) {
|
||||||
case HASH_KEY_IS_STRING:
|
if (string_key->len == 0) {
|
||||||
if (string_key->len == 0) {
|
continue;
|
||||||
continue;
|
}
|
||||||
}
|
sizeenv += string_key->len + 2;
|
||||||
sizeenv += string_key->len + 2;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
} ZEND_HASH_FOREACH_END();
|
||||||
|
|
||||||
#ifndef PHP_WIN32
|
#ifndef PHP_WIN32
|
||||||
ep = env.envarray = (char **) pecalloc(cnt + 1, sizeof(char *), is_persistent);
|
ep = env.envarray = (char **) pecalloc(cnt + 1, sizeof(char *), is_persistent);
|
||||||
#endif
|
#endif
|
||||||
p = env.envp = (char *) pecalloc(sizeenv + 4, 1, is_persistent);
|
p = env.envp = (char *) pecalloc(sizeenv + 4, 1, is_persistent);
|
||||||
|
|
||||||
for (zend_hash_internal_pointer_reset_ex(target_hash, &pos);
|
ZEND_HASH_FOREACH_KEY_VAL(target_hash, num_key, string_key, element) {
|
||||||
(element = zend_hash_get_current_data_ex(target_hash, &pos)) != NULL;
|
|
||||||
zend_hash_move_forward_ex(target_hash, &pos)) {
|
|
||||||
|
|
||||||
convert_to_string_ex(element);
|
convert_to_string_ex(element);
|
||||||
el_len = Z_STRLEN_P(element);
|
el_len = Z_STRLEN_P(element);
|
||||||
|
|
||||||
@ -148,40 +139,34 @@ static php_process_env_t _php_array_to_envp(zval *environment, int is_persistent
|
|||||||
}
|
}
|
||||||
|
|
||||||
data = Z_STRVAL_P(element);
|
data = Z_STRVAL_P(element);
|
||||||
switch (zend_hash_get_current_key_ex(target_hash, &string_key, &num_key, 0, &pos)) {
|
|
||||||
case HASH_KEY_IS_STRING:
|
|
||||||
if (string_key->len == 0) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
l = string_key->len + el_len + 2;
|
if (string_key) {
|
||||||
memcpy(p, string_key->val, string_key->len);
|
if (string_key->len == 0) {
|
||||||
strncat(p, "=", 1);
|
continue;
|
||||||
strncat(p, data, el_len);
|
}
|
||||||
|
|
||||||
|
l = string_key->len + el_len + 2;
|
||||||
|
memcpy(p, string_key->val, string_key->len);
|
||||||
|
strncat(p, "=", 1);
|
||||||
|
strncat(p, data, el_len);
|
||||||
|
|
||||||
#ifndef PHP_WIN32
|
#ifndef PHP_WIN32
|
||||||
*ep = p;
|
*ep = p;
|
||||||
++ep;
|
++ep;
|
||||||
#endif
|
#endif
|
||||||
p += l;
|
p += l;
|
||||||
break;
|
} else {
|
||||||
case HASH_KEY_IS_LONG:
|
memcpy(p,data,el_len);
|
||||||
memcpy(p,data,el_len);
|
|
||||||
#ifndef PHP_WIN32
|
#ifndef PHP_WIN32
|
||||||
*ep = p;
|
*ep = p;
|
||||||
++ep;
|
++ep;
|
||||||
#endif
|
#endif
|
||||||
p += el_len + 1;
|
p += el_len + 1;
|
||||||
break;
|
|
||||||
case HASH_KEY_NON_EXISTENT:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
} ZEND_HASH_FOREACH_END();
|
||||||
|
|
||||||
assert((uint)(p - env.envp) <= sizeenv);
|
assert((uint)(p - env.envp) <= sizeenv);
|
||||||
|
|
||||||
zend_hash_internal_pointer_reset_ex(target_hash, &pos);
|
|
||||||
|
|
||||||
return env;
|
return env;
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
@ -442,7 +427,8 @@ PHP_FUNCTION(proc_open)
|
|||||||
int ndesc = 0;
|
int ndesc = 0;
|
||||||
int i;
|
int i;
|
||||||
zval *descitem = NULL;
|
zval *descitem = NULL;
|
||||||
HashPosition pos;
|
zend_string *str_index;
|
||||||
|
ulong nindex;
|
||||||
struct php_proc_open_descriptor_item descriptors[PHP_PROC_OPEN_MAX_DESCRIPTORS];
|
struct php_proc_open_descriptor_item descriptors[PHP_PROC_OPEN_MAX_DESCRIPTORS];
|
||||||
#ifdef PHP_WIN32
|
#ifdef PHP_WIN32
|
||||||
PROCESS_INFORMATION pi;
|
PROCESS_INFORMATION pi;
|
||||||
@ -519,15 +505,9 @@ PHP_FUNCTION(proc_open)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* walk the descriptor spec and set up files/pipes */
|
/* walk the descriptor spec and set up files/pipes */
|
||||||
zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(descriptorspec), &pos);
|
ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(descriptorspec), nindex, str_index, descitem) {
|
||||||
while ((descitem = zend_hash_get_current_data_ex(Z_ARRVAL_P(descriptorspec), &pos)) != NULL) {
|
|
||||||
zend_string *str_index;
|
|
||||||
ulong nindex;
|
|
||||||
zval *ztype;
|
zval *ztype;
|
||||||
|
|
||||||
str_index = NULL;
|
|
||||||
zend_hash_get_current_key_ex(Z_ARRVAL_P(descriptorspec), &str_index, &nindex, 0, &pos);
|
|
||||||
|
|
||||||
if (str_index) {
|
if (str_index) {
|
||||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "descriptor spec must be an integer indexed array");
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "descriptor spec must be an integer indexed array");
|
||||||
goto exit_fail;
|
goto exit_fail;
|
||||||
@ -685,10 +665,9 @@ PHP_FUNCTION(proc_open)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
zend_hash_move_forward_ex(Z_ARRVAL_P(descriptorspec), &pos);
|
|
||||||
if (++ndesc == PHP_PROC_OPEN_MAX_DESCRIPTORS)
|
if (++ndesc == PHP_PROC_OPEN_MAX_DESCRIPTORS)
|
||||||
break;
|
break;
|
||||||
}
|
} ZEND_HASH_FOREACH_END();
|
||||||
|
|
||||||
#ifdef PHP_WIN32
|
#ifdef PHP_WIN32
|
||||||
if (cwd == NULL) {
|
if (cwd == NULL) {
|
||||||
|
@ -555,14 +555,10 @@ PHP_FUNCTION(stream_get_transports)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ((stream_xport_hash = php_stream_xport_get_hash())) {
|
if ((stream_xport_hash = php_stream_xport_get_hash())) {
|
||||||
HashPosition pos;
|
|
||||||
array_init(return_value);
|
array_init(return_value);
|
||||||
zend_hash_internal_pointer_reset_ex(stream_xport_hash, &pos);
|
ZEND_HASH_FOREACH_KEY(stream_xport_hash, num_key, stream_xport) {
|
||||||
while (zend_hash_get_current_key_ex(stream_xport_hash,
|
|
||||||
&stream_xport, &num_key, 0, &pos) == HASH_KEY_IS_STRING) {
|
|
||||||
add_next_index_str(return_value, STR_COPY(stream_xport));
|
add_next_index_str(return_value, STR_COPY(stream_xport));
|
||||||
zend_hash_move_forward_ex(stream_xport_hash, &pos);
|
} ZEND_HASH_FOREACH_END();
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
RETURN_FALSE;
|
RETURN_FALSE;
|
||||||
}
|
}
|
||||||
@ -583,15 +579,12 @@ PHP_FUNCTION(stream_get_wrappers)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ((url_stream_wrappers_hash = php_stream_get_url_stream_wrappers_hash())) {
|
if ((url_stream_wrappers_hash = php_stream_get_url_stream_wrappers_hash())) {
|
||||||
HashPosition pos;
|
|
||||||
array_init(return_value);
|
array_init(return_value);
|
||||||
for (zend_hash_internal_pointer_reset_ex(url_stream_wrappers_hash, &pos);
|
ZEND_HASH_FOREACH_KEY(url_stream_wrappers_hash, num_key, stream_protocol) {
|
||||||
(key_flags = zend_hash_get_current_key_ex(url_stream_wrappers_hash, &stream_protocol, &num_key, 0, &pos)) != HASH_KEY_NON_EXISTENT;
|
if (key_flags == HASH_KEY_IS_STRING) {
|
||||||
zend_hash_move_forward_ex(url_stream_wrappers_hash, &pos)) {
|
add_next_index_str(return_value, STR_COPY(stream_protocol));
|
||||||
if (key_flags == HASH_KEY_IS_STRING) {
|
}
|
||||||
add_next_index_str(return_value, STR_COPY(stream_protocol));
|
} ZEND_HASH_FOREACH_END();
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
RETURN_FALSE;
|
RETURN_FALSE;
|
||||||
}
|
}
|
||||||
@ -610,10 +603,7 @@ static int stream_array_to_fd_set(zval *stream_array, fd_set *fds, php_socket_t
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (zend_hash_internal_pointer_reset(Z_ARRVAL_P(stream_array));
|
ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(stream_array), elem) {
|
||||||
(elem = zend_hash_get_current_data(Z_ARRVAL_P(stream_array))) != NULL;
|
|
||||||
zend_hash_move_forward(Z_ARRVAL_P(stream_array))) {
|
|
||||||
|
|
||||||
/* Temporary int fd is needed for the STREAM data type on windows, passing this_fd directly to php_stream_cast()
|
/* Temporary int fd is needed for the STREAM data type on windows, passing this_fd directly to php_stream_cast()
|
||||||
would eventually bring a wrong result on x64. php_stream_cast() casts to int internally, and this will leave
|
would eventually bring a wrong result on x64. php_stream_cast() casts to int internally, and this will leave
|
||||||
the higher bits of a SOCKET variable uninitialized on systems with little endian. */
|
the higher bits of a SOCKET variable uninitialized on systems with little endian. */
|
||||||
@ -639,7 +629,8 @@ static int stream_array_to_fd_set(zval *stream_array, fd_set *fds, php_socket_t
|
|||||||
}
|
}
|
||||||
cnt++;
|
cnt++;
|
||||||
}
|
}
|
||||||
}
|
} ZEND_HASH_FOREACH_END();
|
||||||
|
|
||||||
return cnt ? 1 : 0;
|
return cnt ? 1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -648,6 +639,8 @@ static int stream_array_from_fd_set(zval *stream_array, fd_set *fds TSRMLS_DC)
|
|||||||
zval *elem, *dest_elem, new_array;
|
zval *elem, *dest_elem, new_array;
|
||||||
php_stream *stream;
|
php_stream *stream;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
zend_string *key;
|
||||||
|
ulong num_ind;
|
||||||
|
|
||||||
if (Z_TYPE_P(stream_array) != IS_ARRAY) {
|
if (Z_TYPE_P(stream_array) != IS_ARRAY) {
|
||||||
return 0;
|
return 0;
|
||||||
@ -655,26 +648,12 @@ static int stream_array_from_fd_set(zval *stream_array, fd_set *fds TSRMLS_DC)
|
|||||||
ZVAL_NEW_ARR(&new_array);
|
ZVAL_NEW_ARR(&new_array);
|
||||||
zend_hash_init(Z_ARRVAL(new_array), zend_hash_num_elements(Z_ARRVAL_P(stream_array)), NULL, ZVAL_PTR_DTOR, 0);
|
zend_hash_init(Z_ARRVAL(new_array), zend_hash_num_elements(Z_ARRVAL_P(stream_array)), NULL, ZVAL_PTR_DTOR, 0);
|
||||||
|
|
||||||
for (zend_hash_internal_pointer_reset(Z_ARRVAL_P(stream_array));
|
ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(stream_array), num_ind, key, elem) {
|
||||||
zend_hash_has_more_elements(Z_ARRVAL_P(stream_array)) == SUCCESS;
|
|
||||||
zend_hash_move_forward(Z_ARRVAL_P(stream_array))) {
|
|
||||||
|
|
||||||
int type;
|
|
||||||
zend_string *key;
|
|
||||||
ulong num_ind;
|
|
||||||
/* Temporary int fd is needed for the STREAM data type on windows, passing this_fd directly to php_stream_cast()
|
/* Temporary int fd is needed for the STREAM data type on windows, passing this_fd directly to php_stream_cast()
|
||||||
would eventually bring a wrong result on x64. php_stream_cast() casts to int internally, and this will leave
|
would eventually bring a wrong result on x64. php_stream_cast() casts to int internally, and this will leave
|
||||||
the higher bits of a SOCKET variable uninitialized on systems with little endian. */
|
the higher bits of a SOCKET variable uninitialized on systems with little endian. */
|
||||||
int tmp_fd;
|
int tmp_fd;
|
||||||
|
|
||||||
|
|
||||||
type = zend_hash_get_current_key(Z_ARRVAL_P(stream_array),
|
|
||||||
&key, &num_ind, 0);
|
|
||||||
if (type == HASH_KEY_NON_EXISTENT ||
|
|
||||||
(elem = zend_hash_get_current_data(Z_ARRVAL_P(stream_array))) == NULL) {
|
|
||||||
continue; /* should not happen */
|
|
||||||
}
|
|
||||||
|
|
||||||
php_stream_from_zval_no_verify(stream, elem);
|
php_stream_from_zval_no_verify(stream, elem);
|
||||||
if (stream == NULL) {
|
if (stream == NULL) {
|
||||||
continue;
|
continue;
|
||||||
@ -689,9 +668,9 @@ static int stream_array_from_fd_set(zval *stream_array, fd_set *fds TSRMLS_DC)
|
|||||||
php_socket_t this_fd = (php_socket_t)tmp_fd;
|
php_socket_t this_fd = (php_socket_t)tmp_fd;
|
||||||
|
|
||||||
if (PHP_SAFE_FD_ISSET(this_fd, fds)) {
|
if (PHP_SAFE_FD_ISSET(this_fd, fds)) {
|
||||||
if (type == HASH_KEY_IS_LONG) {
|
if (!key) {
|
||||||
dest_elem = zend_hash_index_update(Z_ARRVAL(new_array), num_ind, elem);
|
dest_elem = zend_hash_index_update(Z_ARRVAL(new_array), num_ind, elem);
|
||||||
} else { /* HASH_KEY_IS_STRING */
|
} else {
|
||||||
dest_elem = zend_hash_update(Z_ARRVAL(new_array), key, elem);
|
dest_elem = zend_hash_update(Z_ARRVAL(new_array), key, elem);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -702,14 +681,13 @@ static int stream_array_from_fd_set(zval *stream_array, fd_set *fds TSRMLS_DC)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} ZEND_HASH_FOREACH_END();
|
||||||
|
|
||||||
/* destroy old array and add new one */
|
/* destroy old array and add new one */
|
||||||
zend_hash_destroy(Z_ARRVAL_P(stream_array));
|
zend_hash_destroy(Z_ARRVAL_P(stream_array));
|
||||||
GC_REMOVE_FROM_BUFFER(Z_ARR_P(stream_array));
|
GC_REMOVE_FROM_BUFFER(Z_ARR_P(stream_array));
|
||||||
efree(Z_ARR_P(stream_array));
|
efree(Z_ARR_P(stream_array));
|
||||||
|
|
||||||
zend_hash_internal_pointer_reset(Z_ARRVAL(new_array));
|
|
||||||
Z_ARR_P(stream_array) = Z_ARR(new_array);
|
Z_ARR_P(stream_array) = Z_ARR(new_array);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
@ -727,10 +705,7 @@ static int stream_array_emulate_read_fd_set(zval *stream_array TSRMLS_DC)
|
|||||||
ZVAL_NEW_ARR(&new_array);
|
ZVAL_NEW_ARR(&new_array);
|
||||||
zend_hash_init(Z_ARRVAL(new_array), zend_hash_num_elements(Z_ARRVAL_P(stream_array)), NULL, ZVAL_PTR_DTOR, 0);
|
zend_hash_init(Z_ARRVAL(new_array), zend_hash_num_elements(Z_ARRVAL_P(stream_array)), NULL, ZVAL_PTR_DTOR, 0);
|
||||||
|
|
||||||
for (zend_hash_internal_pointer_reset(Z_ARRVAL_P(stream_array));
|
ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(stream_array), elem) {
|
||||||
(elem = zend_hash_get_current_data(Z_ARRVAL_P(stream_array))) != NULL;
|
|
||||||
zend_hash_move_forward(Z_ARRVAL_P(stream_array))) {
|
|
||||||
|
|
||||||
php_stream_from_zval_no_verify(stream, elem);
|
php_stream_from_zval_no_verify(stream, elem);
|
||||||
if (stream == NULL) {
|
if (stream == NULL) {
|
||||||
continue;
|
continue;
|
||||||
@ -749,14 +724,12 @@ static int stream_array_emulate_read_fd_set(zval *stream_array TSRMLS_DC)
|
|||||||
ret++;
|
ret++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
} ZEND_HASH_FOREACH_END();
|
||||||
|
|
||||||
if (ret > 0) {
|
if (ret > 0) {
|
||||||
/* destroy old array and add new one */
|
/* destroy old array and add new one */
|
||||||
zend_hash_destroy(Z_ARRVAL_P(stream_array));
|
zend_hash_destroy(Z_ARRVAL_P(stream_array));
|
||||||
efree(Z_ARR_P(stream_array));
|
efree(Z_ARR_P(stream_array));
|
||||||
|
|
||||||
zend_hash_internal_pointer_reset(Z_ARRVAL(new_array));
|
|
||||||
Z_ARR_P(stream_array) = Z_ARR(new_array);
|
Z_ARR_P(stream_array) = Z_ARR(new_array);
|
||||||
} else {
|
} else {
|
||||||
zend_hash_destroy(Z_ARRVAL(new_array));
|
zend_hash_destroy(Z_ARRVAL(new_array));
|
||||||
@ -911,31 +884,24 @@ static void user_space_stream_notifier_dtor(php_stream_notifier *notifier)
|
|||||||
|
|
||||||
static int parse_context_options(php_stream_context *context, zval *options TSRMLS_DC)
|
static int parse_context_options(php_stream_context *context, zval *options TSRMLS_DC)
|
||||||
{
|
{
|
||||||
HashPosition pos, opos;
|
|
||||||
zval *wval, *oval;
|
zval *wval, *oval;
|
||||||
zend_string *wkey, *okey;
|
zend_string *wkey, *okey;
|
||||||
int ret = SUCCESS;
|
int ret = SUCCESS;
|
||||||
ulong num_key;
|
ulong num_key;
|
||||||
|
|
||||||
zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(options), &pos);
|
ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(options), num_key, wkey, wval) {
|
||||||
while (NULL != (wval = zend_hash_get_current_data_ex(Z_ARRVAL_P(options), &pos))) {
|
if (wkey && Z_TYPE_P(wval) == IS_ARRAY) {
|
||||||
if (HASH_KEY_IS_STRING == zend_hash_get_current_key_ex(Z_ARRVAL_P(options), &wkey, &num_key, 0, &pos)
|
|
||||||
&& Z_TYPE_P(wval) == IS_ARRAY) {
|
|
||||||
|
|
||||||
zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(wval), &opos);
|
ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(wval), num_key, okey, oval) {
|
||||||
while (NULL != (oval = zend_hash_get_current_data_ex(Z_ARRVAL_P(wval), &opos))) {
|
if (okey) {
|
||||||
|
|
||||||
if (HASH_KEY_IS_STRING == zend_hash_get_current_key_ex(Z_ARRVAL_P(wval), &okey, &num_key, 0, &opos)) {
|
|
||||||
php_stream_context_set_option(context, wkey->val, okey->val, oval);
|
php_stream_context_set_option(context, wkey->val, okey->val, oval);
|
||||||
}
|
}
|
||||||
zend_hash_move_forward_ex(Z_ARRVAL_P(wval), &opos);
|
} ZEND_HASH_FOREACH_END();
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "options should have the form [\"wrappername\"][\"optionname\"] = $value");
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "options should have the form [\"wrappername\"][\"optionname\"] = $value");
|
||||||
}
|
}
|
||||||
zend_hash_move_forward_ex(Z_ARRVAL_P(options), &pos);
|
} ZEND_HASH_FOREACH_END();
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -1121,7 +1121,6 @@ PHP_FUNCTION(explode)
|
|||||||
PHPAPI void php_implode(zval *delim, zval *arr, zval *return_value TSRMLS_DC)
|
PHPAPI void php_implode(zval *delim, zval *arr, zval *return_value TSRMLS_DC)
|
||||||
{
|
{
|
||||||
zval *tmp;
|
zval *tmp;
|
||||||
HashPosition pos;
|
|
||||||
smart_str implstr = {0};
|
smart_str implstr = {0};
|
||||||
int numelems, i = 0;
|
int numelems, i = 0;
|
||||||
zval tmp_val;
|
zval tmp_val;
|
||||||
@ -1133,9 +1132,7 @@ PHPAPI void php_implode(zval *delim, zval *arr, zval *return_value TSRMLS_DC)
|
|||||||
RETURN_EMPTY_STRING();
|
RETURN_EMPTY_STRING();
|
||||||
}
|
}
|
||||||
|
|
||||||
zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(arr), &pos);
|
ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(arr), tmp) {
|
||||||
|
|
||||||
while ((tmp = zend_hash_get_current_data_ex(Z_ARRVAL_P(arr), &pos)) != NULL) {
|
|
||||||
again:
|
again:
|
||||||
switch (Z_TYPE_P(tmp)) {
|
switch (Z_TYPE_P(tmp)) {
|
||||||
case IS_STRING:
|
case IS_STRING:
|
||||||
@ -1191,8 +1188,8 @@ again:
|
|||||||
if (++i != numelems) {
|
if (++i != numelems) {
|
||||||
smart_str_appendl(&implstr, Z_STRVAL_P(delim), Z_STRLEN_P(delim));
|
smart_str_appendl(&implstr, Z_STRVAL_P(delim), Z_STRLEN_P(delim));
|
||||||
}
|
}
|
||||||
zend_hash_move_forward_ex(Z_ARRVAL_P(arr), &pos);
|
} ZEND_HASH_FOREACH_END();
|
||||||
}
|
|
||||||
smart_str_0(&implstr);
|
smart_str_0(&implstr);
|
||||||
|
|
||||||
if (implstr.s) {
|
if (implstr.s) {
|
||||||
@ -2871,56 +2868,49 @@ static void php_strtr_free_strp(void *strp)
|
|||||||
static PATNREPL *php_strtr_array_prepare_repls(int slen, HashTable *pats, zend_llist **allocs, int *outsize)
|
static PATNREPL *php_strtr_array_prepare_repls(int slen, HashTable *pats, zend_llist **allocs, int *outsize)
|
||||||
{
|
{
|
||||||
PATNREPL *patterns;
|
PATNREPL *patterns;
|
||||||
HashPosition hpos;
|
|
||||||
zval *entry;
|
zval *entry;
|
||||||
int num_pats = zend_hash_num_elements(pats),
|
int num_pats = zend_hash_num_elements(pats),
|
||||||
i;
|
i = 0;
|
||||||
|
zend_string *string_key;
|
||||||
|
ulong num_key;
|
||||||
|
|
||||||
patterns = safe_emalloc(num_pats, sizeof(*patterns), 0);
|
patterns = safe_emalloc(num_pats, sizeof(*patterns), 0);
|
||||||
*allocs = emalloc(sizeof **allocs);
|
*allocs = emalloc(sizeof **allocs);
|
||||||
zend_llist_init(*allocs, sizeof(zend_string*), &php_strtr_free_strp, 0);
|
zend_llist_init(*allocs, sizeof(zend_string*), &php_strtr_free_strp, 0);
|
||||||
|
|
||||||
for (i = 0, zend_hash_internal_pointer_reset_ex(pats, &hpos);
|
ZEND_HASH_FOREACH_KEY_VAL(pats, num_key, string_key, entry) {
|
||||||
(entry = zend_hash_get_current_data_ex(pats, &hpos)) != NULL;
|
|
||||||
zend_hash_move_forward_ex(pats, &hpos)) {
|
|
||||||
zend_string *string_key;
|
|
||||||
ulong num_key;
|
|
||||||
zval tzv;
|
zval tzv;
|
||||||
|
|
||||||
switch (zend_hash_get_current_key_ex(pats, &string_key, &num_key, 0, &hpos)) {
|
if (!string_key) {
|
||||||
case HASH_KEY_IS_LONG: {
|
|
||||||
char buf[MAX_LENGTH_OF_LONG];
|
char buf[MAX_LENGTH_OF_LONG];
|
||||||
int len = snprintf(buf, sizeof(buf), "%ld", num_key);
|
int len = snprintf(buf, sizeof(buf), "%ld", num_key);
|
||||||
string_key = STR_INIT(buf, len, 0);
|
string_key = STR_INIT(buf, len, 0);
|
||||||
zend_llist_add_element(*allocs, &string_key);
|
zend_llist_add_element(*allocs, &string_key);
|
||||||
/* break missing intentionally */
|
|
||||||
}
|
|
||||||
case HASH_KEY_IS_STRING:
|
|
||||||
if (string_key->len == 0) { /* empty string given as pattern */
|
|
||||||
efree(patterns);
|
|
||||||
zend_llist_destroy(*allocs);
|
|
||||||
efree(*allocs);
|
|
||||||
*allocs = NULL;
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
if (string_key->len > slen) { /* this pattern can never match */
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Z_TYPE_P(entry) != IS_STRING) {
|
|
||||||
ZVAL_DUP(&tzv, entry);
|
|
||||||
convert_to_string(&tzv);
|
|
||||||
entry = &tzv;
|
|
||||||
zend_llist_add_element(*allocs, &Z_STR_P(entry));
|
|
||||||
}
|
|
||||||
|
|
||||||
S(&patterns[i].pat) = string_key->val;
|
|
||||||
L(&patterns[i].pat) = string_key->len;
|
|
||||||
S(&patterns[i].repl) = Z_STRVAL_P(entry);
|
|
||||||
L(&patterns[i].repl) = Z_STRLEN_P(entry);
|
|
||||||
i++;
|
|
||||||
}
|
}
|
||||||
}
|
if (string_key->len == 0) { /* empty string given as pattern */
|
||||||
|
efree(patterns);
|
||||||
|
zend_llist_destroy(*allocs);
|
||||||
|
efree(*allocs);
|
||||||
|
*allocs = NULL;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
if (string_key->len > slen) { /* this pattern can never match */
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Z_TYPE_P(entry) != IS_STRING) {
|
||||||
|
ZVAL_DUP(&tzv, entry);
|
||||||
|
convert_to_string(&tzv);
|
||||||
|
entry = &tzv;
|
||||||
|
zend_llist_add_element(*allocs, &Z_STR_P(entry));
|
||||||
|
}
|
||||||
|
|
||||||
|
S(&patterns[i].pat) = string_key->val;
|
||||||
|
L(&patterns[i].pat) = string_key->len;
|
||||||
|
S(&patterns[i].repl) = Z_STRVAL_P(entry);
|
||||||
|
L(&patterns[i].repl) = Z_STRLEN_P(entry);
|
||||||
|
i++;
|
||||||
|
} ZEND_HASH_FOREACH_END();
|
||||||
|
|
||||||
*outsize = i;
|
*outsize = i;
|
||||||
return patterns;
|
return patterns;
|
||||||
|
@ -694,7 +694,6 @@ PHP_FUNCTION(get_headers)
|
|||||||
php_stream_context *context;
|
php_stream_context *context;
|
||||||
php_stream *stream;
|
php_stream *stream;
|
||||||
zval *prev_val, *hdr = NULL, *h;
|
zval *prev_val, *hdr = NULL, *h;
|
||||||
HashPosition pos;
|
|
||||||
HashTable *hashT;
|
HashTable *hashT;
|
||||||
long format = 0;
|
long format = 0;
|
||||||
|
|
||||||
@ -726,10 +725,8 @@ PHP_FUNCTION(get_headers)
|
|||||||
hashT = HASH_OF(&stream->wrapperdata);
|
hashT = HASH_OF(&stream->wrapperdata);
|
||||||
}
|
}
|
||||||
|
|
||||||
zend_hash_internal_pointer_reset_ex(hashT, &pos);
|
ZEND_HASH_FOREACH_VAL(hashT, hdr) {
|
||||||
while ((hdr = zend_hash_get_current_data_ex(hashT, &pos)) != NULL) {
|
if (Z_TYPE_P(hdr) != IS_STRING) {
|
||||||
if (!hdr || Z_TYPE_P(hdr) != IS_STRING) {
|
|
||||||
zend_hash_move_forward_ex(hashT, &pos);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!format) {
|
if (!format) {
|
||||||
@ -759,8 +756,7 @@ no_name_header:
|
|||||||
goto no_name_header;
|
goto no_name_header;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
zend_hash_move_forward_ex(hashT, &pos);
|
} ZEND_HASH_FOREACH_END();
|
||||||
}
|
|
||||||
|
|
||||||
php_stream_close(stream);
|
php_stream_close(stream);
|
||||||
}
|
}
|
||||||
|
@ -543,12 +543,11 @@ PHP_FUNCTION(stream_get_filters)
|
|||||||
filters_hash = php_get_stream_filters_hash();
|
filters_hash = php_get_stream_filters_hash();
|
||||||
|
|
||||||
if (filters_hash) {
|
if (filters_hash) {
|
||||||
for(zend_hash_internal_pointer_reset(filters_hash);
|
ZEND_HASH_FOREACH_VAL(filters_hash, key_flags) {
|
||||||
(key_flags = zend_hash_get_current_key(filters_hash, &filter_name, &num_key, 0)) != HASH_KEY_NON_EXISTENT;
|
if (key_flags == HASH_KEY_IS_STRING) {
|
||||||
zend_hash_move_forward(filters_hash))
|
add_next_index_str(return_value, STR_COPY(filter_name));
|
||||||
if (key_flags == HASH_KEY_IS_STRING) {
|
}
|
||||||
add_next_index_str(return_value, STR_COPY(filter_name));
|
} ZEND_HASH_FOREACH_END();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/* It's okay to return an empty array if no filters are registered */
|
/* It's okay to return an empty array if no filters are registered */
|
||||||
}
|
}
|
||||||
|
@ -717,27 +717,18 @@ static void php_var_serialize_class(smart_str *buf, zval *struc, zval *retval_pt
|
|||||||
zend_string *key;
|
zend_string *key;
|
||||||
zval *d, *name;
|
zval *d, *name;
|
||||||
ulong index;
|
ulong index;
|
||||||
HashPosition pos;
|
|
||||||
int i;
|
int i;
|
||||||
zval nval, *nvalp;
|
zval nval, *nvalp;
|
||||||
HashTable *propers;
|
HashTable *propers, *ht;
|
||||||
|
|
||||||
ZVAL_NULL(&nval);
|
ZVAL_NULL(&nval);
|
||||||
nvalp = &nval;
|
nvalp = &nval;
|
||||||
|
|
||||||
zend_hash_internal_pointer_reset_ex(HASH_OF(retval_ptr), &pos);
|
ht = HASH_OF(retval_ptr);
|
||||||
|
ZEND_HASH_FOREACH_KEY_VAL(ht, index, key, name) {
|
||||||
for (;; zend_hash_move_forward_ex(HASH_OF(retval_ptr), &pos)) {
|
|
||||||
i = zend_hash_get_current_key_ex(HASH_OF(retval_ptr), &key, &index, 0, &pos);
|
|
||||||
|
|
||||||
if (i == HASH_KEY_NON_EXISTENT) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (incomplete_class && strcmp(key->val, MAGIC_MEMBER) == 0) {
|
if (incomplete_class && strcmp(key->val, MAGIC_MEMBER) == 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
name = zend_hash_get_current_data_ex(HASH_OF(retval_ptr), &pos);
|
|
||||||
|
|
||||||
if (Z_TYPE_P(name) != IS_STRING) {
|
if (Z_TYPE_P(name) != IS_STRING) {
|
||||||
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "__sleep should return an array only containing the names of instance-variables to serialize.");
|
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "__sleep should return an array only containing the names of instance-variables to serialize.");
|
||||||
@ -802,7 +793,7 @@ static void php_var_serialize_class(smart_str *buf, zval *struc, zval *retval_pt
|
|||||||
php_var_serialize_intern(buf, nvalp, var_hash TSRMLS_CC);
|
php_var_serialize_intern(buf, nvalp, var_hash TSRMLS_CC);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} ZEND_HASH_FOREACH_END();
|
||||||
}
|
}
|
||||||
smart_str_appendc(buf, '}');
|
smart_str_appendc(buf, '}');
|
||||||
}
|
}
|
||||||
@ -954,32 +945,17 @@ again:
|
|||||||
zend_string *key;
|
zend_string *key;
|
||||||
zval *data;
|
zval *data;
|
||||||
ulong index;
|
ulong index;
|
||||||
HashPosition pos;
|
|
||||||
|
|
||||||
zend_hash_internal_pointer_reset_ex(myht, &pos);
|
ZEND_HASH_FOREACH_KEY_VAL_IND(myht, index, key, data) {
|
||||||
for (;; zend_hash_move_forward_ex(myht, &pos)) {
|
|
||||||
data = zend_hash_get_current_data_ex(myht, &pos);
|
|
||||||
if (!data) {
|
|
||||||
break;
|
|
||||||
} else if (Z_TYPE_P(data) == IS_INDIRECT) {
|
|
||||||
data = Z_INDIRECT_P(data);
|
|
||||||
if (Z_TYPE_P(data) == IS_UNDEF) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
i = zend_hash_get_current_key_ex(myht, &key, &index, 0, &pos);
|
|
||||||
if (incomplete_class && strcmp(key->val, MAGIC_MEMBER) == 0) {
|
if (incomplete_class && strcmp(key->val, MAGIC_MEMBER) == 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (i) {
|
if (!key) {
|
||||||
case HASH_KEY_IS_LONG:
|
php_var_serialize_long(buf, index);
|
||||||
php_var_serialize_long(buf, index);
|
} else {
|
||||||
break;
|
php_var_serialize_string(buf, key->val, key->len);
|
||||||
case HASH_KEY_IS_STRING:
|
|
||||||
php_var_serialize_string(buf, key->val, key->len);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* we should still add element even if it's not OK,
|
/* we should still add element even if it's not OK,
|
||||||
@ -997,7 +973,7 @@ again:
|
|||||||
Z_ARRVAL_P(data)->nApplyCount--;
|
Z_ARRVAL_P(data)->nApplyCount--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} ZEND_HASH_FOREACH_END();
|
||||||
}
|
}
|
||||||
smart_str_appendc(buf, '}');
|
smart_str_appendc(buf, '}');
|
||||||
return;
|
return;
|
||||||
|
Loading…
Reference in New Issue
Block a user