--- embedaddon/php/ext/spl/spl_fixedarray.c 2012/02/21 23:48:01 1.1.1.1 +++ embedaddon/php/ext/spl/spl_fixedarray.c 2013/07/22 01:32:02 1.1.1.3 @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2012 The PHP Group | + | Copyright (c) 1997-2013 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: spl_fixedarray.c,v 1.1.1.1 2012/02/21 23:48:01 misho Exp $ */ +/* $Id: spl_fixedarray.c,v 1.1.1.3 2013/07/22 01:32:02 misho Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -147,31 +147,49 @@ static void spl_fixedarray_copy(spl_fixedarray *to, sp } /* }}} */ +static HashTable* spl_fixedarray_object_get_gc(zval *obj, zval ***table, int *n TSRMLS_DC) /* {{{{ */ +{ + spl_fixedarray_object *intern = (spl_fixedarray_object*)zend_object_store_get_object(obj TSRMLS_CC); + HashTable *ht = zend_std_get_properties(obj TSRMLS_CC); + + if (intern->array) { + *table = intern->array->elements; + *n = intern->array->size; + } else { + *table = NULL; + *n = 0; + } + + return ht; +} +/* }}}} */ + static HashTable* spl_fixedarray_object_get_properties(zval *obj TSRMLS_DC) /* {{{{ */ { spl_fixedarray_object *intern = (spl_fixedarray_object*)zend_object_store_get_object(obj TSRMLS_CC); + HashTable *ht = zend_std_get_properties(obj TSRMLS_CC); int i = 0; - if (intern->array && !GC_G(gc_active)) { - int j = zend_hash_num_elements(intern->std.properties); + if (intern->array) { + int j = zend_hash_num_elements(ht); for (i = 0; i < intern->array->size; i++) { if (intern->array->elements[i]) { - zend_hash_index_update(intern->std.properties, i, (void *)&intern->array->elements[i], sizeof(zval *), NULL); + zend_hash_index_update(ht, i, (void *)&intern->array->elements[i], sizeof(zval *), NULL); Z_ADDREF_P(intern->array->elements[i]); } else { - zend_hash_index_update(intern->std.properties, i, (void *)&EG(uninitialized_zval_ptr), sizeof(zval *), NULL); + zend_hash_index_update(ht, i, (void *)&EG(uninitialized_zval_ptr), sizeof(zval *), NULL); Z_ADDREF_P(EG(uninitialized_zval_ptr)); } } if (j > intern->array->size) { for (i = intern->array->size; i < j; ++i) { - zend_hash_index_del(intern->std.properties, i); + zend_hash_index_del(ht, i); } } } - return intern->std.properties; + return ht; } /* }}}} */ @@ -206,7 +224,6 @@ static zend_object_value spl_fixedarray_object_new_ex( { zend_object_value retval; spl_fixedarray_object *intern; - zval *tmp; zend_class_entry *parent = class_type; int inherited = 0; @@ -215,7 +232,7 @@ static zend_object_value spl_fixedarray_object_new_ex( ALLOC_INIT_ZVAL(intern->retval); zend_object_std_init(&intern->std, class_type TSRMLS_CC); - zend_hash_copy(intern->std.properties, &class_type->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *)); + object_properties_init(&intern->std, class_type); intern->current = 0; intern->flags = 0; @@ -223,10 +240,14 @@ static zend_object_value spl_fixedarray_object_new_ex( if (orig && clone_orig) { spl_fixedarray_object *other = (spl_fixedarray_object*)zend_object_store_get_object(orig TSRMLS_CC); intern->ce_get_iterator = other->ce_get_iterator; - - intern->array = emalloc(sizeof(spl_fixedarray)); - spl_fixedarray_init(intern->array, other->array->size TSRMLS_CC); - spl_fixedarray_copy(intern->array, other->array TSRMLS_CC); + if (!other->array) { + /* leave a empty object, will be dtor later by CLONE handler */ + zend_throw_exception(spl_ce_RuntimeException, "The instance wasn't initialized properly", 0 TSRMLS_CC); + } else { + intern->array = emalloc(sizeof(spl_fixedarray)); + spl_fixedarray_init(intern->array, other->array->size TSRMLS_CC); + spl_fixedarray_copy(intern->array, other->array TSRMLS_CC); + } } while (parent) { @@ -357,7 +378,11 @@ static zval *spl_fixedarray_object_read_dimension(zval if (intern->fptr_offset_get) { zval *rv; - SEPARATE_ARG_IF_REF(offset); + if (!offset) { + ALLOC_INIT_ZVAL(offset); + } else { + SEPARATE_ARG_IF_REF(offset); + } zend_call_method_with_1_params(&object, intern->std.ce, &intern->fptr_offset_get, "offsetGet", &rv, offset); zval_ptr_dtor(&offset); if (rv) { @@ -603,8 +628,6 @@ SPL_METHOD(SplFixedArray, count) SPL_METHOD(SplFixedArray, toArray) { spl_fixedarray_object *intern; - zval *ret, *tmp; - HashTable *ret_ht, *obj_ht; if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "")) { return; @@ -612,15 +635,19 @@ SPL_METHOD(SplFixedArray, toArray) intern = (spl_fixedarray_object *)zend_object_store_get_object(getThis() TSRMLS_CC); - ALLOC_HASHTABLE(ret_ht); - zend_hash_init(ret_ht, 0, NULL, ZVAL_PTR_DTOR, 0); - ALLOC_INIT_ZVAL(ret); - Z_TYPE_P(ret) = IS_ARRAY; - obj_ht = spl_fixedarray_object_get_properties(getThis() TSRMLS_CC); - zend_hash_copy(ret_ht, obj_ht, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *)); - Z_ARRVAL_P(ret) = ret_ht; - - RETURN_ZVAL(ret, 1, 1); + array_init(return_value); + if (intern->array) { + int i = 0; + for (; i < intern->array->size; i++) { + if (intern->array->elements[i]) { + zend_hash_index_update(Z_ARRVAL_P(return_value), i, (void *)&intern->array->elements[i], sizeof(zval *), NULL); + Z_ADDREF_P(intern->array->elements[i]); + } else { + zend_hash_index_update(Z_ARRVAL_P(return_value), i, (void *)&EG(uninitialized_zval_ptr), sizeof(zval *), NULL); + Z_ADDREF_P(EG(uninitialized_zval_ptr)); + } + } + } } /* }}} */ @@ -1090,6 +1117,7 @@ PHP_MINIT_FUNCTION(spl_fixedarray) spl_handler_SplFixedArray.has_dimension = spl_fixedarray_object_has_dimension; spl_handler_SplFixedArray.count_elements = spl_fixedarray_object_count_elements; spl_handler_SplFixedArray.get_properties = spl_fixedarray_object_get_properties; + spl_handler_SplFixedArray.get_gc = spl_fixedarray_object_get_gc; REGISTER_SPL_IMPLEMENTS(SplFixedArray, Iterator); REGISTER_SPL_IMPLEMENTS(SplFixedArray, ArrayAccess);