Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:38664 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 79005 invoked from network); 28 Jun 2008 02:09:40 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 28 Jun 2008 02:09:40 -0000 Authentication-Results: pb1.pair.com smtp.mail=jordan@wambaugh.org; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=jordan@wambaugh.org; sender-id=unknown Received-SPF: error (pb1.pair.com: domain wambaugh.org from 74.125.46.30 cause and error) X-PHP-List-Original-Sender: jordan@wambaugh.org X-Host-Fingerprint: 74.125.46.30 yw-out-2324.google.com Received: from [74.125.46.30] ([74.125.46.30:7863] helo=yw-out-2324.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id D1/A6-24558-36D95684 for ; Fri, 27 Jun 2008 22:09:40 -0400 Received: by yw-out-2324.google.com with SMTP id 5so316159ywb.83 for ; Fri, 27 Jun 2008 19:09:36 -0700 (PDT) Received: by 10.150.54.1 with SMTP id c1mr3359489yba.63.1214618976561; Fri, 27 Jun 2008 19:09:36 -0700 (PDT) Received: from ?192.168.1.6? ( [70.161.167.72]) by mx.google.com with ESMTPS id a70sm6404202pye.4.2008.06.27.19.09.33 (version=TLSv1/SSLv3 cipher=RC4-MD5); Fri, 27 Jun 2008 19:09:36 -0700 (PDT) Cc: 'PHP Internals' Message-ID: <366BB5B2-12D2-40AB-A0D4-05D27DE67117@wambaugh.org> To: Stanislav Malyshev In-Reply-To: <485AE658.3050204@zend.com> Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit Mime-Version: 1.0 (Apple Message framework v924) Date: Fri, 27 Jun 2008 22:09:12 -0400 References: <485AE658.3050204@zend.com> X-Mailer: Apple Mail (2.924) Subject: Re: [PHP-DEV] cleaning up the functions - any volunteers? From: jordan@wambaugh.org (Jordan Wambaugh) On Jun 19, 2008, at 7:06 PM, Stanislav Malyshev wrote: > While we nearing the release of 5.3 (hopefully?), there are many > functions in the PHP code which still use old parameter parsing API > (zend_get_parameters_ex) instead of the new one > (zend_parse_parameters). This is my first patch submission, so please let me know if you have any pointers. I went ahead and took care of basic_functions.c (because i figured I'd start with basics :-) ). I'll try to do some more tonight. Please let me know if there are any areas you would like me to focus on. Cheers! -- Jordan CM Wambaugh jordan@wambaugh.org Index: basic_functions.c =================================================================== RCS file: /repository/php-src/ext/standard/basic_functions.c,v retrieving revision 1.725.2.31.2.64.2.35 diff -u -r1.725.2.31.2.64.2.35 basic_functions.c --- basic_functions.c 25 May 2008 14:06:13 -0000 1.725.2.31.2.64.2.35 +++ basic_functions.c 28 Jun 2008 01:56:16 -0000 @@ -4924,18 +4924,17 @@ /* }}} */ /* {{{ proto bool set_magic_quotes_runtime(int new_setting) - Set the current active configuration setting of magic_quotes_runtime and return previous */ + Set the current active configuration setting of magic_quotes_runtime. Return true on success, false on failure.*/ PHP_FUNCTION(set_magic_quotes_runtime) { - zval **new_setting; + zend_bool new_setting; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &new_setting) == FAILURE) { + if (ZEND_NUM_ARGS() != 1 || zend_parse_parameters( 1 TSRMLS_CC, "b", &new_setting ) == FAILURE) { RETURN_FALSE; } - convert_to_boolean_ex(new_setting); - - PG(magic_quotes_runtime) = (zend_bool) Z_LVAL_PP(new_setting); + + PG(magic_quotes_runtime) = new_setting; RETURN_TRUE; } /* }}} */ @@ -4973,68 +4972,40 @@ Send an error message somewhere */ PHP_FUNCTION(error_log) { - zval **string, **erropt = NULL, **option = NULL, **emailhead = NULL; + + int opt_err = 0; - char *message, *opt = NULL, *headers = NULL; - - switch (ZEND_NUM_ARGS()) { - case 1: - if (zend_get_parameters_ex(1, &string) == FAILURE) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Argument 1 invalid"); - RETURN_FALSE; - } - break; - - case 2: - if (zend_get_parameters_ex(2, &string, &erropt) == FAILURE) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid arguments"); - RETURN_FALSE; - } - convert_to_long_ex(erropt); - opt_err = Z_LVAL_PP(erropt); - break; - - case 3: - if (zend_get_parameters_ex(3, &string, &erropt, &option) == FAILURE) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid arguments"); - RETURN_FALSE; - } - convert_to_long_ex(erropt); - opt_err = Z_LVAL_PP(erropt); - convert_to_string_ex(option); - opt = Z_STRVAL_PP(option); - break; + char *message, *message_dup, *opt = NULL, *opt_dup, *headers = NULL, *headers_dup; + int message_len, opt_len=0, headers_len=0; - case 4: - if (zend_get_parameters_ex (4, &string, &erropt, &option, &emailhead) == FAILURE) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid arguments"); - RETURN_FALSE; - } - break; - - default: - WRONG_PARAM_COUNT; + if(ZEND_NUM_ARGS() < 1 || ZEND_NUM_ARGS() > 4){ + WRONG_PARAM_COUNT; } - convert_to_string_ex(string); - message = Z_STRVAL_PP(string); - - if (erropt != NULL) { - convert_to_long_ex(erropt); - opt_err = Z_LVAL_PP(erropt); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|lss" + , &message, &message_len + , &opt_err + , &opt, &opt_len + , &headers, &headers_len) == FAILURE) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid Arguments"); + RETURN_FALSE; } - if (option != NULL) { - convert_to_string_ex(option); - opt = Z_STRVAL_PP(option); - } + /*convert our binary-safe strings to unsafe because that's what _php_error_log() expects*/ + message_dup=estrndup(message, message_len); + message_dup=erealloc(message_dup,message_len+1); + message_dup[message_len]=0; + + opt_dup=estrndup(opt, opt_len); + opt_dup=erealloc(opt_dup,opt_len+1); + opt_dup[opt_len]=0; + + headers_dup=estrndup(headers, headers_len); + headers_dup=erealloc(headers_dup,headers_len+1); + headers_dup[headers_len]=0; - if (emailhead != NULL) { - convert_to_string_ex(emailhead); - headers = Z_STRVAL_PP(emailhead); - } - if (_php_error_log(opt_err, message, opt, headers TSRMLS_CC) == FAILURE) { + if (_php_error_log(opt_err, message_dup, opt_dup, headers_dup TSRMLS_CC) == FAILURE) { RETURN_FALSE; }