Skip to content

Commit 78b40b0

Browse files
author
wxxiong6
authored
Update arraylist.c
1 parent 5b880ce commit 78b40b0

File tree

1 file changed

+4
-17
lines changed

1 file changed

+4
-17
lines changed

arraylist.c

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ static void arraylist_init(arraylist *array, zend_long size) /* {{{ */
9393
array->elements = (zval *)ecalloc(size, sizeof(zval));
9494
array->nSize = size;
9595
array->nNextIndex = 0;
96-
// array->nNumUsed = 0;
96+
array->nNumUsed = 0;
9797
}
9898
/* }}} */
9999

@@ -112,11 +112,9 @@ PHP_METHOD(arraylist, __construct)
112112
ZEND_PARSE_PARAMETERS_END();
113113

114114
if (intern->array.nSize > 0) {
115-
/* called __construct() twice, bail out */
116115
return;
117116
}
118117
arraylist_init(&intern->array, size);
119-
120118
}
121119
/* }}} */
122120

@@ -302,15 +300,13 @@ static void arraylist_destruct(arraylist_object *intern)/* {{{ */
302300
{
303301

304302
zend_long i;
305-
printf("size=%zu\n", intern->array.nSize);
306303
if (intern->array.nSize > 0) {
307304
for (i = 0; i < intern->array.nSize; i++) {
308-
if (!Z_ISUNDEF(intern->array.elements[i])) {
305+
if (&(intern->array.elements[i]) != NULL && !Z_ISUNDEF(intern->array.elements[i])) {
309306
zval_ptr_dtor(&(intern->array.elements[i]));
310307
}
311-
312308
}
313-
309+
intern->array.nSize = 0;
314310
if (intern->array.elements) {
315311
efree(intern->array.elements);
316312
intern->array.elements = NULL;
@@ -321,13 +317,6 @@ static void arraylist_destruct(arraylist_object *intern)/* {{{ */
321317

322318
PHP_METHOD(arraylist, __destruct)
323319
{
324-
zval *object = getThis();
325-
arraylist_object *intern;
326-
if (zend_parse_parameters_none() == FAILURE) {
327-
return;
328-
}
329-
intern = Z_ARRAYLIST_P(object);
330-
arraylist_destruct(intern);
331320
}
332321

333322
/* {{{ arraylist_functions[] 扩展函数
@@ -375,15 +364,12 @@ static zend_object *arraylist_object_new_ex(zend_class_entry *class_type, zval *
375364

376365
if (orig && clone_orig) {
377366
arraylist_object *other = Z_ARRAYLIST_P(orig);
378-
// intern->ce_get_iterator = other->ce_get_iterator;
379367
arraylist_init(&intern->array, other->array.nSize);
380-
// spl_fixedarray_copy(&intern->array, &other->array);
381368
}
382369

383370
while (parent) {
384371
if (parent == array_list_ce) {
385372
intern->std.handlers = &handler_array_list;
386-
// class_type->get_iterator = spl_fixedarray_get_iterator;
387373
break;
388374
}
389375

@@ -460,6 +446,7 @@ PHP_MINIT_FUNCTION(arraylist) /* {{{ */ {
460446
sizeof(PHP_ARRAYLIST_VERSION)-1,
461447
CONST_CS|CONST_PERSISTENT
462448
);
449+
463450
INIT_CLASS_ENTRY(ce, "ArrayList", arraylist_methods); //注册类及类方法
464451
array_list_ce = zend_register_internal_class(&ce);
465452
array_list_ce->create_object = arraylist_new;

0 commit comments

Comments
 (0)