Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:60808 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 18032 invoked from network); 12 Jun 2012 22:06:49 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 12 Jun 2012 22:06:49 -0000 Authentication-Results: pb1.pair.com smtp.mail=nikita.ppv@googlemail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=nikita.ppv@googlemail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain googlemail.com designates 209.85.217.170 as permitted sender) X-PHP-List-Original-Sender: nikita.ppv@googlemail.com X-Host-Fingerprint: 209.85.217.170 mail-lb0-f170.google.com Received: from [209.85.217.170] ([209.85.217.170:42181] helo=mail-lb0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 35/D0-10010-77DB7DF4 for ; Tue, 12 Jun 2012 18:06:48 -0400 Received: by lbgc1 with SMTP id c1so869461lbg.29 for ; Tue, 12 Jun 2012 15:06:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=/IfaFym2+PI4Nntwk7nPGIhGgs6gVSoFKGYP6aQiJAQ=; b=tO9iQNRbNMrlI4wGdfVVIo+2Gc5kE1P07JjU1F02bPWIt6AQ7G9LNjmrVIOZfFZFha Mrs8RCa0cYAFTsaIQTHIBuzQ/8xtmOmBCMhm95MUuwNu4VyGftFCKCJ22IhOLwc/5Ts2 sWRPBx8U4bLFOr8BdwWMs23shv7ocsVc4KU7v/zliyAMDCjWrS3fVRENVeoP4cAo3oAQ 9WBY7BglMKBNEjOtKAKgTbW1BSCnuNlIIcUh+8hsmZaG/79ZfDag0CZos85eb6+ziqa2 SMk/KZ+/XSwcDWnremXg9FrEucsU/zABfLG3GaJH7X0lEIdBkaovSHe/x3XiTNI94pWN 9rOw== MIME-Version: 1.0 Received: by 10.152.125.116 with SMTP id mp20mr22001366lab.19.1339538804503; Tue, 12 Jun 2012 15:06:44 -0700 (PDT) Received: by 10.152.114.70 with HTTP; Tue, 12 Jun 2012 15:06:44 -0700 (PDT) In-Reply-To: <4FD7AF94.5000503@gmail.com> References: <18e2afd236c1f0c5901824fa6ab5e9f5.squirrel@webmail.klapt.com> <4FD7AF94.5000503@gmail.com> Date: Wed, 13 Jun 2012 00:06:44 +0200 Message-ID: To: =?ISO-8859-1?Q?=C1ngel_Gonz=E1lez?= Cc: Tom Boutell , ab@php.net, Laruence , PHP internals Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] Generators in PHP From: nikita.ppv@googlemail.com (Nikita Popov) On Tue, Jun 12, 2012 at 11:07 PM, =C1ngel Gonz=E1lez wr= ote: > 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 coul= d > (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