Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:93462 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 19246 invoked from network); 23 May 2016 22:12:34 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 23 May 2016 22:12:34 -0000 Authentication-Results: pb1.pair.com smtp.mail=nikita.ppv@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=nikita.ppv@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.161.175 as permitted sender) X-PHP-List-Original-Sender: nikita.ppv@gmail.com X-Host-Fingerprint: 209.85.161.175 mail-yw0-f175.google.com Received: from [209.85.161.175] ([209.85.161.175:34620] helo=mail-yw0-f175.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 24/BE-14293-15083475 for ; Mon, 23 May 2016 18:12:33 -0400 Received: by mail-yw0-f175.google.com with SMTP id c127so67854565ywb.1 for ; Mon, 23 May 2016 15:12:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc; bh=6A8b/Q4okBQSOfdiHIjA+wmk30KX3WLUf4ByUMyS7rk=; b=NM3PKW9SZ+l+T1RqpenHmAvKL+MaYbtbRNgpIhYh0bJINhTdvtJdJhAV1/n2iTFK+L 7E0UaCzVGx/w7I70X974M6uSQ2AHZQ0JXq3EGBn8FNVGEk8ZulwotGlvG2gZhpq4tJRF y4yvCNKYjd5dWHN63jcNqq6uu/ZsyAQjqs60Vluh8/ruClAgDTETnZhCTmdR2V4laCnB p/WwriGSSM+N552hNAx6rbScqkUA+BCgIH6QRyAV2MbnnOcPmqfDENRSRKQbkskkUfPD Gq0Z1DID6upY0gSLMCIQWNwj+21plf471AaaVt900M0h+gafWjVT5H2yl/M3KFdDI19o 4wTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc; bh=6A8b/Q4okBQSOfdiHIjA+wmk30KX3WLUf4ByUMyS7rk=; b=KZgAoWMj9RwEs5ZKKFSlxzHlIo5VPG6a2ZC6Qllaf2Z5hCuFIy2Eh/rX38YSzE4Vh7 kqxKz1Oh2GTZJHYsLYblI0w3wX6t2CLsdgGE4hfq9vZK9iS5LbfZngpfQBtTwnmfys/o fRUWQb+M63otCb1mMQ5SYtiX9T9rVlrw38hkF5Y27dazIy/l5jYT0BL8T0L1JbDGY7VF q7CVOqZi5hE3npen6DiRQ3TEJAu2uIpKUzDRusXq7CJOC83boWgEzU3PeTsilERm/Yjz hhdC8dVCbJO8WHIWq9W9rfzvZJ207i5GCuU/LuksICeBA9Qx0UVIrXuxlHaHZ+haCqmx wTwg== X-Gm-Message-State: ALyK8tKDH+hJaU7e3JwikYQro8faAhYX6TdqIeO1t0AZZaJ6TvXsu7B+B48Q+BrRIZIj5rcbV2t4ZZLYiuQ9IA== MIME-Version: 1.0 X-Received: by 10.129.40.69 with SMTP id o66mr642167ywo.221.1464041551199; Mon, 23 May 2016 15:12:31 -0700 (PDT) Received: by 10.13.239.3 with HTTP; Mon, 23 May 2016 15:12:31 -0700 (PDT) In-Reply-To: References: Date: Tue, 24 May 2016 00:12:31 +0200 Message-ID: To: Dmitry Stogov Cc: Xinchen Hui , internals Content-Type: multipart/alternative; boundary=001a1140723a988a9d053389bc38 Subject: Re: "finally" handling refactoring (Bug #72213) From: nikita.ppv@gmail.com (Nikita Popov) --001a1140723a988a9d053389bc38 Content-Type: text/plain; charset=UTF-8 On Mon, May 23, 2016 at 11:36 PM, Dmitry Stogov wrote: > Hi, > > On 05/23/2016 07:24 PM, Nikita Popov wrote: > > On Mon, May 23, 2016 at 1:25 PM, Dmitry Stogov wrote: > >> Thanks for review. >> >> Both problems should be fixed now >> >> https://gist.github.com/dstogov/0a809891c6a3ac3fac4bd0d9711dd330 >> >> Do you see any other problems or a better way to fix this? >> > Your fix for DISCARD_EXCEPTION does not look right to me. It will discard > all exceptions too early. For example: > > function test() { > try { > throw new Exception(1); > } finally { > try { > try { > } finally { > return 42; > } > } finally { > throw new Exception(2); > } > } > } > > test(); > > This will now not chain exception 1 and 2, because exception 1 is > discarded at the return statement. > > > I thought about this, and I think that the current behavior is right. > If we remove "throw new Exception(2);" the first exception is going to be > discarded at "return 42;". > I think we should do the same independently from the context. > > Why do you think Exception(1) should be kept? > Because Exception(3) may be discarded by another catch in the finally, in which case we should throw Exception(1). Consider this case: function test() { try { throw new Exception(1); } finally { try { try { try { } finally { return 42; } } finally { throw new Exception(3); } } catch (Exception $e) {} } } test(); This should throw Exception(1), as Exception(3) is thrown and caught inside the finally block. I thought your current patch would not throw anything in this case, but I'm actually getting an assertion failure (and a conditional jump on uninit value in valgrind): php: /home/nikic/php-src/Zend/zend_gc.c:226: gc_possible_root: Assertion `(ref)->gc.u.v.type == 7 || (ref)->gc.u.v.type == 8' failed. > I think this should be handled the same way we do the fast_call dispatch > on return, i.e. when we pop the FAST_CALL from the loop var stack we should > replace it with a DISCARD_EXCEPTION and then pop it after the finally. This > should generate all the necessary DISCARD_EXCEPTION opcodes, and in the > right order. > > > May be I'll commit the existing fix, and you'll try to implement this idea > on top? > > Thanks. Dmitry. > > > Nikita > > > --001a1140723a988a9d053389bc38--