Skip to content

Commit 8d2e895

Browse files
author
wxxiong6
authored
Update arraylist.c
1 parent 78b40b0 commit 8d2e895

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

arraylist.c

+5-4
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ PHP_METHOD(arraylist, __construct)
120120

121121
static void arraylist_resize(arraylist *array) /* {{{ */
122122
{
123-
if (array->nNextIndex == array->nSize)
123+
if (array->nNextIndex >= array->nSize)
124124
{
125125
size_t i = 0;
126126
size_t oldSize = array->nSize == 1? 2 : array->nSize;
@@ -134,7 +134,6 @@ static void arraylist_resize(arraylist *array) /* {{{ */
134134
efree(array->elements);
135135
array->elements = NULL;
136136
array->elements = elements;
137-
// Z_TRY_ADDREF(elements);
138137
array->nSize = newSize;
139138
}
140139
}
@@ -184,11 +183,12 @@ PHP_METHOD(arraylist, add)
184183
ZEND_PARSE_PARAMETERS_END();
185184

186185
intern = Z_ARRAYLIST_P(object);
186+
arraylist_resize(&intern->array);
187187
if (intern->array.nSize > 0 && intern->array.nNextIndex < intern->array.nSize) {
188188
ZVAL_LONG(&offset, intern->array.nNextIndex);
189189
arraylist_object_write_dimension_helper(intern, &offset, val);
190190
intern->array.nNextIndex++;
191-
// intern->array.nNumUsed++;
191+
intern->array.nNumUsed++;
192192
RETURN_TRUE;
193193
} else {
194194
RETURN_FALSE;
@@ -264,6 +264,7 @@ PHP_METHOD(arraylist, getSize)
264264
if (zend_parse_parameters_none() == FAILURE) {
265265
return;
266266
}
267+
intern = Z_ARRAYLIST_P(object);
267268
RETURN_LONG(intern->array.nSize);
268269
}
269270

@@ -446,7 +447,7 @@ PHP_MINIT_FUNCTION(arraylist) /* {{{ */ {
446447
sizeof(PHP_ARRAYLIST_VERSION)-1,
447448
CONST_CS|CONST_PERSISTENT
448449
);
449-
450+
450451
INIT_CLASS_ENTRY(ce, "ArrayList", arraylist_methods); //注册类及类方法
451452
array_list_ce = zend_register_internal_class(&ce);
452453
array_list_ce->create_object = arraylist_new;

0 commit comments

Comments
 (0)