Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:61450 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 87566 invoked from network); 18 Jul 2012 23:27:59 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 18 Jul 2012 23:27:59 -0000 Authentication-Results: pb1.pair.com header.from=glopes@nebm.ist.utl.pt; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=glopes@nebm.ist.utl.pt; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain nebm.ist.utl.pt from 193.136.128.21 cause and error) X-PHP-List-Original-Sender: glopes@nebm.ist.utl.pt X-Host-Fingerprint: 193.136.128.21 smtp1.ist.utl.pt Linux 2.6 Received: from [193.136.128.21] ([193.136.128.21:45064] helo=smtp1.ist.utl.pt) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id A8/59-46800-C7647005 for ; Wed, 18 Jul 2012 19:27:57 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp1.ist.utl.pt (Postfix) with ESMTP id D5E88700042E; Thu, 19 Jul 2012 00:27:53 +0100 (WEST) X-Virus-Scanned: by amavisd-new-2.6.4 (20090625) (Debian) at ist.utl.pt Received: from smtp1.ist.utl.pt ([127.0.0.1]) by localhost (smtp1.ist.utl.pt [127.0.0.1]) (amavisd-new, port 10025) with LMTP id M3PMWGqTu11K; Thu, 19 Jul 2012 00:27:53 +0100 (WEST) Received: from mail2.ist.utl.pt (mail.ist.utl.pt [IPv6:2001:690:2100:1::8]) by smtp1.ist.utl.pt (Postfix) with ESMTP id 8EE117000426; Thu, 19 Jul 2012 00:27:53 +0100 (WEST) Received: from damnation (unknown [IPv6:2001:470:94a2:4:c3b:c2a4:1058:64f9]) (Authenticated sender: ist155741) by mail2.ist.utl.pt (Postfix) with ESMTPSA id C2BFE2005297; Thu, 19 Jul 2012 00:27:52 +0100 (WEST) Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes To: "Stas Malyshev" Cc: "internals@lists.php.net" References: <500742AA.9070307@sugarcrm.com> Date: Thu, 19 Jul 2012 01:27:49 +0200 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Organization: =?utf-8?Q?N=C3=BAcleo_de_Eng=2E_Biom=C3=A9di?= =?utf-8?Q?ca_do_I=2ES=2ET=2E?= Message-ID: In-Reply-To: <500742AA.9070307@sugarcrm.com> User-Agent: Opera Mail/12.50 (Linux) Subject: Re: [PHP-DEV] zend_parse_parameters() improvements From: glopes@nebm.ist.utl.pt ("Gustavo Lopes") Em Thu, 19 Jul 2012 01:11:38 +0200, Stas Malyshev escreveu: >> Example: >> http://lxr.php.net/xref/PHP_TRUNK/ext/intl/timezone/timezone_methods.cpp#143 >> In this case, NULL, int and string are allowed. This would become much >> simpler: >> >> if (arg == NULL || Z_TYPE_PP(arg) == IS_NULL) { >> se = TimeZone::createEnumeration(); >> } else { >> long l; >> char *s; >> int s_len; >> if (zend_parse_parameter(ZEND_PARSE_PARAMS_QUIET, >> 1 TSRMLS_DC, arg, "l", &l) == SUCCESS) { >> TimeZone::createEnumeration((int32_t) l); >> } else if (zend_parse_parameter(ZEND_PARSE_PARAMS_QUIET, >> 1 TSRMLS_DC, arg, "s", &s, &s_len) == SUCCESS) { >> TimeZone::createEnumeration(s); >> } else { >> //raise errror >> } > > Wait, didn't you say applying zpp to arg as l, then as s would change > it? Or your function doesn't change it? Yes, the zval is potentially changed in both calls (that's why the argument is passed with double indirection). But this is not a problem here (in fact, it simplifies resource management -- since the second zend_parse_parameter() changes the zval in the stack, the engine can reclaim the zval and string automatically when the function returns). There's to argument if its processing fails. zend_parse_parameters() (plural) changes the arguments only until it fails. Yes, whether an argument is changed or not depends on its position relative to the failing argument. Since zend_parse_parameter() takes only one argument this is not a problem -- supposedly, you call zend_parse_parameter() successfully only once. In any case, you can always copy the zval yourself. > In any case, I think giving access to single-parameter parsing is a good > idea and allows functions to implement complex cases in more consistent > manner - right now I know there are some functions that return different > error messages than zpp does when they parse arguments, for example - > this can be fixes. -- Gustavo Lopes