php-src/Zend/zend_iterators.c

106 lines
3.3 KiB
C
Raw Permalink Normal View History

/*
+----------------------------------------------------------------------+
| Zend Engine |
+----------------------------------------------------------------------+
2019-01-30 17:23:29 +08:00
| Copyright (c) Zend Technologies Ltd. (http://www.zend.com) |
+----------------------------------------------------------------------+
| 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 |
| 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> |
+----------------------------------------------------------------------+
*/
#include "zend.h"
#include "zend_API.h"
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);
static HashTable *iter_wrapper_get_gc(zend_object *object, zval **table, int *n);
static const zend_object_handlers iterator_object_handlers = {
0,
2014-08-21 15:17:05 +08:00
iter_wrapper_free,
iter_wrapper_dtor,
NULL, /* clone_obj */
NULL, /* prop read */
NULL, /* prop write */
NULL, /* read dim */
NULL, /* write dim */
NULL, /* get_property_ptr_ptr */
NULL, /* has prop */
NULL, /* unset prop */
NULL, /* has dim */
NULL, /* unset dim */
NULL, /* props get */
NULL, /* method get */
NULL, /* get ctor */
NULL, /* get class name */
NULL, /* cast */
2014-12-13 02:57:34 +08:00
NULL, /* count */
NULL, /* get_debug_info */
NULL, /* get_closure */
iter_wrapper_get_gc,
2014-12-13 02:57:34 +08:00
NULL, /* do_operation */
NULL, /* compare */
NULL /* get_properties_for */
};
2014-12-14 06:06:14 +08:00
ZEND_API void zend_register_iterator_wrapper(void)
{
INIT_CLASS_ENTRY(zend_iterator_class_entry, "__iterator_wrapper", NULL);
zend_iterator_class_entry.default_object_handlers = &iterator_object_handlers;
}
2014-12-14 06:06:14 +08:00
static void iter_wrapper_free(zend_object *object)
{
zend_object_iterator *iter = (zend_object_iterator*)object;
2014-12-14 06:06:14 +08:00
iter->funcs->dtor(iter);
}
2014-12-14 06:06:14 +08:00
static void iter_wrapper_dtor(zend_object *object)
2014-08-21 15:17:05 +08:00
{
}
static HashTable *iter_wrapper_get_gc(zend_object *object, zval **table, int *n) {
zend_object_iterator *iter = (zend_object_iterator*)object;
if (iter->funcs->get_gc) {
return iter->funcs->get_gc(iter, table, n);
}
*table = NULL;
*n = 0;
return NULL;
}
2014-12-14 06:06:14 +08:00
ZEND_API void zend_iterator_init(zend_object_iterator *iter)
{
2014-12-14 06:06:14 +08:00
zend_object_std_init(&iter->std, &zend_iterator_class_entry);
}
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
{
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)
{
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);
}
2014-09-16 05:34:27 +08:00
return NULL;
}