Skip to content

Commit 1c77f59

Browse files
committed
updated to the new parameter-parsing api
1 parent 95e4196 commit 1c77f59

8 files changed

+234
-315
lines changed

ext/mbstring/mbstring.c

+164-227
Large diffs are not rendered by default.

ext/mbstring/php_mbregex.c

+59-79
Original file line numberDiff line numberDiff line change
@@ -487,29 +487,33 @@ _php_mb_regex_init_options(const char *parg, int narg, OnigOptionType *option, O
487487
Returns the current encoding for regex as a string. */
488488
PHP_FUNCTION(mb_regex_encoding)
489489
{
490-
zval **arg1;
490+
size_t argc = ZEND_NUM_ARGS();
491+
char *encoding;
492+
long encoding_len;
491493
OnigEncoding mbctype;
492494

493-
if (ZEND_NUM_ARGS() == 0) {
495+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &encoding, &encoding_len) == FAILURE) {
496+
return;
497+
}
498+
499+
if (argc == 0) {
494500
const char *retval = php_mb_regex_mbctype2name(MBSTRG(current_mbctype));
495-
if ( retval != NULL ) {
496-
RETVAL_STRING((char *)retval, 1);
497-
} else {
498-
RETVAL_FALSE;
501+
502+
if (retval == NULL) {
503+
RETURN_FALSE;
499504
}
500-
} else if (ZEND_NUM_ARGS() == 1 &&
501-
zend_get_parameters_ex(1, &arg1) != FAILURE) {
502-
convert_to_string_ex(arg1);
503-
mbctype = php_mb_regex_name2mbctype(Z_STRVAL_PP(arg1));
505+
506+
RETURN_STRING((char *)retval, 1);
507+
} else if (argc == 1) {
508+
mbctype = php_mb_regex_name2mbctype(encoding);
509+
504510
if (mbctype == ONIG_ENCODING_UNDEF) {
505-
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown encoding \"%s\"", Z_STRVAL_PP(arg1));
506-
RETVAL_FALSE;
507-
} else {
508-
MBSTRG(current_mbctype) = mbctype;
509-
RETVAL_TRUE;
511+
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown encoding \"%s\"", encoding);
512+
RETURN_FALSE;
510513
}
511-
} else {
512-
WRONG_PARAM_COUNT;
514+
515+
MBSTRG(current_mbctype) = mbctype;
516+
RETURN_TRUE;
513517
}
514518
}
515519
/* }}} */
@@ -940,37 +944,27 @@ PHP_FUNCTION(mb_ereg_match)
940944
static void
941945
_php_mb_regex_ereg_search_exec(INTERNAL_FUNCTION_PARAMETERS, int mode)
942946
{
943-
zval **arg_pattern, **arg_options;
947+
size_t argc = ZEND_NUM_ARGS();
948+
char *arg_pattern, *arg_options;
949+
long arg_pattern_len, arg_options_len;
944950
int n, i, err, pos, len, beg, end, option;
945951
OnigUChar *str;
946952
OnigSyntaxType *syntax;
947953

954+
if (zend_parse_parameters(argc TSRMLS_CC, "|ss", &arg_pattern, &arg_pattern_len, &arg_options, &arg_options_len) == FAILURE) {
955+
return;
956+
}
957+
948958
option = MBSTRG(regex_default_options);
949-
switch (ZEND_NUM_ARGS()) {
950-
case 0:
951-
break;
952-
case 1:
953-
if (zend_get_parameters_ex(1, &arg_pattern) == FAILURE) {
954-
WRONG_PARAM_COUNT;
955-
}
956-
break;
957-
case 2:
958-
if (zend_get_parameters_ex(2, &arg_pattern, &arg_options) == FAILURE) {
959-
WRONG_PARAM_COUNT;
960-
}
961-
convert_to_string_ex(arg_options);
959+
960+
if (argc == 2) {
962961
option = 0;
963-
_php_mb_regex_init_options(Z_STRVAL_PP(arg_options), Z_STRLEN_PP(arg_options), &option, &syntax, NULL);
964-
break;
965-
default:
966-
WRONG_PARAM_COUNT;
967-
break;
962+
_php_mb_regex_init_options(arg_options, arg_options_len, &option, &syntax, NULL);
968963
}
969-
if (ZEND_NUM_ARGS() > 0) {
970-
/* create regex pattern buffer */
971-
convert_to_string_ex(arg_pattern);
972964

973-
if ((MBSTRG(search_re) = php_mbregex_compile_pattern(Z_STRVAL_PP(arg_pattern), Z_STRLEN_PP(arg_pattern), option, MBSTRG(current_mbctype), MBSTRG(regex_default_syntax) TSRMLS_CC)) == NULL) {
965+
if (argc > 0) {
966+
/* create regex pattern buffer */
967+
if ((MBSTRG(search_re) = php_mbregex_compile_pattern(arg_pattern, arg_pattern_len, option, MBSTRG(current_mbctype), MBSTRG(regex_default_syntax) TSRMLS_CC)) == NULL) {
974968
RETURN_FALSE;
975969
}
976970
}
@@ -1079,41 +1073,28 @@ PHP_FUNCTION(mb_ereg_search_regs)
10791073
Initialize string and regular expression for search. */
10801074
PHP_FUNCTION(mb_ereg_search_init)
10811075
{
1082-
zval **arg_str, **arg_pattern, **arg_options;
1076+
size_t argc = ZEND_NUM_ARGS();
1077+
zval *arg_str;
1078+
char *arg_pattern, *arg_options;
1079+
long arg_pattern_len, arg_options_len;
10831080
OnigSyntaxType *syntax = NULL;
10841081
int option;
10851082

1083+
if (zend_parse_parameters(argc TSRMLS_CC, "z|ss", &arg_str, &arg_pattern, &arg_pattern_len, &arg_options, &arg_options_len) == FAILURE) {
1084+
return;
1085+
}
1086+
10861087
option = MBSTRG(regex_default_options);
10871088
syntax = MBSTRG(regex_default_syntax);
1088-
switch (ZEND_NUM_ARGS()) {
1089-
case 1:
1090-
if (zend_get_parameters_ex(1, &arg_str) == FAILURE) {
1091-
WRONG_PARAM_COUNT;
1092-
}
1093-
break;
1094-
case 2:
1095-
if (zend_get_parameters_ex(2, &arg_str, &arg_pattern) == FAILURE) {
1096-
WRONG_PARAM_COUNT;
1097-
}
1098-
break;
1099-
case 3:
1100-
if (zend_get_parameters_ex(3, &arg_str, &arg_pattern, &arg_options) == FAILURE) {
1101-
WRONG_PARAM_COUNT;
1102-
}
1103-
convert_to_string_ex(arg_options);
1089+
1090+
if (argc == 3) {
11041091
option = 0;
1105-
_php_mb_regex_init_options(Z_STRVAL_PP(arg_options), Z_STRLEN_PP(arg_options), &option, &syntax, NULL);
1106-
break;
1107-
default:
1108-
WRONG_PARAM_COUNT;
1109-
break;
1110-
}
1111-
convert_to_string_ex(arg_str);
1112-
if (ZEND_NUM_ARGS() > 1) {
1113-
/* create regex pattern buffer */
1114-
convert_to_string_ex(arg_pattern);
1092+
_php_mb_regex_init_options(arg_options, arg_options_len, &option, &syntax, NULL);
1093+
}
11151094

1116-
if ((MBSTRG(search_re) = php_mbregex_compile_pattern(Z_STRVAL_PP(arg_pattern), Z_STRLEN_PP(arg_pattern), option, MBSTRG(current_mbctype), syntax TSRMLS_CC)) == NULL) {
1095+
if (argc > 1) {
1096+
/* create regex pattern buffer */
1097+
if ((MBSTRG(search_re) = php_mbregex_compile_pattern(arg_pattern, arg_pattern_len, option, MBSTRG(current_mbctype), syntax TSRMLS_CC)) == NULL) {
11171098
RETURN_FALSE;
11181099
}
11191100
}
@@ -1123,7 +1104,7 @@ PHP_FUNCTION(mb_ereg_search_init)
11231104
MBSTRG(search_str) = (zval *)NULL;
11241105
}
11251106

1126-
MBSTRG(search_str) = *arg_str;
1107+
MBSTRG(search_str) = arg_str;
11271108
Z_ADDREF_P(MBSTRG(search_str));
11281109
SEPARATE_ZVAL_IF_NOT_REF(&MBSTRG(search_str));
11291110

@@ -1178,22 +1159,21 @@ PHP_FUNCTION(mb_ereg_search_getpos)
11781159
Set search start position */
11791160
PHP_FUNCTION(mb_ereg_search_setpos)
11801161
{
1181-
zval **arg_pos;
1162+
long position;
11821163
int n;
11831164

1184-
if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg_pos) == FAILURE) {
1185-
WRONG_PARAM_COUNT;
1165+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &position) == FAILURE) {
1166+
return;
11861167
}
1187-
convert_to_long_ex(arg_pos);
1188-
n = Z_LVAL_PP(arg_pos);
1189-
if (n < 0 || (MBSTRG(search_str) != NULL && Z_TYPE_P(MBSTRG(search_str)) == IS_STRING && n >= Z_STRLEN_P(MBSTRG(search_str)))) {
1168+
1169+
if (position < 0 || (MBSTRG(search_str) != NULL && Z_TYPE_P(MBSTRG(search_str)) == IS_STRING && position >= Z_STRLEN_P(MBSTRG(search_str)))) {
11901170
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Position is out of range");
11911171
MBSTRG(search_pos) = 0;
1192-
RETVAL_FALSE;
1193-
} else {
1194-
MBSTRG(search_pos) = n;
1195-
RETVAL_TRUE;
1172+
RETURN_FALSE;
11961173
}
1174+
1175+
MBSTRG(search_pos) = position;
1176+
RETURN_TRUE;
11971177
}
11981178
/* }}} */
11991179

ext/mbstring/tests/mb_ereg2.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ array(1) {
3131
string(2) "-1"
3232
}
3333

34-
Notice: Array to string conversion in %s on line %d
34+
Warning: mbereg_search_init() expects parameter 3 to be string, array given in %s on line %d
3535
int(-1)
3636
int(-1)
3737
array(1) {

ext/mbstring/tests/mb_regex_encoding_error1.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@ echo "Done";
3131

3232
-- Testing mb_regex_encoding() function with more than expected no. of arguments --
3333

34-
Warning: Wrong parameter count for mb_regex_encoding() in %s on line %d
34+
Warning: mb_regex_encoding() expects at most 1 parameter, 2 given in %s on line %d
3535
NULL
3636
Done

ext/mbstring/tests/mb_regex_encoding_variation1.phpt

+2-2
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,6 @@ bool(false)
210210

211211
-- Iteration 24 --
212212

213-
Warning: mb_regex_encoding(): Unknown encoding "Resource id #%d" in %s on line %d
214-
bool(false)
213+
Warning: mb_regex_encoding() expects parameter 1 to be string, resource given in %s on line %d
214+
NULL
215215
Done

ext/mbstring/tests/mb_substr_error1.phpt

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ echo "Done";
3939

4040
-- Testing mb_substr() function with more than expected no. of arguments --
4141

42-
Warning: Wrong parameter count for mb_substr() in %s on line %d
42+
Warning: mb_substr() expects at most 4 parameters, 5 given in %s on line %d
4343
NULL
4444

4545
-- Testing mb_substr() function with less than expected no. of arguments --
4646

47-
Warning: Wrong parameter count for mb_substr() in %s on line %d
47+
Warning: mb_substr() expects at least 2 parameters, 1 given in %s on line %d
4848
NULL
4949
Done

ext/mbstring/tests/mb_substr_variation1.phpt

+3-1
Original file line numberDiff line numberDiff line change
@@ -175,5 +175,7 @@ string(0) ""
175175
string(0) ""
176176

177177
-- Iteration 24 --
178-
string(5) "Resou"
178+
179+
Warning: mb_substr() expects parameter 1 to be string, resource given in %s on line %d
180+
NULL
179181
Done

ext/mbstring/tests/mb_substr_variation2.phpt

+2-2
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,6 @@ bool(false)
215215

216216
-- Iteration 24 --
217217

218-
Warning: mb_substr(): Unknown encoding "Resource id #%d" in %s on line %d
219-
bool(false)
218+
Warning: mb_substr() expects parameter 4 to be string, resource given in %s on line %d
219+
NULL
220220
Done

0 commit comments

Comments
 (0)