Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:91948 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 88439 invoked from network); 25 Mar 2016 13:44:48 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 25 Mar 2016 13:44:48 -0000 Authentication-Results: pb1.pair.com header.from=nikita.ppv@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=nikita.ppv@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.161.179 as permitted sender) X-PHP-List-Original-Sender: nikita.ppv@gmail.com X-Host-Fingerprint: 209.85.161.179 mail-yw0-f179.google.com Received: from [209.85.161.179] ([209.85.161.179:35532] helo=mail-yw0-f179.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id C4/02-10214-FC045F65 for ; Fri, 25 Mar 2016 08:44:48 -0500 Received: by mail-yw0-f179.google.com with SMTP id g127so95139416ywf.2 for ; Fri, 25 Mar 2016 06:44:47 -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=KeAa7yP25J0DfdLQEV8arA0U+OfGBhCvYXwldhhj2Cw=; b=sfF7J3LYuRSSpNkaMO+wTzBiwin9YxP4dDNHIw3PKca1wwjb5rLnZ2/m43BWuWokoY qLAeYq2cnw4GX/tF+KyoZ0KWjfPeCiet5ZA2VAta4sPmT1Zft6BruiVmlnXBE3rsj8cP PFd7mOrIqJt6tMZ0XAKewQWzWKR9XqQEFuGCMO0Fiq6NHY1Q5UfGB8OVtnwXjGbomAjg NbCly8+STM2SBNu1YBgkFBXAIMVmeR8CIZRTZPADKEpTm6128a0eKgh8V9MWYZ09A26G vsj14Ng9p3s/Ahbl8ek3afbEWLb+kEYoxCtKDY1XwMuSeK2wXG9ghdaHmsFa4ncl/wbR upOA== 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=KeAa7yP25J0DfdLQEV8arA0U+OfGBhCvYXwldhhj2Cw=; b=G1okaWXWqO8C4FyiAmLTzVgIDd+knHkqB3II8gwe9lXXo1RjUE2WJFQ4JezFgdVK5I d1cN+DwZFW/XSw+KWTVPDhECVQR+eyInA7FU9awUGAMZaZlN47FwKjY8cMbT0DGkRqj2 WJCJea7/FI42WrDEEZUxYqUsftrO+7EjU2aDnG6Yfx1L9RYfkqHZzi+7WYcP5z+/yxNm IjFPZlzx+uZSfk7JHKqBKNKuyYzdVGIxWbGcQVC3se99/neI1dZVEEVn9l9bMch7hiUm PORE8qCyVG/5dIS5urKDZs9jcOtLnUrKV1uBBK8Kl32ciNpicPWU/+UWvKH4Ofs7xvoY 6kfw== X-Gm-Message-State: AD7BkJKNPhP36zU//r1UgPI/DDnwWlMrYVkerR5nw5y08HEaJb8h+U+Etmn3QggKPVLA37mkCYY5ZQCES4b3ow== MIME-Version: 1.0 X-Received: by 10.129.48.77 with SMTP id w74mr8244034yww.147.1458913484193; Fri, 25 Mar 2016 06:44:44 -0700 (PDT) Received: by 10.129.148.70 with HTTP; Fri, 25 Mar 2016 06:44:44 -0700 (PDT) In-Reply-To: References: Date: Fri, 25 Mar 2016 14:44:44 +0100 Message-ID: To: Sara Golemon Cc: PHP internals Content-Type: multipart/alternative; boundary=001a114084a2fbc8ab052edfc3d0 Subject: Re: [PHP-DEV] Re: [RFC] [Vote] Short Ternary Assignment Operator From: nikita.ppv@gmail.com (Nikita Popov) --001a114084a2fbc8ab052edfc3d0 Content-Type: text/plain; charset=UTF-8 On Fri, Mar 25, 2016 at 4:25 AM, Sara Golemon wrote: > On Thu, Mar 24, 2016 at 11:12 AM, Sara Golemon wrote: > > After some discussion (and realizing the referenced implementation > > needed more work that a simple replacement of tokens), I've decided > > the close this vote, work with Midori on both implementations some > > more, and reopen at a later time with a complete implementation > > (possibly combined with ??=) > > > > https://github.com/php/php-src/compare/master...sgolemon:short-ternary.coalesce > > I've gone from scratch to implement this branch which doesn't > introduce any new opcodes, but it does add a new AST kind which is > compiled into something closely (but not quite) resembling a regular > short ternary. > > It cheats slightly by assuming that since child[0] comes from a > `variable` in the parser that zend_compile_var() on it will always > yield IS_CV/IS_VAR, and I've got an assert in to guard on that, but a > second set of eyes would be nice there. > > You'll notice there's a new runtime check in ZEND_JMP_SET to handle > the IS_INDIRECT case (which I see resulting from the dim/obj paths. > It's hidden behind an existing check for IS_VAR/IS_CV, so anything > producing a TMP won't hit it. Hopefully it's not too harsh. > > Based on feedback, I hope to add the ??= version of this > implementation as another commit and let Midori unify the two RFCs > into one. (unless someone objects to that) > I don't think the current implementation is entirely correct. In particular, it doesn't look memory-safe to me. You're doing an RW fetch on the LHS first, then evaluate the RHS expression and then ASSIGN to the result of the RW fetch. This means you're running user code between the RW fetch and the assignment to it. The code of the RHS expression may cause a reallocation of the buffer into which the INDIRECT points, making it a dangling pointer. Something like $a = [false]; $a[0] ?:= ($a[''] = 42); will probably result in valgrinds. Nikita --001a114084a2fbc8ab052edfc3d0--