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 /* $Id$ */
21
22 #include "zend.h"
23 #include "zend_API.h"
24
25 static zend_class_entry zend_iterator_class_entry;
26
27 static void iter_wrapper_free(zend_object *object);
28 static void iter_wrapper_dtor(zend_object *object);
29
30 static zend_object_handlers iterator_object_handlers = {
31 0,
32 iter_wrapper_free,
33 iter_wrapper_dtor,
34 NULL,
35 NULL, /* prop read */
36 NULL, /* prop write */
37 NULL, /* read dim */
38 NULL, /* write dim */
39 NULL,
40 NULL, /* get */
41 NULL, /* set */
42 NULL, /* has prop */
43 NULL, /* unset prop */
44 NULL, /* has dim */
45 NULL, /* unset dim */
46 NULL, /* props get */
47 NULL, /* method get */
48 NULL, /* call */
49 NULL, /* get ctor */
50 NULL, /* get class name */
51 NULL, /* compare */
52 NULL, /* cast */
53 NULL, /* count */
54 NULL, /* get_debug_info */
55 NULL, /* get_closure */
56 NULL, /* get_gc */
57 NULL, /* do_operation */
58 NULL /* compare */
59 };
60
zend_register_iterator_wrapper(void)61 ZEND_API void zend_register_iterator_wrapper(void)
62 {
63 INIT_CLASS_ENTRY(zend_iterator_class_entry, "__iterator_wrapper", NULL);
64 }
65
iter_wrapper_free(zend_object * object)66 static void iter_wrapper_free(zend_object *object)
67 {
68 zend_object_iterator *iter = (zend_object_iterator*)object;
69 iter->funcs->dtor(iter);
70 }
71
iter_wrapper_dtor(zend_object * object)72 static void iter_wrapper_dtor(zend_object *object)
73 {
74 }
75
zend_iterator_init(zend_object_iterator * iter)76 ZEND_API void zend_iterator_init(zend_object_iterator *iter)
77 {
78 zend_object_std_init(&iter->std, &zend_iterator_class_entry);
79 iter->std.handlers = &iterator_object_handlers;
80 }
81
zend_iterator_dtor(zend_object_iterator * iter)82 ZEND_API void zend_iterator_dtor(zend_object_iterator *iter)
83 {
84 if (--GC_REFCOUNT(&iter->std) > 0) {
85 return;
86 }
87
88 zend_objects_store_del(&iter->std);
89 }
90
zend_iterator_unwrap(zval * array_ptr)91 ZEND_API zend_object_iterator* zend_iterator_unwrap(zval *array_ptr)
92 {
93 ZEND_ASSERT(Z_TYPE_P(array_ptr) == IS_OBJECT);
94 if (Z_OBJ_HT_P(array_ptr) == &iterator_object_handlers) {
95 return (zend_object_iterator *)Z_OBJ_P(array_ptr);
96 }
97 return NULL;
98 }
99
100 /*
101 * Local variables:
102 * tab-width: 4
103 * c-basic-offset: 4
104 * indent-tabs-mode: t
105 * End:
106 */
107