Re: Generators in PHP

From: Date: Tue, 12 Jun 2012 21:07:32 +0000
Subject: Re: Generators in PHP
References: 1 2 3 4 5 6  Groups: php.internals 
Request: Send a blank email to internals+get-60807@lists.php.net to get a copy of this message
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. As it's treating "threads" non-preemtively, that should work. The C code would also view a different thread, but because it is viewing different globals (some extensions might need changes). Not really involving setjmp() / longjmp(). You could make userland context switches (adding arch-specific code) for the C code by switching the stack under your ESP, but it's highly likely to produce some obscure bugs by missing to keep a register...

« previous php.internals (#60807) next »