Re: Generators in PHP
| From: | Nikita Popov | Date: | Tue, 12 Jun 2012 22:06:44 +0000 |
| Subject: | Re: Generators in PHP | ||
| References: | 1 2 3 4 5 6 7 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-60808@lists.php.net to get a copy of this message | ||
On Tue, Jun 12, 2012 at 11:07 PM, Ángel González <keisial@gmail.com> wrote:
> On 11/06/12 23:12, Tom Boutell wrote:
>> Can you really use setjmp and longjmp in that way safely? I thought it
>> was only safe to longjmp "back," not "forward" - you can use them to
>> fake exception support but that's it because you'll smash the stack
>> otherwise. Something like that...
> My first reaction was also "How do you return to the mid-running function?"
>
> However, given that the running function is in PHP-land, I think you could
> (in non-zts, it's direct in zts), save EG() contents and replace with
> new values, and then continue the execution.
That's how it is currently implemented. The generator backs up the
current execution context (execute_data, CVs, Ts), pushed stack
arguments and several executor globals. When the generator is resumed
everything is restored and it continues to run as if nothing happened
:)
Doing context switching using setjmp family functions seems to me like
a really scary thing to do. I don't think that one can do that in a
sane way.
Nikita