Skip to content

Commit 51f750e

Browse files
committed
Merge branch 'PHP-8.1'
* PHP-8.1: Allowing catching arg type deprecations in intl classes
2 parents f235f13 + 925a309 commit 51f750e

File tree

9 files changed

+133
-39
lines changed

9 files changed

+133
-39
lines changed

ext/intl/breakiterator/rulebasedbreakiterator_methods.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ static inline RuleBasedBreakIterator *fetch_rbbi(BreakIterator_object *bio) {
3131
return (RuleBasedBreakIterator*)bio->biter;
3232
}
3333

34-
static void _php_intlrbbi_constructor_body(INTERNAL_FUNCTION_PARAMETERS)
34+
static void _php_intlrbbi_constructor_body(INTERNAL_FUNCTION_PARAMETERS, zend_error_handling *error_handling, bool *error_handling_replaced)
3535
{
3636
char *rules;
3737
size_t rules_len;
@@ -51,6 +51,9 @@ static void _php_intlrbbi_constructor_body(INTERNAL_FUNCTION_PARAMETERS)
5151
RETURN_THROWS();
5252
}
5353

54+
zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, error_handling);
55+
*error_handling_replaced = 1;
56+
5457
// instantiation of ICU object
5558
RuleBasedBreakIterator *rbbi;
5659

@@ -95,11 +98,13 @@ static void _php_intlrbbi_constructor_body(INTERNAL_FUNCTION_PARAMETERS)
9598
U_CFUNC PHP_METHOD(IntlRuleBasedBreakIterator, __construct)
9699
{
97100
zend_error_handling error_handling;
101+
bool error_handling_replaced = 0;
98102

99-
zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, &error_handling);
100103
return_value = ZEND_THIS;
101-
_php_intlrbbi_constructor_body(INTERNAL_FUNCTION_PARAM_PASSTHRU);
102-
zend_restore_error_handling(&error_handling);
104+
_php_intlrbbi_constructor_body(INTERNAL_FUNCTION_PARAM_PASSTHRU, &error_handling, &error_handling_replaced);
105+
if (error_handling_replaced) {
106+
zend_restore_error_handling(&error_handling);
107+
}
103108
}
104109

105110
U_CFUNC PHP_METHOD(IntlRuleBasedBreakIterator, getRules)

ext/intl/calendar/gregoriancalendar_methods.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ static inline GregorianCalendar *fetch_greg(Calendar_object *co) {
4444
}
4545

4646
static void _php_intlgregcal_constructor_body(
47-
INTERNAL_FUNCTION_PARAMETERS, bool is_constructor)
47+
INTERNAL_FUNCTION_PARAMETERS, bool is_constructor, zend_error_handling *error_handling, bool *error_handling_replaced)
4848
{
4949
zval *tz_object = NULL;
5050
zval args_a[6],
@@ -84,6 +84,11 @@ static void _php_intlgregcal_constructor_body(
8484
RETURN_THROWS();
8585
}
8686

87+
if (error_handling != NULL) {
88+
zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, error_handling);
89+
*error_handling_replaced = 1;
90+
}
91+
8792
// instantion of ICU object
8893
Calendar_object *co = Z_INTL_CALENDAR_P(return_value);
8994
GregorianCalendar *gcal = NULL;
@@ -188,17 +193,19 @@ U_CFUNC PHP_FUNCTION(intlgregcal_create_instance)
188193
intl_error_reset(NULL);
189194

190195
object_init_ex(return_value, GregorianCalendar_ce_ptr);
191-
_php_intlgregcal_constructor_body(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
196+
_php_intlgregcal_constructor_body(INTERNAL_FUNCTION_PARAM_PASSTHRU, /* is_constructor */ 0, NULL, NULL);
192197
}
193198

194199
U_CFUNC PHP_METHOD(IntlGregorianCalendar, __construct)
195200
{
196201
zend_error_handling error_handling;
202+
bool error_handling_replaced = 0;
197203

198-
zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, &error_handling);
199204
return_value = ZEND_THIS;
200-
_php_intlgregcal_constructor_body(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
201-
zend_restore_error_handling(&error_handling);
205+
_php_intlgregcal_constructor_body(INTERNAL_FUNCTION_PARAM_PASSTHRU, /* is_constructor */ 1, &error_handling, &error_handling_replaced);
206+
if (error_handling_replaced) {
207+
zend_restore_error_handling(&error_handling);
208+
}
202209
}
203210

204211
U_CFUNC PHP_FUNCTION(intlgregcal_set_gregorian_change)

ext/intl/collator/collator_create.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#include "intl_data.h"
2323

2424
/* {{{ */
25-
static int collator_ctor(INTERNAL_FUNCTION_PARAMETERS)
25+
static int collator_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_error_handling *error_handling, bool *error_handling_replaced)
2626
{
2727
const char* locale;
2828
size_t locale_len = 0;
@@ -38,6 +38,11 @@ static int collator_ctor(INTERNAL_FUNCTION_PARAMETERS)
3838
return FAILURE;
3939
}
4040

41+
if (error_handling != NULL) {
42+
zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, error_handling);
43+
*error_handling_replaced = 1;
44+
}
45+
4146
INTL_CHECK_LOCALE_LEN_OR_FAILURE(locale_len);
4247
COLLATOR_METHOD_FETCH_OBJECT;
4348

@@ -56,7 +61,7 @@ static int collator_ctor(INTERNAL_FUNCTION_PARAMETERS)
5661
PHP_FUNCTION( collator_create )
5762
{
5863
object_init_ex( return_value, Collator_ce_ptr );
59-
if (collator_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU) == FAILURE) {
64+
if (collator_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, NULL, NULL) == FAILURE) {
6065
zval_ptr_dtor(return_value);
6166
RETURN_NULL();
6267
}
@@ -67,14 +72,16 @@ PHP_FUNCTION( collator_create )
6772
PHP_METHOD( Collator, __construct )
6873
{
6974
zend_error_handling error_handling;
75+
bool error_handling_replaced = 0;
7076

71-
zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, &error_handling);
7277
return_value = ZEND_THIS;
73-
if (collator_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU) == FAILURE) {
78+
if (collator_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, &error_handling, &error_handling_replaced) == FAILURE) {
7479
if (!EG(exception)) {
7580
zend_throw_exception(IntlException_ce_ptr, "Constructor failed", 0);
7681
}
7782
}
78-
zend_restore_error_handling(&error_handling);
83+
if (error_handling_replaced) {
84+
zend_restore_error_handling(&error_handling);
85+
}
7986
}
8087
/* }}} */

ext/intl/dateformat/dateformat_create.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ extern "C" {
4545
UDAT_PATTERN == (i))
4646

4747
/* {{{ */
48-
static zend_result datefmt_ctor(INTERNAL_FUNCTION_PARAMETERS)
48+
static zend_result datefmt_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_error_handling *error_handling, bool *error_handling_replaced)
4949
{
5050
zval *object;
5151
char *locale_str;
@@ -81,6 +81,11 @@ static zend_result datefmt_ctor(INTERNAL_FUNCTION_PARAMETERS)
8181
Z_PARAM_STRING_OR_NULL(pattern_str, pattern_str_len)
8282
ZEND_PARSE_PARAMETERS_END_EX(return FAILURE);
8383

84+
if (error_handling != NULL) {
85+
zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, error_handling);
86+
*error_handling_replaced = 1;
87+
}
88+
8489
DATE_FORMAT_METHOD_FETCH_OBJECT_NO_CHECK;
8590

8691
if (DATE_FORMAT_OBJECT(dfo) != NULL) {
@@ -189,7 +194,7 @@ return FAILURE;
189194
U_CFUNC PHP_FUNCTION( datefmt_create )
190195
{
191196
object_init_ex( return_value, IntlDateFormatter_ce_ptr );
192-
if (datefmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU) == FAILURE) {
197+
if (datefmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, NULL, NULL) == FAILURE) {
193198
zval_ptr_dtor(return_value);
194199
RETURN_NULL();
195200
}
@@ -200,18 +205,20 @@ U_CFUNC PHP_FUNCTION( datefmt_create )
200205
U_CFUNC PHP_METHOD( IntlDateFormatter, __construct )
201206
{
202207
zend_error_handling error_handling;
208+
bool error_handling_replaced = 0;
203209

204-
zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, &error_handling);
205210
/* return_value param is being changed, therefore we will always return
206211
* NULL here */
207212
return_value = ZEND_THIS;
208-
if (datefmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU) == FAILURE) {
213+
if (datefmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, &error_handling, &error_handling_replaced) == FAILURE) {
209214
if (!EG(exception)) {
210215
zend_string *err = intl_error_get_message(NULL);
211216
zend_throw_exception(IntlException_ce_ptr, ZSTR_VAL(err), intl_error_get_code(NULL));
212217
zend_string_release_ex(err, 0);
213218
}
214219
}
215-
zend_restore_error_handling(&error_handling);
220+
if (error_handling_replaced) {
221+
zend_restore_error_handling(&error_handling);
222+
}
216223
}
217224
/* }}} */

ext/intl/dateformat/datepatterngenerator_methods.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ using icu::DateTimePatternGenerator;
3030
using icu::Locale;
3131
using icu::StringPiece;
3232

33-
static zend_result dtpg_ctor(INTERNAL_FUNCTION_PARAMETERS)
33+
static zend_result dtpg_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_error_handling *error_handling, bool *error_handling_replaced)
3434
{
3535
char *locale_str;
3636
size_t locale_len = 0;
@@ -44,6 +44,11 @@ static zend_result dtpg_ctor(INTERNAL_FUNCTION_PARAMETERS)
4444
Z_PARAM_STRING_OR_NULL(locale_str, locale_len)
4545
ZEND_PARSE_PARAMETERS_END_EX(return FAILURE);
4646

47+
if (error_handling != NULL) {
48+
zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, error_handling);
49+
*error_handling_replaced = 1;
50+
}
51+
4752
DTPATTERNGEN_METHOD_FETCH_OBJECT_NO_CHECK;
4853

4954
if (dtpgo->dtpg != NULL) {
@@ -74,7 +79,7 @@ static zend_result dtpg_ctor(INTERNAL_FUNCTION_PARAMETERS)
7479
U_CFUNC PHP_METHOD( IntlDatePatternGenerator, create )
7580
{
7681
object_init_ex( return_value, IntlDatePatternGenerator_ce_ptr );
77-
if (dtpg_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU) == FAILURE) {
82+
if (dtpg_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, NULL, NULL) == FAILURE) {
7883
zval_ptr_dtor(return_value);
7984
RETURN_NULL();
8085
}
@@ -83,19 +88,21 @@ U_CFUNC PHP_METHOD( IntlDatePatternGenerator, create )
8388
U_CFUNC PHP_METHOD( IntlDatePatternGenerator, __construct )
8489
{
8590
zend_error_handling error_handling;
91+
bool error_handling_replaced = 0;
8692

87-
zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, &error_handling);
8893
/* return_value param is being changed, therefore we will always return
8994
* NULL here */
9095
return_value = ZEND_THIS;
91-
if (dtpg_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU) == FAILURE) {
96+
if (dtpg_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, &error_handling, &error_handling_replaced) == FAILURE) {
9297
if (!EG(exception)) {
9398
zend_string *err = intl_error_get_message(NULL);
9499
zend_throw_exception(IntlException_ce_ptr, ZSTR_VAL(err), intl_error_get_code(NULL));
95100
zend_string_release_ex(err, 0);
96101
}
97102
}
98-
zend_restore_error_handling(&error_handling);
103+
if (error_handling_replaced) {
104+
zend_restore_error_handling(&error_handling);
105+
}
99106
}
100107

101108

ext/intl/formatter/formatter_main.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#include "intl_convert.h"
2424

2525
/* {{{ */
26-
static int numfmt_ctor(INTERNAL_FUNCTION_PARAMETERS)
26+
static int numfmt_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_error_handling *error_handling, bool *error_handling_replaced)
2727
{
2828
const char* locale;
2929
char* pattern = NULL;
@@ -40,6 +40,11 @@ static int numfmt_ctor(INTERNAL_FUNCTION_PARAMETERS)
4040
return FAILURE;
4141
}
4242

43+
if (error_handling != NULL) {
44+
zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, error_handling);
45+
*error_handling_replaced = 1;
46+
}
47+
4348
INTL_CHECK_LOCALE_LEN_OR_FAILURE(locale_len);
4449
object = return_value;
4550
FORMATTER_METHOD_FETCH_OBJECT_NO_CHECK;
@@ -74,7 +79,7 @@ static int numfmt_ctor(INTERNAL_FUNCTION_PARAMETERS)
7479
PHP_FUNCTION( numfmt_create )
7580
{
7681
object_init_ex( return_value, NumberFormatter_ce_ptr );
77-
if (numfmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU) == FAILURE) {
82+
if (numfmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, NULL, NULL) == FAILURE) {
7883
zval_ptr_dtor(return_value);
7984
RETURN_NULL();
8085
}
@@ -85,15 +90,17 @@ PHP_FUNCTION( numfmt_create )
8590
PHP_METHOD( NumberFormatter, __construct )
8691
{
8792
zend_error_handling error_handling;
93+
bool error_handling_replaced = 0;
8894

89-
zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, &error_handling);
9095
return_value = ZEND_THIS;
91-
if (numfmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU) == FAILURE) {
96+
if (numfmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, &error_handling, &error_handling_replaced) == FAILURE) {
9297
if (!EG(exception)) {
9398
zend_throw_exception(IntlException_ce_ptr, "Constructor failed", 0);
9499
}
95100
}
96-
zend_restore_error_handling(&error_handling);
101+
if (error_handling_replaced) {
102+
zend_restore_error_handling(&error_handling);
103+
}
97104
}
98105
/* }}} */
99106

ext/intl/msgformat/msgformat.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#include "intl_convert.h"
2626

2727
/* {{{ */
28-
static int msgfmt_ctor(INTERNAL_FUNCTION_PARAMETERS)
28+
static int msgfmt_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_error_handling *error_handling, bool *error_handling_replaced)
2929
{
3030
const char* locale;
3131
char* pattern;
@@ -45,6 +45,11 @@ static int msgfmt_ctor(INTERNAL_FUNCTION_PARAMETERS)
4545
return FAILURE;
4646
}
4747

48+
if (error_handling != NULL) {
49+
zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, error_handling);
50+
*error_handling_replaced = 1;
51+
}
52+
4853
INTL_CHECK_LOCALE_LEN_OR_FAILURE(locale_len);
4954
MSG_FORMAT_METHOD_FETCH_OBJECT_NO_CHECK;
5055

@@ -104,7 +109,7 @@ static int msgfmt_ctor(INTERNAL_FUNCTION_PARAMETERS)
104109
PHP_FUNCTION( msgfmt_create )
105110
{
106111
object_init_ex( return_value, MessageFormatter_ce_ptr );
107-
if (msgfmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU) == FAILURE) {
112+
if (msgfmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, NULL, NULL) == FAILURE) {
108113
zval_ptr_dtor(return_value);
109114
RETURN_NULL();
110115
}
@@ -115,17 +120,19 @@ PHP_FUNCTION( msgfmt_create )
115120
PHP_METHOD( MessageFormatter, __construct )
116121
{
117122
zend_error_handling error_handling;
123+
bool error_handling_replaced = 0;
118124

119-
zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, &error_handling);
120125
return_value = ZEND_THIS;
121-
if (msgfmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU) == FAILURE) {
126+
if (msgfmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, &error_handling, &error_handling_replaced) == FAILURE) {
122127
if (!EG(exception)) {
123128
zend_string *err = intl_error_get_message(NULL);
124129
zend_throw_exception(IntlException_ce_ptr, ZSTR_VAL(err), intl_error_get_code(NULL));
125130
zend_string_release_ex(err, 0);
126131
}
127132
}
128-
zend_restore_error_handling(&error_handling);
133+
if (error_handling_replaced) {
134+
zend_restore_error_handling(&error_handling);
135+
}
129136
}
130137
/* }}} */
131138

ext/intl/resourcebundle/resourcebundle_class.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ static zend_object *ResourceBundle_object_create( zend_class_entry *ce )
7474
/* }}} */
7575

7676
/* {{{ ResourceBundle_ctor */
77-
static int resourcebundle_ctor(INTERNAL_FUNCTION_PARAMETERS)
77+
static int resourcebundle_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_error_handling *error_handling, bool *error_handling_replaced)
7878
{
7979
const char *bundlename;
8080
size_t bundlename_len = 0;
@@ -93,6 +93,11 @@ static int resourcebundle_ctor(INTERNAL_FUNCTION_PARAMETERS)
9393
return FAILURE;
9494
}
9595

96+
if (error_handling != NULL) {
97+
zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, error_handling);
98+
*error_handling_replaced = 1;
99+
}
100+
96101
if (rb->me) {
97102
zend_throw_error(NULL, "ResourceBundle object is already constructed");
98103
return FAILURE;
@@ -139,23 +144,25 @@ static int resourcebundle_ctor(INTERNAL_FUNCTION_PARAMETERS)
139144
PHP_METHOD( ResourceBundle, __construct )
140145
{
141146
zend_error_handling error_handling;
147+
bool error_handling_replaced = 0;
142148

143-
zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, &error_handling);
144149
return_value = ZEND_THIS;
145-
if (resourcebundle_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU) == FAILURE) {
150+
if (resourcebundle_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, &error_handling, &error_handling_replaced) == FAILURE) {
146151
if (!EG(exception)) {
147152
zend_throw_exception(IntlException_ce_ptr, "Constructor failed", 0);
148153
}
149154
}
150-
zend_restore_error_handling(&error_handling);
155+
if (error_handling_replaced) {
156+
zend_restore_error_handling(&error_handling);
157+
}
151158
}
152159
/* }}} */
153160

154161
/* {{{ */
155162
PHP_FUNCTION( resourcebundle_create )
156163
{
157164
object_init_ex( return_value, ResourceBundle_ce_ptr );
158-
if (resourcebundle_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU) == FAILURE) {
165+
if (resourcebundle_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, NULL, NULL) == FAILURE) {
159166
zval_ptr_dtor(return_value);
160167
RETURN_NULL();
161168
}

0 commit comments

Comments
 (0)