Re: cleaning up the functions - any volunteers?
| From: | Jordan Wambaugh | Date: | Sat, 28 Jun 2008 02:09:12 +0000 |
| Subject: | Re: cleaning up the functions - any volunteers? | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-38664@lists.php.net to get a copy of this message | ||
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; }