Commit: 05f10480c556ebe52bbef52cb2da5a0aca8ee070 Author: Nikita Popov <ni...@php.net> Mon, 20 Aug 2012 12:53:18 +0200 Parents: 7195a5b3768e519b8f50d131a8c7041a0b57959e Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=05f10480c556ebe52bbef52cb2da5a0aca8ee070 Log: Drop Generator::close() method Changed paths: M Zend/tests/generators/clone_with_foreach.phpt M Zend/tests/generators/clone_with_stack.phpt M Zend/tests/generators/clone_with_symbol_table.phpt M Zend/tests/generators/clone_with_this.phpt D Zend/tests/generators/close_inside_generator.phpt D Zend/tests/generators/generator_close.phpt M Zend/tests/generators/yield_during_method_call.phpt M Zend/zend_generators.c M Zend/zend_generators.h Diff: diff --git a/Zend/tests/generators/clone_with_foreach.phpt b/Zend/tests/generators/clone_with_foreach.phpt index b887338..b05ed07 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 673c0e5..5a8e6d8 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 0d1bd4e..e1fefeb 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 66efd02..b242d85 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 1df64bf..0000000 --- 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 3dec285..0000000 --- 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 e8859ac..5fbe84f 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 716b0a7..41c6dfc 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 d67ea41..f58dafd 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; -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php