helly Mon Jan 24 16:38:30 2005 EDT
Added files: (Branch: PHP_5_0)
/php-src/ext/spl/tests bug31346.phpt
Modified files:
/php-src/ext/spl spl_array.c
/php-src/ext/spl/tests bug28822.phpt
Log:
- MFH
http://cvs.php.net/diff.php/php-src/ext/spl/spl_array.c?r1=1.49.2.1&r2=1.49.2.2&ty=u
Index: php-src/ext/spl/spl_array.c
diff -u php-src/ext/spl/spl_array.c:1.49.2.1
php-src/ext/spl/spl_array.c:1.49.2.2
--- php-src/ext/spl/spl_array.c:1.49.2.1 Tue Aug 31 16:56:08 2004
+++ php-src/ext/spl/spl_array.c Mon Jan 24 16:38:29 2005
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: spl_array.c,v 1.49.2.1 2004/08/31 20:56:08 helly Exp $ */
+/* $Id: spl_array.c,v 1.49.2.2 2005/01/24 21:38:29 helly Exp $ */
#ifdef HAVE_CONFIG_H
# include "config.h"
@@ -26,6 +26,7 @@
#include "php_ini.h"
#include "ext/standard/info.h"
#include "zend_interfaces.h"
+#include "zend_exceptions.h"
#include "php_spl.h"
#include "spl_functions.h"
@@ -119,6 +120,7 @@
zend_object std;
zval *array;
HashPosition pos;
+ int is_ref;
} spl_array_object;
/* {{{ spl_array_object_free_storage */
@@ -154,9 +156,11 @@
if (orig) {
intern->array = orig->array;
ZVAL_ADDREF(intern->array);
+ intern->is_ref = 1;
} else {
MAKE_STD_ZVAL(intern->array);
array_init(intern->array);
+ intern->is_ref = 0;
}
zend_hash_internal_pointer_reset_ex(HASH_OF(intern->array),
&intern->pos);
@@ -365,20 +369,12 @@
spl_array_write_dimension(getThis(), index, value TSRMLS_CC);
} /* }}} */
-/* {{{ proto void ArrayObject::append(mixed $newval)
- proto void ArrayIterator::append(mixed $newval)
- Appends the value (cannot be called for objects). */
-SPL_METHOD(Array, append)
+
+void spl_array_iterator_append(zval *object, zval *append_value TSRMLS_DC) /*
{{{ */
{
- zval *object = getThis();
spl_array_object *intern =
(spl_array_object*)zend_object_store_get_object(object TSRMLS_CC);
HashTable *aht = HASH_OF(intern->array);
- zval *value;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &value) ==
FAILURE) {
- return;
- }
-
if (!aht) {
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Array was modified
outside object and is no longer an array");
return;
@@ -388,12 +384,25 @@
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Cannot append
properties to objects, use %s::offsetSet() instead", Z_OBJCE_P(object)->name);
}
- spl_array_write_dimension(object, NULL, value TSRMLS_CC);
+ spl_array_write_dimension(object, NULL, append_value TSRMLS_CC);
if (!intern->pos) {
intern->pos = aht->pListTail;
}
} /* }}} */
+/* {{{ proto void ArrayObject::append(mixed $newval)
+ proto void ArrayIterator::append(mixed $newval)
+ Appends the value (cannot be called for objects). */
+SPL_METHOD(Array, append)
+{
+ zval *value;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &value) ==
FAILURE) {
+ return;
+ }
+ spl_array_iterator_append(getThis(), value TSRMLS_CC);
+} /* }}} */
+
/* {{{ proto void ArrayObject::offsetUnset(mixed $index)
proto void ArrayIterator::offsetUnset(mixed $index)
Unsets the value at the specified $index. */
@@ -478,11 +487,16 @@
{
HashTable *aht = HASH_OF(intern->array);
- zend_hash_move_forward_ex(aht, &intern->pos);
- if (Z_TYPE_P(intern->array) == IS_OBJECT) {
- return spl_array_skip_protected(intern TSRMLS_CC);
+ if (intern->is_ref && spl_hash_verify_pos(intern TSRMLS_CC) == FAILURE)
{
+ php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Array was modified
outside object and internal position is no longer valid");
+ return FAILURE;
} else {
- return zend_hash_has_more_elements_ex(aht, &intern->pos);
+ zend_hash_move_forward_ex(aht, &intern->pos);
+ if (Z_TYPE_P(intern->array) == IS_OBJECT) {
+ return spl_array_skip_protected(intern TSRMLS_CC);
+ } else {
+ return zend_hash_has_more_elements_ex(aht,
&intern->pos);
+ }
}
} /* }}} */
@@ -513,7 +527,7 @@
return FAILURE;
}
- if (object->pos && object->array->is_ref && spl_hash_verify_pos(object
TSRMLS_CC) == FAILURE) {
+ if (object->pos && object->is_ref && spl_hash_verify_pos(object
TSRMLS_CC) == FAILURE) {
php_error_docref(NULL TSRMLS_CC, E_NOTICE,
"ArrayIterator::valid(): Array was modified outside object and internal
position is no longer valid");
return FAILURE;
} else {
@@ -545,7 +559,7 @@
return HASH_KEY_NON_EXISTANT;
}
- if (object->array->is_ref && spl_hash_verify_pos(object TSRMLS_CC) ==
FAILURE) {
+ if (object->is_ref && spl_hash_verify_pos(object TSRMLS_CC) == FAILURE)
{
php_error_docref(NULL TSRMLS_CC, E_NOTICE,
"ArrayIterator::current(): Array was modified outside object and internal
position is no longer valid");
return HASH_KEY_NON_EXISTANT;
}
@@ -566,7 +580,7 @@
return;
}
- if (object->array->is_ref && spl_hash_verify_pos(object TSRMLS_CC) ==
FAILURE) {
+ if (object->is_ref && spl_hash_verify_pos(object TSRMLS_CC) == FAILURE)
{
php_error_docref(NULL TSRMLS_CC, E_NOTICE,
"ArrayIterator::next(): Array was modified outside object and internal position
is no longer valid");
} else {
spl_array_next(object TSRMLS_CC);
@@ -626,8 +640,7 @@
if (ZEND_NUM_ARGS() == 0) {
return; /* nothing to do */
}
-/* exceptions do not work yet
- php_set_error_handling(EH_THROW, zend_exception_get_default()
TSRMLS_CC);*/
+ php_set_error_handling(EH_THROW, zend_exception_get_default()
TSRMLS_CC);
intern = (spl_array_object*)zend_object_store_get_object(object
TSRMLS_CC);
@@ -641,8 +654,8 @@
intern->array = other->array;
} else {
if (!HASH_OF(*array)) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Passed
variable is not an array or object, using empty array instead");
php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC);
+ zend_throw_exception(zend_exception_get_default(),
"Passed variable is not an array or object, using empty array instead", 0
TSRMLS_CC);
return;
}
zval_dtor(intern->array);
@@ -773,7 +786,7 @@
return;
}
- if (intern->array->is_ref && spl_hash_verify_pos(intern TSRMLS_CC) ==
FAILURE) {
+ if (intern->is_ref && spl_hash_verify_pos(intern TSRMLS_CC) == FAILURE)
{
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Array was modified
outside object and internal position is no longer valid");
return;
}
@@ -802,7 +815,7 @@
return;
}
- if (intern->array->is_ref && spl_hash_verify_pos(intern TSRMLS_CC) ==
FAILURE) {
+ if (intern->is_ref && spl_hash_verify_pos(intern TSRMLS_CC) == FAILURE)
{
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Array was modified
outside object and internal position is no longer valid");
return;
}
@@ -833,11 +846,7 @@
return;
}
- if (intern->array->is_ref && spl_hash_verify_pos(intern TSRMLS_CC) ==
FAILURE) {
- php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Array was modified
outside object and internal position is no longer valid");
- } else {
- spl_array_next(intern TSRMLS_CC);
- }
+ spl_array_next(intern TSRMLS_CC);
}
/* }}} */
@@ -854,7 +863,7 @@
return;
}
- if (intern->pos && intern->array->is_ref && spl_hash_verify_pos(intern
TSRMLS_CC) == FAILURE) {
+ if (intern->pos && intern->is_ref && spl_hash_verify_pos(intern
TSRMLS_CC) == FAILURE) {
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Array was modified
outside object and internal position is no longer valid");
RETURN_FALSE;
} else {
http://cvs.php.net/diff.php/php-src/ext/spl/tests/bug28822.phpt?r1=1.1.2.1&r2=1.1.2.2&ty=u
Index: php-src/ext/spl/tests/bug28822.phpt
diff -u php-src/ext/spl/tests/bug28822.phpt:1.1.2.1
php-src/ext/spl/tests/bug28822.phpt:1.1.2.2
--- php-src/ext/spl/tests/bug28822.phpt:1.1.2.1 Wed Sep 29 16:16:03 2004
+++ php-src/ext/spl/tests/bug28822.phpt Mon Jan 24 16:38:29 2005
@@ -1,5 +1,5 @@
--TEST--
-Bug #28822: ArrayObject::offsetExists() works inverted
+Bug #28822 (ArrayObject::offsetExists() works inverted)
--SKIPIF--
<?php if (!extension_loaded("spl")) print "skip"; ?>
--FILE--
http://cvs.php.net/co.php/php-src/ext/spl/tests/bug31346.phpt?r=1.1&p=1
Index: php-src/ext/spl/tests/bug31346.phpt
+++ php-src/ext/spl/tests/bug31346.phpt
--TEST--
Bug #31486 (ArrayIterator::next segfaults)
--FILE--
<?php
$obj = new stdClass;
$obj->var1=1;
$ao = new ArrayObject($obj);
$i = $ao->getIterator();
$ao->offsetUnset($i->key());
$i->next();
?>
===DONE===
--EXPECTF--
Notice: ArrayIterator::next(): Array was modified outside object and internal
position is no longer valid in %sbug31346.php on line %d
===DONE===
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php