summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikita Popov <nikic@php.net>2012-08-20 12:53:18 +0200
committerNikita Popov <nikic@php.net>2012-08-20 12:53:18 +0200
commit05f10480c556ebe52bbef52cb2da5a0aca8ee070 (patch)
tree0c05673c6345bfc7cbdf09c6795485669d0bf74d
parent7195a5b3768e519b8f50d131a8c7041a0b57959e (diff)
downloadphp-git-05f10480c556ebe52bbef52cb2da5a0aca8ee070.tar.gz
Drop Generator::close() method
-rw-r--r--Zend/tests/generators/clone_with_foreach.phpt2
-rw-r--r--Zend/tests/generators/clone_with_stack.phpt2
-rw-r--r--Zend/tests/generators/clone_with_symbol_table.phpt2
-rw-r--r--Zend/tests/generators/clone_with_this.phpt2
-rw-r--r--Zend/tests/generators/close_inside_generator.phpt22
-rw-r--r--Zend/tests/generators/generator_close.phpt32
-rw-r--r--Zend/tests/generators/yield_during_method_call.phpt4
-rw-r--r--Zend/zend_generators.c30
-rw-r--r--Zend/zend_generators.h4
9 files changed, 6 insertions, 94 deletions
diff --git a/Zend/tests/generators/clone_with_foreach.phpt b/Zend/tests/generators/clone_with_foreach.phpt
index b887338036..b05ed07312 100644
--- a/Zend/tests/generators/clone_with_foreach.phpt
+++ b/Zend/tests/generators/clone_with_foreach.phpt
@@ -20,7 +20,7 @@ $g2->next();
var_dump($g1->current());
var_dump($g2->current());
-$g1->close();
+unset($g1);
$g2->next();
var_dump($g2->current());
diff --git a/Zend/tests/generators/clone_with_stack.phpt b/Zend/tests/generators/clone_with_stack.phpt
index 673c0e5d1e..5a8e6d842c 100644
--- a/Zend/tests/generators/clone_with_stack.phpt
+++ b/Zend/tests/generators/clone_with_stack.phpt
@@ -10,7 +10,7 @@ function gen() {
$g1 = gen();
$g1->rewind();
$g2 = clone $g1;
-$g1->close();
+unset($g1);
$g2->send(10);
?>
diff --git a/Zend/tests/generators/clone_with_symbol_table.phpt b/Zend/tests/generators/clone_with_symbol_table.phpt
index 0d1bd4ec3c..e1fefebd8f 100644
--- a/Zend/tests/generators/clone_with_symbol_table.phpt
+++ b/Zend/tests/generators/clone_with_symbol_table.phpt
@@ -19,7 +19,7 @@ function gen() {
$g1 = gen();
$g1->rewind();
$g2 = clone $g1;
-$g1->close();
+unset($g1);
$g2->next();
?>
diff --git a/Zend/tests/generators/clone_with_this.phpt b/Zend/tests/generators/clone_with_this.phpt
index 66efd02987..b242d851eb 100644
--- a/Zend/tests/generators/clone_with_this.phpt
+++ b/Zend/tests/generators/clone_with_this.phpt
@@ -16,7 +16,7 @@ class Test {
$g1 = (new Test)->gen();
$g1->rewind(); // goto yield
$g2 = clone $g1;
-$g1->close();
+unset($g1);
$g2->next();
?>
diff --git a/Zend/tests/generators/close_inside_generator.phpt b/Zend/tests/generators/close_inside_generator.phpt
deleted file mode 100644
index 1df64bf6b1..0000000000
--- a/Zend/tests/generators/close_inside_generator.phpt
+++ /dev/null
@@ -1,22 +0,0 @@
---TEST--
-Calling close() during the exectution of the generator
---FILE--
-<?php
-
-function gen() {
- /* Pass the generator object itself in */
- $gen = yield;
-
- /* Close generator while it is currently running */
- $gen->close();
-
- echo "Still running";
-}
-
-$gen = gen();
-$gen->send($gen);
-
-?>
---EXPECTF--
-Warning: A generator cannot be closed while it is running in %s on line %d
-Still running
diff --git a/Zend/tests/generators/generator_close.phpt b/Zend/tests/generators/generator_close.phpt
deleted file mode 100644
index 3dec285409..0000000000
--- a/Zend/tests/generators/generator_close.phpt
+++ /dev/null
@@ -1,32 +0,0 @@
---TEST--
-Generator can be closed by calling ->close()
---FILE--
-<?php
-
-function allNumbers() {
- for ($i = 0; true; ++$i) {
- yield $i;
- }
-}
-
-$numbers = allNumbers();
-
-foreach ($numbers as $n) {
- var_dump($n);
- if ($n == 9) {
- $numbers->close();
- }
-}
-
-?>
---EXPECT--
-int(0)
-int(1)
-int(2)
-int(3)
-int(4)
-int(5)
-int(6)
-int(7)
-int(8)
-int(9)
diff --git a/Zend/tests/generators/yield_during_method_call.phpt b/Zend/tests/generators/yield_during_method_call.phpt
index e8859ac0c2..5fbe84fff5 100644
--- a/Zend/tests/generators/yield_during_method_call.phpt
+++ b/Zend/tests/generators/yield_during_method_call.phpt
@@ -20,13 +20,13 @@ $gen->send('foo');
// test resource cleanup
$gen = gen();
$gen->rewind();
-$gen->close();
+unset($gen);
// test cloning
$g1 = gen();
$g1->rewind();
$g2 = clone $g1;
-$g1->close();
+unset($g1);
$g2->send('bar');
?>
diff --git a/Zend/zend_generators.c b/Zend/zend_generators.c
index 716b0a782e..41c6dfcd94 100644
--- a/Zend/zend_generators.c
+++ b/Zend/zend_generators.c
@@ -301,8 +301,6 @@ static zend_object_value zend_generator_create(zend_class_entry *class_type TSRM
/* The key will be incremented on first use, so it'll start at 0 */
generator->largest_used_integer_key = -1;
- generator->is_currently_running = 0;
-
zend_object_std_init(&generator->std, class_type TSRMLS_CC);
object.handle = zend_objects_store_put(generator, NULL,
@@ -391,8 +389,6 @@ static void zend_generator_resume(zend_generator *generator TSRMLS_DC) /* {{{ */
zend_class_entry *original_scope = EG(scope);
zend_class_entry *original_called_scope = EG(called_scope);
- zend_bool original_is_currently_running = generator->is_currently_running;
-
/* Remember the current stack position so we can back up pushed args */
generator->original_stack_top = zend_vm_stack_top(TSRMLS_C);
@@ -417,8 +413,6 @@ static void zend_generator_resume(zend_generator *generator TSRMLS_DC) /* {{{ */
EG(scope) = generator->execute_data->current_scope;
EG(called_scope) = generator->execute_data->current_called_scope;
- generator->is_currently_running = 1;
-
/* We want the backtrace to look as if the generator function was
* called from whatever method we are current running (e.g. next()).
* The first prev_execute_data contains an additional stack frame,
@@ -440,8 +434,6 @@ static void zend_generator_resume(zend_generator *generator TSRMLS_DC) /* {{{ */
EG(scope) = original_scope;
EG(called_scope) = original_called_scope;
- generator->is_currently_running = original_is_currently_running;
-
/* The stack top before and after the execution differ, i.e. there are
* arguments pushed to the stack. */
if (generator->original_stack_top != zend_vm_stack_top(TSRMLS_C)) {
@@ -598,27 +590,6 @@ ZEND_METHOD(Generator, send)
}
}
-/* {{{ proto void Generator::close()
- * Closes the generator */
-ZEND_METHOD(Generator, close)
-{
- zend_generator *generator;
-
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
-
- generator = (zend_generator *) zend_object_store_get_object(getThis() TSRMLS_CC);
-
- if (generator->is_currently_running) {
- zend_error(E_WARNING, "A generator cannot be closed while it is running");
- return;
- }
-
- zend_generator_close(generator, 0 TSRMLS_CC);
-}
-/* }}} */
-
/* get_iterator implementation */
typedef struct _zend_generator_iterator {
@@ -747,7 +718,6 @@ static const zend_function_entry generator_functions[] = {
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)
- ZEND_ME(Generator, close, arginfo_generator_void, ZEND_ACC_PUBLIC)
ZEND_FE_END
};
diff --git a/Zend/zend_generators.h b/Zend/zend_generators.h
index d67ea4137b..f58dafdb1f 100644
--- a/Zend/zend_generators.h
+++ b/Zend/zend_generators.h
@@ -46,10 +46,6 @@ typedef struct _zend_generator {
temp_variable *send_target;
/* Largest used integer key for auto-incrementing keys */
long largest_used_integer_key;
-
- /* We need to know whether the generator is currently executed to avoid it
- * being closed while still running */
- zend_bool is_currently_running;
} zend_generator;
extern ZEND_API zend_class_entry *zend_ce_generator;