From 263723ec9b9d1f7b82a7de1e2cef25803bf24baa Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Tue, 4 May 2004 15:03:48 +0000 Subject: [PATCH] Update for count_elements handler for overloaded objects. --- ext/com_dotnet/com_handlers.c | 22 +++++++++++++++++++++- ext/com_dotnet/com_saproxy.c | 20 +++++++++++++++++++- ext/simplexml/simplexml.c | 3 ++- ext/standard/array.c | 7 +++++++ 4 files changed, 49 insertions(+), 3 deletions(-) diff --git a/ext/com_dotnet/com_handlers.c b/ext/com_dotnet/com_handlers.c index 9c80d9f4f9..cfe15d4355 100644 --- a/ext/com_dotnet/com_handlers.c +++ b/ext/com_dotnet/com_handlers.c @@ -548,6 +548,25 @@ static int com_object_cast(zval *readobj, zval *writeobj, int type, int should_f return SUCCESS; } +static int com_object_count(zval *object, long *count TSRMLS_DC) +{ + php_com_dotnet_object *obj; + LONG ubound = 0, lbound = 0; + + obj = CDNO_FETCH(object); + + if (!V_ISARRAY(&obj->v)) { + return FAILURE; + } + + SafeArrayGetLBound(V_ARRAY(&obj->v), 1, &lbound); + SafeArrayGetUBound(V_ARRAY(&obj->v), 1, &ubound); + + *count = ubound - lbound + 1; + + return SUCCESS; +} + zend_object_handlers php_com_object_handlers = { ZEND_OBJECTS_STORE_HANDLERS, com_property_read, @@ -568,7 +587,8 @@ zend_object_handlers php_com_object_handlers = { com_class_entry_get, com_class_name_get, com_objects_compare, - com_object_cast + com_object_cast, + com_object_count }; void php_com_object_enable_event_sink(php_com_dotnet_object *obj, int enable TSRMLS_DC) diff --git a/ext/com_dotnet/com_saproxy.c b/ext/com_dotnet/com_saproxy.c index 85d9b978a5..1dfbad5a1e 100644 --- a/ext/com_dotnet/com_saproxy.c +++ b/ext/com_dotnet/com_saproxy.c @@ -362,6 +362,23 @@ static int saproxy_object_cast(zval *readobj, zval *writeobj, int type, int shou return FAILURE; } +static int saproxy_count_elements(zval *object, long *count TSRMLS_DC) +{ + php_com_saproxy *proxy = SA_FETCH(object); + LONG ubound, lbound; + + if (!V_ISARRAY(&proxy->obj->v)) { + return FAILURE; + } + + SafeArrayGetLBound(V_ARRAY(&proxy->obj->v), proxy->dimensions, &lbound); + SafeArrayGetUBound(V_ARRAY(&proxy->obj->v), proxy->dimensions, &ubound); + + *count = ubound - lbound + 1; + + return SUCCESS; +} + zend_object_handlers php_com_saproxy_handlers = { ZEND_OBJECTS_STORE_HANDLERS, saproxy_property_read, @@ -382,7 +399,8 @@ zend_object_handlers php_com_saproxy_handlers = { saproxy_class_entry_get, saproxy_class_name_get, saproxy_objects_compare, - saproxy_object_cast + saproxy_object_cast, + saproxy_count_elements }; static void saproxy_free_storage(void *object TSRMLS_DC) diff --git a/ext/simplexml/simplexml.c b/ext/simplexml/simplexml.c index 968e528a75..b2af53d210 100644 --- a/ext/simplexml/simplexml.c +++ b/ext/simplexml/simplexml.c @@ -1077,7 +1077,8 @@ static zend_object_handlers sxe_object_handlers = { NULL, /* zend_get_std_object_handlers()->get_class_entry,*/ NULL, /* zend_get_std_object_handlers()->get_class_name,*/ sxe_objects_compare, - sxe_object_cast + sxe_object_cast, + NULL }; /* {{{ sxe_object_clone() diff --git a/ext/standard/array.c b/ext/standard/array.c index 539848322e..0100d02cd3 100644 --- a/ext/standard/array.c +++ b/ext/standard/array.c @@ -290,6 +290,13 @@ PHP_FUNCTION(count) case IS_ARRAY: RETURN_LONG (php_count_recursive (array, mode TSRMLS_CC)); break; + case IS_OBJECT: + if (Z_OBJ_HT(*array)->count_elements) { + RETVAL_LONG(1); + if (SUCCESS == Z_OBJ_HT(*array)->count_elements(array, &Z_LVAL_P(return_value) TSRMLS_CC)) { + return; + } + } default: RETURN_LONG(1); break; -- 2.40.0