Skip to content

Commit 22b858e

Browse files
committed
Throw exception for unconstructed intl objects
1 parent 0f89d40 commit 22b858e

File tree

13 files changed

+28
-35
lines changed

13 files changed

+28
-35
lines changed

ext/intl/breakiterator/breakiterator_class.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ static inline BreakIterator_object *php_intl_breakiterator_fetch_object(zend_obj
5858
BREAKITER_METHOD_FETCH_OBJECT_NO_CHECK; \
5959
if (bio->biter == NULL) \
6060
{ \
61-
intl_errors_set(&bio->err, U_ILLEGAL_ARGUMENT_ERROR, "Found unconstructed BreakIterator", 0); \
62-
RETURN_FALSE; \
61+
zend_throw_error(NULL, "Found unconstructed BreakIterator"); \
62+
RETURN_THROWS(); \
6363
}
6464

6565
void breakiterator_object_create(zval *object, BreakIterator *break_iter, int brand_new);

ext/intl/calendar/calendar_class.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ static inline Calendar_object *php_intl_calendar_fetch_object(zend_object *obj)
5555
CALENDAR_METHOD_FETCH_OBJECT_NO_CHECK; \
5656
if (co->ucal == NULL) \
5757
{ \
58-
intl_errors_set(&co->err, U_ILLEGAL_ARGUMENT_ERROR, "Found unconstructed IntlCalendar", 0); \
59-
RETURN_FALSE; \
58+
zend_throw_error(NULL, "Found unconstructed IntlCalendar"); \
59+
RETURN_THROWS(); \
6060
}
6161

6262
void calendar_object_create(zval *object, Calendar *calendar);

ext/intl/common/common_enum.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ extern "C" {
4141
object = ZEND_THIS; \
4242
INTLITERATOR_METHOD_FETCH_OBJECT_NO_CHECK; \
4343
if (ii->iterator == NULL) { \
44-
intl_errors_set(&ii->err, U_ILLEGAL_ARGUMENT_ERROR, "Found unconstructed IntlIterator", 0); \
45-
RETURN_FALSE; \
44+
zend_throw_error(NULL, "Found unconstructed IntlIterator"); \
45+
RETURN_THROWS(); \
4646
}
4747

4848
typedef struct {

ext/intl/dateformat/dateformat_class.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ extern zend_class_entry *IntlDateFormatter_ce_ptr;
4646
DATE_FORMAT_METHOD_FETCH_OBJECT_NO_CHECK; \
4747
if (dfo->datef_data.udatf == NULL) \
4848
{ \
49-
intl_errors_set(&dfo->datef_data.error, U_ILLEGAL_ARGUMENT_ERROR, "Found unconstructed IntlDateFormatter", 0); \
50-
RETURN_FALSE; \
49+
zend_throw_error(NULL, "Found unconstructed IntlDateFormatter"); \
50+
RETURN_THROWS(); \
5151
}
5252

5353
#define DATE_FORMAT_OBJECT(dfo) (dfo)->datef_data.udatf

ext/intl/formatter/formatter_class.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,8 @@ extern zend_class_entry *NumberFormatter_ce_ptr;
4444
FORMATTER_METHOD_FETCH_OBJECT_NO_CHECK; \
4545
if (FORMATTER_OBJECT(nfo) == NULL) \
4646
{ \
47-
intl_errors_set(&nfo->nf_data.error, U_ILLEGAL_ARGUMENT_ERROR, \
48-
"Found unconstructed NumberFormatter", 0); \
49-
RETURN_FALSE; \
47+
zend_throw_error(NULL, "Found unconstructed NumberFormatter"); \
48+
RETURN_THROWS(); \
5049
}
5150

5251

ext/intl/msgformat/msgformat_class.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,8 @@ extern zend_class_entry *MessageFormatter_ce_ptr;
4646
#define MSG_FORMAT_METHOD_FETCH_OBJECT \
4747
MSG_FORMAT_METHOD_FETCH_OBJECT_NO_CHECK; \
4848
if (MSG_FORMAT_OBJECT(mfo) == NULL) { \
49-
intl_errors_set(&mfo->mf_data.error, U_ILLEGAL_ARGUMENT_ERROR, \
50-
"Found unconstructed MessageFormatter", 0); \
51-
RETURN_FALSE; \
49+
zend_throw_error(NULL, "Found unconstructed MessageFormatter"); \
50+
RETURN_THROWS(); \
5251
}
5352

5453
#define MSG_FORMAT_OBJECT(mfo) (mfo)->mf_data.umsgf

ext/intl/resourcebundle/resourcebundle.stub.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public static function create(?string $locale, ?string $bundlename, bool $fallba
1313
*/
1414
public function get($index, bool $fallback = true) {}
1515

16-
/** @return int|false */
16+
/** @return int */
1717
public function count() {}
1818

1919
/** @return array|false */
@@ -34,7 +34,7 @@ function resourcebundle_create(?string $locale, ?string $bundlename, bool $fallb
3434
*/
3535
function resourcebundle_get(ResourceBundle $bundle, $index) {}
3636

37-
function resourcebundle_count(ResourceBundle $bundle): int|false {}
37+
function resourcebundle_count(ResourceBundle $bundle): int {}
3838

3939
function resourcebundle_locales(string $bundlename): array|false {}
4040

ext/intl/resourcebundle/resourcebundle_arginfo.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,15 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_resourcebundle_get, 0, 0, 2)
3535
ZEND_ARG_INFO(0, index)
3636
ZEND_END_ARG_INFO()
3737

38-
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_resourcebundle_count, 0, 1, MAY_BE_LONG|MAY_BE_FALSE)
38+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_resourcebundle_count, 0, 1, IS_LONG, 0)
3939
ZEND_ARG_OBJ_INFO(0, bundle, ResourceBundle, 0)
4040
ZEND_END_ARG_INFO()
4141

4242
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_resourcebundle_locales, 0, 1, MAY_BE_ARRAY|MAY_BE_FALSE)
4343
ZEND_ARG_TYPE_INFO(0, bundlename, IS_STRING, 0)
4444
ZEND_END_ARG_INFO()
4545

46-
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_resourcebundle_get_error_code, 0, 1, IS_LONG, 0)
47-
ZEND_ARG_OBJ_INFO(0, bundle, ResourceBundle, 0)
48-
ZEND_END_ARG_INFO()
46+
#define arginfo_resourcebundle_get_error_code arginfo_resourcebundle_count
4947

5048
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_resourcebundle_get_error_message, 0, 1, IS_STRING, 0)
5149
ZEND_ARG_OBJ_INFO(0, bundle, ResourceBundle, 0)

ext/intl/resourcebundle/resourcebundle_class.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,12 @@ static inline ResourceBundle_object *php_intl_resourcebundle_fetch_object(zend_o
3838
#define RESOURCEBUNDLE_METHOD_INIT_VARS INTL_METHOD_INIT_VARS(ResourceBundle, rb)
3939
#define RESOURCEBUNDLE_METHOD_FETCH_OBJECT_NO_CHECK INTL_METHOD_FETCH_OBJECT(INTL_RESOURCEBUNDLE, rb)
4040
#define RESOURCEBUNDLE_METHOD_FETCH_OBJECT \
41-
INTL_METHOD_FETCH_OBJECT(INTL_RESOURCEBUNDLE, rb); \
41+
INTL_METHOD_FETCH_OBJECT(INTL_RESOURCEBUNDLE, rb); \
4242
if (RESOURCEBUNDLE_OBJECT(rb) == NULL) { \
43-
intl_errors_set(&rb->error, U_ILLEGAL_ARGUMENT_ERROR, \
44-
"Found unconstructed ResourceBundle", 0); \
45-
RETURN_FALSE; \
43+
zend_throw_error(NULL, "Found unconstructed ResourceBundle"); \
44+
RETURN_THROWS(); \
4645
}
4746

48-
4947
#define RESOURCEBUNDLE_OBJECT(rb) (rb)->me
5048

5149
void resourcebundle_register_class( void );

ext/intl/spoofchecker/spoofchecker.stub.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ public function isSuspicious(string $text, &$error = null) {}
1010
/** @return bool */
1111
public function areConfusable(string $s1, string $s2, &$error = null) {}
1212

13-
/** @return null|false */
13+
/** @return void */
1414
public function setAllowedLocales(string $locale_list) {}
1515

16-
/** @return null|false */
16+
/** @return void */
1717
public function setChecks(int $checks) {}
1818

1919
#if U_ICU_VERSION_MAJOR_NUM >= 58
20-
/** @return null|false */
20+
/** @return void */
2121
public function setRestrictionLevel(int $level) {}
2222
#endif
2323
}

ext/intl/spoofchecker/spoofchecker_class.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,8 @@ extern zend_class_entry *Spoofchecker_ce_ptr;
6363
#define SPOOFCHECKER_METHOD_FETCH_OBJECT \
6464
SPOOFCHECKER_METHOD_FETCH_OBJECT_NO_CHECK; \
6565
if (co->uspoof == NULL) { \
66-
intl_errors_set(&co->err, U_ILLEGAL_ARGUMENT_ERROR, \
67-
"Found unconstructed Spoofchecker", 0); \
68-
RETURN_FALSE; \
66+
zend_throw_error(NULL, "Found unconstructed Spoofchecker"); \
67+
RETURN_THROWS(); \
6968
}
7069

7170
// Macro to check return value of a ucol_* function call.

ext/intl/timezone/timezone_class.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ static inline TimeZone_object *php_intl_timezone_fetch_object(zend_object *obj)
6060
#define TIMEZONE_METHOD_FETCH_OBJECT\
6161
TIMEZONE_METHOD_FETCH_OBJECT_NO_CHECK; \
6262
if (to->utimezone == NULL) { \
63-
intl_errors_set(&to->err, U_ILLEGAL_ARGUMENT_ERROR, "Found unconstructed IntlTimeZone", 0); \
64-
RETURN_FALSE; \
63+
zend_throw_error(NULL, "Found unconstructed IntlTimeZone"); \
64+
RETURN_THROWS(); \
6565
}
6666

6767
zval *timezone_convert_to_datetimezone(const TimeZone *timeZone, intl_error *outside_error, const char *func, zval *ret);

ext/intl/transliterator/transliterator_class.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ static inline Transliterator_object *php_intl_transliterator_fetch_object(zend_o
5252
TRANSLITERATOR_METHOD_FETCH_OBJECT_NO_CHECK; \
5353
if( to->utrans == NULL ) \
5454
{ \
55-
intl_errors_set( &to->err, U_ILLEGAL_ARGUMENT_ERROR, "Found unconstructed transliterator", 0 ); \
56-
RETURN_FALSE; \
55+
zend_throw_error(NULL, "Found unconstructed transliterator"); \
56+
RETURN_THROWS(); \
5757
}
5858

5959
int transliterator_object_construct( zval *object,

0 commit comments

Comments
 (0)