Skip to content

Commit

Permalink
Allowing catching arg type deprecations in intl classes
Browse files Browse the repository at this point in the history
Closes GH-8115
Closes GH-8117
  • Loading branch information
iluuu1994 committed Mar 3, 2022
1 parent 723058c commit 925a309
Show file tree
Hide file tree
Showing 10 changed files with 136 additions and 39 deletions.
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ PHP NEWS
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
?? ??? ????, PHP 8.1.5

- Intl:
. Fixed bug GH-8115 (Can't catch arg type deprecation when instantiating Intl
classes). (ilutov)

17 Mar 2022, PHP 8.1.4

Expand Down
13 changes: 9 additions & 4 deletions ext/intl/breakiterator/rulebasedbreakiterator_methods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ static inline RuleBasedBreakIterator *fetch_rbbi(BreakIterator_object *bio) {
return (RuleBasedBreakIterator*)bio->biter;
}

static void _php_intlrbbi_constructor_body(INTERNAL_FUNCTION_PARAMETERS)
static void _php_intlrbbi_constructor_body(INTERNAL_FUNCTION_PARAMETERS, zend_error_handling *error_handling, bool *error_handling_replaced)
{
char *rules;
size_t rules_len;
Expand All @@ -51,6 +51,9 @@ static void _php_intlrbbi_constructor_body(INTERNAL_FUNCTION_PARAMETERS)
RETURN_THROWS();
}

zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, error_handling);
*error_handling_replaced = 1;

// instantiation of ICU object
RuleBasedBreakIterator *rbbi;

Expand Down Expand Up @@ -95,11 +98,13 @@ static void _php_intlrbbi_constructor_body(INTERNAL_FUNCTION_PARAMETERS)
U_CFUNC PHP_METHOD(IntlRuleBasedBreakIterator, __construct)
{
zend_error_handling error_handling;
bool error_handling_replaced = 0;

zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, &error_handling);
return_value = ZEND_THIS;
_php_intlrbbi_constructor_body(INTERNAL_FUNCTION_PARAM_PASSTHRU);
zend_restore_error_handling(&error_handling);
_php_intlrbbi_constructor_body(INTERNAL_FUNCTION_PARAM_PASSTHRU, &error_handling, &error_handling_replaced);
if (error_handling_replaced) {
zend_restore_error_handling(&error_handling);
}
}

U_CFUNC PHP_METHOD(IntlRuleBasedBreakIterator, getRules)
Expand Down
17 changes: 12 additions & 5 deletions ext/intl/calendar/gregoriancalendar_methods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ static inline GregorianCalendar *fetch_greg(Calendar_object *co) {
}

static void _php_intlgregcal_constructor_body(
INTERNAL_FUNCTION_PARAMETERS, bool is_constructor)
INTERNAL_FUNCTION_PARAMETERS, bool is_constructor, zend_error_handling *error_handling, bool *error_handling_replaced)
{
zval *tz_object = NULL;
zval args_a[6],
Expand Down Expand Up @@ -84,6 +84,11 @@ static void _php_intlgregcal_constructor_body(
RETURN_THROWS();
}

if (error_handling != NULL) {
zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, error_handling);
*error_handling_replaced = 1;
}

// instantion of ICU object
Calendar_object *co = Z_INTL_CALENDAR_P(return_value);
GregorianCalendar *gcal = NULL;
Expand Down Expand Up @@ -188,17 +193,19 @@ U_CFUNC PHP_FUNCTION(intlgregcal_create_instance)
intl_error_reset(NULL);

object_init_ex(return_value, GregorianCalendar_ce_ptr);
_php_intlgregcal_constructor_body(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
_php_intlgregcal_constructor_body(INTERNAL_FUNCTION_PARAM_PASSTHRU, /* is_constructor */ 0, NULL, NULL);
}

U_CFUNC PHP_METHOD(IntlGregorianCalendar, __construct)
{
zend_error_handling error_handling;
bool error_handling_replaced = 0;

zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, &error_handling);
return_value = ZEND_THIS;
_php_intlgregcal_constructor_body(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
zend_restore_error_handling(&error_handling);
_php_intlgregcal_constructor_body(INTERNAL_FUNCTION_PARAM_PASSTHRU, /* is_constructor */ 1, &error_handling, &error_handling_replaced);
if (error_handling_replaced) {
zend_restore_error_handling(&error_handling);
}
}

U_CFUNC PHP_FUNCTION(intlgregcal_set_gregorian_change)
Expand Down
17 changes: 12 additions & 5 deletions ext/intl/collator/collator_create.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include "intl_data.h"

/* {{{ */
static int collator_ctor(INTERNAL_FUNCTION_PARAMETERS)
static int collator_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_error_handling *error_handling, bool *error_handling_replaced)
{
const char* locale;
size_t locale_len = 0;
Expand All @@ -38,6 +38,11 @@ static int collator_ctor(INTERNAL_FUNCTION_PARAMETERS)
return FAILURE;
}

if (error_handling != NULL) {
zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, error_handling);
*error_handling_replaced = 1;
}

INTL_CHECK_LOCALE_LEN_OR_FAILURE(locale_len);
COLLATOR_METHOD_FETCH_OBJECT;

Expand All @@ -56,7 +61,7 @@ static int collator_ctor(INTERNAL_FUNCTION_PARAMETERS)
PHP_FUNCTION( collator_create )
{
object_init_ex( return_value, Collator_ce_ptr );
if (collator_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU) == FAILURE) {
if (collator_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, NULL, NULL) == FAILURE) {
zval_ptr_dtor(return_value);
RETURN_NULL();
}
Expand All @@ -67,14 +72,16 @@ PHP_FUNCTION( collator_create )
PHP_METHOD( Collator, __construct )
{
zend_error_handling error_handling;
bool error_handling_replaced = 0;

zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, &error_handling);
return_value = ZEND_THIS;
if (collator_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU) == FAILURE) {
if (collator_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, &error_handling, &error_handling_replaced) == FAILURE) {
if (!EG(exception)) {
zend_throw_exception(IntlException_ce_ptr, "Constructor failed", 0);
}
}
zend_restore_error_handling(&error_handling);
if (error_handling_replaced) {
zend_restore_error_handling(&error_handling);
}
}
/* }}} */
17 changes: 12 additions & 5 deletions ext/intl/dateformat/dateformat_create.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ extern "C" {
UDAT_PATTERN == (i))

/* {{{ */
static zend_result datefmt_ctor(INTERNAL_FUNCTION_PARAMETERS)
static zend_result datefmt_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_error_handling *error_handling, bool *error_handling_replaced)
{
zval *object;
char *locale_str;
Expand Down Expand Up @@ -81,6 +81,11 @@ static zend_result datefmt_ctor(INTERNAL_FUNCTION_PARAMETERS)
Z_PARAM_STRING_OR_NULL(pattern_str, pattern_str_len)
ZEND_PARSE_PARAMETERS_END_EX(return FAILURE);

if (error_handling != NULL) {
zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, error_handling);
*error_handling_replaced = 1;
}

DATE_FORMAT_METHOD_FETCH_OBJECT_NO_CHECK;

if (DATE_FORMAT_OBJECT(dfo) != NULL) {
Expand Down Expand Up @@ -189,7 +194,7 @@ return FAILURE;
U_CFUNC PHP_FUNCTION( datefmt_create )
{
object_init_ex( return_value, IntlDateFormatter_ce_ptr );
if (datefmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU) == FAILURE) {
if (datefmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, NULL, NULL) == FAILURE) {
zval_ptr_dtor(return_value);
RETURN_NULL();
}
Expand All @@ -200,18 +205,20 @@ U_CFUNC PHP_FUNCTION( datefmt_create )
U_CFUNC PHP_METHOD( IntlDateFormatter, __construct )
{
zend_error_handling error_handling;
bool error_handling_replaced = 0;

zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, &error_handling);
/* return_value param is being changed, therefore we will always return
* NULL here */
return_value = ZEND_THIS;
if (datefmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU) == FAILURE) {
if (datefmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, &error_handling, &error_handling_replaced) == FAILURE) {
if (!EG(exception)) {
zend_string *err = intl_error_get_message(NULL);
zend_throw_exception(IntlException_ce_ptr, ZSTR_VAL(err), intl_error_get_code(NULL));
zend_string_release_ex(err, 0);
}
}
zend_restore_error_handling(&error_handling);
if (error_handling_replaced) {
zend_restore_error_handling(&error_handling);
}
}
/* }}} */
17 changes: 12 additions & 5 deletions ext/intl/dateformat/datepatterngenerator_methods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ using icu::DateTimePatternGenerator;
using icu::Locale;
using icu::StringPiece;

static zend_result dtpg_ctor(INTERNAL_FUNCTION_PARAMETERS)
static zend_result dtpg_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_error_handling *error_handling, bool *error_handling_replaced)
{
char *locale_str;
size_t locale_len = 0;
Expand All @@ -44,6 +44,11 @@ static zend_result dtpg_ctor(INTERNAL_FUNCTION_PARAMETERS)
Z_PARAM_STRING_OR_NULL(locale_str, locale_len)
ZEND_PARSE_PARAMETERS_END_EX(return FAILURE);

if (error_handling != NULL) {
zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, error_handling);
*error_handling_replaced = 1;
}

DTPATTERNGEN_METHOD_FETCH_OBJECT_NO_CHECK;

if (dtpgo->dtpg != NULL) {
Expand Down Expand Up @@ -74,7 +79,7 @@ static zend_result dtpg_ctor(INTERNAL_FUNCTION_PARAMETERS)
U_CFUNC PHP_METHOD( IntlDatePatternGenerator, create )
{
object_init_ex( return_value, IntlDatePatternGenerator_ce_ptr );
if (dtpg_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU) == FAILURE) {
if (dtpg_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, NULL, NULL) == FAILURE) {
zval_ptr_dtor(return_value);
RETURN_NULL();
}
Expand All @@ -83,19 +88,21 @@ U_CFUNC PHP_METHOD( IntlDatePatternGenerator, create )
U_CFUNC PHP_METHOD( IntlDatePatternGenerator, __construct )
{
zend_error_handling error_handling;
bool error_handling_replaced = 0;

zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, &error_handling);
/* return_value param is being changed, therefore we will always return
* NULL here */
return_value = ZEND_THIS;
if (dtpg_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU) == FAILURE) {
if (dtpg_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, &error_handling, &error_handling_replaced) == FAILURE) {
if (!EG(exception)) {
zend_string *err = intl_error_get_message(NULL);
zend_throw_exception(IntlException_ce_ptr, ZSTR_VAL(err), intl_error_get_code(NULL));
zend_string_release_ex(err, 0);
}
}
zend_restore_error_handling(&error_handling);
if (error_handling_replaced) {
zend_restore_error_handling(&error_handling);
}
}


Expand Down
17 changes: 12 additions & 5 deletions ext/intl/formatter/formatter_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include "intl_convert.h"

/* {{{ */
static int numfmt_ctor(INTERNAL_FUNCTION_PARAMETERS)
static int numfmt_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_error_handling *error_handling, bool *error_handling_replaced)
{
const char* locale;
char* pattern = NULL;
Expand All @@ -40,6 +40,11 @@ static int numfmt_ctor(INTERNAL_FUNCTION_PARAMETERS)
return FAILURE;
}

if (error_handling != NULL) {
zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, error_handling);
*error_handling_replaced = 1;
}

INTL_CHECK_LOCALE_LEN_OR_FAILURE(locale_len);
object = return_value;
FORMATTER_METHOD_FETCH_OBJECT_NO_CHECK;
Expand Down Expand Up @@ -74,7 +79,7 @@ static int numfmt_ctor(INTERNAL_FUNCTION_PARAMETERS)
PHP_FUNCTION( numfmt_create )
{
object_init_ex( return_value, NumberFormatter_ce_ptr );
if (numfmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU) == FAILURE) {
if (numfmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, NULL, NULL) == FAILURE) {
zval_ptr_dtor(return_value);
RETURN_NULL();
}
Expand All @@ -85,15 +90,17 @@ PHP_FUNCTION( numfmt_create )
PHP_METHOD( NumberFormatter, __construct )
{
zend_error_handling error_handling;
bool error_handling_replaced = 0;

zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, &error_handling);
return_value = ZEND_THIS;
if (numfmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU) == FAILURE) {
if (numfmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, &error_handling, &error_handling_replaced) == FAILURE) {
if (!EG(exception)) {
zend_throw_exception(IntlException_ce_ptr, "Constructor failed", 0);
}
}
zend_restore_error_handling(&error_handling);
if (error_handling_replaced) {
zend_restore_error_handling(&error_handling);
}
}
/* }}} */

Expand Down
17 changes: 12 additions & 5 deletions ext/intl/msgformat/msgformat.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include "intl_convert.h"

/* {{{ */
static int msgfmt_ctor(INTERNAL_FUNCTION_PARAMETERS)
static int msgfmt_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_error_handling *error_handling, bool *error_handling_replaced)
{
const char* locale;
char* pattern;
Expand All @@ -45,6 +45,11 @@ static int msgfmt_ctor(INTERNAL_FUNCTION_PARAMETERS)
return FAILURE;
}

if (error_handling != NULL) {
zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, error_handling);
*error_handling_replaced = 1;
}

INTL_CHECK_LOCALE_LEN_OR_FAILURE(locale_len);
MSG_FORMAT_METHOD_FETCH_OBJECT_NO_CHECK;

Expand Down Expand Up @@ -104,7 +109,7 @@ static int msgfmt_ctor(INTERNAL_FUNCTION_PARAMETERS)
PHP_FUNCTION( msgfmt_create )
{
object_init_ex( return_value, MessageFormatter_ce_ptr );
if (msgfmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU) == FAILURE) {
if (msgfmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, NULL, NULL) == FAILURE) {
zval_ptr_dtor(return_value);
RETURN_NULL();
}
Expand All @@ -115,17 +120,19 @@ PHP_FUNCTION( msgfmt_create )
PHP_METHOD( MessageFormatter, __construct )
{
zend_error_handling error_handling;
bool error_handling_replaced = 0;

zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, &error_handling);
return_value = ZEND_THIS;
if (msgfmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU) == FAILURE) {
if (msgfmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, &error_handling, &error_handling_replaced) == FAILURE) {
if (!EG(exception)) {
zend_string *err = intl_error_get_message(NULL);
zend_throw_exception(IntlException_ce_ptr, ZSTR_VAL(err), intl_error_get_code(NULL));
zend_string_release_ex(err, 0);
}
}
zend_restore_error_handling(&error_handling);
if (error_handling_replaced) {
zend_restore_error_handling(&error_handling);
}
}
/* }}} */

Expand Down

0 comments on commit 925a309

Please sign in to comment.