Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:97195 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 78211 invoked from network); 26 Nov 2016 00:47:23 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 26 Nov 2016 00:47:23 -0000 Authentication-Results: pb1.pair.com header.from=thruska@cubiclesoft.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=thruska@cubiclesoft.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain cubiclesoft.com designates 149.56.142.28 as permitted sender) X-PHP-List-Original-Sender: thruska@cubiclesoft.com X-Host-Fingerprint: 149.56.142.28 28.ip-149-56-142.net Received: from [149.56.142.28] ([149.56.142.28:59610] helo=28.ip-149-56-142.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 8A/2D-21589-89BD8385 for ; Fri, 25 Nov 2016 19:47:21 -0500 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: thruska@cubiclesoft.com) with ESMTPSA id 897AE3E81B To: Jakub Zelenka , Kalle Sommer Nielsen References: <56e89e82-00aa-5521-f014-14cf4d588157@cubiclesoft.com> <5d865bc1-dc06-54b8-800e-99f1c2914632@cubiclesoft.com> Cc: PHP internals list Message-ID: <024beaa8-b93a-10e5-bbe1-f1af1b950b81@cubiclesoft.com> Date: Fri, 25 Nov 2016 17:47:14 -0700 User-Agent: Mozilla/5.0 (X11; Linux i686; rv:11.0) Gecko/20120327 Thunderbird/11.0.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Translating optional zval ** with zend_parse_parameters() to PHP 7 From: thruska@cubiclesoft.com (Thomas Hruska) On 11/25/2016 4:32 PM, Jakub Zelenka wrote: > On 25 Nov 2016 20:43, "Kalle Sommer Nielsen" wrote: > > 2016-11-25 13:30 GMT+01:00 Thomas Hruska : >> I need to be able to *modify* the original variable that was passed in. > I already use "|l" and zend_long >> elsewhere in the extension > > Ah my bad I misread it! > > In that case take a look at where such is implemented in php-src, > dns_get_record() is an example despite the slightly clouded code: > http://git.php.net/?p=php-src.git;a=blob;f=ext/standard/dns.c;h= > f92015eee90d3e93a801e93d6381d89923825166;hb=refs/heads/master#l1011 > > See $weight_list: > > - Check if the argument is passed > - zval_dtor() > - Populate it (ZVAL_LONG is the same) > > The main difference from your code is to use 'z' (lower case) in ZPP, > and then use zval* (which is what 'z' returns). > > > > You also need set 1 for the first param of ZEND_ARG_INFO (specify that it > is a ref param) otherwise it won't use the changed val... > > Jakub 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. -- Thomas Hruska CubicleSoft President I've got great, time saving software that you will find useful. http://cubiclesoft.com/