2003-10-18 01:19:44 +08:00
|
|
|
/*
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| Zend Engine |
|
|
|
|
+----------------------------------------------------------------------+
|
2019-01-30 17:23:29 +08:00
|
|
|
| Copyright (c) Zend Technologies Ltd. (http://www.zend.com) |
|
2003-10-18 01:19:44 +08:00
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| This source file is subject to version 2.00 of the Zend license, |
|
2015-01-03 17:22:58 +08:00
|
|
|
| that is bundled with this package in the file LICENSE, and is |
|
2003-10-18 01:19:44 +08:00
|
|
|
| available through the world-wide-web at the following url: |
|
|
|
|
| http://www.zend.com/license/2_00.txt. |
|
|
|
|
| If you did not receive a copy of the Zend license and are unable to |
|
|
|
|
| obtain it through the world-wide-web, please send a note to |
|
|
|
|
| license@zend.com so we can mail you a copy immediately. |
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| Author: Wez Furlong <wez@thebrainroom.com> |
|
|
|
|
| Marcus Boerger <helly@php.net> |
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
*/
|
|
|
|
|
2023-01-16 19:22:54 +08:00
|
|
|
#include "zend.h"
|
|
|
|
#include "zend_API.h"
|
2003-10-18 01:19:44 +08:00
|
|
|
|
|
|
|
static zend_class_entry zend_iterator_class_entry;
|
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
static void iter_wrapper_free(zend_object *object);
|
|
|
|
static void iter_wrapper_dtor(zend_object *object);
|
2019-01-31 23:47:58 +08:00
|
|
|
static HashTable *iter_wrapper_get_gc(zend_object *object, zval **table, int *n);
|
2014-02-12 22:08:11 +08:00
|
|
|
|
2018-03-14 19:01:45 +08:00
|
|
|
static const zend_object_handlers iterator_object_handlers = {
|
2014-04-09 05:50:15 +08:00
|
|
|
0,
|
2014-08-21 15:17:05 +08:00
|
|
|
iter_wrapper_free,
|
2014-02-12 22:08:11 +08:00
|
|
|
iter_wrapper_dtor,
|
2020-02-10 18:46:19 +08:00
|
|
|
NULL, /* clone_obj */
|
2003-10-18 01:19:44 +08:00
|
|
|
NULL, /* prop read */
|
|
|
|
NULL, /* prop write */
|
|
|
|
NULL, /* read dim */
|
|
|
|
NULL, /* write dim */
|
2020-02-10 18:46:19 +08:00
|
|
|
NULL, /* get_property_ptr_ptr */
|
2003-11-11 02:05:02 +08:00
|
|
|
NULL, /* has prop */
|
|
|
|
NULL, /* unset prop */
|
|
|
|
NULL, /* has dim */
|
|
|
|
NULL, /* unset dim */
|
2003-10-18 01:19:44 +08:00
|
|
|
NULL, /* props get */
|
|
|
|
NULL, /* method get */
|
|
|
|
NULL, /* get ctor */
|
|
|
|
NULL, /* get class name */
|
2004-05-04 23:03:28 +08:00
|
|
|
NULL, /* cast */
|
2014-12-13 02:57:34 +08:00
|
|
|
NULL, /* count */
|
|
|
|
NULL, /* get_debug_info */
|
|
|
|
NULL, /* get_closure */
|
2019-01-15 20:52:32 +08:00
|
|
|
iter_wrapper_get_gc,
|
2014-12-13 02:57:34 +08:00
|
|
|
NULL, /* do_operation */
|
2020-02-10 18:46:19 +08:00
|
|
|
NULL, /* compare */
|
|
|
|
NULL /* get_properties_for */
|
2003-10-18 01:19:44 +08:00
|
|
|
};
|
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
ZEND_API void zend_register_iterator_wrapper(void)
|
2003-10-18 01:19:44 +08:00
|
|
|
{
|
|
|
|
INIT_CLASS_ENTRY(zend_iterator_class_entry, "__iterator_wrapper", NULL);
|
2022-08-25 00:41:34 +08:00
|
|
|
zend_iterator_class_entry.default_object_handlers = &iterator_object_handlers;
|
2003-10-18 01:19:44 +08:00
|
|
|
}
|
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
static void iter_wrapper_free(zend_object *object)
|
2003-10-18 01:19:44 +08:00
|
|
|
{
|
|
|
|
zend_object_iterator *iter = (zend_object_iterator*)object;
|
2014-12-14 06:06:14 +08:00
|
|
|
iter->funcs->dtor(iter);
|
2003-10-18 01:19:44 +08:00
|
|
|
}
|
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
static void iter_wrapper_dtor(zend_object *object)
|
2014-08-21 15:17:05 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-01-31 23:47:58 +08:00
|
|
|
static HashTable *iter_wrapper_get_gc(zend_object *object, zval **table, int *n) {
|
2020-07-01 17:49:44 +08:00
|
|
|
zend_object_iterator *iter = (zend_object_iterator*)object;
|
|
|
|
if (iter->funcs->get_gc) {
|
|
|
|
return iter->funcs->get_gc(iter, table, n);
|
|
|
|
}
|
|
|
|
|
2019-01-15 20:52:32 +08:00
|
|
|
*table = NULL;
|
|
|
|
*n = 0;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
ZEND_API void zend_iterator_init(zend_object_iterator *iter)
|
2003-10-18 01:19:44 +08:00
|
|
|
{
|
2014-12-14 06:06:14 +08:00
|
|
|
zend_object_std_init(&iter->std, &zend_iterator_class_entry);
|
2003-10-18 01:19:44 +08:00
|
|
|
}
|
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
ZEND_API void zend_iterator_dtor(zend_object_iterator *iter)
|
2014-02-28 15:03:43 +08:00
|
|
|
{
|
2017-10-27 06:28:58 +08:00
|
|
|
if (GC_DELREF(&iter->std) > 0) {
|
2014-02-28 15:03:43 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
zend_objects_store_del(&iter->std);
|
2014-02-28 15:03:43 +08:00
|
|
|
}
|
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
ZEND_API zend_object_iterator* zend_iterator_unwrap(zval *array_ptr)
|
2003-10-18 01:19:44 +08:00
|
|
|
{
|
2016-06-08 17:11:47 +08:00
|
|
|
ZEND_ASSERT(Z_TYPE_P(array_ptr) == IS_OBJECT);
|
|
|
|
if (Z_OBJ_HT_P(array_ptr) == &iterator_object_handlers) {
|
2014-09-16 05:34:27 +08:00
|
|
|
return (zend_object_iterator *)Z_OBJ_P(array_ptr);
|
2003-10-18 01:19:44 +08:00
|
|
|
}
|
2014-09-16 05:34:27 +08:00
|
|
|
return NULL;
|
2003-10-18 01:19:44 +08:00
|
|
|
}
|