Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:68692 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 55082 invoked from network); 30 Aug 2013 00:30:19 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 30 Aug 2013 00:30:19 -0000 Authentication-Results: pb1.pair.com smtp.mail=ellison.terry@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=ellison.terry@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.43 as permitted sender) X-PHP-List-Original-Sender: ellison.terry@gmail.com X-Host-Fingerprint: 74.125.82.43 mail-wg0-f43.google.com Received: from [74.125.82.43] ([74.125.82.43:44214] helo=mail-wg0-f43.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 8B/37-10946-997EF125 for ; Thu, 29 Aug 2013 20:30:18 -0400 Received: by mail-wg0-f43.google.com with SMTP id z11so1034261wgg.10 for ; Thu, 29 Aug 2013 17:30:13 -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=+Fi40Qwy4PK6KUl5mIEX8khCm6Y1J/o/z96axqhZh6M=; b=vXDJbcMQ0RjB/ywmILpjDXmnqNd7IhdJIcU+C2bH4NJt3Ktc9N/ddZqGc/mtV5GBZ+ G0ryF36ETQL0pwsRVS4EzngaSPnix5iLgzE/6cfl8kH8BTBq45pFxHXVPcQXDCYjIbz4 +NdUUSpGPVkGBq7tjIv/fEkawg1D5Q7vtfAnBiiZkKeIeh8DMNUSrWt0itDJjxyEKhw4 briFRRvG54SXYmY689CIyRDvHM9FZy8X/dv4+QfuzSF5w3P/PBbWrd4LVyHHEgn9kRkO ZA4oAicROkK8uH1N8UFBLtYatdO59BfwMJ3shuUsBd0DBGvZ4e/4ErirKyXhTZgGdp1t 5CAg== X-Received: by 10.180.39.212 with SMTP id r20mr208974wik.13.1377822613638; Thu, 29 Aug 2013 17:30:13 -0700 (PDT) Received: from [192.168.1.66] (host81-129-189-210.range81-129.btcentralplus.com. [81.129.189.210]) by mx.google.com with ESMTPSA id li9sm442030wic.4.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 29 Aug 2013 17:30:13 -0700 (PDT) Message-ID: <521FE78E.3060900@gmail.com> Date: Fri, 30 Aug 2013 01:30:06 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130803 Thunderbird/17.0.8 MIME-Version: 1.0 To: Nikita Popov CC: PHP internals References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Re: Always set return_value_ptr? From: ellison.terry@gmail.com (Terry Ellison) On 27/08/13 10:40, Nikita Popov wrote: > On Sat, Aug 3, 2013 at 8:16 PM, Nikita Popov wrote: > >> Hi internals! >> >> Is there any particular reason why we only pass return_value_ptr to >> internal functions if they have the ACC_RETURN_REFERENCE flag set? >> >> Why can't we always provide the retval ptr, even for functions that don't >> return by reference? This would allow returning zvals without having to >> copy them first (what RETVAL_ZVAL does). >> >> Motivation for this is the following SO question: >> http://stackoverflow.com/q/17844379/385378 >> > Patch for this change can be found here: > https://github.com/php/php-src/pull/420 > > The patch also adds new macros to allow easy use of this feature called > RETVAL_ZVAL_FAST/RETURN_ZVAL_FAST (anyone got a better name?) > > If no one objects I'll merge this sometime soon. +1 Though looking through the ext uses, most functions returning an array build it directly in return_value and thus avoid the copy. I also see that you've picked up all of the cases in ext/standard/array.c where these macros can be applied. There's another one in string.c, in PHP_FUNCTION(pathinfo), that could be applied as well, though there's little performance gain in avoiding the copy of a 4 element string array. BTW, looking at this pathinfo code, it doesn't do what the documentation says it does -- or at least this states that the optional argument if present should be _one_ of PATHINFO_DIRNAME, PATHINFO_BASENAME, PATHINFO_EXTENSION or PATHINFO_FILENAME. However, if a bitmask is supplied then this function returns the element corresponding to the lowest bit value rather than an error return, for example: $ php -r 'echo pathinfo("/tmp/x.fred", PATHINFO_FILENAME|PATHINFO_EXTENSION),"\n";' fred This is a bizarre behaviour. At a minimum the documentation should actually state what the function does. Or do we bother to raise a patch to fix this sort of thing, given that returning an empty string (or more consistently with other functions, NULL) in this case could create a BC break with existing buggy code? Regards Terry