Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:60807 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 14795 invoked from network); 12 Jun 2012 21:08:02 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 12 Jun 2012 21:08:02 -0000 Authentication-Results: pb1.pair.com smtp.mail=keisial@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=keisial@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.54 as permitted sender) X-PHP-List-Original-Sender: keisial@gmail.com X-Host-Fingerprint: 74.125.82.54 mail-wg0-f54.google.com Received: from [74.125.82.54] ([74.125.82.54:40537] helo=mail-wg0-f54.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 09/60-10010-1BFA7DF4 for ; Tue, 12 Jun 2012 17:08:01 -0400 Received: by wgbfg15 with SMTP id fg15so3718143wgb.11 for ; Tue, 12 Jun 2012 14:07:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; bh=sNBD9Dr0hBlFshdJVfJfUve89E4DDtIrdL1+9FDVRd8=; b=EdzDOSsjX1gYwNAte/rpzmTivfAd21BB95xl2w184ZKB7nTnwV5ETIJgri0tex4vVL 87Ybts192C4sx8N/Ch3Hq5lgmmUnOir0pXPbWTL5l4+O645VbF3daiWhuDVdc29vf4aQ vr28HZuzBBw3kKdCnGco6t0BLS5BHtSrd+wqETV1kUvi2kcZ551acrXtxUdcf3unTk/a XCYn2clhkS0JcqwhN1y88WyvD10eDlcIViSks4fmQxnOSAYceI/i6COTvIVXOcsrPmnb bADTai55dm2s1Sb5WTS82qJ+LnBcaHYEoXmx/1ZPXiEl008NqfgkSORc3fJW2V/hKf2s GwFA== Received: by 10.180.102.36 with SMTP id fl4mr32069848wib.2.1339535276975; Tue, 12 Jun 2012 14:07:56 -0700 (PDT) Received: from [192.168.1.26] (247.Red-83-35-1.dynamicIP.rima-tde.net. [83.35.1.247]) by mx.google.com with ESMTPS id dg2sm1677971wib.4.2012.06.12.14.07.55 (version=SSLv3 cipher=OTHER); Tue, 12 Jun 2012 14:07:56 -0700 (PDT) Message-ID: <4FD7AF94.5000503@gmail.com> Date: Tue, 12 Jun 2012 23:07:32 +0200 User-Agent: Thunderbird MIME-Version: 1.0 To: Tom Boutell CC: ab@php.net, Laruence , Nikita Popov , PHP internals References: <18e2afd236c1f0c5901824fa6ab5e9f5.squirrel@webmail.klapt.com> In-Reply-To: Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Generators in PHP From: keisial@gmail.com (=?windows-1252?Q?=C1ngel_Gonz=E1lez?=) 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...