Skip to content

Commit e44db0c

Browse files
kn1g78LamentXU123
authored andcommitted
ext/intl: Reset IntlChar error state on method entry (#22500)
IntlChar methods could leave stale global intl error state after a later successful call. Reset the intl error state when entering each IntlChar method so successful calls report U_ZERO_ERROR. Closes #22500
1 parent 8da53b5 commit e44db0c

3 files changed

Lines changed: 67 additions & 0 deletions

File tree

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ PHP NEWS
1111
fallback locale when a language tag cannot be canonicalized. (Weilin Du)
1212
. Fixed memory leaks when calling Collator::__construct() or
1313
Spoofchecker::__construct() twice. (Weilin Du)
14+
. Fixed IntlChar methods leaving stale global error state after successful
15+
calls. (Xuyang Zhang)
1416

1517
- Phar:
1618
. Fixed inconsistent handling of the magic ".phar" directory. Paths such as
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--TEST--
2+
IntlChar methods reset intl error on success
3+
--EXTENSIONS--
4+
intl
5+
--FILE--
6+
<?php
7+
var_dump(IntlChar::digit('a', 1));
8+
var_dump(intl_get_error_code() !== U_ZERO_ERROR);
9+
10+
var_dump(IntlChar::forDigit(1) === ord('1'));
11+
var_dump(intl_get_error_code() === U_ZERO_ERROR);
12+
var_dump(intl_get_error_message() === 'U_ZERO_ERROR');
13+
?>
14+
--EXPECT--
15+
bool(false)
16+
bool(true)
17+
bool(true)
18+
bool(true)
19+
bool(true)

ext/intl/uchar/uchar.c

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ IC_METHOD(chr) {
5454
char buffer[5];
5555
int buffer_len = 0;
5656

57+
intl_error_reset(NULL);
58+
5759
if (parse_code_point_param(INTERNAL_FUNCTION_PARAM_PASSTHRU, &cp) == FAILURE) {
5860
RETURN_NULL();
5961
}
@@ -73,6 +75,8 @@ IC_METHOD(chr) {
7375
IC_METHOD(ord) {
7476
UChar32 cp;
7577

78+
intl_error_reset(NULL);
79+
7680
if (parse_code_point_param(INTERNAL_FUNCTION_PARAM_PASSTHRU, &cp) == FAILURE) {
7781
RETURN_NULL();
7882
}
@@ -88,6 +92,8 @@ IC_METHOD(hasBinaryProperty) {
8892
zend_string *string_codepoint;
8993
zend_long int_codepoint = 0;
9094

95+
intl_error_reset(NULL);
96+
9197
ZEND_PARSE_PARAMETERS_START(2, 2)
9298
Z_PARAM_STR_OR_LONG(string_codepoint, int_codepoint)
9399
Z_PARAM_LONG(prop)
@@ -108,6 +114,8 @@ IC_METHOD(getIntPropertyValue) {
108114
zend_string *string_codepoint;
109115
zend_long int_codepoint = 0;
110116

117+
intl_error_reset(NULL);
118+
111119
ZEND_PARSE_PARAMETERS_START(2, 2)
112120
Z_PARAM_STR_OR_LONG(string_codepoint, int_codepoint)
113121
Z_PARAM_LONG(prop)
@@ -125,6 +133,8 @@ IC_METHOD(getIntPropertyValue) {
125133
IC_METHOD(getIntPropertyMinValue) {
126134
zend_long prop;
127135

136+
intl_error_reset(NULL);
137+
128138
ZEND_PARSE_PARAMETERS_START(1, 1)
129139
Z_PARAM_LONG(prop)
130140
ZEND_PARSE_PARAMETERS_END();
@@ -137,6 +147,8 @@ IC_METHOD(getIntPropertyMinValue) {
137147
IC_METHOD(getIntPropertyMaxValue) {
138148
zend_long prop;
139149

150+
intl_error_reset(NULL);
151+
140152
ZEND_PARSE_PARAMETERS_START(1, 1)
141153
Z_PARAM_LONG(prop)
142154
ZEND_PARSE_PARAMETERS_END();
@@ -149,6 +161,8 @@ IC_METHOD(getIntPropertyMaxValue) {
149161
IC_METHOD(getNumericValue) {
150162
UChar32 cp;
151163

164+
intl_error_reset(NULL);
165+
152166
if (parse_code_point_param(INTERNAL_FUNCTION_PARAM_PASSTHRU, &cp) == FAILURE) {
153167
RETURN_NULL();
154168
}
@@ -191,6 +205,8 @@ static UBool enumCharType_callback(enumCharType_data *context,
191205
IC_METHOD(enumCharTypes) {
192206
enumCharType_data context;
193207

208+
intl_error_reset(NULL);
209+
194210
ZEND_PARSE_PARAMETERS_START(1, 1)
195211
Z_PARAM_FUNC(context.fci, context.fci_cache)
196212
ZEND_PARSE_PARAMETERS_END();
@@ -202,6 +218,8 @@ IC_METHOD(enumCharTypes) {
202218
IC_METHOD(getBlockCode) {
203219
UChar32 cp;
204220

221+
intl_error_reset(NULL);
222+
205223
if (parse_code_point_param(INTERNAL_FUNCTION_PARAM_PASSTHRU, &cp) == FAILURE) {
206224
RETURN_NULL();
207225
}
@@ -220,6 +238,8 @@ IC_METHOD(charName) {
220238
zend_string *buffer = NULL;
221239
int32_t buffer_len;
222240

241+
intl_error_reset(NULL);
242+
223243
ZEND_PARSE_PARAMETERS_START(1, 2)
224244
Z_PARAM_STR_OR_LONG(string_codepoint, int_codepoint)
225245
Z_PARAM_OPTIONAL
@@ -250,6 +270,8 @@ IC_METHOD(charFromName) {
250270
UChar32 ret;
251271
UErrorCode error = U_ZERO_ERROR;
252272

273+
intl_error_reset(NULL);
274+
253275
ZEND_PARSE_PARAMETERS_START(1, 2)
254276
Z_PARAM_STRING(name, name_len)
255277
Z_PARAM_OPTIONAL
@@ -301,6 +323,7 @@ IC_METHOD(enumCharNames) {
301323
zend_long nameChoice = U_UNICODE_CHAR_NAME;
302324
UErrorCode error = U_ZERO_ERROR;
303325

326+
intl_error_reset(NULL);
304327

305328
ZEND_PARSE_PARAMETERS_START(3, 4)
306329
Z_PARAM_STR_OR_LONG(string_start, int_start)
@@ -326,6 +349,8 @@ IC_METHOD(getPropertyName) {
326349
zend_long nameChoice = U_LONG_PROPERTY_NAME;
327350
const char *ret;
328351

352+
intl_error_reset(NULL);
353+
329354
ZEND_PARSE_PARAMETERS_START(1, 2)
330355
Z_PARAM_LONG(property)
331356
Z_PARAM_OPTIONAL
@@ -348,6 +373,8 @@ IC_METHOD(getPropertyEnum) {
348373
char *alias;
349374
size_t alias_len;
350375

376+
intl_error_reset(NULL);
377+
351378
ZEND_PARSE_PARAMETERS_START(1, 1)
352379
Z_PARAM_STRING(alias, alias_len)
353380
ZEND_PARSE_PARAMETERS_END();
@@ -361,6 +388,8 @@ IC_METHOD(getPropertyValueName) {
361388
zend_long property, value, nameChoice = U_LONG_PROPERTY_NAME;
362389
const char *ret;
363390

391+
intl_error_reset(NULL);
392+
364393
ZEND_PARSE_PARAMETERS_START(2, 3)
365394
Z_PARAM_LONG(property)
366395
Z_PARAM_LONG(value)
@@ -385,6 +414,8 @@ IC_METHOD(getPropertyValueEnum) {
385414
char *name;
386415
size_t name_len;
387416

417+
intl_error_reset(NULL);
418+
388419
ZEND_PARSE_PARAMETERS_START(2, 2)
389420
Z_PARAM_LONG(property)
390421
Z_PARAM_STRING(name, name_len)
@@ -401,6 +432,8 @@ IC_METHOD(foldCase) {
401432
zend_string *string_codepoint;
402433
zend_long int_codepoint = 0;
403434

435+
intl_error_reset(NULL);
436+
404437
ZEND_PARSE_PARAMETERS_START(1, 2)
405438
Z_PARAM_STR_OR_LONG(string_codepoint, int_codepoint)
406439
Z_PARAM_OPTIONAL
@@ -432,6 +465,8 @@ IC_METHOD(digit) {
432465
zend_string *string_codepoint;
433466
zend_long int_codepoint = 0;
434467

468+
intl_error_reset(NULL);
469+
435470
ZEND_PARSE_PARAMETERS_START(1, 2)
436471
Z_PARAM_STR_OR_LONG(string_codepoint, int_codepoint)
437472
Z_PARAM_OPTIONAL
@@ -456,6 +491,8 @@ IC_METHOD(digit) {
456491
IC_METHOD(forDigit) {
457492
zend_long digit, radix = 10;
458493

494+
intl_error_reset(NULL);
495+
459496
ZEND_PARSE_PARAMETERS_START(1, 2)
460497
Z_PARAM_LONG(digit)
461498
Z_PARAM_OPTIONAL
@@ -472,6 +509,8 @@ IC_METHOD(charAge) {
472509
UVersionInfo version;
473510
int i;
474511

512+
intl_error_reset(NULL);
513+
475514
if (parse_code_point_param(INTERNAL_FUNCTION_PARAM_PASSTHRU, &cp) == FAILURE) {
476515
RETURN_NULL();
477516
}
@@ -489,6 +528,8 @@ IC_METHOD(getUnicodeVersion) {
489528
UVersionInfo version;
490529
int i;
491530

531+
intl_error_reset(NULL);
532+
492533
ZEND_PARSE_PARAMETERS_NONE();
493534

494535
u_getUnicodeVersion(version);
@@ -507,6 +548,8 @@ IC_METHOD(getFC_NFKC_Closure) {
507548
int32_t closure_len;
508549
UErrorCode error = U_ZERO_ERROR;
509550

551+
intl_error_reset(NULL);
552+
510553
if (parse_code_point_param(INTERNAL_FUNCTION_PARAM_PASSTHRU, &cp) == FAILURE) {
511554
RETURN_NULL();
512555
}
@@ -535,6 +578,7 @@ IC_METHOD(getFC_NFKC_Closure) {
535578
#define IC_BOOL_METHOD_CHAR(name) \
536579
IC_METHOD(name) { \
537580
UChar32 cp; \
581+
intl_error_reset(NULL); \
538582
if (parse_code_point_param(INTERNAL_FUNCTION_PARAM_PASSTHRU, &cp) == FAILURE) { \
539583
RETURN_NULL(); \
540584
} \
@@ -575,6 +619,7 @@ IC_BOOL_METHOD_CHAR(isJavaIDPart)
575619
#define IC_INT_METHOD_CHAR(name) \
576620
IC_METHOD(name) { \
577621
UChar32 cp; \
622+
intl_error_reset(NULL); \
578623
if (parse_code_point_param(INTERNAL_FUNCTION_PARAM_PASSTHRU, &cp) == FAILURE) { \
579624
RETURN_NULL(); \
580625
} \
@@ -595,6 +640,7 @@ IC_METHOD(name) { \
595640
UChar32 cp, ret; \
596641
zend_string *string_codepoint; \
597642
zend_long int_codepoint = -1; \
643+
intl_error_reset(NULL); \
598644
ZEND_PARSE_PARAMETERS_START(1, 1) \
599645
Z_PARAM_STR_OR_LONG(string_codepoint, int_codepoint) \
600646
ZEND_PARSE_PARAMETERS_END(); \

0 commit comments

Comments
 (0)