Skip to content

ext/intl: calendar/locale use fast ZPP. #14425

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 15 additions & 17 deletions ext/intl/calendar/calendar_methods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,17 @@ U_CFUNC PHP_METHOD(IntlCalendar, __construct)
U_CFUNC PHP_FUNCTION(intlcal_create_instance)
{
zval *zv_timezone = NULL;
const char *locale_str = NULL;
size_t dummy;
char *locale_str = NULL;
size_t locale_len = 0;
TimeZone *timeZone;
UErrorCode status = U_ZERO_ERROR;
intl_error_reset(NULL);

if (zend_parse_parameters(ZEND_NUM_ARGS(), "|zs!",
&zv_timezone, &locale_str, &dummy) == FAILURE) {
RETURN_THROWS();
}
ZEND_PARSE_PARAMETERS_START(0, 2)
Z_PARAM_OPTIONAL
Z_PARAM_ZVAL(zv_timezone)
Z_PARAM_STRING_OR_NULL(locale_str, locale_len)
ZEND_PARSE_PARAMETERS_END();

timeZone = timezone_process_timezone_argument(zv_timezone, NULL,
"intlcal_create_instance");
Expand All @@ -91,7 +92,7 @@ U_CFUNC PHP_FUNCTION(intlcal_create_instance)
}

if (!locale_str) {
locale_str = intl_locale_get_default();
locale_str = (char *)intl_locale_get_default();
}

Calendar *cal = Calendar::createInstance(timeZone,
Expand Down Expand Up @@ -168,10 +169,11 @@ U_CFUNC PHP_FUNCTION(intlcal_get_keyword_values_for_locale)
bool commonly_used;
intl_error_reset(NULL);

if (zend_parse_parameters(ZEND_NUM_ARGS(), "ssb",
&key, &key_len, &locale, &locale_len, &commonly_used) == FAILURE) {
RETURN_THROWS();
}
ZEND_PARSE_PARAMETERS_START(3, 3)
Z_PARAM_STRING(key, key_len)
Z_PARAM_STRING(locale, locale_len)
Z_PARAM_BOOL(commonly_used)
ZEND_PARSE_PARAMETERS_END();

StringEnumeration *se = Calendar::getKeywordValuesForLocale(key,
Locale::createFromName(locale), (UBool)commonly_used,
Expand All @@ -189,9 +191,7 @@ U_CFUNC PHP_FUNCTION(intlcal_get_now)
{
intl_error_reset(NULL);

if (zend_parse_parameters_none() == FAILURE) {
RETURN_THROWS();
}
ZEND_PARSE_PARAMETERS_NONE();

RETURN_DOUBLE((double)Calendar::getNow());
}
Expand All @@ -200,9 +200,7 @@ U_CFUNC PHP_FUNCTION(intlcal_get_available_locales)
{
intl_error_reset(NULL);

if (zend_parse_parameters_none() == FAILURE) {
RETURN_THROWS();
}
ZEND_PARSE_PARAMETERS_NONE();

int32_t count;
const Locale *availLocales = Calendar::getAvailableLocales(count);
Expand Down
55 changes: 33 additions & 22 deletions ext/intl/calendar/gregoriancalendar_methods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,14 @@ static void _php_intlgregcal_constructor_body(
// argument parsing
if (variant <= 2) {
if (zend_parse_parameters(MIN(ZEND_NUM_ARGS(), 2),
"|z!s!", &tz_object, &locale, &locale_len) == FAILURE) {
RETURN_THROWS();
}
}
if (variant > 2 && zend_parse_parameters(ZEND_NUM_ARGS(),
"lll|lll", &largs[0], &largs[1], &largs[2], &largs[3], &largs[4],
&largs[5]) == FAILURE) {
RETURN_THROWS();
"|z!s!", &tz_object, &locale, &locale_len) == FAILURE) {
RETURN_THROWS();
}
}
if (variant > 2 && zend_parse_parameters(ZEND_NUM_ARGS(),
"lll|lll", &largs[0], &largs[1], &largs[2], &largs[3], &largs[4],
&largs[5]) == FAILURE) {
RETURN_THROWS();
}

if (error_handling != NULL) {
Expand Down Expand Up @@ -238,9 +238,11 @@ U_CFUNC PHP_METHOD(IntlGregorianCalendar, createFromDate)

intl_error_reset(NULL);

if (zend_parse_parameters(ZEND_NUM_ARGS(), "lll", &year, &month, &day) == FAILURE) {
RETURN_THROWS();
}
ZEND_PARSE_PARAMETERS_START(3, 3)
Z_PARAM_LONG(year)
Z_PARAM_LONG(month)
Z_PARAM_LONG(day)
ZEND_PARSE_PARAMETERS_END();

ZEND_VALUE_ERROR_OUT_OF_BOUND_VALUE(year, 1);
ZEND_VALUE_ERROR_OUT_OF_BOUND_VALUE(month, 2);
Expand Down Expand Up @@ -273,9 +275,15 @@ U_CFUNC PHP_METHOD(IntlGregorianCalendar, createFromDateTime)

intl_error_reset(NULL);

if (zend_parse_parameters(ZEND_NUM_ARGS(), "lllll|l!", &year, &month, &day, &hour, &minute, &second, &second_is_null) == FAILURE) {
RETURN_THROWS();
}
ZEND_PARSE_PARAMETERS_START(5, 6)
Z_PARAM_LONG(year)
Z_PARAM_LONG(month)
Z_PARAM_LONG(day)
Z_PARAM_LONG(hour)
Z_PARAM_LONG(minute)
Z_PARAM_OPTIONAL
Z_PARAM_LONG_OR_NULL(second, second_is_null)
ZEND_PARSE_PARAMETERS_END();

ZEND_VALUE_ERROR_OUT_OF_BOUND_VALUE(year, 1);
ZEND_VALUE_ERROR_OUT_OF_BOUND_VALUE(month, 2);
Expand Down Expand Up @@ -310,9 +318,10 @@ U_CFUNC PHP_FUNCTION(intlgregcal_set_gregorian_change)
CALENDAR_METHOD_INIT_VARS;

if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(),
"Od", &object, GregorianCalendar_ce_ptr, &date) == FAILURE) {
RETURN_THROWS();
}
"Od", &object, GregorianCalendar_ce_ptr, &date) == FAILURE) {
RETURN_THROWS();
}


CALENDAR_METHOD_FETCH_OBJECT;

Expand All @@ -328,9 +337,10 @@ U_CFUNC PHP_FUNCTION(intlgregcal_get_gregorian_change)
CALENDAR_METHOD_INIT_VARS;

if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(),
"O", &object, GregorianCalendar_ce_ptr) == FAILURE) {
"O", &object, GregorianCalendar_ce_ptr) == FAILURE) {
RETURN_THROWS();
}
}


CALENDAR_METHOD_FETCH_OBJECT;

Expand All @@ -343,9 +353,10 @@ U_CFUNC PHP_FUNCTION(intlgregcal_is_leap_year)
CALENDAR_METHOD_INIT_VARS;

if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(),
"Ol", &object, GregorianCalendar_ce_ptr, &year) == FAILURE) {
RETURN_THROWS();
}
"Ol", &object, GregorianCalendar_ce_ptr, &year) == FAILURE) {
RETURN_THROWS();
}


if (UNEXPECTED(year < INT32_MIN || year > INT32_MAX)) {
zend_argument_value_error(hasThis() ? 1 : 2, "must be between %d and %d", INT32_MIN, INT32_MAX);
Expand Down
Loading
Loading