Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:97198 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 7657 invoked from network); 26 Nov 2016 12:55:24 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 26 Nov 2016 12:55:24 -0000 Authentication-Results: pb1.pair.com header.from=cmbecker69@gmx.de; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=cmbecker69@gmx.de; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmx.de designates 212.227.15.15 as permitted sender) X-PHP-List-Original-Sender: cmbecker69@gmx.de X-Host-Fingerprint: 212.227.15.15 mout.gmx.net Received: from [212.227.15.15] ([212.227.15.15:57371] helo=mout.gmx.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id C1/DF-21589-A3689385 for ; Sat, 26 Nov 2016 07:55:23 -0500 Received: from [192.168.1.190] ([217.82.239.250]) by mail.gmx.com (mrgmx003 [212.227.17.190]) with ESMTPSA (Nemesis) id 0MOOdZ-1c73ji3kQf-005m9h; Sat, 26 Nov 2016 13:55:16 +0100 To: Nikita Popov References: <56e89e82-00aa-5521-f014-14cf4d588157@cubiclesoft.com> <5d865bc1-dc06-54b8-800e-99f1c2914632@cubiclesoft.com> <024beaa8-b93a-10e5-bbe1-f1af1b950b81@cubiclesoft.com> Cc: Thomas Hruska , Jakub Zelenka , Kalle Sommer Nielsen , PHP internals list Message-ID: Date: Sat, 26 Nov 2016 13:55:34 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.5.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Provags-ID: V03:K0:dvW61N50yyjQ6riNK0DhXvTcpJIB/vcAVn6o7Bq3yrTsrPq23z1 kd3yL337fmC4im7ZDnqy9E+103wbDg4BMCX1dAC7kxW89BM1zKgfxHvgOvctpoe6zT5XslO QIseQBGxw7+ujP5FnYyGKyW89Sx5f+nCrZ5ZJYB7ms/Az6omlQt4XwWBCxYGXGRkvH4Qa5U oQnDRmhJlg29hM9pQfEjw== X-UI-Out-Filterresults: notjunk:1;V01:K0:TvsyUkr8lKE=:Drtm4C/2p3uLJ7H6js0pxe eyU0MlmQTlJu/x3Sh9JCXt3lEn+Ue3RBMv2GUBbFwlQZBPhnBy2nfvEiX5LwksTy3b0Mj0gqH 1qXOaliAh6otK/T8iDZaqamEjFSMprjUC/iWInkvlnbR6nTwg6hmek7/htLSCMpJRUTi4q/JS c+BW1xnWNIhhrTz3nN0dBmkIyc42GvYEI/7aoY/Q9IVwcPufK3GCGaurdLypg+Pg+cmjo85OY VEEmA+fZxRYNKoMNBJJ9+zwjwVQaKJH6gbry6XaFo1t1hNknU8GcbQLAa1lDelbTxbi23eGAy y2YQ/MevIzv40lkNgN/qZtfT7yBI1T7yYOq91mrYsv3fJiGX1N52FeQHRlQAiWBjId7eLSSXJ flR2o1tSdSnl6qBzpxNlNlnR1PNk5zJRxADkTtN2gtFF+QX6HV593RmM1Vr24RmwBMVLU3jJ0 1KAVOUqNBgpX/Rr79PZeTX0BgIVTfw5qZ5hHndCdCfK4vlSJtZiNykAwfbfS25RNCdmCbm0cA N1mbGJQHitI1c8dPrGmL0wfoW4Xf4zD3wsHsmuv15/M0SvkgSFU15AeOw6hjd/bhYpHfrINaM is2LA5zs7dzhoVUVaZRmtQIooAQVBPpGDApeK4gkiiO2cE+e5+XXWM273Oj4lG/0cAyJWcmK9 bUR1VuNUENYReZQwrOOgJf+4StWqrYXEdfJvepr9UCu9s+d5nLYGcDiNNYTFlDtQkMtuYawmd ODzEIAkqbbRyllqGnP2cZS2uJajRkWscgrfJIsFqEBteyLmimU1QW4sFroOjms2BNw+YQ/Xkg i1n2prA Subject: Re: [PHP-DEV] Translating optional zval ** withzend_parse_parameters()to PHP 7 From: cmbecker69@gmx.de ("Christoph M. Becker") On 26.11.2016 at 12:45, Nikita Popov wrote: > On Sat, Nov 26, 2016 at 12:29 PM, Christoph M. Becker > wrote: > >> On 26.11.2016 at 01:47, Thomas Hruska wrote: >> >>> Okay, everyone has been helpful. Thanks. I'll go with: >>> >>> >>> zval *zprevcount = NULL; >>> zend_long count; >>> >>> if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|z/", >>> &zprevcount) == FAILURE) return; >>> >>> ... >>> >>> if (zprevcount != NULL) >>> { >>> count = (zend_long)PrevCount; >>> >>> zval_dtor(zprevcount); >>> ZVAL_LONG(zprevcount, count); >>> } >>> >>> >>> Just one little thing I found in php_str_replace_common() in >>> ext/standard/string.c. That particular function calls zval_ptr_dtor() >>> instead of zval_dtor() on zcount. Just wondering why it does that - I'm >>> thinking it has something to do with removing the ZPP call for PHP 7 and >>> using the (mostly undocumented?) Z_PARAM_ZVAL_EX() macro. However, >>> php_do_pcre_match() over in ext/pcre/php_pcre.c calls zval_dtor() on >>> subpats but also uses the Z_PARAM_ZVAL_EX() macro in a similar fashion. >>> Looking back at PHP 5.6's php_str_replace_common() shows that it >>> previously called zval_dtor(). So it might also be a bug of some sort. >> >> zval_dtor() destroys the value; zval_ptr_dtor() decrements the refcount, >> and destroys the value only if the refcount has dropped to 0. See also >> (which is >> written for PHP 5, but is still useful). >> >> In your case, zval_dtor() is appropriate, as the zval has already been >> separated (ZPP's /), so there can't be other references. > > The situation here has become a bit confusing in PHP 7. zval_dtor() is now > actually the same as zval_ptr_dtor_nogc(). As such, you can use zval_dtor() > on zvals with rc>1, but collectible zvals will not be added to the GC root > buffer. > > In the vast majority of cases, you will want to use zval_ptr_dtor(). > zval_dtor() / zval_ptr_dtor_nogc() are useful either as an optimization in > cases where you know for certain that a value is a root, or to prevent > values from being placed in the GC root buffer, in cases where this > violates the memory model (e.g. this is relevant for opcache'd literals). Thanks for the explanation, Nikita. > The fact that php_pcre.c uses zval_dtor() is simply a bug, because code like > > $obj = new stdClass; > $obj->obj = $obj; > preg_match('/./', 'x', $obj); > > leaks. Indeed. At least preg_replace()'s $count parameter has the same issue. Is there already a bug report about this? -- Christoph M. Becker