colder Sun Jul 6 23:45:38 2008 UTC
Added files:
/php-src/ext/spl/tests array_024.phpt dllist_008.phpt
fixedarray_018.phpt heap_010.phpt
Modified files:
/php-src/ext/spl spl_array.c spl_dllist.c spl_fixedarray.c
spl_heap.c
/php-src/ext/spl/tests sxe_004.phpt sxe_005.phpt
Log:
First part of count/handlers related fixes
http://cvs.php.net/viewvc.cgi/php-src/ext/spl/spl_array.c?r1=1.139&r2=1.140&diff_format=u
Index: php-src/ext/spl/spl_array.c
diff -u php-src/ext/spl/spl_array.c:1.139 php-src/ext/spl/spl_array.c:1.140
--- php-src/ext/spl/spl_array.c:1.139 Tue May 20 12:04:37 2008
+++ php-src/ext/spl/spl_array.c Sun Jul 6 23:45:38 2008
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: spl_array.c,v 1.139 2008/05/20 12:04:37 tony2001 Exp $ */
+/* $Id: spl_array.c,v 1.140 2008/07/06 23:45:38 colder Exp $ */
#ifdef HAVE_CONFIG_H
# include "config.h"
@@ -66,10 +66,11 @@
HashPosition pos;
int ar_flags;
int is_self;
- zend_function * fptr_offset_get;
- zend_function * fptr_offset_set;
- zend_function * fptr_offset_has;
- zend_function * fptr_offset_del;
+ zend_function *fptr_offset_get;
+ zend_function *fptr_offset_set;
+ zend_function *fptr_offset_has;
+ zend_function *fptr_offset_del;
+ zend_function *fptr_count;
zend_class_entry* ce_get_iterator;
} spl_array_object;
@@ -202,6 +203,10 @@
if (intern->fptr_offset_del->common.scope == parent) {
intern->fptr_offset_del = NULL;
}
+ zend_hash_find(&class_type->function_table, "count",
sizeof("count"), (void **) &intern->fptr_count);
+ if (intern->fptr_count->common.scope == parent) {
+ intern->fptr_count = NULL;
+ }
}
/* Cache iterator functions if ArrayIterator or derived. Check
current's */
/* cache since only current is always required */
@@ -1164,9 +1169,8 @@
zend_throw_exception_ex(spl_ce_OutOfBoundsException, 0 TSRMLS_CC, "Seek
position %ld is out of range", opos);
} /* }}} */
-int spl_array_object_count_elements(zval *object, long *count TSRMLS_DC) /*
{{{ */
+int inline spl_array_object_count_elements_helper(spl_array_object *intern,
long *count TSRMLS_DC) /* {{{ */
{
- spl_array_object *intern =
(spl_array_object*)zend_object_store_get_object(object TSRMLS_CC);
HashTable *aht = spl_array_get_hash_table(intern, 0 TSRMLS_CC);
HashPosition pos;
@@ -1193,14 +1197,36 @@
}
} /* }}} */
+int spl_array_object_count_elements(zval *object, long *count TSRMLS_DC) /*
{{{ */
+{
+ spl_array_object *intern =
(spl_array_object*)zend_object_store_get_object(object TSRMLS_CC);
+
+ if (intern->fptr_count) {
+ zval *rv;
+ zend_call_method_with_0_params(&object, intern->std.ce,
&intern->fptr_count, "count", &rv);
+ if (rv) {
+ zval_ptr_dtor(&intern->retval);
+ MAKE_STD_ZVAL(intern->retval);
+ ZVAL_ZVAL(intern->retval, rv, 1, 1);
+ convert_to_long(intern->retval);
+ *count = (long) Z_LVAL_P(intern->retval);
+ return SUCCESS;
+ }
+ *count = 0;
+ return FAILURE;
+ }
+ return spl_array_object_count_elements_helper(intern, count TSRMLS_CC);
+} /* }}} */
+
/* {{{ proto int ArrayObject::count() U
proto int ArrayIterator::count() U
Return the number of elements in the Iterator. */
SPL_METHOD(Array, count)
{
long count;
+ spl_array_object *intern =
(spl_array_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
- spl_array_object_count_elements(getThis(), &count TSRMLS_CC);
+ spl_array_object_count_elements_helper(intern, &count TSRMLS_CC);
RETURN_LONG(count);
} /* }}} */
@@ -1220,9 +1246,11 @@
zend_throw_exception(spl_ce_BadMethodCallException,
"Function expects exactly one argument", 0 TSRMLS_CC);
return;
}
- zend_call_method(NULL, NULL, NULL, fname, fname_len,
&return_value, 2, &tmp, arg TSRMLS_CC);
+ zval_ptr_dtor(return_value_ptr);
+ zend_call_method(NULL, NULL, NULL, fname, fname_len,
return_value_ptr, 2, &tmp, arg TSRMLS_CC);
} else {
- zend_call_method(NULL, NULL, NULL, fname, fname_len,
&return_value, 1, &tmp, NULL TSRMLS_CC);
+ zval_ptr_dtor(return_value_ptr);
+ zend_call_method(NULL, NULL, NULL, fname, fname_len,
return_value_ptr, 1, &tmp, NULL TSRMLS_CC);
}
} /* }}} */
http://cvs.php.net/viewvc.cgi/php-src/ext/spl/spl_dllist.c?r1=1.12&r2=1.13&diff_format=u
Index: php-src/ext/spl/spl_dllist.c
diff -u php-src/ext/spl/spl_dllist.c:1.12 php-src/ext/spl/spl_dllist.c:1.13
--- php-src/ext/spl/spl_dllist.c:1.12 Fri Jun 6 23:53:10 2008
+++ php-src/ext/spl/spl_dllist.c Sun Jul 6 23:45:38 2008
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: spl_dllist.c,v 1.12 2008/06/06 23:53:10 colder Exp $ */
+/* $Id: spl_dllist.c,v 1.13 2008/07/06 23:45:38 colder Exp $ */
#ifdef HAVE_CONFIG_H
# include "config.h"
@@ -92,6 +92,7 @@
zend_function *fptr_offset_set;
zend_function *fptr_offset_has;
zend_function *fptr_offset_del;
+ zend_function *fptr_count;
zend_class_entry *ce_get_iterator;
};
@@ -432,6 +433,10 @@
if (intern->fptr_offset_del->common.scope == parent) {
intern->fptr_offset_del = NULL;
}
+ zend_hash_find(&class_type->function_table, "count",
sizeof("count"), (void **) &intern->fptr_count);
+ if (intern->fptr_count->common.scope == parent) {
+ intern->fptr_count = NULL;
+ }
}
return retval;
@@ -467,8 +472,22 @@
{
spl_dllist_object *intern =
(spl_dllist_object*)zend_object_store_get_object(object TSRMLS_CC);
- *count = spl_ptr_llist_count(intern->llist);
+ if (intern->fptr_count) {
+ zval *rv;
+ zend_call_method_with_0_params(&object, intern->std.ce,
&intern->fptr_count, "count", &rv);
+ if (rv) {
+ zval_ptr_dtor(&intern->retval);
+ MAKE_STD_ZVAL(intern->retval);
+ ZVAL_ZVAL(intern->retval, rv, 1, 1);
+ convert_to_long(intern->retval);
+ *count = (long) Z_LVAL_P(intern->retval);
+ return SUCCESS;
+ }
+ *count = 0;
+ return FAILURE;
+ }
+ *count = spl_ptr_llist_count(intern->llist);
return SUCCESS;
}
/* }}} */
@@ -655,12 +674,13 @@
SPL_METHOD(SplDoublyLinkedList, count)
{
long count;
+ spl_dllist_object *intern =
(spl_dllist_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
if (zend_parse_parameters_none() == FAILURE) {
return;
}
- spl_dllist_object_count_elements(getThis(), &count TSRMLS_CC);
+ count = spl_ptr_llist_count(intern->llist);
RETURN_LONG(count);
}
/* }}} */
http://cvs.php.net/viewvc.cgi/php-src/ext/spl/spl_fixedarray.c?r1=1.1&r2=1.2&diff_format=u
Index: php-src/ext/spl/spl_fixedarray.c
diff -u php-src/ext/spl/spl_fixedarray.c:1.1
php-src/ext/spl/spl_fixedarray.c:1.2
--- php-src/ext/spl/spl_fixedarray.c:1.1 Wed Jun 18 14:54:27 2008
+++ php-src/ext/spl/spl_fixedarray.c Sun Jul 6 23:45:38 2008
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: spl_fixedarray.c,v 1.1 2008/06/18 14:54:27 colder Exp $ */
+/* $Id: spl_fixedarray.c,v 1.2 2008/07/06 23:45:38 colder Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -61,6 +61,7 @@
zend_function *fptr_it_current;
zend_function *fptr_it_key;
zend_function *fptr_it_valid;
+ zend_function *fptr_count;
int current;
zend_class_entry *ce_get_iterator;
} spl_fixedarray_object;
@@ -292,6 +293,10 @@
if (intern->fptr_it_valid->common.scope == parent) {
intern->fptr_it_valid = NULL;
}
+ zend_hash_find(&class_type->function_table, "count",
sizeof("count"), (void **) &intern->fptr_count);
+ if (intern->fptr_count->common.scope == parent) {
+ intern->fptr_count = NULL;
+ }
}
return retval;
@@ -512,12 +517,23 @@
spl_fixedarray_object *intern;
intern = (spl_fixedarray_object *)zend_object_store_get_object(object
TSRMLS_CC);
- if (intern->array) {
+ if (intern->fptr_count) {
+ zval *rv;
+ zend_call_method_with_0_params(&object, intern->std.ce,
&intern->fptr_count, "count", &rv);
+ if (rv) {
+ zval_ptr_dtor(&intern->retval);
+ MAKE_STD_ZVAL(intern->retval);
+ ZVAL_ZVAL(intern->retval, rv, 1, 1);
+ convert_to_long(intern->retval);
+ *count = (long) Z_LVAL_P(intern->retval);
+ return SUCCESS;
+ }
+ } else if (intern->array) {
*count = intern->array->size;
- } else {
- *count = 0;
+ return SUCCESS;
}
+ *count = 0;
return SUCCESS;
}
/* }}} */
@@ -945,7 +961,6 @@
memcpy(&spl_handler_SplFixedArray, zend_get_std_object_handlers(),
sizeof(zend_object_handlers));
spl_handler_SplFixedArray.clone_obj = spl_fixedarray_object_clone;
- spl_handler_SplFixedArray.count_elements =
spl_fixedarray_object_count_elements;
spl_handler_SplFixedArray.read_dimension =
spl_fixedarray_object_read_dimension;
spl_handler_SplFixedArray.write_dimension =
spl_fixedarray_object_write_dimension;
spl_handler_SplFixedArray.unset_dimension =
spl_fixedarray_object_unset_dimension;
http://cvs.php.net/viewvc.cgi/php-src/ext/spl/spl_heap.c?r1=1.6&r2=1.7&diff_format=u
Index: php-src/ext/spl/spl_heap.c
diff -u php-src/ext/spl/spl_heap.c:1.6 php-src/ext/spl/spl_heap.c:1.7
--- php-src/ext/spl/spl_heap.c:1.6 Sat May 24 14:37:53 2008
+++ php-src/ext/spl/spl_heap.c Sun Jul 6 23:45:38 2008
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: spl_heap.c,v 1.6 2008/05/24 14:37:53 colder Exp $ */
+/* $Id: spl_heap.c,v 1.7 2008/07/06 23:45:38 colder Exp $ */
#ifdef HAVE_CONFIG_H
# include "config.h"
@@ -75,6 +75,7 @@
int flags;
zend_class_entry *ce_get_iterator;
zend_function *fptr_cmp;
+ zend_function *fptr_count;
};
/* define an overloaded iterator structure */
@@ -441,10 +442,13 @@
if (inherited) {
zend_hash_find(&class_type->function_table, "compare",
sizeof("compare"), (void **) &intern->fptr_cmp);
-
if (intern->fptr_cmp->common.scope == parent) {
intern->fptr_cmp = NULL;
}
+ zend_hash_find(&class_type->function_table, "count",
sizeof("count"), (void **) &intern->fptr_count);
+ if (intern->fptr_count->common.scope == parent) {
+ intern->fptr_count = NULL;
+ }
}
return retval;
@@ -480,6 +484,21 @@
{
spl_heap_object *intern =
(spl_heap_object*)zend_object_store_get_object(object TSRMLS_CC);
+ if (intern->fptr_count) {
+ zval *rv;
+ zend_call_method_with_0_params(&object, intern->std.ce,
&intern->fptr_count, "count", &rv);
+ if (rv) {
+ zval_ptr_dtor(&intern->retval);
+ MAKE_STD_ZVAL(intern->retval);
+ ZVAL_ZVAL(intern->retval, rv, 1, 1);
+ convert_to_long(intern->retval);
+ *count = (long) Z_LVAL_P(intern->retval);
+ return SUCCESS;
+ }
+ *count = 0;
+ return FAILURE;
+ }
+
*count = spl_ptr_heap_count(intern->heap);
return SUCCESS;
@@ -545,12 +564,13 @@
SPL_METHOD(SplHeap, count)
{
long count;
+ spl_heap_object *intern =
(spl_heap_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "") == FAILURE) {
return;
}
- spl_heap_object_count_elements(getThis(), &count TSRMLS_CC);
+ count = spl_ptr_heap_count(intern->heap);
RETURN_LONG(count);
}
/* }}} */
@@ -559,14 +579,13 @@
Return true if the heap is empty. */
SPL_METHOD(SplHeap, isEmpty)
{
- long count;
+ spl_heap_object *intern =
(spl_heap_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "") == FAILURE) {
return;
}
- spl_heap_object_count_elements(getThis(), &count TSRMLS_CC);
- RETURN_BOOL(count==0);
+ RETURN_BOOL(spl_ptr_heap_count(intern->heap)==0);
}
/* }}} */
http://cvs.php.net/viewvc.cgi/php-src/ext/spl/tests/sxe_004.phpt?r1=1.7&r2=1.8&diff_format=u
Index: php-src/ext/spl/tests/sxe_004.phpt
diff -u php-src/ext/spl/tests/sxe_004.phpt:1.7
php-src/ext/spl/tests/sxe_004.phpt:1.8
--- php-src/ext/spl/tests/sxe_004.phpt:1.7 Tue May 27 02:55:51 2008
+++ php-src/ext/spl/tests/sxe_004.phpt Sun Jul 6 23:45:38 2008
@@ -1,5 +1,5 @@
--TEST--
-SPL: SimpleXMLIterator and getChildren()
+SPL: SimpleXMLIterator and overridden iterator methods()
--SKIPIF--
<?php
if (!extension_loaded('simplexml')) print 'skip';
http://cvs.php.net/viewvc.cgi/php-src/ext/spl/tests/sxe_005.phpt?r1=1.3&r2=1.4&diff_format=u
Index: php-src/ext/spl/tests/sxe_005.phpt
diff -u php-src/ext/spl/tests/sxe_005.phpt:1.3
php-src/ext/spl/tests/sxe_005.phpt:1.4
--- php-src/ext/spl/tests/sxe_005.phpt:1.3 Sat May 24 14:12:00 2008
+++ php-src/ext/spl/tests/sxe_005.phpt Sun Jul 6 23:45:38 2008
@@ -1,5 +1,5 @@
--TEST--
-SPL: SimpleXMLIterator and getChildren()
+SPL: SimpleXMLIterator and overriden count()
--SKIPIF--
<?php
if (!extension_loaded('simplexml')) print 'skip';
http://cvs.php.net/viewvc.cgi/php-src/ext/spl/tests/array_024.phpt?view=markup&rev=1.1
Index: php-src/ext/spl/tests/array_024.phpt
+++ php-src/ext/spl/tests/array_024.phpt
--TEST--
SPL: ArrayObject with overriden count()
--FILE--
<?php
$obj = new ArrayObject(array(1,2));
var_dump(count($obj));
class ArrayObject2 extends ArrayObject {
public function count() {
return -parent::count();
}
}
$obj = new ArrayObject2(array(1,2));
var_dump(count($obj));
?>
--EXPECT--
int(2)
int(-2)
http://cvs.php.net/viewvc.cgi/php-src/ext/spl/tests/dllist_008.phpt?view=markup&rev=1.1
Index: php-src/ext/spl/tests/dllist_008.phpt
+++ php-src/ext/spl/tests/dllist_008.phpt
--TEST--
SPL: SplDoublyLinkedList with overriden count()
--FILE--
<?php
$obj = new SplDoublyLinkedList();
$obj[] = 1;
$obj[] = 2;
var_dump(count($obj));
class SplDoublyLinkedList2 extends SplDoublyLinkedList{
public function count() {
return -parent::count();
}
}
$obj = new SplDoublyLinkedList2();
$obj[] = 1;
$obj[] = 2;
var_dump(count($obj));
?>
--EXPECT--
int(2)
int(-2)
http://cvs.php.net/viewvc.cgi/php-src/ext/spl/tests/fixedarray_018.phpt?view=markup&rev=1.1
Index: php-src/ext/spl/tests/fixedarray_018.phpt
+++ php-src/ext/spl/tests/fixedarray_018.phpt
--TEST--
SPL: SplFixedArray with overriden count()
--FILE--
<?php
$obj = new SplFixedArray(2);
var_dump(count($obj));
class SplFixedArray2 extends SplFixedArray {
public function count() {
return -parent::count();
}
}
$obj = new SplFixedArray2(2);
var_dump(count($obj));
?>
--EXPECT--
int(2)
int(-2)
http://cvs.php.net/viewvc.cgi/php-src/ext/spl/tests/heap_010.phpt?view=markup&rev=1.1
Index: php-src/ext/spl/tests/heap_010.phpt
+++ php-src/ext/spl/tests/heap_010.phpt
--TEST--
SPL: SplHeap with overriden count()
--FILE--
<?php
$obj = new SplMaxHeap();
$obj->insert(1);
$obj->insert(2);
var_dump(count($obj));
class SplMaxHeap2 extends SplMaxHeap{
public function count() {
return -parent::count();
}
}
$obj = new SplMaxHeap2();
$obj->insert(1);
$obj->insert(2);
var_dump(count($obj));
?>
--EXPECT--
int(2)
int(-2)
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php