felipe Sat Aug 16 21:32:41 2008 UTC Modified files: (Branch: PHP_5_3) /php-src/ext/standard string.c /php-src/ext/standard/tests/strings setlocale_error.phpt strtok_error.phpt strtok_variation1.phpt strtok_variation2.phpt Log: - New parameter parsing API (zend_get_parameters_array_ex--) - Fixed tests
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/string.c?r1=1.445.2.14.2.69.2.34&r2=1.445.2.14.2.69.2.35&diff_format=u Index: php-src/ext/standard/string.c diff -u php-src/ext/standard/string.c:1.445.2.14.2.69.2.34 php-src/ext/standard/string.c:1.445.2.14.2.69.2.35 --- php-src/ext/standard/string.c:1.445.2.14.2.69.2.34 Thu Aug 14 02:56:23 2008 +++ php-src/ext/standard/string.c Sat Aug 16 21:32:41 2008 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: string.c,v 1.445.2.14.2.69.2.34 2008/08/14 02:56:23 kalle Exp $ */ +/* $Id: string.c,v 1.445.2.14.2.69.2.35 2008/08/16 21:32:41 felipe Exp $ */ /* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */ @@ -1177,38 +1177,34 @@ /* {{{ proto string strtok([string str,] string token) Tokenize a string */ PHP_FUNCTION(strtok) -{ - zval **args[2]; - zval **tok, **str; +{ + char *str, *tok = NULL; + int str_len, tok_len = 0; + zval *zv; + char *token; char *token_end; char *p; char *pe; int skipped = 0; - if (ZEND_NUM_ARGS() < 1 || ZEND_NUM_ARGS() > 2 || zend_get_parameters_array_ex(ZEND_NUM_ARGS(), args) == FAILURE) { - WRONG_PARAM_COUNT; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s", &str, &str_len, &tok, &tok_len) == FAILURE) { + return; } - - switch (ZEND_NUM_ARGS()) { - case 1: - tok = args[0]; - break; - default: - case 2: - str = args[0]; - tok = args[1]; - convert_to_string_ex(str); - - zval_add_ref(str); - if (BG(strtok_zval)) { - zval_ptr_dtor(&BG(strtok_zval)); - } - BG(strtok_zval) = *str; - BG(strtok_last) = BG(strtok_string) = Z_STRVAL_PP(str); - BG(strtok_len) = Z_STRLEN_PP(str); - break; + if (ZEND_NUM_ARGS() == 1) { + tok = str; + tok_len = str_len; + } else { + if (BG(strtok_zval)) { + zval_ptr_dtor(&BG(strtok_zval)); + } + MAKE_STD_ZVAL(zv); + ZVAL_STRINGL(zv, str, str_len, 1); + + BG(strtok_zval) = zv; + BG(strtok_last) = BG(strtok_string) = Z_STRVAL_P(zv); + BG(strtok_len) = str_len; } p = BG(strtok_last); /* Where we start to search */ @@ -1217,11 +1213,9 @@ if (!p || p >= pe) { RETURN_FALSE; } - - convert_to_string_ex(tok); - token = Z_STRVAL_PP(tok); - token_end = token + Z_STRLEN_PP(tok); + token = tok; + token_end = token + tok_len; while (token < token_end) { STRTOK_TABLE(token++) = 1; @@ -1256,7 +1250,7 @@ /* Restore table -- usually faster then memset'ing the table on every invocation */ restore: - token = Z_STRVAL_PP(tok); + token = tok; while (token < token_end) { STRTOK_TABLE(token++) = 0; @@ -4001,61 +3995,64 @@ Set locale information */ PHP_FUNCTION(setlocale) { - zval ***args = (zval ***) safe_emalloc(sizeof(zval **), ZEND_NUM_ARGS(), 0); + zval ***args = NULL; zval **pcategory, **plocale; - int i, cat, n_args=ZEND_NUM_ARGS(); + int num_args, cat, i = 0; char *loc, *retval; - if (zend_get_parameters_array_ex(n_args, args) == FAILURE || n_args < 2) { - efree(args); - WRONG_PARAM_COUNT; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Z+", &pcategory, &args, &num_args) == FAILURE) { + return; } + #ifdef HAVE_SETLOCALE - pcategory = args[0]; if (Z_TYPE_PP(pcategory) == IS_LONG) { convert_to_long_ex(pcategory); cat = Z_LVAL_PP(pcategory); - } else { /* FIXME: The following behaviour should be removed. */ + } else { + /* FIXME: The following behaviour should be removed. */ char *category; + php_error_docref(NULL TSRMLS_CC, E_DEPRECATED, "Passing locale category name as string is deprecated. Use the LC_* -constants instead"); + convert_to_string_ex(pcategory); - category = Z_STRVAL_P(*pcategory); + category = Z_STRVAL_PP(pcategory); - if (!strcasecmp ("LC_ALL", category)) + if (!strcasecmp("LC_ALL", category)) { cat = LC_ALL; - else if (!strcasecmp ("LC_COLLATE", category)) + } else if (!strcasecmp("LC_COLLATE", category)) { cat = LC_COLLATE; - else if (!strcasecmp ("LC_CTYPE", category)) + } else if (!strcasecmp("LC_CTYPE", category)) { cat = LC_CTYPE; #ifdef LC_MESSAGES - else if (!strcasecmp ("LC_MESSAGES", category)) + } else if (!strcasecmp("LC_MESSAGES", category)) { cat = LC_MESSAGES; #endif - else if (!strcasecmp ("LC_MONETARY", category)) + } else if (!strcasecmp("LC_MONETARY", category)) { cat = LC_MONETARY; - else if (!strcasecmp ("LC_NUMERIC", category)) + } else if (!strcasecmp("LC_NUMERIC", category)) { cat = LC_NUMERIC; - else if (!strcasecmp ("LC_TIME", category)) + } else if (!strcasecmp("LC_TIME", category)) { cat = LC_TIME; - else { + } else { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid locale category name %s, must be one of LC_ALL, LC_COLLATE, LC_CTYPE, LC_MONETARY, LC_NUMERIC, or LC_TIME", category); - efree(args); + + if (args) { + efree(args); + } RETURN_FALSE; } } - if (Z_TYPE_PP(args[1]) == IS_ARRAY) { - zend_hash_internal_pointer_reset(Z_ARRVAL_PP(args[1])); - i=0; /* not needed in this case: only kill a compiler warning */ - } else { - i=1; + if (Z_TYPE_PP(args[0]) == IS_ARRAY) { + zend_hash_internal_pointer_reset(Z_ARRVAL_PP(args[0])); } + while (1) { - if (Z_TYPE_PP(args[1]) == IS_ARRAY) { - if (!zend_hash_num_elements(Z_ARRVAL_PP(args[1]))) { + if (Z_TYPE_PP(args[0]) == IS_ARRAY) { + if (!zend_hash_num_elements(Z_ARRVAL_PP(args[0]))) { break; } - zend_hash_get_current_data(Z_ARRVAL_PP(args[1]),(void **)&plocale); + zend_hash_get_current_data(Z_ARRVAL_PP(args[0]), (void **)&plocale); } else { plocale = args[i]; } @@ -4072,7 +4069,7 @@ } } - retval = setlocale (cat, loc); + retval = setlocale(cat, loc); zend_update_current_locale(); if (retval) { /* Remember if locale was changed */ @@ -4080,23 +4077,24 @@ STR_FREE(BG(locale_string)); BG(locale_string) = estrdup(retval); } - - efree(args); - RETVAL_STRING(retval, 1); - - return; + + if (args) { + efree(args); + } + RETURN_STRING(retval, 1); } - if (Z_TYPE_PP(args[1]) == IS_ARRAY) { - if (zend_hash_move_forward(Z_ARRVAL_PP(args[1])) == FAILURE) break; + if (Z_TYPE_PP(args[0]) == IS_ARRAY) { + if (zend_hash_move_forward(Z_ARRVAL_PP(args[0])) == FAILURE) break; } else { - if (++i >= n_args) break; + if (++i >= num_args) break; } } #endif - efree(args); - + if (args) { + efree(args); + } RETURN_FALSE; } /* }}} */ @@ -4847,29 +4845,21 @@ Implements an ANSI C compatible sscanf */ PHP_FUNCTION(sscanf) { - zval ***args; - int result; - int argc = ZEND_NUM_ARGS(); + zval ***args = NULL; + char *str, *format; + int str_len, format_len, result, num_args = 0; - if (argc < 2) { - WRONG_PARAM_COUNT; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss*", &str, &str_len, &format, &format_len, + &args, &num_args) == FAILURE) { + return; } - - args = (zval ***) safe_emalloc(argc, sizeof(zval **), 0); - if (zend_get_parameters_array_ex(argc, args) == FAILURE) { + + result = php_sscanf_internal(str, format, num_args, args, 0, &return_value TSRMLS_CC); + + if (args) { efree(args); - WRONG_PARAM_COUNT; } - convert_to_string_ex(args[0]); - convert_to_string_ex(args[1]); - - result = php_sscanf_internal(Z_STRVAL_PP(args[0]), - Z_STRVAL_PP(args[1]), - argc, args, - 2, &return_value TSRMLS_CC); - efree(args); - if (SCAN_ERROR_WRONG_PARAM_COUNT == result) { WRONG_PARAM_COUNT; } http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/strings/setlocale_error.phpt?r1=1.1.4.3&r2=1.1.4.4&diff_format=u Index: php-src/ext/standard/tests/strings/setlocale_error.phpt diff -u php-src/ext/standard/tests/strings/setlocale_error.phpt:1.1.4.3 php-src/ext/standard/tests/strings/setlocale_error.phpt:1.1.4.4 --- php-src/ext/standard/tests/strings/setlocale_error.phpt:1.1.4.3 Sat Feb 23 17:06:22 2008 +++ php-src/ext/standard/tests/strings/setlocale_error.phpt Sat Aug 16 21:32:41 2008 @@ -43,15 +43,14 @@ echo "\nDone"; ?> --EXPECTF-- - *** Testing setlocale() : error conditions *** -- Testing setlocale() function with Zero arguments -- -Warning: Wrong parameter count for setlocale() in %s on line %d +Warning: setlocale() expects at least 2 parameters, 0 given in %s on line %d NULL -- Testing setlocale() function with One argument, 'category' = LC_ALL -- -Warning: Wrong parameter count for setlocale() in %s on line %d +Warning: setlocale() expects at least 2 parameters, 1 given in %s on line %d NULL -- Testing setlocale() function with invalid locale array, 'category' = LC_ALL -- http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/strings/strtok_error.phpt?r1=1.1.2.1&r2=1.1.2.1.2.1&diff_format=u Index: php-src/ext/standard/tests/strings/strtok_error.phpt diff -u php-src/ext/standard/tests/strings/strtok_error.phpt:1.1.2.1 php-src/ext/standard/tests/strings/strtok_error.phpt:1.1.2.1.2.1 --- php-src/ext/standard/tests/strings/strtok_error.phpt:1.1.2.1 Sat Sep 22 07:39:57 2007 +++ php-src/ext/standard/tests/strings/strtok_error.phpt Sat Aug 16 21:32:41 2008 @@ -40,12 +40,12 @@ -- Testing strtok() function with Zero arguments -- -Warning: Wrong parameter count for strtok() in %s on line %d +Warning: strtok() expects at least 1 parameter, 0 given in %s on line %d NULL -- Testing strtok() function with more than expected no. of arguments -- -Warning: Wrong parameter count for strtok() in %s on line %d +Warning: strtok() expects at most 2 parameters, 3 given in %s on line %d NULL string(13) "sample string" http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/strings/strtok_variation1.phpt?r1=1.1.2.1.2.3&r2=1.1.2.1.2.4&diff_format=u Index: php-src/ext/standard/tests/strings/strtok_variation1.phpt diff -u php-src/ext/standard/tests/strings/strtok_variation1.phpt:1.1.2.1.2.3 php-src/ext/standard/tests/strings/strtok_variation1.phpt:1.1.2.1.2.4 --- php-src/ext/standard/tests/strings/strtok_variation1.phpt:1.1.2.1.2.3 Sat May 24 15:22:21 2008 +++ php-src/ext/standard/tests/strings/strtok_variation1.phpt Sat Aug 16 21:32:41 2008 @@ -127,24 +127,24 @@ string(3) "0.5" -- Iteration 10 -- -Notice: Array to string conversion in %s on line %d -string(5) "Array" +Warning: strtok() expects parameter 1 to be string, array given in %s on line %d +NULL -- Iteration 11 -- -Notice: Array to string conversion in %s on line %d -string(5) "Array" +Warning: strtok() expects parameter 1 to be string, array given in %s on line %d +NULL -- Iteration 12 -- -Notice: Array to string conversion in %s on line %d -string(5) "Array" +Warning: strtok() expects parameter 1 to be string, array given in %s on line %d +NULL -- Iteration 13 -- -Notice: Array to string conversion in %s on line %d -string(5) "Array" +Warning: strtok() expects parameter 1 to be string, array given in %s on line %d +NULL -- Iteration 14 -- -Notice: Array to string conversion in %s on line %d -string(5) "Array" +Warning: strtok() expects parameter 1 to be string, array given in %s on line %d +NULL -- Iteration 15 -- string(1) "1" -- Iteration 16 -- @@ -168,5 +168,7 @@ -- Iteration 25 -- bool(false) -- Iteration 26 -- -string(%d) "Resource id #%d" -Done \ No newline at end of file + +Warning: strtok() expects parameter 1 to be string, resource given in %s on line %d +NULL +Done http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/strings/strtok_variation2.phpt?r1=1.1.2.1&r2=1.1.2.1.2.1&diff_format=u Index: php-src/ext/standard/tests/strings/strtok_variation2.phpt diff -u php-src/ext/standard/tests/strings/strtok_variation2.phpt:1.1.2.1 php-src/ext/standard/tests/strings/strtok_variation2.phpt:1.1.2.1.2.1 --- php-src/ext/standard/tests/strings/strtok_variation2.phpt:1.1.2.1 Sat Sep 22 07:39:57 2007 +++ php-src/ext/standard/tests/strings/strtok_variation2.phpt Sat Aug 16 21:32:41 2008 @@ -127,24 +127,24 @@ string(37) "this testcase test strtok() function " -- Iteration 10 -- -Notice: Array to string conversion in %s on line %d -string(10) "this testc" +Warning: strtok() expects parameter 2 to be string, array given in %s on line %d +NULL -- Iteration 11 -- -Notice: Array to string conversion in %s on line %d -string(10) "this testc" +Warning: strtok() expects parameter 2 to be string, array given in %s on line %d +NULL -- Iteration 12 -- -Notice: Array to string conversion in %s on line %d -string(10) "this testc" +Warning: strtok() expects parameter 2 to be string, array given in %s on line %d +NULL -- Iteration 13 -- -Notice: Array to string conversion in %s on line %d -string(10) "this testc" +Warning: strtok() expects parameter 2 to be string, array given in %s on line %d +NULL -- Iteration 14 -- -Notice: Array to string conversion in %s on line %d -string(10) "this testc" +Warning: strtok() expects parameter 2 to be string, array given in %s on line %d +NULL -- Iteration 15 -- string(37) "this testcase test strtok() function " -- Iteration 16 -- @@ -168,5 +168,7 @@ -- Iteration 25 -- string(37) "this testcase test strtok() function " -- Iteration 26 -- -string(2) "th" + +Warning: strtok() expects parameter 2 to be string, resource given in %s on line %d +NULL Done
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php