Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:97197 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 3905 invoked from network); 26 Nov 2016 11:45:52 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 26 Nov 2016 11:45:52 -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.210.181 as permitted sender) X-PHP-List-Original-Sender: nikita.ppv@gmail.com X-Host-Fingerprint: 209.85.210.181 mail-wj0-f181.google.com Received: from [209.85.210.181] ([209.85.210.181:34216] helo=mail-wj0-f181.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id D6/5F-21589-CE579385 for ; Sat, 26 Nov 2016 06:45:49 -0500 Received: by mail-wj0-f181.google.com with SMTP id mp19so77943041wjc.1 for ; Sat, 26 Nov 2016 03:45:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=npLEBM0wxWK9plm0Sr3cGemL4azS2pF5qEFCUvL2Hz8=; b=NvGHdpmrawWiNmCuDwqg8Qc9jNoNWPwLg58LCueIGqFJTYv5Td7FNgJlJCg0xFSwIR TjDmKoSNmQ7YL/OLEMcNs/4dgpRXTdnTIzDdBAQtTaYppnyoEJx9R5pmO5m1BiYnQSde Sw3YfEM0bKfBXtrk8+qmjk9yf4pRthcP3fhN+gMXv2Y0FdzjhOzYFlFhqBzL45CjE5OT 7+tV3y2b0cSGW3Hhy/7cEa28hp4s5qmTQKah03Sv5sxyfaoHsxTYZpwVXGniE661qw88 FumHmXc1muFCdC7WnSt+70z02FE3b86x53jG1Cmv8Lq1gPm9kwXN6y/mhGDRvV4ecEsg jeIw== 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:from:date :message-id:subject:to:cc; bh=npLEBM0wxWK9plm0Sr3cGemL4azS2pF5qEFCUvL2Hz8=; b=KhG94cMFRMJVSIIrJ3l1QxUau0o3Z0z107rhcbp1kRufMmFo5Kb+V5G+5YjKahlG+U D4sILCCVbgYgNavQff4YxLhSBiyz9s7vNQG8Tmm7cjns1NbAqTOjYEuXJSLtPN9Svx3p iR6xjCwOQ/kqGsCbFEG2sqMuY20AXUWWCGbYStjvRe/UybdzvcrlmS3SXH+GCQHoco3W /xy+RA3Womaendq2oOTW56JQLh39jpUpVXK8FvfuwJ/vIFa0vuBbeEZ15wLRuRtulSUY YKmTDTEhsHPZy9OOIF++KAOUw3izOo3C/4inN5DZlAlkuuYXO9/CSFJIDJteMyHDIJ6h +8PQ== X-Gm-Message-State: AKaTC00kzyDrLn2aME7zw58BHVRndqTyRVZH/b/bchhP0VZYvrpW204TlT5/rG5slCE9JecggrdnXhsWRiUZDg== X-Received: by 10.194.243.106 with SMTP id wx10mr13374268wjc.191.1480160745616; Sat, 26 Nov 2016 03:45:45 -0800 (PST) MIME-Version: 1.0 Received: by 10.80.170.79 with HTTP; Sat, 26 Nov 2016 03:45:45 -0800 (PST) In-Reply-To: References: <56e89e82-00aa-5521-f014-14cf4d588157@cubiclesoft.com> <5d865bc1-dc06-54b8-800e-99f1c2914632@cubiclesoft.com> <024beaa8-b93a-10e5-bbe1-f1af1b950b81@cubiclesoft.com> Date: Sat, 26 Nov 2016 12:45:45 +0100 Message-ID: To: "Christoph M. Becker" Cc: Thomas Hruska , Jakub Zelenka , Kalle Sommer Nielsen , PHP internals list Content-Type: multipart/alternative; boundary=089e0149414473fa4e054232c735 Subject: Re: [PHP-DEV] Translating optional zval ** withzend_parse_parameters() to PHP 7 From: nikita.ppv@gmail.com (Nikita Popov) --089e0149414473fa4e054232c735 Content-Type: text/plain; charset=UTF-8 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). 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. Nikita --089e0149414473fa4e054232c735--