Skip to content

Commit 694bb32

Browse files
authored
ext/intl: timezone using fast ZPP and fixing SpoofChecker (#14415)
1 parent 8b1bb91 commit 694bb32

File tree

2 files changed

+49
-54
lines changed

2 files changed

+49
-54
lines changed

ext/intl/spoofchecker/spoofchecker_main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ PHP_METHOD(Spoofchecker, isSuspicious)
3131
ZEND_PARSE_PARAMETERS_START(1, 2)
3232
Z_PARAM_STRING(text, text_len)
3333
Z_PARAM_OPTIONAL
34-
Z_PARAM_ZVAL_OR_NULL(error_code)
34+
Z_PARAM_ZVAL(error_code)
3535
ZEND_PARSE_PARAMETERS_END();
3636

3737
SPOOFCHECKER_METHOD_FETCH_OBJECT;
@@ -76,7 +76,7 @@ PHP_METHOD(Spoofchecker, areConfusable)
7676
Z_PARAM_STRING(s1, s1_len)
7777
Z_PARAM_STRING(s2, s2_len)
7878
Z_PARAM_OPTIONAL
79-
Z_PARAM_ZVAL_OR_NULL(error_code)
79+
Z_PARAM_ZVAL(error_code)
8080
ZEND_PARSE_PARAMETERS_END();
8181

8282
SPOOFCHECKER_METHOD_FETCH_OBJECT;

ext/intl/timezone/timezone_methods.cpp

Lines changed: 47 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ U_CFUNC PHP_FUNCTION(intltz_create_time_zone)
5252
size_t str_id_len;
5353
intl_error_reset(NULL);
5454

55-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &str_id, &str_id_len) == FAILURE) {
56-
RETURN_THROWS();
57-
}
55+
ZEND_PARSE_PARAMETERS_START(1, 1)
56+
Z_PARAM_STRING(str_id, str_id_len)
57+
ZEND_PARSE_PARAMETERS_END();
5858

5959
UErrorCode status = UErrorCode();
6060
UnicodeString id = UnicodeString();
@@ -76,10 +76,9 @@ U_CFUNC PHP_FUNCTION(intltz_from_date_time_zone)
7676
php_timezone_obj *tzobj;
7777
intl_error_reset(NULL);
7878

79-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "O",
80-
&zv_timezone, php_date_get_timezone_ce()) == FAILURE) {
81-
RETURN_THROWS();
82-
}
79+
ZEND_PARSE_PARAMETERS_START(1, 1)
80+
Z_PARAM_OBJECT_OF_CLASS(zv_timezone, php_date_get_timezone_ce())
81+
ZEND_PARSE_PARAMETERS_END();
8382

8483
tzobj = Z_PHPTIMEZONE_P(zv_timezone);
8584
if (!tzobj->initialized) {
@@ -102,9 +101,7 @@ U_CFUNC PHP_FUNCTION(intltz_create_default)
102101
{
103102
intl_error_reset(NULL);
104103

105-
if (zend_parse_parameters_none() == FAILURE) {
106-
return;
107-
}
104+
ZEND_PARSE_PARAMETERS_NONE();
108105

109106
TimeZone *tz = TimeZone::createDefault();
110107
timezone_object_construct(tz, return_value, 1);
@@ -114,9 +111,7 @@ U_CFUNC PHP_FUNCTION(intltz_get_gmt)
114111
{
115112
intl_error_reset(NULL);
116113

117-
if (zend_parse_parameters_none() == FAILURE) {
118-
RETURN_THROWS();
119-
}
114+
ZEND_PARSE_PARAMETERS_NONE();
120115

121116
timezone_object_construct(TimeZone::getGMT(), return_value, 0);
122117
}
@@ -125,9 +120,7 @@ U_CFUNC PHP_FUNCTION(intltz_get_unknown)
125120
{
126121
intl_error_reset(NULL);
127122

128-
if (zend_parse_parameters_none() == FAILURE) {
129-
RETURN_THROWS();
130-
}
123+
ZEND_PARSE_PARAMETERS_NONE();
131124

132125
timezone_object_construct(&TimeZone::getUnknown(), return_value, 0);
133126
}
@@ -140,9 +133,10 @@ U_CFUNC PHP_FUNCTION(intltz_create_enumeration)
140133

141134
/* double indirection to have the zend engine destroy the new zval that
142135
* results from separation */
143-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|z", &arg) == FAILURE) {
144-
RETURN_THROWS();
145-
}
136+
ZEND_PARSE_PARAMETERS_START(0, 1)
137+
Z_PARAM_OPTIONAL
138+
Z_PARAM_ZVAL(arg)
139+
ZEND_PARSE_PARAMETERS_END();
146140

147141
if (arg == NULL || Z_TYPE_P(arg) == IS_NULL) {
148142
se = TimeZone::createEnumeration();
@@ -199,10 +193,9 @@ U_CFUNC PHP_FUNCTION(intltz_count_equivalent_ids)
199193
size_t str_id_len;
200194
intl_error_reset(NULL);
201195

202-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s",
203-
&str_id, &str_id_len) == FAILURE) {
204-
RETURN_THROWS();
205-
}
196+
ZEND_PARSE_PARAMETERS_START(1, 1)
197+
Z_PARAM_STRING(str_id, str_id_len)
198+
ZEND_PARSE_PARAMETERS_END();
206199

207200
UErrorCode status = UErrorCode();
208201
UnicodeString id = UnicodeString();
@@ -221,17 +214,19 @@ U_CFUNC PHP_FUNCTION(intltz_create_time_zone_id_enumeration)
221214
zend_long zoneType,
222215
offset_arg;
223216
char *region = NULL;
224-
size_t region_len = 0;
217+
size_t region_len = 0;
225218
int32_t offset,
226219
*offsetp = NULL;
227220
bool arg3isnull = 1;
228221

229222
intl_error_reset(NULL);
230223

231-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "l|s!l!",
232-
&zoneType, &region, &region_len, &offset_arg, &arg3isnull) == FAILURE) {
233-
RETURN_THROWS();
234-
}
224+
ZEND_PARSE_PARAMETERS_START(1, 3)
225+
Z_PARAM_LONG(zoneType)
226+
Z_PARAM_OPTIONAL
227+
Z_PARAM_STRING_OR_NULL(region, region_len)
228+
Z_PARAM_LONG_OR_NULL(offset_arg, arg3isnull)
229+
ZEND_PARSE_PARAMETERS_END();
235230

236231
if (zoneType != UCAL_ZONE_TYPE_ANY && zoneType != UCAL_ZONE_TYPE_CANONICAL
237232
&& zoneType != UCAL_ZONE_TYPE_CANONICAL_LOCATION) {
@@ -266,10 +261,11 @@ U_CFUNC PHP_FUNCTION(intltz_get_canonical_id)
266261
zval *is_systemid = NULL;
267262
intl_error_reset(NULL);
268263

269-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|z",
270-
&str_id, &str_id_len, &is_systemid) == FAILURE) {
271-
RETURN_THROWS();
272-
}
264+
ZEND_PARSE_PARAMETERS_START(1, 2)
265+
Z_PARAM_STRING(str_id, str_id_len)
266+
Z_PARAM_OPTIONAL
267+
Z_PARAM_ZVAL(is_systemid)
268+
ZEND_PARSE_PARAMETERS_END();
273269

274270
UErrorCode status = UErrorCode();
275271
UnicodeString id;
@@ -303,10 +299,9 @@ U_CFUNC PHP_FUNCTION(intltz_get_region)
303299
char outbuf[3];
304300
intl_error_reset(NULL);
305301

306-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s",
307-
&str_id, &str_id_len) == FAILURE) {
308-
RETURN_THROWS();
309-
}
302+
ZEND_PARSE_PARAMETERS_START(1, 1)
303+
Z_PARAM_STRING(str_id, str_id_len)
304+
ZEND_PARSE_PARAMETERS_END();
310305

311306
UErrorCode status = UErrorCode();
312307
UnicodeString id;
@@ -326,9 +321,7 @@ U_CFUNC PHP_FUNCTION(intltz_get_tz_data_version)
326321
{
327322
intl_error_reset(NULL);
328323

329-
if (zend_parse_parameters_none() == FAILURE) {
330-
RETURN_THROWS();
331-
}
324+
ZEND_PARSE_PARAMETERS_NONE();
332325

333326
UErrorCode status = UErrorCode();
334327
const char *res = TimeZone::getTZDataVersion(status);
@@ -344,9 +337,10 @@ U_CFUNC PHP_FUNCTION(intltz_get_equivalent_id)
344337
zend_long index;
345338
intl_error_reset(NULL);
346339

347-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "sl", &str_id, &str_id_len, &index) == FAILURE) {
348-
RETURN_THROWS();
349-
}
340+
ZEND_PARSE_PARAMETERS_START(2, 2)
341+
Z_PARAM_STRING(str_id, str_id_len)
342+
Z_PARAM_LONG(index)
343+
ZEND_PARSE_PARAMETERS_END();
350344

351345
if (UNEXPECTED(index < (zend_long)INT32_MIN || index > (zend_long)INT32_MAX)) {
352346
RETURN_FALSE;
@@ -375,10 +369,9 @@ U_CFUNC PHP_FUNCTION(intltz_get_iana_id)
375369
size_t str_id_len;
376370
intl_error_reset(NULL);
377371

378-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s",
379-
&str_id, &str_id_len) == FAILURE) {
380-
RETURN_THROWS();
381-
}
372+
ZEND_PARSE_PARAMETERS_START(1, 1)
373+
Z_PARAM_STRING(str_id, str_id_len)
374+
ZEND_PARSE_PARAMETERS_END();
382375

383376
UErrorCode status = UErrorCode();
384377
UnicodeString id;
@@ -635,9 +628,9 @@ U_CFUNC PHP_FUNCTION(intltz_get_windows_id)
635628
UnicodeString uID, uWinID;
636629
UErrorCode error;
637630

638-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &id) == FAILURE) {
639-
RETURN_THROWS();
640-
}
631+
ZEND_PARSE_PARAMETERS_START(1, 1)
632+
Z_PARAM_STR(id)
633+
ZEND_PARSE_PARAMETERS_END();
641634

642635
error = U_ZERO_ERROR;
643636
if (intl_stringFromChar(uID, id->val, id->len, &error) == FAILURE) {
@@ -671,9 +664,11 @@ U_CFUNC PHP_FUNCTION(intltz_get_id_for_windows_id)
671664
UnicodeString uWinID, uID;
672665
UErrorCode error;
673666

674-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|S!", &winID, &region) == FAILURE) {
675-
RETURN_THROWS();
676-
}
667+
ZEND_PARSE_PARAMETERS_START(1, 2)
668+
Z_PARAM_STR(winID)
669+
Z_PARAM_OPTIONAL
670+
Z_PARAM_STR_OR_NULL(region)
671+
ZEND_PARSE_PARAMETERS_END();
677672

678673
error = U_ZERO_ERROR;
679674
if (intl_stringFromChar(uWinID, winID->val, winID->len, &error) == FAILURE) {

0 commit comments

Comments
 (0)