2012-05-20 06:03:27 +08:00
|
|
|
/*
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| Zend Engine |
|
|
|
|
+----------------------------------------------------------------------+
|
2015-01-15 23:27:30 +08:00
|
|
|
| Copyright (c) 1998-2015 Zend Technologies Ltd. (http://www.zend.com) |
|
2012-05-20 06:03:27 +08:00
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| 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"
|
2012-05-23 22:07:15 +08:00
|
|
|
#include "zend_interfaces.h"
|
2012-07-22 23:46:46 +08:00
|
|
|
#include "zend_exceptions.h"
|
2012-05-20 06:03:27 +08:00
|
|
|
#include "zend_generators.h"
|
|
|
|
|
|
|
|
ZEND_API zend_class_entry *zend_ce_generator;
|
2012-05-20 20:19:16 +08:00
|
|
|
static zend_object_handlers zend_generator_handlers;
|
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
static zend_object *zend_generator_create(zend_class_entry *class_type);
|
2013-02-02 01:33:26 +08:00
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
static void zend_generator_cleanup_unfinished_execution(zend_generator *generator) /* {{{ */
|
2013-11-30 20:35:33 +08:00
|
|
|
{
|
|
|
|
zend_execute_data *execute_data = generator->execute_data;
|
2014-06-27 03:51:14 +08:00
|
|
|
zend_op_array *op_array = &execute_data->func->op_array;
|
2013-11-30 20:35:33 +08:00
|
|
|
|
|
|
|
if (generator->send_target) {
|
2014-02-26 17:58:59 +08:00
|
|
|
if (Z_REFCOUNTED_P(generator->send_target)) Z_DELREF_P(generator->send_target);
|
2013-11-30 20:35:33 +08:00
|
|
|
generator->send_target = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Manually free loop variables, as execution couldn't reach their
|
|
|
|
* SWITCH_FREE / FREE opcodes. */
|
|
|
|
{
|
|
|
|
/* -1 required because we want the last run opcode, not the
|
|
|
|
* next to-be-run one. */
|
2014-08-26 01:28:33 +08:00
|
|
|
uint32_t op_num = execute_data->opline - op_array->opcodes - 1;
|
2013-11-30 20:35:33 +08:00
|
|
|
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < op_array->last_brk_cont; ++i) {
|
|
|
|
zend_brk_cont_element *brk_cont = op_array->brk_cont_array + i;
|
|
|
|
|
|
|
|
if (brk_cont->start < 0) {
|
|
|
|
continue;
|
2014-10-13 15:12:15 +08:00
|
|
|
} else if ((uint32_t)brk_cont->start > op_num) {
|
2013-11-30 20:35:33 +08:00
|
|
|
break;
|
2014-10-13 15:12:15 +08:00
|
|
|
} else if (brk_cont->brk >= 0 && (uint32_t)brk_cont->brk > op_num) {
|
2013-11-30 20:35:33 +08:00
|
|
|
zend_op *brk_opline = op_array->opcodes + brk_cont->brk;
|
|
|
|
|
2014-09-23 21:21:29 +08:00
|
|
|
if (brk_opline->opcode == ZEND_FREE) {
|
2014-11-28 16:11:33 +08:00
|
|
|
zval *var = EX_VAR(brk_opline->op1.var);
|
2014-09-23 21:21:29 +08:00
|
|
|
zval_ptr_dtor_nogc(var);
|
2015-02-12 18:57:12 +08:00
|
|
|
} else if (brk_opline->opcode == ZEND_FE_FREE) {
|
|
|
|
zval *var = EX_VAR(brk_opline->op1.var);
|
|
|
|
if (Z_TYPE_P(var) != IS_ARRAY && Z_FE_ITER_P(var) != (uint32_t)-1) {
|
|
|
|
zend_hash_iterator_del(Z_FE_ITER_P(var));
|
|
|
|
}
|
|
|
|
zval_ptr_dtor_nogc(var);
|
2013-11-30 20:35:33 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If yield was used as a function argument there may be active
|
|
|
|
* method calls those objects need to be freed */
|
2014-06-24 06:17:16 +08:00
|
|
|
while (execute_data->call) {
|
2014-10-03 23:32:46 +08:00
|
|
|
if (Z_OBJ(execute_data->call->This)) {
|
|
|
|
OBJ_RELEASE(Z_OBJ(execute_data->call->This));
|
2014-03-28 06:11:22 +08:00
|
|
|
}
|
2014-10-01 14:46:13 +08:00
|
|
|
execute_data->call = execute_data->call->prev_execute_data;
|
2013-11-30 20:35:33 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
ZEND_API void zend_generator_close(zend_generator *generator, zend_bool finished_execution) /* {{{ */
|
2012-05-20 20:19:16 +08:00
|
|
|
{
|
2014-02-10 14:04:30 +08:00
|
|
|
if (Z_TYPE(generator->value) != IS_UNDEF) {
|
2012-12-22 00:28:20 +08:00
|
|
|
zval_ptr_dtor(&generator->value);
|
2014-02-10 14:04:30 +08:00
|
|
|
ZVAL_UNDEF(&generator->value);
|
2012-12-22 00:28:20 +08:00
|
|
|
}
|
|
|
|
|
2014-02-10 14:04:30 +08:00
|
|
|
if (Z_TYPE(generator->key) != IS_UNDEF) {
|
2012-12-22 00:28:20 +08:00
|
|
|
zval_ptr_dtor(&generator->key);
|
2014-02-10 14:04:30 +08:00
|
|
|
ZVAL_UNDEF(&generator->key);
|
2012-12-22 00:28:20 +08:00
|
|
|
}
|
|
|
|
|
2012-05-23 20:20:25 +08:00
|
|
|
if (generator->execute_data) {
|
|
|
|
zend_execute_data *execute_data = generator->execute_data;
|
2014-06-27 03:51:14 +08:00
|
|
|
zend_op_array *op_array = &execute_data->func->op_array;
|
2012-12-12 21:47:55 +08:00
|
|
|
|
2012-05-23 20:20:25 +08:00
|
|
|
if (!execute_data->symbol_table) {
|
2014-12-14 06:06:14 +08:00
|
|
|
zend_free_compiled_variables(execute_data);
|
2012-05-23 20:20:25 +08:00
|
|
|
} else {
|
2014-12-14 06:06:14 +08:00
|
|
|
zend_clean_and_cache_symbol_table(execute_data->symbol_table);
|
2012-05-23 20:20:25 +08:00
|
|
|
}
|
|
|
|
|
2014-10-03 23:32:46 +08:00
|
|
|
if (Z_OBJ(execute_data->This)) {
|
|
|
|
OBJ_RELEASE(Z_OBJ(execute_data->This));
|
2014-03-28 06:11:22 +08:00
|
|
|
}
|
2012-05-27 09:50:31 +08:00
|
|
|
|
2013-07-08 05:40:16 +08:00
|
|
|
/* A fatal error / die occurred during the generator execution. Trying to clean
|
2013-06-30 03:51:54 +08:00
|
|
|
* up the stack may not be safe in this case. */
|
|
|
|
if (CG(unclean_shutdown)) {
|
2014-07-02 23:33:31 +08:00
|
|
|
generator->execute_data = NULL;
|
2013-06-30 03:51:54 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
zend_vm_stack_free_extra_args(generator->execute_data);
|
2012-06-09 06:40:47 +08:00
|
|
|
|
2013-11-30 20:35:33 +08:00
|
|
|
/* Some cleanups are only necessary if the generator was closued
|
|
|
|
* before it could finish execution (reach a return statement). */
|
|
|
|
if (!finished_execution) {
|
2014-12-14 06:06:14 +08:00
|
|
|
zend_generator_cleanup_unfinished_execution(generator);
|
2013-11-30 20:35:33 +08:00
|
|
|
}
|
|
|
|
|
2012-09-05 13:50:55 +08:00
|
|
|
/* Free a clone of closure */
|
|
|
|
if (op_array->fn_flags & ZEND_ACC_CLOSURE) {
|
2014-12-14 06:06:14 +08:00
|
|
|
destroy_op_array(op_array);
|
2014-08-28 00:49:56 +08:00
|
|
|
efree_size(op_array, sizeof(zend_op_array));
|
2012-09-05 13:50:55 +08:00
|
|
|
}
|
|
|
|
|
2012-11-30 17:39:23 +08:00
|
|
|
efree(generator->stack);
|
2012-05-27 05:59:22 +08:00
|
|
|
generator->execute_data = NULL;
|
2012-05-23 20:20:25 +08:00
|
|
|
}
|
2012-05-27 05:59:22 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
static void zend_generator_dtor_storage(zend_object *object) /* {{{ */
|
2013-01-31 06:52:02 +08:00
|
|
|
{
|
2014-02-10 14:04:30 +08:00
|
|
|
zend_generator *generator = (zend_generator*) object;
|
2013-01-31 06:52:02 +08:00
|
|
|
zend_execute_data *ex = generator->execute_data;
|
2014-11-27 14:56:43 +08:00
|
|
|
uint32_t op_num, finally_op_num, finally_op_end;
|
2013-01-31 06:52:02 +08:00
|
|
|
int i;
|
|
|
|
|
2014-08-28 02:45:27 +08:00
|
|
|
if (!ex || !(ex->func->op_array.fn_flags & ZEND_ACC_HAS_FINALLY_BLOCK)) {
|
2013-01-31 06:52:02 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -1 required because we want the last run opcode, not the
|
|
|
|
* next to-be-run one. */
|
2014-06-27 03:51:14 +08:00
|
|
|
op_num = ex->opline - ex->func->op_array.opcodes - 1;
|
2013-01-31 06:52:02 +08:00
|
|
|
|
|
|
|
/* Find next finally block */
|
|
|
|
finally_op_num = 0;
|
2014-11-27 14:56:43 +08:00
|
|
|
finally_op_end = 0;
|
2014-06-27 03:51:14 +08:00
|
|
|
for (i = 0; i < ex->func->op_array.last_try_catch; i++) {
|
|
|
|
zend_try_catch_element *try_catch = &ex->func->op_array.try_catch_array[i];
|
2013-01-31 06:52:02 +08:00
|
|
|
|
|
|
|
if (op_num < try_catch->try_op) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (op_num < try_catch->finally_op) {
|
|
|
|
finally_op_num = try_catch->finally_op;
|
2014-11-27 14:56:43 +08:00
|
|
|
finally_op_end = try_catch->finally_end;
|
2013-01-31 06:52:02 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If a finally block was found we jump directly to it and
|
|
|
|
* resume the generator. */
|
|
|
|
if (finally_op_num) {
|
2014-11-28 16:11:33 +08:00
|
|
|
zval *fast_call = ZEND_CALL_VAR(ex, ex->func->op_array.opcodes[finally_op_end].op1.var);
|
2014-11-27 14:56:43 +08:00
|
|
|
|
2014-12-02 21:05:30 +08:00
|
|
|
Z_OBJ_P(fast_call) = NULL;
|
2014-11-27 14:56:43 +08:00
|
|
|
fast_call->u2.lineno = (uint32_t)-1;
|
2014-06-27 03:51:14 +08:00
|
|
|
ex->opline = &ex->func->op_array.opcodes[finally_op_num];
|
2013-01-31 06:52:02 +08:00
|
|
|
generator->flags |= ZEND_GENERATOR_FORCED_CLOSE;
|
2014-12-14 06:06:14 +08:00
|
|
|
zend_generator_resume(generator);
|
2013-01-31 06:52:02 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
static void zend_generator_free_storage(zend_object *object) /* {{{ */
|
2012-05-27 05:59:22 +08:00
|
|
|
{
|
2014-02-10 14:04:30 +08:00
|
|
|
zend_generator *generator = (zend_generator*) object;
|
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
zend_generator_close(generator, 0);
|
2012-05-27 05:59:22 +08:00
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
zend_object_std_dtor(&generator->std);
|
2014-03-19 21:00:28 +08:00
|
|
|
|
2014-04-09 05:50:15 +08:00
|
|
|
if (generator->iterator) {
|
2014-12-14 06:06:14 +08:00
|
|
|
zend_iterator_dtor(generator->iterator);
|
2014-03-21 03:05:38 +08:00
|
|
|
}
|
2012-05-20 20:19:16 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
static zend_object *zend_generator_create(zend_class_entry *class_type) /* {{{ */
|
2012-05-20 20:19:16 +08:00
|
|
|
{
|
|
|
|
zend_generator *generator;
|
|
|
|
|
|
|
|
generator = emalloc(sizeof(zend_generator));
|
|
|
|
memset(generator, 0, sizeof(zend_generator));
|
|
|
|
|
2012-05-30 11:05:49 +08:00
|
|
|
/* The key will be incremented on first use, so it'll start at 0 */
|
|
|
|
generator->largest_used_integer_key = -1;
|
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
zend_object_std_init(&generator->std, class_type);
|
2014-02-10 14:04:30 +08:00
|
|
|
generator->std.handlers = &zend_generator_handlers;
|
2012-05-20 20:19:16 +08:00
|
|
|
|
2014-02-10 14:04:30 +08:00
|
|
|
return (zend_object*)generator;
|
2012-05-20 20:19:16 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
static int copy_closure_static_var(zval *var, int num_args, va_list args, zend_hash_key *key) /* {{{ */
|
2013-09-30 02:18:12 +08:00
|
|
|
{
|
|
|
|
HashTable *target = va_arg(args, HashTable *);
|
|
|
|
|
2014-06-05 20:04:11 +08:00
|
|
|
ZVAL_MAKE_REF(var);
|
2014-02-10 14:04:30 +08:00
|
|
|
Z_ADDREF_P(var);
|
|
|
|
zend_hash_update(target, key->key, var);
|
2014-05-25 20:04:35 +08:00
|
|
|
return 0;
|
2013-09-30 02:18:12 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2014-07-04 22:03:45 +08:00
|
|
|
/* Requires globals EG(scope), EG(This) and EG(current_execute_data). */
|
2014-12-14 06:06:14 +08:00
|
|
|
ZEND_API void zend_generator_create_zval(zend_execute_data *call, zend_op_array *op_array, zval *return_value) /* {{{ */
|
2012-07-20 06:49:50 +08:00
|
|
|
{
|
|
|
|
zend_generator *generator;
|
2012-09-05 18:53:29 +08:00
|
|
|
zend_execute_data *current_execute_data;
|
|
|
|
zend_execute_data *execute_data;
|
2014-10-10 00:29:02 +08:00
|
|
|
zend_vm_stack current_stack = EG(vm_stack);
|
2012-07-20 06:49:50 +08:00
|
|
|
|
2014-10-10 00:29:02 +08:00
|
|
|
current_stack->top = EG(vm_stack_top);
|
2012-09-05 13:50:55 +08:00
|
|
|
/* Create a clone of closure, because it may be destroyed */
|
|
|
|
if (op_array->fn_flags & ZEND_ACC_CLOSURE) {
|
|
|
|
zend_op_array *op_array_copy = (zend_op_array*)emalloc(sizeof(zend_op_array));
|
|
|
|
*op_array_copy = *op_array;
|
2013-09-30 02:18:12 +08:00
|
|
|
|
2015-02-20 19:59:30 +08:00
|
|
|
if (op_array->refcount) {
|
|
|
|
(*op_array->refcount)++;
|
|
|
|
}
|
2013-09-30 02:18:12 +08:00
|
|
|
op_array->run_time_cache = NULL;
|
|
|
|
if (op_array->static_variables) {
|
|
|
|
ALLOC_HASHTABLE(op_array_copy->static_variables);
|
|
|
|
zend_hash_init(
|
2015-01-03 17:22:58 +08:00
|
|
|
op_array_copy->static_variables,
|
2013-09-30 02:18:12 +08:00
|
|
|
zend_hash_num_elements(op_array->static_variables),
|
|
|
|
NULL, ZVAL_PTR_DTOR, 0
|
|
|
|
);
|
|
|
|
zend_hash_apply_with_arguments(
|
2014-12-14 06:06:14 +08:00
|
|
|
op_array->static_variables,
|
2015-01-03 17:22:58 +08:00
|
|
|
copy_closure_static_var, 1,
|
2014-05-25 20:04:35 +08:00
|
|
|
op_array_copy->static_variables
|
2013-09-30 02:18:12 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2012-09-05 13:50:55 +08:00
|
|
|
op_array = op_array_copy;
|
|
|
|
}
|
2015-01-03 17:22:58 +08:00
|
|
|
|
2012-07-20 06:49:50 +08:00
|
|
|
/* Create new execution context. We have to back up and restore
|
2014-07-04 22:03:45 +08:00
|
|
|
* EG(current_execute_data) here. */
|
2012-09-05 18:53:29 +08:00
|
|
|
current_execute_data = EG(current_execute_data);
|
2014-12-14 06:06:14 +08:00
|
|
|
execute_data = zend_create_generator_execute_data(call, op_array, return_value);
|
2012-07-20 06:49:50 +08:00
|
|
|
EG(current_execute_data) = current_execute_data;
|
|
|
|
|
|
|
|
object_init_ex(return_value, zend_ce_generator);
|
|
|
|
|
2014-10-03 23:32:46 +08:00
|
|
|
if (Z_OBJ(call->This)) {
|
|
|
|
Z_ADDREF(call->This);
|
2012-07-20 06:49:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Save execution context in generator object. */
|
2014-02-10 14:04:30 +08:00
|
|
|
generator = (zend_generator *) Z_OBJ_P(return_value);
|
2014-06-27 03:51:14 +08:00
|
|
|
execute_data->prev_execute_data = NULL;
|
2012-07-20 06:49:50 +08:00
|
|
|
generator->execute_data = execute_data;
|
2014-10-10 00:29:02 +08:00
|
|
|
generator->stack = EG(vm_stack);
|
|
|
|
generator->stack->top = EG(vm_stack_top);
|
|
|
|
EG(vm_stack_top) = current_stack->top;
|
|
|
|
EG(vm_stack_end) = current_stack->end;
|
|
|
|
EG(vm_stack) = current_stack;
|
2014-02-26 17:58:59 +08:00
|
|
|
|
|
|
|
/* EX(return_value) keeps pointer to zend_object (not a real zval) */
|
|
|
|
execute_data->return_value = (zval*)generator;
|
2012-07-20 06:49:50 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
static zend_function *zend_generator_get_constructor(zend_object *object) /* {{{ */
|
2012-05-20 20:19:16 +08:00
|
|
|
{
|
2015-03-10 15:31:55 +08:00
|
|
|
zend_error(E_EXCEPTION | E_ERROR, "The \"Generator\" class is reserved for internal use and cannot be manually instantiated");
|
2012-05-20 20:19:16 +08:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
/* }}} */
|
2012-05-20 06:03:27 +08:00
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
ZEND_API void zend_generator_resume(zend_generator *generator) /* {{{ */
|
2012-05-26 23:53:13 +08:00
|
|
|
{
|
2012-05-27 05:59:22 +08:00
|
|
|
/* The generator is already closed, thus can't resume */
|
|
|
|
if (!generator->execute_data) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-08-25 23:40:08 +08:00
|
|
|
if (generator->flags & ZEND_GENERATOR_CURRENTLY_RUNNING) {
|
|
|
|
zend_error(E_ERROR, "Cannot resume an already running generator");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Drop the AT_FIRST_YIELD flag */
|
|
|
|
generator->flags &= ~ZEND_GENERATOR_AT_FIRST_YIELD;
|
|
|
|
|
2012-05-27 09:50:31 +08:00
|
|
|
{
|
|
|
|
/* Backup executor globals */
|
2012-05-28 06:24:58 +08:00
|
|
|
zend_execute_data *original_execute_data = EG(current_execute_data);
|
2012-05-27 09:50:31 +08:00
|
|
|
zend_class_entry *original_scope = EG(scope);
|
2014-10-10 00:29:02 +08:00
|
|
|
zend_vm_stack original_stack = EG(vm_stack);
|
|
|
|
original_stack->top = EG(vm_stack_top);
|
2015-01-10 00:58:41 +08:00
|
|
|
|
2012-05-27 09:50:31 +08:00
|
|
|
/* Set executor globals */
|
2012-05-28 06:24:58 +08:00
|
|
|
EG(current_execute_data) = generator->execute_data;
|
2014-11-28 15:21:18 +08:00
|
|
|
EG(scope) = generator->execute_data->func->common.scope;
|
2014-10-10 00:29:02 +08:00
|
|
|
EG(vm_stack_top) = generator->stack->top;
|
|
|
|
EG(vm_stack_end) = generator->stack->end;
|
|
|
|
EG(vm_stack) = generator->stack;
|
2012-05-27 09:50:31 +08:00
|
|
|
|
2012-06-09 06:40:47 +08:00
|
|
|
/* We want the backtrace to look as if the generator function was
|
|
|
|
* called from whatever method we are current running (e.g. next()).
|
2015-01-10 00:58:41 +08:00
|
|
|
* So we have to link generator call frame with caller call frame. */
|
2014-07-03 02:01:25 +08:00
|
|
|
generator->execute_data->prev_execute_data = original_execute_data;
|
2012-06-03 08:00:11 +08:00
|
|
|
|
2012-05-27 09:50:31 +08:00
|
|
|
/* Resume execution */
|
2012-08-25 23:40:08 +08:00
|
|
|
generator->flags |= ZEND_GENERATOR_CURRENTLY_RUNNING;
|
2014-12-14 06:06:14 +08:00
|
|
|
zend_execute_ex(generator->execute_data);
|
2012-08-25 23:40:08 +08:00
|
|
|
generator->flags &= ~ZEND_GENERATOR_CURRENTLY_RUNNING;
|
2012-05-27 09:50:31 +08:00
|
|
|
|
2015-01-13 05:30:38 +08:00
|
|
|
/* Unlink generator call_frame from the caller and backup vm_stack_top */
|
2014-07-07 19:50:44 +08:00
|
|
|
if (generator->execute_data) {
|
2015-01-13 05:30:38 +08:00
|
|
|
generator->stack = EG(vm_stack);
|
|
|
|
generator->stack->top = EG(vm_stack_top);
|
2014-06-27 03:51:14 +08:00
|
|
|
generator->execute_data->prev_execute_data = NULL;
|
|
|
|
}
|
|
|
|
|
2012-05-27 09:50:31 +08:00
|
|
|
/* Restore executor globals */
|
2012-05-28 06:24:58 +08:00
|
|
|
EG(current_execute_data) = original_execute_data;
|
2012-05-27 09:50:31 +08:00
|
|
|
EG(scope) = original_scope;
|
2014-10-10 00:29:02 +08:00
|
|
|
EG(vm_stack_top) = original_stack->top;
|
|
|
|
EG(vm_stack_end) = original_stack->end;
|
|
|
|
EG(vm_stack) = original_stack;
|
2012-09-23 01:12:21 +08:00
|
|
|
|
2012-07-22 23:46:46 +08:00
|
|
|
/* If an exception was thrown in the generator we have to internally
|
|
|
|
* rethrow it in the parent scope. */
|
|
|
|
if (UNEXPECTED(EG(exception) != NULL)) {
|
2014-12-14 06:06:14 +08:00
|
|
|
zend_throw_exception_internal(NULL);
|
2012-07-22 23:46:46 +08:00
|
|
|
}
|
2012-05-27 09:50:31 +08:00
|
|
|
}
|
2012-05-26 23:53:13 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
static void zend_generator_ensure_initialized(zend_generator *generator) /* {{{ */
|
2012-05-26 23:53:13 +08:00
|
|
|
{
|
2014-02-10 14:04:30 +08:00
|
|
|
if (generator->execute_data && Z_TYPE(generator->value) == IS_UNDEF) {
|
2014-12-14 06:06:14 +08:00
|
|
|
zend_generator_resume(generator);
|
2012-08-25 23:40:08 +08:00
|
|
|
generator->flags |= ZEND_GENERATOR_AT_FIRST_YIELD;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
static void zend_generator_rewind(zend_generator *generator) /* {{{ */
|
2012-08-25 23:40:08 +08:00
|
|
|
{
|
2014-12-14 06:06:14 +08:00
|
|
|
zend_generator_ensure_initialized(generator);
|
2012-08-25 23:40:08 +08:00
|
|
|
|
|
|
|
if (!(generator->flags & ZEND_GENERATOR_AT_FIRST_YIELD)) {
|
2014-12-14 06:06:14 +08:00
|
|
|
zend_throw_exception(NULL, "Cannot rewind a generator that was already run", 0);
|
2012-05-26 23:53:13 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2012-05-23 22:07:15 +08:00
|
|
|
/* {{{ proto void Generator::rewind()
|
|
|
|
* Rewind the generator */
|
|
|
|
ZEND_METHOD(Generator, rewind)
|
|
|
|
{
|
2012-05-26 23:53:13 +08:00
|
|
|
zend_generator *generator;
|
|
|
|
|
2012-05-23 22:07:15 +08:00
|
|
|
if (zend_parse_parameters_none() == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
2012-05-26 23:53:13 +08:00
|
|
|
|
2014-02-10 14:04:30 +08:00
|
|
|
generator = (zend_generator *) Z_OBJ_P(getThis());
|
2012-05-26 23:53:13 +08:00
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
zend_generator_rewind(generator);
|
2012-05-23 22:07:15 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ proto bool Generator::valid()
|
|
|
|
* Check whether the generator is valid */
|
|
|
|
ZEND_METHOD(Generator, valid)
|
|
|
|
{
|
2012-05-26 23:53:13 +08:00
|
|
|
zend_generator *generator;
|
|
|
|
|
2012-05-23 22:07:15 +08:00
|
|
|
if (zend_parse_parameters_none() == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
2012-05-26 23:53:13 +08:00
|
|
|
|
2014-02-10 14:04:30 +08:00
|
|
|
generator = (zend_generator *) Z_OBJ_P(getThis());
|
2012-05-26 23:53:13 +08:00
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
zend_generator_ensure_initialized(generator);
|
2012-05-27 05:07:05 +08:00
|
|
|
|
2014-02-10 14:04:30 +08:00
|
|
|
RETURN_BOOL(Z_TYPE(generator->value) != IS_UNDEF);
|
2012-05-23 22:07:15 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ proto mixed Generator::current()
|
|
|
|
* Get the current value */
|
|
|
|
ZEND_METHOD(Generator, current)
|
|
|
|
{
|
2012-05-26 23:53:13 +08:00
|
|
|
zend_generator *generator;
|
|
|
|
|
2012-05-23 22:07:15 +08:00
|
|
|
if (zend_parse_parameters_none() == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
2012-05-26 23:53:13 +08:00
|
|
|
|
2014-02-10 14:04:30 +08:00
|
|
|
generator = (zend_generator *) Z_OBJ_P(getThis());
|
2012-05-26 23:53:13 +08:00
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
zend_generator_ensure_initialized(generator);
|
2012-05-27 05:07:05 +08:00
|
|
|
|
2014-02-10 14:04:30 +08:00
|
|
|
if (Z_TYPE(generator->value) != IS_UNDEF) {
|
|
|
|
RETURN_ZVAL_FAST(&generator->value);
|
2012-05-27 05:07:05 +08:00
|
|
|
}
|
2012-05-23 22:07:15 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ proto mixed Generator::key()
|
|
|
|
* Get the current key */
|
|
|
|
ZEND_METHOD(Generator, key)
|
|
|
|
{
|
2012-05-26 23:53:13 +08:00
|
|
|
zend_generator *generator;
|
|
|
|
|
2012-05-23 22:07:15 +08:00
|
|
|
if (zend_parse_parameters_none() == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
2012-05-26 23:53:13 +08:00
|
|
|
|
2014-02-10 14:04:30 +08:00
|
|
|
generator = (zend_generator *) Z_OBJ_P(getThis());
|
2012-05-26 23:53:13 +08:00
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
zend_generator_ensure_initialized(generator);
|
2012-05-30 08:44:06 +08:00
|
|
|
|
2014-02-10 14:04:30 +08:00
|
|
|
if (Z_TYPE(generator->key) != IS_UNDEF) {
|
|
|
|
RETURN_ZVAL_FAST(&generator->key);
|
2012-05-30 08:44:06 +08:00
|
|
|
}
|
2012-05-23 22:07:15 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ proto void Generator::next()
|
|
|
|
* Advances the generator */
|
|
|
|
ZEND_METHOD(Generator, next)
|
|
|
|
{
|
2012-05-26 23:53:13 +08:00
|
|
|
zend_generator *generator;
|
|
|
|
|
2012-05-23 22:07:15 +08:00
|
|
|
if (zend_parse_parameters_none() == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
2012-05-26 23:53:13 +08:00
|
|
|
|
2014-02-10 14:04:30 +08:00
|
|
|
generator = (zend_generator *) Z_OBJ_P(getThis());
|
2012-05-26 23:53:13 +08:00
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
zend_generator_ensure_initialized(generator);
|
2012-05-27 05:07:05 +08:00
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
zend_generator_resume(generator);
|
2012-05-23 22:07:15 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2012-12-18 05:02:32 +08:00
|
|
|
/* {{{ proto mixed Generator::send(mixed $value)
|
2012-05-29 23:34:33 +08:00
|
|
|
* Sends a value to the generator */
|
|
|
|
ZEND_METHOD(Generator, send)
|
|
|
|
{
|
2012-06-23 20:43:52 +08:00
|
|
|
zval *value;
|
2012-05-29 23:34:33 +08:00
|
|
|
zend_generator *generator;
|
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &value) == FAILURE) {
|
2012-05-29 23:34:33 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-02-10 14:04:30 +08:00
|
|
|
generator = (zend_generator *) Z_OBJ_P(getThis());
|
2012-05-29 23:34:33 +08:00
|
|
|
|
2015-01-03 17:22:58 +08:00
|
|
|
zend_generator_ensure_initialized(generator);
|
2012-05-29 23:34:33 +08:00
|
|
|
|
2012-05-30 00:01:08 +08:00
|
|
|
/* The generator is already closed, thus can't send anything */
|
|
|
|
if (!generator->execute_data) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-11-30 20:05:40 +08:00
|
|
|
/* Put sent value in the target VAR slot, if it is used */
|
|
|
|
if (generator->send_target) {
|
2014-02-26 17:58:59 +08:00
|
|
|
if (Z_REFCOUNTED_P(generator->send_target)) Z_DELREF_P(generator->send_target);
|
|
|
|
ZVAL_COPY(generator->send_target, value);
|
2013-11-30 20:05:40 +08:00
|
|
|
}
|
2012-05-29 23:34:33 +08:00
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
zend_generator_resume(generator);
|
2012-06-01 02:03:18 +08:00
|
|
|
|
2014-02-10 14:04:30 +08:00
|
|
|
if (Z_TYPE(generator->value) != IS_UNDEF) {
|
|
|
|
RETURN_ZVAL_FAST(&generator->value);
|
2012-06-01 02:03:18 +08:00
|
|
|
}
|
2012-05-29 23:34:33 +08:00
|
|
|
}
|
2012-08-30 02:49:14 +08:00
|
|
|
/* }}} */
|
2012-05-29 23:34:33 +08:00
|
|
|
|
2012-12-18 05:02:32 +08:00
|
|
|
/* {{{ proto mixed Generator::throw(Exception $exception)
|
|
|
|
* Throws an exception into the generator */
|
|
|
|
ZEND_METHOD(Generator, throw)
|
|
|
|
{
|
2014-02-10 14:04:30 +08:00
|
|
|
zval *exception, exception_copy;
|
2012-12-18 05:02:32 +08:00
|
|
|
zend_generator *generator;
|
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &exception) == FAILURE) {
|
2012-12-18 05:02:32 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-03-06 04:45:53 +08:00
|
|
|
ZVAL_DUP(&exception_copy, exception);
|
2012-12-18 05:02:32 +08:00
|
|
|
|
2014-02-10 14:04:30 +08:00
|
|
|
generator = (zend_generator *) Z_OBJ_P(getThis());
|
2012-12-18 05:02:32 +08:00
|
|
|
|
2015-01-03 17:22:58 +08:00
|
|
|
zend_generator_ensure_initialized(generator);
|
2013-12-01 20:37:56 +08:00
|
|
|
|
2012-12-18 05:02:32 +08:00
|
|
|
if (generator->execute_data) {
|
|
|
|
/* Throw the exception in the context of the generator */
|
|
|
|
zend_execute_data *current_execute_data = EG(current_execute_data);
|
|
|
|
EG(current_execute_data) = generator->execute_data;
|
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
zend_throw_exception_object(&exception_copy);
|
2012-12-18 05:02:32 +08:00
|
|
|
|
|
|
|
EG(current_execute_data) = current_execute_data;
|
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
zend_generator_resume(generator);
|
2012-12-18 05:02:32 +08:00
|
|
|
|
2014-02-10 14:04:30 +08:00
|
|
|
if (Z_TYPE(generator->value) != IS_UNDEF) {
|
|
|
|
RETURN_ZVAL_FAST(&generator->value);
|
2012-12-18 05:02:32 +08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* If the generator is already closed throw the exception in the
|
|
|
|
* current context */
|
2014-12-14 06:06:14 +08:00
|
|
|
zend_throw_exception_object(&exception_copy);
|
2012-12-18 05:02:32 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2012-08-30 02:49:14 +08:00
|
|
|
/* {{{ proto void Generator::__wakeup()
|
2012-08-20 22:01:16 +08:00
|
|
|
* Throws an Exception as generators can't be serialized */
|
|
|
|
ZEND_METHOD(Generator, __wakeup)
|
|
|
|
{
|
|
|
|
/* Just specifying the zend_class_unserialize_deny handler is not enough,
|
|
|
|
* because it is only invoked for C unserialization. For O the error has
|
|
|
|
* to be thrown in __wakeup. */
|
|
|
|
|
|
|
|
if (zend_parse_parameters_none() == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
zend_throw_exception(NULL, "Unserialization of 'Generator' is not allowed", 0);
|
2012-08-20 22:01:16 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2012-06-23 07:28:16 +08:00
|
|
|
/* get_iterator implementation */
|
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
static void zend_generator_iterator_dtor(zend_object_iterator *iterator) /* {{{ */
|
2012-06-23 07:28:16 +08:00
|
|
|
{
|
2014-04-09 05:50:15 +08:00
|
|
|
zend_generator *generator = (zend_generator*)Z_OBJ(iterator->data);
|
|
|
|
generator->iterator = NULL;
|
2014-04-09 14:47:03 +08:00
|
|
|
zval_ptr_dtor(&iterator->data);
|
2014-12-14 06:06:14 +08:00
|
|
|
zend_iterator_dtor(iterator);
|
2012-06-23 07:28:16 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
static int zend_generator_iterator_valid(zend_object_iterator *iterator) /* {{{ */
|
2012-06-23 07:28:16 +08:00
|
|
|
{
|
2014-02-27 19:19:02 +08:00
|
|
|
zend_generator *generator = (zend_generator*)Z_OBJ(iterator->data);
|
2012-06-23 07:28:16 +08:00
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
zend_generator_ensure_initialized(generator);
|
2012-06-23 07:28:16 +08:00
|
|
|
|
2014-02-10 14:04:30 +08:00
|
|
|
return Z_TYPE(generator->value) != IS_UNDEF ? SUCCESS : FAILURE;
|
2012-06-23 07:28:16 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
static zval *zend_generator_iterator_get_data(zend_object_iterator *iterator) /* {{{ */
|
2012-06-23 07:28:16 +08:00
|
|
|
{
|
2014-02-27 19:19:02 +08:00
|
|
|
zend_generator *generator = (zend_generator*)Z_OBJ(iterator->data);
|
2012-06-23 07:28:16 +08:00
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
zend_generator_ensure_initialized(generator);
|
2012-06-23 07:28:16 +08:00
|
|
|
|
2014-02-10 14:04:30 +08:00
|
|
|
return &generator->value;
|
2012-06-23 07:28:16 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
static void zend_generator_iterator_get_key(zend_object_iterator *iterator, zval *key) /* {{{ */
|
2012-06-23 07:28:16 +08:00
|
|
|
{
|
2014-02-27 19:19:02 +08:00
|
|
|
zend_generator *generator = (zend_generator*)Z_OBJ(iterator->data);
|
2012-06-23 07:28:16 +08:00
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
zend_generator_ensure_initialized(generator);
|
2012-06-23 07:28:16 +08:00
|
|
|
|
2014-02-10 14:04:30 +08:00
|
|
|
if (Z_TYPE(generator->key) != IS_UNDEF) {
|
|
|
|
ZVAL_ZVAL(key, &generator->key, 1, 0);
|
2013-02-17 02:13:36 +08:00
|
|
|
} else {
|
|
|
|
ZVAL_NULL(key);
|
2012-06-23 07:28:16 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
static void zend_generator_iterator_move_forward(zend_object_iterator *iterator) /* {{{ */
|
2012-06-23 07:28:16 +08:00
|
|
|
{
|
2014-02-27 19:19:02 +08:00
|
|
|
zend_generator *generator = (zend_generator*)Z_OBJ(iterator->data);
|
2012-06-23 07:28:16 +08:00
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
zend_generator_ensure_initialized(generator);
|
2012-06-23 07:28:16 +08:00
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
zend_generator_resume(generator);
|
2012-06-23 07:28:16 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
static void zend_generator_iterator_rewind(zend_object_iterator *iterator) /* {{{ */
|
2012-08-25 23:40:08 +08:00
|
|
|
{
|
2014-02-27 19:19:02 +08:00
|
|
|
zend_generator *generator = (zend_generator*)Z_OBJ(iterator->data);
|
2012-08-25 23:40:08 +08:00
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
zend_generator_rewind(generator);
|
2012-08-25 23:40:08 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2012-06-23 07:28:16 +08:00
|
|
|
static zend_object_iterator_funcs zend_generator_iterator_functions = {
|
|
|
|
zend_generator_iterator_dtor,
|
|
|
|
zend_generator_iterator_valid,
|
|
|
|
zend_generator_iterator_get_data,
|
|
|
|
zend_generator_iterator_get_key,
|
|
|
|
zend_generator_iterator_move_forward,
|
2012-08-25 23:40:08 +08:00
|
|
|
zend_generator_iterator_rewind
|
2012-06-23 07:28:16 +08:00
|
|
|
};
|
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
zend_object_iterator *zend_generator_get_iterator(zend_class_entry *ce, zval *object, int by_ref) /* {{{ */
|
2012-06-23 07:28:16 +08:00
|
|
|
{
|
2014-02-27 19:19:02 +08:00
|
|
|
zend_object_iterator *iterator;
|
|
|
|
zend_generator *generator = (zend_generator*)Z_OBJ_P(object);
|
2012-06-23 20:43:52 +08:00
|
|
|
|
2012-08-30 02:46:56 +08:00
|
|
|
if (!generator->execute_data) {
|
2014-12-14 06:06:14 +08:00
|
|
|
zend_throw_exception(NULL, "Cannot traverse an already closed generator", 0);
|
2012-08-30 02:46:56 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-06-27 03:51:14 +08:00
|
|
|
if (by_ref && !(generator->execute_data->func->op_array.fn_flags & ZEND_ACC_RETURN_REFERENCE)) {
|
2014-12-14 06:06:14 +08:00
|
|
|
zend_throw_exception(NULL, "You can only iterate a generator by-reference if it declared that it yields by-reference", 0);
|
2012-08-30 02:46:56 +08:00
|
|
|
return NULL;
|
2012-07-17 19:24:27 +08:00
|
|
|
}
|
|
|
|
|
2014-04-09 05:50:15 +08:00
|
|
|
iterator = generator->iterator = emalloc(sizeof(zend_object_iterator));
|
2015-01-03 17:22:58 +08:00
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
zend_iterator_init(iterator);
|
2012-06-23 07:28:16 +08:00
|
|
|
|
2014-02-27 19:19:02 +08:00
|
|
|
iterator->funcs = &zend_generator_iterator_functions;
|
|
|
|
ZVAL_COPY(&iterator->data, object);
|
2012-06-23 07:28:16 +08:00
|
|
|
|
2014-02-27 19:19:02 +08:00
|
|
|
return iterator;
|
2012-06-23 07:28:16 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2012-05-23 22:07:15 +08:00
|
|
|
ZEND_BEGIN_ARG_INFO(arginfo_generator_void, 0)
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
2012-05-29 23:34:33 +08:00
|
|
|
ZEND_BEGIN_ARG_INFO_EX(arginfo_generator_send, 0, 0, 1)
|
|
|
|
ZEND_ARG_INFO(0, value)
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
2012-12-18 05:02:32 +08:00
|
|
|
ZEND_BEGIN_ARG_INFO_EX(arginfo_generator_throw, 0, 0, 1)
|
|
|
|
ZEND_ARG_INFO(0, exception)
|
|
|
|
ZEND_END_ARG_INFO()
|
|
|
|
|
2012-05-20 06:03:27 +08:00
|
|
|
static const zend_function_entry generator_functions[] = {
|
2012-08-20 22:01:16 +08:00
|
|
|
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_ME(Generator, send, arginfo_generator_send, ZEND_ACC_PUBLIC)
|
2012-12-18 05:02:32 +08:00
|
|
|
ZEND_ME(Generator, throw, arginfo_generator_throw, ZEND_ACC_PUBLIC)
|
2012-08-20 22:01:16 +08:00
|
|
|
ZEND_ME(Generator, __wakeup, arginfo_generator_void, ZEND_ACC_PUBLIC)
|
2012-05-20 06:03:27 +08:00
|
|
|
ZEND_FE_END
|
|
|
|
};
|
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
void zend_register_generator_ce(void) /* {{{ */
|
2012-05-20 06:03:27 +08:00
|
|
|
{
|
|
|
|
zend_class_entry ce;
|
|
|
|
|
|
|
|
INIT_CLASS_ENTRY(ce, "Generator", generator_functions);
|
2014-12-14 06:06:14 +08:00
|
|
|
zend_ce_generator = zend_register_internal_class(&ce);
|
2014-11-22 12:57:55 +08:00
|
|
|
zend_ce_generator->ce_flags |= ZEND_ACC_FINAL;
|
2012-05-20 20:19:16 +08:00
|
|
|
zend_ce_generator->create_object = zend_generator_create;
|
2012-08-20 22:01:16 +08:00
|
|
|
zend_ce_generator->serialize = zend_class_serialize_deny;
|
|
|
|
zend_ce_generator->unserialize = zend_class_unserialize_deny;
|
2012-05-20 20:19:16 +08:00
|
|
|
|
2012-07-26 23:07:24 +08:00
|
|
|
/* get_iterator has to be assigned *after* implementing the inferface */
|
2014-12-14 06:06:14 +08:00
|
|
|
zend_class_implements(zend_ce_generator, 1, zend_ce_iterator);
|
2012-07-26 23:07:24 +08:00
|
|
|
zend_ce_generator->get_iterator = zend_generator_get_iterator;
|
|
|
|
zend_ce_generator->iterator_funcs.funcs = &zend_generator_iterator_functions;
|
2012-05-23 22:07:15 +08:00
|
|
|
|
2012-05-20 20:19:16 +08:00
|
|
|
memcpy(&zend_generator_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
|
2014-02-10 14:04:30 +08:00
|
|
|
zend_generator_handlers.free_obj = zend_generator_free_storage;
|
|
|
|
zend_generator_handlers.dtor_obj = zend_generator_dtor_storage;
|
2013-03-26 00:40:58 +08:00
|
|
|
zend_generator_handlers.clone_obj = NULL;
|
2014-02-10 14:04:30 +08:00
|
|
|
zend_generator_handlers.get_constructor = zend_generator_get_constructor;
|
2012-05-20 06:03:27 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Local variables:
|
|
|
|
* tab-width: 4
|
|
|
|
* c-basic-offset: 4
|
|
|
|
* indent-tabs-mode: t
|
|
|
|
* End:
|
|
|
|
*/
|