php-src/Zend/zend_iterators.c

109 lines
3.0 KiB
C
Raw Normal View History

/*
+----------------------------------------------------------------------+
| Zend Engine |
+----------------------------------------------------------------------+
2017-01-02 23:30:12 +08:00
| Copyright (c) 1998-2017 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> |
+----------------------------------------------------------------------+
*/
/* $Id$ */
#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 zend_object_handlers iterator_object_handlers = {
0,
2014-08-21 15:17:05 +08:00
iter_wrapper_free,
iter_wrapper_dtor,
NULL,
NULL, /* prop read */
NULL, /* prop write */
NULL, /* read dim */
NULL, /* write dim */
NULL,
NULL, /* get */
NULL, /* set */
NULL, /* has prop */
NULL, /* unset prop */
NULL, /* has dim */
NULL, /* unset dim */
NULL, /* props get */
NULL, /* method get */
NULL, /* call */
NULL, /* get ctor */
NULL, /* get class name */
NULL, /* compare */
NULL, /* cast */
2014-12-13 02:57:34 +08:00
NULL, /* count */
NULL, /* get_debug_info */
NULL, /* get_closure */
NULL, /* get_gc */
NULL, /* do_operation */
NULL /* compare */
};
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);
}
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
{
}
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);
iter->std.handlers = &iterator_object_handlers;
}
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;
}
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* indent-tabs-mode: t
* End:
2017-07-05 00:12:45 +08:00
* vim600: sw=4 ts=4 fdm=marker
* vim<600: sw=4 ts=4
*/