Skip to content

Commit 650a371

Browse files
committed
ext/intl: Reset IntlChar error state on method entry
1 parent 44b11b7 commit 650a371

3 files changed

Lines changed: 46 additions & 0 deletions

File tree

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ PHP NEWS
8585
. Upgrade xxHash to 0.8.2. (timwolla)
8686

8787
- Intl:
88+
. Fixed IntlChar methods leaving stale global error state after successful
89+
calls. (Xuyang Zhang)
8890
. Fixed malformed ResourceBundle::get() error message when fallback is
8991
disabled. (Weilin Du)
9092
. Fix incorrect argument positions for invalid start/end arguments in
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.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ static zend_never_inline int parse_code_point_param(INTERNAL_FUNCTION_PARAMETERS
6666
* Acts as an identify function when given a valid UTF-8 encoded codepoint
6767
*/
6868
IC_METHOD(chr) {
69+
intl_error_reset(NULL);
6970
UChar32 cp;
7071
char buffer[5];
7172
int buffer_len = 0;
@@ -87,6 +88,7 @@ IC_METHOD(chr) {
8788
* Acts as an identity function when passed a valid integer codepoint
8889
*/
8990
IC_METHOD(ord) {
91+
intl_error_reset(NULL);
9092
UChar32 cp;
9193

9294
if (parse_code_point_param(INTERNAL_FUNCTION_PARAM_PASSTHRU, &cp) == FAILURE) {
@@ -99,6 +101,7 @@ IC_METHOD(ord) {
99101

100102
/* {{{ */
101103
IC_METHOD(hasBinaryProperty) {
104+
intl_error_reset(NULL);
102105
UChar32 cp;
103106
zend_long prop;
104107
zend_string *string_codepoint;
@@ -119,6 +122,7 @@ IC_METHOD(hasBinaryProperty) {
119122

120123
/* {{{ */
121124
IC_METHOD(getIntPropertyValue) {
125+
intl_error_reset(NULL);
122126
UChar32 cp;
123127
zend_long prop;
124128
zend_string *string_codepoint;
@@ -139,6 +143,7 @@ IC_METHOD(getIntPropertyValue) {
139143

140144
/* {{{ */
141145
IC_METHOD(getIntPropertyMinValue) {
146+
intl_error_reset(NULL);
142147
zend_long prop;
143148

144149
ZEND_PARSE_PARAMETERS_START(1, 1)
@@ -151,6 +156,7 @@ IC_METHOD(getIntPropertyMinValue) {
151156

152157
/* {{{ */
153158
IC_METHOD(getIntPropertyMaxValue) {
159+
intl_error_reset(NULL);
154160
zend_long prop;
155161

156162
ZEND_PARSE_PARAMETERS_START(1, 1)
@@ -163,6 +169,7 @@ IC_METHOD(getIntPropertyMaxValue) {
163169

164170
/* {{{ */
165171
IC_METHOD(getNumericValue) {
172+
intl_error_reset(NULL);
166173
UChar32 cp;
167174

168175
if (parse_code_point_param(INTERNAL_FUNCTION_PARAM_PASSTHRU, &cp) == FAILURE) {
@@ -205,6 +212,7 @@ static UBool enumCharType_callback(enumCharType_data *context,
205212
return 1;
206213
}
207214
IC_METHOD(enumCharTypes) {
215+
intl_error_reset(NULL);
208216
enumCharType_data context;
209217

210218
ZEND_PARSE_PARAMETERS_START(1, 1)
@@ -216,6 +224,7 @@ IC_METHOD(enumCharTypes) {
216224

217225
/* {{{ */
218226
IC_METHOD(getBlockCode) {
227+
intl_error_reset(NULL);
219228
UChar32 cp;
220229

221230
if (parse_code_point_param(INTERNAL_FUNCTION_PARAM_PASSTHRU, &cp) == FAILURE) {
@@ -228,6 +237,7 @@ IC_METHOD(getBlockCode) {
228237

229238
/* {{{ */
230239
IC_METHOD(charName) {
240+
intl_error_reset(NULL);
231241
UChar32 cp;
232242
zend_string *string_codepoint;
233243
zend_long int_codepoint = 0;
@@ -260,6 +270,7 @@ IC_METHOD(charName) {
260270

261271
/* {{{ */
262272
IC_METHOD(charFromName) {
273+
intl_error_reset(NULL);
263274
char *name;
264275
size_t name_len;
265276
zend_long nameChoice = U_UNICODE_CHAR_NAME;
@@ -310,6 +321,7 @@ static UBool enumCharNames_callback(enumCharNames_data *context,
310321
return 1;
311322
}
312323
IC_METHOD(enumCharNames) {
324+
intl_error_reset(NULL);
313325
UChar32 start, limit;
314326
zend_string *string_start, *string_limit;
315327
zend_long int_start = 0, int_limit = 0;
@@ -338,6 +350,7 @@ IC_METHOD(enumCharNames) {
338350

339351
/* {{{ */
340352
IC_METHOD(getPropertyName) {
353+
intl_error_reset(NULL);
341354
zend_long property;
342355
zend_long nameChoice = U_LONG_PROPERTY_NAME;
343356
const char *ret;
@@ -361,6 +374,7 @@ IC_METHOD(getPropertyName) {
361374

362375
/* {{{ */
363376
IC_METHOD(getPropertyEnum) {
377+
intl_error_reset(NULL);
364378
char *alias;
365379
size_t alias_len;
366380

@@ -374,6 +388,7 @@ IC_METHOD(getPropertyEnum) {
374388

375389
/* {{{ */
376390
IC_METHOD(getPropertyValueName) {
391+
intl_error_reset(NULL);
377392
zend_long property, value, nameChoice = U_LONG_PROPERTY_NAME;
378393
const char *ret;
379394

@@ -397,6 +412,7 @@ IC_METHOD(getPropertyValueName) {
397412

398413
/* {{{ */
399414
IC_METHOD(getPropertyValueEnum) {
415+
intl_error_reset(NULL);
400416
zend_long property;
401417
char *name;
402418
size_t name_len;
@@ -412,6 +428,7 @@ IC_METHOD(getPropertyValueEnum) {
412428

413429
/* {{{ */
414430
IC_METHOD(foldCase) {
431+
intl_error_reset(NULL);
415432
UChar32 cp, ret;
416433
zend_long options = U_FOLD_CASE_DEFAULT;
417434
zend_string *string_codepoint;
@@ -442,6 +459,7 @@ IC_METHOD(foldCase) {
442459

443460
/* {{{ */
444461
IC_METHOD(digit) {
462+
intl_error_reset(NULL);
445463
UChar32 cp;
446464
zend_long radix = 10;
447465
int ret;
@@ -470,6 +488,7 @@ IC_METHOD(digit) {
470488

471489
/* {{{ */
472490
IC_METHOD(forDigit) {
491+
intl_error_reset(NULL);
473492
zend_long digit, radix = 10;
474493

475494
ZEND_PARSE_PARAMETERS_START(1, 2)
@@ -484,6 +503,7 @@ IC_METHOD(forDigit) {
484503

485504
/* {{{ */
486505
IC_METHOD(charAge) {
506+
intl_error_reset(NULL);
487507
UChar32 cp;
488508
UVersionInfo version;
489509
int i;
@@ -502,6 +522,7 @@ IC_METHOD(charAge) {
502522

503523
/* {{{ */
504524
IC_METHOD(getUnicodeVersion) {
525+
intl_error_reset(NULL);
505526
UVersionInfo version;
506527
int i;
507528

@@ -517,6 +538,7 @@ IC_METHOD(getUnicodeVersion) {
517538

518539
/* {{{ */
519540
IC_METHOD(getFC_NFKC_Closure) {
541+
intl_error_reset(NULL);
520542
UChar32 cp;
521543
UChar *closure;
522544
zend_string *u8str;
@@ -550,6 +572,7 @@ IC_METHOD(getFC_NFKC_Closure) {
550572
/* {{{ */
551573
#define IC_BOOL_METHOD_CHAR(name) \
552574
IC_METHOD(name) { \
575+
intl_error_reset(NULL); \
553576
UChar32 cp; \
554577
if (parse_code_point_param(INTERNAL_FUNCTION_PARAM_PASSTHRU, &cp) == FAILURE) { \
555578
RETURN_NULL(); \
@@ -590,6 +613,7 @@ IC_BOOL_METHOD_CHAR(isJavaIDPart)
590613
/* {{{ */
591614
#define IC_INT_METHOD_CHAR(name) \
592615
IC_METHOD(name) { \
616+
intl_error_reset(NULL); \
593617
UChar32 cp; \
594618
if (parse_code_point_param(INTERNAL_FUNCTION_PARAM_PASSTHRU, &cp) == FAILURE) { \
595619
RETURN_NULL(); \
@@ -608,6 +632,7 @@ IC_INT_METHOD_CHAR(charDigitValue)
608632
*/
609633
#define IC_CHAR_METHOD_CHAR(name) \
610634
IC_METHOD(name) { \
635+
intl_error_reset(NULL); \
611636
UChar32 cp, ret; \
612637
zend_string *string_codepoint; \
613638
zend_long int_codepoint = -1; \

0 commit comments

Comments
 (0)