Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 113 lines (92 sloc) 3.597 kb
ca59e54 Nikita Popov Add empty Generator class
nikic authored
1 /*
2 +----------------------------------------------------------------------+
3 | Zend Engine |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 1998-2012 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_generators.h"
24
25 ZEND_API zend_class_entry *zend_ce_generator;
40b7533 Nikita Popov Add some boilerplate code for Generator class
nikic authored
26 static zend_object_handlers zend_generator_handlers;
27
28 static void zend_generator_free_storage(zend_generator *generator TSRMLS_DC) /* {{{ */
29 {
30 zend_object_std_dtor(&generator->std TSRMLS_CC);
31
9ce9a7e Nikita Popov Add initial code for suspending execution
nikic authored
32 if (generator->execute_data) {
33 zend_execute_data *execute_data = generator->execute_data;
34
35 if (!execute_data->symbol_table) {
36 int i;
37 for (i = 0; i < execute_data->op_array->last_var; ++i) {
38 if (execute_data->CVs[i]) {
39 zval_ptr_dtor(execute_data->CVs[i]);
40 }
41 }
42 } else {
43 if (EG(symtable_cache_ptr) >= EG(symtable_cache_limit)) {
44 zend_hash_destroy(execute_data->symbol_table);
45 FREE_HASHTABLE(execute_data->symbol_table);
46 } else {
47 zend_hash_clean(execute_data->symbol_table);
48 *(++EG(symtable_cache_ptr)) = execute_data->symbol_table;
49 }
50 }
51
52 efree(execute_data);
53 }
54
40b7533 Nikita Popov Add some boilerplate code for Generator class
nikic authored
55 efree(generator);
56 }
57 /* }}} */
58
59 static zend_object_value zend_generator_create(zend_class_entry *class_type TSRMLS_DC) /* {{{ */
60 {
61 zend_generator *generator;
62 zend_object_value object;
63
64 generator = emalloc(sizeof(zend_generator));
65 memset(generator, 0, sizeof(zend_generator));
66
67 zend_object_std_init(&generator->std, class_type TSRMLS_CC);
68
69 object.handle = zend_objects_store_put(generator, NULL,
70 (zend_objects_free_object_storage_t) zend_generator_free_storage,
71 NULL /* no clone handler for now */
72 TSRMLS_CC
73 );
74 object.handlers = &zend_generator_handlers;
75
76 return object;
77 }
78 /* }}} */
79
80 static zend_function *zend_generator_get_constructor(zval *object TSRMLS_DC) /* {{{ */
81 {
82 zend_error(E_RECOVERABLE_ERROR, "The \"Generator\" class is reserved for internal use and cannot be manually instantiated");
83
84 return NULL;
85 }
86 /* }}} */
ca59e54 Nikita Popov Add empty Generator class
nikic authored
87
88 static const zend_function_entry generator_functions[] = {
89 ZEND_FE_END
90 };
91
92 void zend_register_generator_ce(TSRMLS_D) /* {{{ */
93 {
94 zend_class_entry ce;
95
96 INIT_CLASS_ENTRY(ce, "Generator", generator_functions);
97 zend_ce_generator = zend_register_internal_class(&ce TSRMLS_CC);
98 zend_ce_generator->ce_flags |= ZEND_ACC_FINAL_CLASS;
40b7533 Nikita Popov Add some boilerplate code for Generator class
nikic authored
99 zend_ce_generator->create_object = zend_generator_create;
100
101 memcpy(&zend_generator_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
102 zend_generator_handlers.get_constructor = zend_generator_get_constructor;
ca59e54 Nikita Popov Add empty Generator class
nikic authored
103 }
104 /* }}} */
105
106 /*
107 * Local variables:
108 * tab-width: 4
109 * c-basic-offset: 4
110 * indent-tabs-mode: t
111 * End:
112 */
Something went wrong with that request. Please try again.