1/*
2   +----------------------------------------------------------------------+
3   | Zend Engine                                                          |
4   +----------------------------------------------------------------------+
5   | Copyright (c) 1998-2014 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   | Authors: Nikita Popov <nikic@php.net>                                |
16   +----------------------------------------------------------------------+
17*/
18
19/* $Id$ */
20
21#include "zend.h"
22#include "zend_API.h"
23#include "zend_interfaces.h"
24#include "zend_exceptions.h"
25#include "zend_generators.h"
26
27ZEND_API zend_class_entry *zend_ce_generator;
28static zend_object_handlers zend_generator_handlers;
29
30static zend_object *zend_generator_create(zend_class_entry *class_type TSRMLS_DC);
31
32static void zend_generator_cleanup_unfinished_execution(zend_generator *generator TSRMLS_DC) /* {{{ */
33{
34    zend_execute_data *execute_data = generator->execute_data;
35    zend_op_array *op_array = &execute_data->func->op_array;
36
37    if (generator->send_target) {
38        if (Z_REFCOUNTED_P(generator->send_target)) Z_DELREF_P(generator->send_target);
39        generator->send_target = NULL;
40    }
41
42    /* Manually free loop variables, as execution couldn't reach their
43     * SWITCH_FREE / FREE opcodes. */
44    {
45        /* -1 required because we want the last run opcode, not the
46         * next to-be-run one. */
47        uint32_t op_num = execute_data->opline - op_array->opcodes - 1;
48
49        int i;
50        for (i = 0; i < op_array->last_brk_cont; ++i) {
51            zend_brk_cont_element *brk_cont = op_array->brk_cont_array + i;
52
53            if (brk_cont->start < 0) {
54                continue;
55            } else if (brk_cont->start > op_num) {
56                break;
57            } else if (brk_cont->brk > op_num) {
58                zend_op *brk_opline = op_array->opcodes + brk_cont->brk;
59
60                if (brk_opline->opcode == ZEND_FREE) {
61                    zval *var = EX_VAR_2(execute_data, brk_opline->op1.var);
62                    zval_ptr_dtor_nogc(var);
63                }
64            }
65        }
66    }
67
68    /* If yield was used as a function argument there may be active
69     * method calls those objects need to be freed */
70    while (execute_data->call) {
71        if (execute_data->call->object) {
72            OBJ_RELEASE(execute_data->call->object);
73        }
74        execute_data->call = execute_data->call->prev_nested_call;
75    }
76}
77/* }}} */
78
79ZEND_API void zend_generator_close(zend_generator *generator, zend_bool finished_execution TSRMLS_DC) /* {{{ */
80{
81    if (Z_TYPE(generator->value) != IS_UNDEF) {
82        zval_ptr_dtor(&generator->value);
83        ZVAL_UNDEF(&generator->value);
84    }
85
86    if (Z_TYPE(generator->key) != IS_UNDEF) {
87        zval_ptr_dtor(&generator->key);
88        ZVAL_UNDEF(&generator->key);
89    }
90
91    if (generator->execute_data) {
92        zend_execute_data *execute_data = generator->execute_data;
93        zend_op_array *op_array = &execute_data->func->op_array;
94
95        if (!execute_data->symbol_table) {
96            zend_free_compiled_variables(execute_data TSRMLS_CC);
97        } else {
98            zend_clean_and_cache_symbol_table(execute_data->symbol_table TSRMLS_CC);
99        }
100
101        if (execute_data->object) {
102            OBJ_RELEASE(execute_data->object);
103        }
104
105        /* A fatal error / die occurred during the generator execution. Trying to clean
106         * up the stack may not be safe in this case. */
107        if (CG(unclean_shutdown)) {
108            generator->execute_data = NULL;
109            return;
110        }
111
112        zend_vm_stack_free_extra_args(generator->execute_data TSRMLS_CC);
113
114        /* Some cleanups are only necessary if the generator was closued
115         * before it could finish execution (reach a return statement). */
116        if (!finished_execution) {
117            zend_generator_cleanup_unfinished_execution(generator TSRMLS_CC);
118        }
119
120        /* Free a clone of closure */
121        if (op_array->fn_flags & ZEND_ACC_CLOSURE) {
122            destroy_op_array(op_array TSRMLS_CC);
123            efree_size(op_array, sizeof(zend_op_array));
124        }
125
126        efree(generator->stack);
127        generator->execute_data = NULL;
128    }
129}
130/* }}} */
131
132static void zend_generator_dtor_storage(zend_object *object TSRMLS_DC) /* {{{ */
133{
134    zend_generator *generator = (zend_generator*) object;
135    zend_execute_data *ex = generator->execute_data;
136    uint32_t op_num, finally_op_num;
137    int i;
138
139    if (!ex || !(ex->func->op_array.fn_flags & ZEND_ACC_HAS_FINALLY_BLOCK)) {
140        return;
141    }
142
143    /* -1 required because we want the last run opcode, not the
144     * next to-be-run one. */
145    op_num = ex->opline - ex->func->op_array.opcodes - 1;
146
147    /* Find next finally block */
148    finally_op_num = 0;
149    for (i = 0; i < ex->func->op_array.last_try_catch; i++) {
150        zend_try_catch_element *try_catch = &ex->func->op_array.try_catch_array[i];
151
152        if (op_num < try_catch->try_op) {
153            break;
154        }
155
156        if (op_num < try_catch->finally_op) {
157            finally_op_num = try_catch->finally_op;
158        }
159    }
160
161    /* If a finally block was found we jump directly to it and
162     * resume the generator. */
163    if (finally_op_num) {
164        ex->opline = &ex->func->op_array.opcodes[finally_op_num];
165        ex->fast_ret = NULL;
166        generator->flags |= ZEND_GENERATOR_FORCED_CLOSE;
167        zend_generator_resume(generator TSRMLS_CC);
168    }
169}
170/* }}} */
171
172static void zend_generator_free_storage(zend_object *object TSRMLS_DC) /* {{{ */
173{
174    zend_generator *generator = (zend_generator*) object;
175
176    zend_generator_close(generator, 0 TSRMLS_CC);
177
178    zend_object_std_dtor(&generator->std TSRMLS_CC);
179
180    if (generator->iterator) {
181        zend_iterator_dtor(generator->iterator TSRMLS_CC);
182    }
183}
184/* }}} */
185
186static zend_object *zend_generator_create(zend_class_entry *class_type TSRMLS_DC) /* {{{ */
187{
188    zend_generator *generator;
189
190    generator = emalloc(sizeof(zend_generator));
191    memset(generator, 0, sizeof(zend_generator));
192
193    /* The key will be incremented on first use, so it'll start at 0 */
194    generator->largest_used_integer_key = -1;
195
196    zend_object_std_init(&generator->std, class_type TSRMLS_CC);
197    generator->std.handlers = &zend_generator_handlers;
198
199    return (zend_object*)generator;
200}
201/* }}} */
202
203static int copy_closure_static_var(zval *var TSRMLS_DC, int num_args, va_list args, zend_hash_key *key) /* {{{ */
204{
205    HashTable *target = va_arg(args, HashTable *);
206
207    ZVAL_MAKE_REF(var);
208    Z_ADDREF_P(var);
209    zend_hash_update(target, key->key, var);
210    return 0;
211}
212/* }}} */
213
214/* Requires globals EG(scope), EG(This) and EG(current_execute_data). */
215ZEND_API void zend_generator_create_zval(zend_execute_data *call, zend_op_array *op_array, zval *return_value TSRMLS_DC) /* {{{ */
216{
217    zend_generator *generator;
218    zend_execute_data *current_execute_data;
219    zend_execute_data *execute_data;
220    zend_vm_stack current_stack = EG(argument_stack);
221
222    /* Create a clone of closure, because it may be destroyed */
223    if (op_array->fn_flags & ZEND_ACC_CLOSURE) {
224        zend_op_array *op_array_copy = (zend_op_array*)emalloc(sizeof(zend_op_array));
225        *op_array_copy = *op_array;
226
227        (*op_array->refcount)++;
228        op_array->run_time_cache = NULL;
229        if (op_array->static_variables) {
230            ALLOC_HASHTABLE(op_array_copy->static_variables);
231            zend_hash_init(
232                op_array_copy->static_variables,
233                zend_hash_num_elements(op_array->static_variables),
234                NULL, ZVAL_PTR_DTOR, 0
235            );
236            zend_hash_apply_with_arguments(
237                op_array->static_variables TSRMLS_CC,
238                copy_closure_static_var, 1,
239                op_array_copy->static_variables
240            );
241        }
242
243        op_array = op_array_copy;
244    }
245
246    /* Create new execution context. We have to back up and restore
247     * EG(current_execute_data) here. */
248    current_execute_data = EG(current_execute_data);
249    execute_data = zend_create_generator_execute_data(call, op_array, return_value TSRMLS_CC);
250    EG(current_execute_data) = current_execute_data;
251
252    object_init_ex(return_value, zend_ce_generator);
253
254    if (Z_OBJ(EG(This))) {
255        Z_ADDREF(EG(This));
256    }
257
258    /* Save execution context in generator object. */
259    generator = (zend_generator *) Z_OBJ_P(return_value);
260    execute_data->prev_execute_data = NULL;
261    generator->execute_data = execute_data;
262    generator->stack = EG(argument_stack);
263    EG(argument_stack) = current_stack;
264
265    /* EX(return_value) keeps pointer to zend_object (not a real zval) */
266    execute_data->return_value = (zval*)generator;
267}
268/* }}} */
269
270static zend_function *zend_generator_get_constructor(zend_object *object TSRMLS_DC) /* {{{ */
271{
272    zend_error(E_RECOVERABLE_ERROR, "The \"Generator\" class is reserved for internal use and cannot be manually instantiated");
273
274    return NULL;
275}
276/* }}} */
277
278ZEND_API void zend_generator_resume(zend_generator *generator TSRMLS_DC) /* {{{ */
279{
280    /* The generator is already closed, thus can't resume */
281    if (!generator->execute_data) {
282        return;
283    }
284
285    if (generator->flags & ZEND_GENERATOR_CURRENTLY_RUNNING) {
286        zend_error(E_ERROR, "Cannot resume an already running generator");
287    }
288
289    /* Drop the AT_FIRST_YIELD flag */
290    generator->flags &= ~ZEND_GENERATOR_AT_FIRST_YIELD;
291
292    {
293        /* Backup executor globals */
294        zend_execute_data *original_execute_data = EG(current_execute_data);
295        zend_object *original_This;
296        zend_class_entry *original_scope = EG(scope);
297        zend_vm_stack original_stack = EG(argument_stack);
298
299        original_This = Z_OBJ(EG(This));
300
301        /* Set executor globals */
302        EG(current_execute_data) = generator->execute_data;
303        Z_OBJ(EG(This)) = generator->execute_data->object;
304        EG(scope) = generator->execute_data->scope;
305        EG(argument_stack) = generator->stack;
306
307        /* We want the backtrace to look as if the generator function was
308         * called from whatever method we are current running (e.g. next()).
309         * So we have to link generator call frame with caller call frames */
310
311        generator->execute_data->prev_execute_data = original_execute_data;
312
313        /* Resume execution */
314        generator->flags |= ZEND_GENERATOR_CURRENTLY_RUNNING;
315        zend_execute_ex(generator->execute_data TSRMLS_CC);
316        generator->flags &= ~ZEND_GENERATOR_CURRENTLY_RUNNING;
317
318        /* Unlink generator call_frame from the caller */
319        if (generator->execute_data) {
320            generator->execute_data->prev_execute_data = NULL;
321        }
322
323        /* Restore executor globals */
324        EG(current_execute_data) = original_execute_data;
325        Z_OBJ(EG(This)) = original_This;
326        EG(scope) = original_scope;
327        EG(argument_stack) = original_stack;
328
329        /* If an exception was thrown in the generator we have to internally
330         * rethrow it in the parent scope. */
331        if (UNEXPECTED(EG(exception) != NULL)) {
332            zend_throw_exception_internal(NULL TSRMLS_CC);
333        }
334    }
335}
336/* }}} */
337
338static void zend_generator_ensure_initialized(zend_generator *generator TSRMLS_DC) /* {{{ */
339{
340    if (generator->execute_data && Z_TYPE(generator->value) == IS_UNDEF) {
341        zend_generator_resume(generator TSRMLS_CC);
342        generator->flags |= ZEND_GENERATOR_AT_FIRST_YIELD;
343    }
344}
345/* }}} */
346
347static void zend_generator_rewind(zend_generator *generator TSRMLS_DC) /* {{{ */
348{
349    zend_generator_ensure_initialized(generator TSRMLS_CC);
350
351    if (!(generator->flags & ZEND_GENERATOR_AT_FIRST_YIELD)) {
352        zend_throw_exception(NULL, "Cannot rewind a generator that was already run", 0 TSRMLS_CC);
353    }
354}
355/* }}} */
356
357/* {{{ proto void Generator::rewind()
358 * Rewind the generator */
359ZEND_METHOD(Generator, rewind)
360{
361    zend_generator *generator;
362
363    if (zend_parse_parameters_none() == FAILURE) {
364        return;
365    }
366
367    generator = (zend_generator *) Z_OBJ_P(getThis());
368
369    zend_generator_rewind(generator TSRMLS_CC);
370}
371/* }}} */
372
373/* {{{ proto bool Generator::valid()
374 * Check whether the generator is valid */
375ZEND_METHOD(Generator, valid)
376{
377    zend_generator *generator;
378
379    if (zend_parse_parameters_none() == FAILURE) {
380        return;
381    }
382
383    generator = (zend_generator *) Z_OBJ_P(getThis());
384
385    zend_generator_ensure_initialized(generator TSRMLS_CC);
386
387    RETURN_BOOL(Z_TYPE(generator->value) != IS_UNDEF);
388}
389/* }}} */
390
391/* {{{ proto mixed Generator::current()
392 * Get the current value */
393ZEND_METHOD(Generator, current)
394{
395    zend_generator *generator;
396
397    if (zend_parse_parameters_none() == FAILURE) {
398        return;
399    }
400
401    generator = (zend_generator *) Z_OBJ_P(getThis());
402
403    zend_generator_ensure_initialized(generator TSRMLS_CC);
404
405    if (Z_TYPE(generator->value) != IS_UNDEF) {
406        RETURN_ZVAL_FAST(&generator->value);
407    }
408}
409/* }}} */
410
411/* {{{ proto mixed Generator::key()
412 * Get the current key */
413ZEND_METHOD(Generator, key)
414{
415    zend_generator *generator;
416
417    if (zend_parse_parameters_none() == FAILURE) {
418        return;
419    }
420
421    generator = (zend_generator *) Z_OBJ_P(getThis());
422
423    zend_generator_ensure_initialized(generator TSRMLS_CC);
424
425    if (Z_TYPE(generator->key) != IS_UNDEF) {
426        RETURN_ZVAL_FAST(&generator->key);
427    }
428}
429/* }}} */
430
431/* {{{ proto void Generator::next()
432 * Advances the generator */
433ZEND_METHOD(Generator, next)
434{
435    zend_generator *generator;
436
437    if (zend_parse_parameters_none() == FAILURE) {
438        return;
439    }
440
441    generator = (zend_generator *) Z_OBJ_P(getThis());
442
443    zend_generator_ensure_initialized(generator TSRMLS_CC);
444
445    zend_generator_resume(generator TSRMLS_CC);
446}
447/* }}} */
448
449/* {{{ proto mixed Generator::send(mixed $value)
450 * Sends a value to the generator */
451ZEND_METHOD(Generator, send)
452{
453    zval *value;
454    zend_generator *generator;
455
456    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &value) == FAILURE) {
457        return;
458    }
459
460    generator = (zend_generator *) Z_OBJ_P(getThis());
461
462    zend_generator_ensure_initialized(generator TSRMLS_CC);
463
464    /* The generator is already closed, thus can't send anything */
465    if (!generator->execute_data) {
466        return;
467    }
468
469    /* Put sent value in the target VAR slot, if it is used */
470    if (generator->send_target) {
471        if (Z_REFCOUNTED_P(generator->send_target)) Z_DELREF_P(generator->send_target);
472        ZVAL_COPY(generator->send_target, value);
473    }
474
475    zend_generator_resume(generator TSRMLS_CC);
476
477    if (Z_TYPE(generator->value) != IS_UNDEF) {
478        RETURN_ZVAL_FAST(&generator->value);
479    }
480}
481/* }}} */
482
483/* {{{ proto mixed Generator::throw(Exception $exception)
484 * Throws an exception into the generator */
485ZEND_METHOD(Generator, throw)
486{
487    zval *exception, exception_copy;
488    zend_generator *generator;
489
490    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &exception) == FAILURE) {
491        return;
492    }
493
494    ZVAL_DUP(&exception_copy, exception);
495
496    generator = (zend_generator *) Z_OBJ_P(getThis());
497
498    zend_generator_ensure_initialized(generator TSRMLS_CC);
499
500    if (generator->execute_data) {
501        /* Throw the exception in the context of the generator */
502        zend_execute_data *current_execute_data = EG(current_execute_data);
503        EG(current_execute_data) = generator->execute_data;
504
505        zend_throw_exception_object(&exception_copy TSRMLS_CC);
506
507        EG(current_execute_data) = current_execute_data;
508
509        zend_generator_resume(generator TSRMLS_CC);
510
511        if (Z_TYPE(generator->value) != IS_UNDEF) {
512            RETURN_ZVAL_FAST(&generator->value);
513        }
514    } else {
515        /* If the generator is already closed throw the exception in the
516         * current context */
517        zend_throw_exception_object(&exception_copy TSRMLS_CC);
518    }
519}
520/* }}} */
521
522/* {{{ proto void Generator::__wakeup()
523 * Throws an Exception as generators can't be serialized */
524ZEND_METHOD(Generator, __wakeup)
525{
526    /* Just specifying the zend_class_unserialize_deny handler is not enough,
527     * because it is only invoked for C unserialization. For O the error has
528     * to be thrown in __wakeup. */
529
530    if (zend_parse_parameters_none() == FAILURE) {
531        return;
532    }
533
534    zend_throw_exception(NULL, "Unserialization of 'Generator' is not allowed", 0 TSRMLS_CC);
535}
536/* }}} */
537
538/* get_iterator implementation */
539
540static void zend_generator_iterator_dtor(zend_object_iterator *iterator TSRMLS_DC) /* {{{ */
541{
542    zend_generator *generator = (zend_generator*)Z_OBJ(iterator->data);
543    generator->iterator = NULL;
544    zval_ptr_dtor(&iterator->data);
545    zend_iterator_dtor(iterator TSRMLS_CC);
546}
547/* }}} */
548
549static int zend_generator_iterator_valid(zend_object_iterator *iterator TSRMLS_DC) /* {{{ */
550{
551    zend_generator *generator = (zend_generator*)Z_OBJ(iterator->data);
552
553    zend_generator_ensure_initialized(generator TSRMLS_CC);
554
555    return Z_TYPE(generator->value) != IS_UNDEF ? SUCCESS : FAILURE;
556}
557/* }}} */
558
559static zval *zend_generator_iterator_get_data(zend_object_iterator *iterator TSRMLS_DC) /* {{{ */
560{
561    zend_generator *generator = (zend_generator*)Z_OBJ(iterator->data);
562
563    zend_generator_ensure_initialized(generator TSRMLS_CC);
564
565    return &generator->value;
566}
567/* }}} */
568
569static void zend_generator_iterator_get_key(zend_object_iterator *iterator, zval *key TSRMLS_DC) /* {{{ */
570{
571    zend_generator *generator = (zend_generator*)Z_OBJ(iterator->data);
572
573    zend_generator_ensure_initialized(generator TSRMLS_CC);
574
575    if (Z_TYPE(generator->key) != IS_UNDEF) {
576        ZVAL_ZVAL(key, &generator->key, 1, 0);
577    } else {
578        ZVAL_NULL(key);
579    }
580}
581/* }}} */
582
583static void zend_generator_iterator_move_forward(zend_object_iterator *iterator TSRMLS_DC) /* {{{ */
584{
585    zend_generator *generator = (zend_generator*)Z_OBJ(iterator->data);
586
587    zend_generator_ensure_initialized(generator TSRMLS_CC);
588
589    zend_generator_resume(generator TSRMLS_CC);
590}
591/* }}} */
592
593static void zend_generator_iterator_rewind(zend_object_iterator *iterator TSRMLS_DC) /* {{{ */
594{
595    zend_generator *generator = (zend_generator*)Z_OBJ(iterator->data);
596
597    zend_generator_rewind(generator TSRMLS_CC);
598}
599/* }}} */
600
601static zend_object_iterator_funcs zend_generator_iterator_functions = {
602    zend_generator_iterator_dtor,
603    zend_generator_iterator_valid,
604    zend_generator_iterator_get_data,
605    zend_generator_iterator_get_key,
606    zend_generator_iterator_move_forward,
607    zend_generator_iterator_rewind
608};
609
610zend_object_iterator *zend_generator_get_iterator(zend_class_entry *ce, zval *object, int by_ref TSRMLS_DC) /* {{{ */
611{
612    zend_object_iterator *iterator;
613    zend_generator *generator = (zend_generator*)Z_OBJ_P(object);
614
615    if (!generator->execute_data) {
616        zend_throw_exception(NULL, "Cannot traverse an already closed generator", 0 TSRMLS_CC);
617        return NULL;
618    }
619
620    if (by_ref && !(generator->execute_data->func->op_array.fn_flags & ZEND_ACC_RETURN_REFERENCE)) {
621        zend_throw_exception(NULL, "You can only iterate a generator by-reference if it declared that it yields by-reference", 0 TSRMLS_CC);
622        return NULL;
623    }
624
625    iterator = generator->iterator = emalloc(sizeof(zend_object_iterator));
626
627    zend_iterator_init(iterator TSRMLS_CC);
628
629    iterator->funcs = &zend_generator_iterator_functions;
630    ZVAL_COPY(&iterator->data, object);
631
632    return iterator;
633}
634/* }}} */
635
636ZEND_BEGIN_ARG_INFO(arginfo_generator_void, 0)
637ZEND_END_ARG_INFO()
638
639ZEND_BEGIN_ARG_INFO_EX(arginfo_generator_send, 0, 0, 1)
640    ZEND_ARG_INFO(0, value)
641ZEND_END_ARG_INFO()
642
643ZEND_BEGIN_ARG_INFO_EX(arginfo_generator_throw, 0, 0, 1)
644    ZEND_ARG_INFO(0, exception)
645ZEND_END_ARG_INFO()
646
647static const zend_function_entry generator_functions[] = {
648    ZEND_ME(Generator, rewind,   arginfo_generator_void, ZEND_ACC_PUBLIC)
649    ZEND_ME(Generator, valid,    arginfo_generator_void, ZEND_ACC_PUBLIC)
650    ZEND_ME(Generator, current,  arginfo_generator_void, ZEND_ACC_PUBLIC)
651    ZEND_ME(Generator, key,      arginfo_generator_void, ZEND_ACC_PUBLIC)
652    ZEND_ME(Generator, next,     arginfo_generator_void, ZEND_ACC_PUBLIC)
653    ZEND_ME(Generator, send,     arginfo_generator_send, ZEND_ACC_PUBLIC)
654    ZEND_ME(Generator, throw,    arginfo_generator_throw, ZEND_ACC_PUBLIC)
655    ZEND_ME(Generator, __wakeup, arginfo_generator_void, ZEND_ACC_PUBLIC)
656    ZEND_FE_END
657};
658
659void zend_register_generator_ce(TSRMLS_D) /* {{{ */
660{
661    zend_class_entry ce;
662
663    INIT_CLASS_ENTRY(ce, "Generator", generator_functions);
664    zend_ce_generator = zend_register_internal_class(&ce TSRMLS_CC);
665    zend_ce_generator->ce_flags |= ZEND_ACC_FINAL_CLASS;
666    zend_ce_generator->create_object = zend_generator_create;
667    zend_ce_generator->serialize = zend_class_serialize_deny;
668    zend_ce_generator->unserialize = zend_class_unserialize_deny;
669
670    /* get_iterator has to be assigned *after* implementing the inferface */
671    zend_class_implements(zend_ce_generator TSRMLS_CC, 1, zend_ce_iterator);
672    zend_ce_generator->get_iterator = zend_generator_get_iterator;
673    zend_ce_generator->iterator_funcs.funcs = &zend_generator_iterator_functions;
674
675    memcpy(&zend_generator_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
676    zend_generator_handlers.free_obj = zend_generator_free_storage;
677    zend_generator_handlers.dtor_obj = zend_generator_dtor_storage;
678    zend_generator_handlers.clone_obj = NULL;
679    zend_generator_handlers.get_constructor = zend_generator_get_constructor;
680}
681/* }}} */
682
683/*
684 * Local variables:
685 * tab-width: 4
686 * c-basic-offset: 4
687 * indent-tabs-mode: t
688 * End:
689 */
690