Browse Source

Use new zend_hash API

pull/686/head
Dmitry Stogov 12 years ago
parent
commit
e34a6e9211
  1. 28
      Zend/zend_API.c
  2. 15
      Zend/zend_builtin_functions.c
  3. 2
      Zend/zend_execute.c
  4. 2
      Zend/zend_list.c
  5. 2
      Zend/zend_operators.c

28
Zend/zend_API.c

@ -1095,31 +1095,25 @@ ZEND_API int _array_init(zval *arg, uint size ZEND_FILE_LINE_DC) /* {{{ */
}
/* }}} */
static int zend_merge_property(zval *value TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key) /* {{{ */
{
/* which name should a numeric property have ? */
if (hash_key->key) {
zval *obj = va_arg(args, zval *);
zend_object_handlers *obj_ht = va_arg(args, zend_object_handlers *);
zval member;
ZVAL_STR(&member, STR_COPY(hash_key->key));
obj_ht->write_property(obj, &member, value, -1 TSRMLS_CC);
zval_ptr_dtor(&member);
}
return ZEND_HASH_APPLY_KEEP;
}
/* }}} */
/* This function should be called after the constructor has been called
* because it may call __set from the uninitialized object otherwise. */
ZEND_API void zend_merge_properties(zval *obj, HashTable *properties, int destroy_ht TSRMLS_DC) /* {{{ */
{
const zend_object_handlers *obj_ht = Z_OBJ_HT_P(obj);
zend_class_entry *old_scope = EG(scope);
zend_string *key;
zval *value;
EG(scope) = Z_OBJCE_P(obj);
zend_hash_apply_with_arguments(properties TSRMLS_CC, zend_merge_property, 2, obj, obj_ht);
ZEND_HASH_FOREACH_STR_KEY_VAL(properties, key, value) {
if (key) {
zval member;
ZVAL_STR(&member, STR_COPY(key));
obj_ht->write_property(obj, &member, value, -1 TSRMLS_CC);
zval_ptr_dtor(&member);
}
} ZEND_HASH_FOREACH_END();
EG(scope) = old_scope;
if (destroy_ht) {

15
Zend/zend_builtin_functions.c

@ -582,7 +582,6 @@ ZEND_FUNCTION(each)
{
zval *array, *entry, tmp;
ulong num_key;
zval *inserted_pointer;
HashTable *target_hash;
zend_string *key;
@ -609,7 +608,8 @@ ZEND_FUNCTION(each)
}
break;
}
array_init(return_value);
array_init_size(return_value, 4);
zend_hash_real_init(Z_ARRVAL_P(return_value), 0);
/* add value elements */
if (Z_ISREF_P(entry)) {
@ -620,17 +620,18 @@ ZEND_FUNCTION(each)
if (Z_REFCOUNTED_P(entry)) Z_ADDREF_P(entry);
if (Z_REFCOUNTED_P(entry)) Z_ADDREF_P(entry);
}
zend_hash_index_update(Z_ARRVAL_P(return_value), 1, entry);
zend_hash_index_add_new(Z_ARRVAL_P(return_value), 1, entry);
zend_hash_str_add_new(Z_ARRVAL_P(return_value), "value", sizeof("value")-1, entry);
/* add the key elements */
if (zend_hash_get_current_key(target_hash, &key, &num_key, 0) == HASH_KEY_IS_STRING) {
inserted_pointer = add_get_index_str(return_value, 0, STR_COPY(key));
ZVAL_STR(&tmp, STR_COPY(key));
if (Z_REFCOUNTED(tmp)) Z_ADDREF(tmp);
} else {
inserted_pointer = add_get_index_long(return_value, 0, num_key);
ZVAL_LONG(&tmp, num_key);
}
zend_hash_str_add_new(Z_ARRVAL_P(return_value), "key", sizeof("key")-1, inserted_pointer);
if (Z_REFCOUNTED_P(inserted_pointer)) Z_ADDREF_P(inserted_pointer);
zend_hash_index_add_new(Z_ARRVAL_P(return_value), 0, &tmp);
zend_hash_str_add_new(Z_ARRVAL_P(return_value), "key", sizeof("key")-1, &tmp);
zend_hash_move_forward(target_hash);
}
/* }}} */

2
Zend/zend_execute.c

@ -1035,7 +1035,7 @@ num_index:
zend_error(E_NOTICE,"Undefined offset: %ld", hval);
/* break missing intentionally */
case BP_VAR_W:
retval = zend_hash_index_update(ht, hval, &EG(uninitialized_zval));
retval = zend_hash_index_add_new(ht, hval, &EG(uninitialized_zval));
break;
}
}

2
Zend/zend_list.c

@ -41,7 +41,7 @@ ZEND_API zval *zend_list_insert(void *ptr, int type TSRMLS_DC)
index = 1;
}
ZVAL_NEW_RES(&zv, index, ptr, type);
return zend_hash_index_update(&EG(regular_list), index, &zv);
return zend_hash_index_add_new(&EG(regular_list), index, &zv);
}
ZEND_API int _zend_list_delete(zend_resource *res TSRMLS_DC)

2
Zend/zend_operators.c

@ -650,7 +650,7 @@ static void convert_scalar_to_array(zval *op TSRMLS_DC) /* {{{ */
ZVAL_NEW_ARR(op);
zend_hash_init(Z_ARRVAL_P(op), 8, NULL, ZVAL_PTR_DTOR, 0);
zend_hash_index_update(Z_ARRVAL_P(op), 0, &entry);
zend_hash_index_add_new(Z_ARRVAL_P(op), 0, &entry);
}
/* }}} */

Loading…
Cancel
Save