xref: /PHP-7.3/Zend/zend_iterators.c (revision 8d3f8ca1)
1 /*
2    +----------------------------------------------------------------------+
3    | Zend Engine                                                          |
4    +----------------------------------------------------------------------+
5    | Copyright (c) 1998-2018 Zend Technologies Ltd. (http://www.zend.com) |
6    +----------------------------------------------------------------------+
7    | This source file is subject to version 2.00 of the Zend license,     |
8    | that is bundled with this package in the file LICENSE, and is        |
9    | available through the world-wide-web at the following url:           |
10    | http://www.zend.com/license/2_00.txt.                                |
11    | If you did not receive a copy of the Zend license and are unable to  |
12    | obtain it through the world-wide-web, please send a note to          |
13    | license@zend.com so we can mail you a copy immediately.              |
14    +----------------------------------------------------------------------+
15    | Author: Wez Furlong <wez@thebrainroom.com>                           |
16    |         Marcus Boerger <helly@php.net>                               |
17    +----------------------------------------------------------------------+
18 */
19 
20 #include "zend.h"
21 #include "zend_API.h"
22 
23 static zend_class_entry zend_iterator_class_entry;
24 
25 static void iter_wrapper_free(zend_object *object);
26 static void iter_wrapper_dtor(zend_object *object);
27 
28 static const zend_object_handlers iterator_object_handlers = {
29 	0,
30 	iter_wrapper_free,
31 	iter_wrapper_dtor,
32 	NULL,
33 	NULL, /* prop read */
34 	NULL, /* prop write */
35 	NULL, /* read dim */
36 	NULL, /* write dim */
37 	NULL,
38 	NULL, /* get */
39 	NULL, /* set */
40 	NULL, /* has prop */
41 	NULL, /* unset prop */
42 	NULL, /* has dim */
43 	NULL, /* unset dim */
44 	NULL, /* props get */
45 	NULL, /* method get */
46 	NULL, /* call */
47 	NULL, /* get ctor */
48 	NULL, /* get class name */
49 	NULL, /* compare */
50 	NULL, /* cast */
51 	NULL, /* count */
52 	NULL, /* get_debug_info */
53 	NULL, /* get_closure */
54 	NULL, /* get_gc */
55 	NULL, /* do_operation */
56 	NULL  /* compare */
57 };
58 
zend_register_iterator_wrapper(void)59 ZEND_API void zend_register_iterator_wrapper(void)
60 {
61 	INIT_CLASS_ENTRY(zend_iterator_class_entry, "__iterator_wrapper", NULL);
62 }
63 
iter_wrapper_free(zend_object * object)64 static void iter_wrapper_free(zend_object *object)
65 {
66 	zend_object_iterator *iter = (zend_object_iterator*)object;
67 	iter->funcs->dtor(iter);
68 }
69 
iter_wrapper_dtor(zend_object * object)70 static void iter_wrapper_dtor(zend_object *object)
71 {
72 }
73 
zend_iterator_init(zend_object_iterator * iter)74 ZEND_API void zend_iterator_init(zend_object_iterator *iter)
75 {
76 	zend_object_std_init(&iter->std, &zend_iterator_class_entry);
77 	iter->std.handlers = &iterator_object_handlers;
78 }
79 
zend_iterator_dtor(zend_object_iterator * iter)80 ZEND_API void zend_iterator_dtor(zend_object_iterator *iter)
81 {
82 	if (GC_DELREF(&iter->std) > 0) {
83 		return;
84 	}
85 
86 	zend_objects_store_del(&iter->std);
87 }
88 
zend_iterator_unwrap(zval * array_ptr)89 ZEND_API zend_object_iterator* zend_iterator_unwrap(zval *array_ptr)
90 {
91 	ZEND_ASSERT(Z_TYPE_P(array_ptr) == IS_OBJECT);
92 	if (Z_OBJ_HT_P(array_ptr) == &iterator_object_handlers) {
93 		return (zend_object_iterator *)Z_OBJ_P(array_ptr);
94 	}
95 	return NULL;
96 }
97 
98 /*
99  * Local variables:
100  * tab-width: 4
101  * c-basic-offset: 4
102  * indent-tabs-mode: t
103  * End:
104  * vim600: sw=4 ts=4 fdm=marker
105  * vim<600: sw=4 ts=4
106  */
107