1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
|
/*
+----------------------------------------------------------------------+
| Zend Engine |
+----------------------------------------------------------------------+
| Copyright (c) 1998-2012 Zend Technologies Ltd. (http://www.zend.com) |
+----------------------------------------------------------------------+
| This source file is subject to version 2.00 of the Zend license, |
| 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. |
+----------------------------------------------------------------------+
| Authors: Nikita Popov <nikic@php.net> |
+----------------------------------------------------------------------+
*/
/* $Id$ */
#include "zend.h"
#include "zend_API.h"
#include "zend_interfaces.h"
#include "zend_generators.h"
ZEND_API zend_class_entry *zend_ce_generator;
static zend_object_handlers zend_generator_handlers;
static void zend_generator_free_storage(zend_generator *generator TSRMLS_DC) /* {{{ */
{
zend_object_std_dtor(&generator->std TSRMLS_CC);
if (generator->execute_data) {
zend_execute_data *execute_data = generator->execute_data;
if (!execute_data->symbol_table) {
int i;
for (i = 0; i < execute_data->op_array->last_var; ++i) {
if (execute_data->CVs[i]) {
zval_ptr_dtor(execute_data->CVs[i]);
}
}
} else {
if (EG(symtable_cache_ptr) >= EG(symtable_cache_limit)) {
zend_hash_destroy(execute_data->symbol_table);
FREE_HASHTABLE(execute_data->symbol_table);
} else {
zend_hash_clean(execute_data->symbol_table);
*(++EG(symtable_cache_ptr)) = execute_data->symbol_table;
}
}
efree(execute_data);
}
efree(generator);
}
/* }}} */
static zend_object_value zend_generator_create(zend_class_entry *class_type TSRMLS_DC) /* {{{ */
{
zend_generator *generator;
zend_object_value object;
generator = emalloc(sizeof(zend_generator));
memset(generator, 0, sizeof(zend_generator));
zend_object_std_init(&generator->std, class_type TSRMLS_CC);
object.handle = zend_objects_store_put(generator, NULL,
(zend_objects_free_object_storage_t) zend_generator_free_storage,
NULL /* no clone handler for now */
TSRMLS_CC
);
object.handlers = &zend_generator_handlers;
return object;
}
/* }}} */
static zend_function *zend_generator_get_constructor(zval *object TSRMLS_DC) /* {{{ */
{
zend_error(E_RECOVERABLE_ERROR, "The \"Generator\" class is reserved for internal use and cannot be manually instantiated");
return NULL;
}
/* }}} */
/* {{{ proto void Generator::rewind()
* Rewind the generator */
ZEND_METHOD(Generator, rewind)
{
if (zend_parse_parameters_none() == FAILURE) {
return;
}
}
/* }}} */
/* {{{ proto bool Generator::valid()
* Check whether the generator is valid */
ZEND_METHOD(Generator, valid)
{
if (zend_parse_parameters_none() == FAILURE) {
return;
}
}
/* }}} */
/* {{{ proto mixed Generator::current()
* Get the current value */
ZEND_METHOD(Generator, current)
{
if (zend_parse_parameters_none() == FAILURE) {
return;
}
}
/* }}} */
/* {{{ proto mixed Generator::key()
* Get the current key */
ZEND_METHOD(Generator, key)
{
if (zend_parse_parameters_none() == FAILURE) {
return;
}
}
/* }}} */
/* {{{ proto void Generator::next()
* Advances the generator */
ZEND_METHOD(Generator, next)
{
if (zend_parse_parameters_none() == FAILURE) {
return;
}
}
/* }}} */
ZEND_BEGIN_ARG_INFO(arginfo_generator_void, 0)
ZEND_END_ARG_INFO()
static const zend_function_entry generator_functions[] = {
ZEND_ME(Generator, rewind, arginfo_generator_void, ZEND_ACC_PUBLIC)
ZEND_ME(Generator, valid, arginfo_generator_void, ZEND_ACC_PUBLIC)
ZEND_ME(Generator, current, arginfo_generator_void, ZEND_ACC_PUBLIC)
ZEND_ME(Generator, key, arginfo_generator_void, ZEND_ACC_PUBLIC)
ZEND_ME(Generator, next, arginfo_generator_void, ZEND_ACC_PUBLIC)
ZEND_FE_END
};
void zend_register_generator_ce(TSRMLS_D) /* {{{ */
{
zend_class_entry ce;
INIT_CLASS_ENTRY(ce, "Generator", generator_functions);
zend_ce_generator = zend_register_internal_class(&ce TSRMLS_CC);
zend_ce_generator->ce_flags |= ZEND_ACC_FINAL_CLASS;
zend_ce_generator->create_object = zend_generator_create;
zend_class_implements(zend_ce_generator TSRMLS_CC, 1, zend_ce_iterator);
memcpy(&zend_generator_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
zend_generator_handlers.get_constructor = zend_generator_get_constructor;
}
/* }}} */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* indent-tabs-mode: t
* End:
*/
|