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