1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

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

This commit is contained in:
David CARLIER
2024-06-02 08:47:08 +01:00
committed by GitHub
parent 9437c32cf4
commit 354b64720c
3 changed files with 103 additions and 105 deletions

View File

@@ -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");
@@ -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,
@@ -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,
@@ -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());
}
@@ -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);

View File

@@ -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) {
@@ -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);
@@ -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);
@@ -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;
@@ -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;
@@ -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);

View File

@@ -298,9 +298,7 @@ static zend_off_t getSingletonPos(const char* str)
/* {{{ Get default locale */
PHP_NAMED_FUNCTION(zif_locale_get_default)
{
if (zend_parse_parameters_none() == FAILURE) {
RETURN_THROWS();
}
ZEND_PARSE_PARAMETERS_NONE();
RETURN_STRING( intl_locale_get_default( ) );
}
@@ -316,10 +314,9 @@ PHP_NAMED_FUNCTION(zif_locale_set_default)
zend_string *ini_name;
char *default_locale = NULL;
if(zend_parse_parameters( ZEND_NUM_ARGS(), "S", &locale_name) == FAILURE)
{
RETURN_THROWS();
}
ZEND_PARSE_PARAMETERS_START(1, 1)
Z_PARAM_STR(locale_name)
ZEND_PARSE_PARAMETERS_END();
if (ZSTR_LEN(locale_name) == 0) {
default_locale = (char *)uloc_getDefault();
@@ -470,7 +467,7 @@ static zend_string* get_icu_value_internal( const char* loc_name , char* tag_nam
static void get_icu_value_src_php( char* tag_name, INTERNAL_FUNCTION_PARAMETERS)
{
const char* loc_name = NULL;
char* loc_name = NULL;
size_t loc_name_len = 0;
zend_string* tag_value = NULL;
@@ -483,13 +480,12 @@ static void get_icu_value_src_php( char* tag_name, INTERNAL_FUNCTION_PARAMETERS)
intl_error_reset( NULL );
if(zend_parse_parameters( ZEND_NUM_ARGS(), "s",
&loc_name ,&loc_name_len ) == FAILURE) {
RETURN_THROWS();
}
ZEND_PARSE_PARAMETERS_START(1, 1)
Z_PARAM_STRING(loc_name, loc_name_len)
ZEND_PARSE_PARAMETERS_END();
if(loc_name_len == 0) {
loc_name = intl_locale_get_default();
loc_name = (char *)intl_locale_get_default();
loc_name_len = strlen(loc_name);
}
@@ -550,10 +546,10 @@ PHP_FUNCTION(locale_get_primary_language )
}}} */
static void get_icu_disp_value_src_php( char* tag_name, INTERNAL_FUNCTION_PARAMETERS)
{
const char* loc_name = NULL;
char* loc_name = NULL;
size_t loc_name_len = 0;
const char* disp_loc_name = NULL;
char* disp_loc_name = NULL;
size_t disp_loc_name_len = 0;
int free_loc_name = 0;
@@ -571,12 +567,11 @@ static void get_icu_disp_value_src_php( char* tag_name, INTERNAL_FUNCTION_PARAME
intl_error_reset( NULL );
if(zend_parse_parameters( ZEND_NUM_ARGS(), "s|s!",
&loc_name, &loc_name_len ,
&disp_loc_name ,&disp_loc_name_len ) == FAILURE)
{
RETURN_THROWS();
}
ZEND_PARSE_PARAMETERS_START(1, 2)
Z_PARAM_STRING(loc_name, loc_name_len)
Z_PARAM_OPTIONAL
Z_PARAM_STRING_OR_NULL(disp_loc_name, disp_loc_name_len)
ZEND_PARSE_PARAMETERS_END();
if(loc_name_len > ULOC_FULLNAME_CAPACITY) {
/* See bug 67397: overlong locale names cause trouble in uloc_getDisplayName */
@@ -587,7 +582,7 @@ static void get_icu_disp_value_src_php( char* tag_name, INTERNAL_FUNCTION_PARAME
}
if(loc_name_len == 0) {
loc_name = intl_locale_get_default();
loc_name = (char *)intl_locale_get_default();
}
if( strcmp(tag_name, DISP_NAME) != 0 ){
@@ -734,21 +729,19 @@ PHP_FUNCTION( locale_get_keywords )
const char* kw_key = NULL;
int32_t kw_key_len = 0;
const char* loc_name = NULL;
char* loc_name = NULL;
size_t loc_name_len = 0;
intl_error_reset( NULL );
if(zend_parse_parameters( ZEND_NUM_ARGS(), "s",
&loc_name, &loc_name_len ) == FAILURE)
{
RETURN_THROWS();
}
ZEND_PARSE_PARAMETERS_START(1, 1)
Z_PARAM_STRING(loc_name, loc_name_len)
ZEND_PARSE_PARAMETERS_END();
INTL_CHECK_LOCALE_LEN(strlen(loc_name));
if(loc_name_len == 0) {
loc_name = intl_locale_get_default();
loc_name = (char *)intl_locale_get_default();
}
/* Get the keywords */
@@ -952,11 +945,9 @@ PHP_FUNCTION(locale_compose)
intl_error_reset( NULL );
if(zend_parse_parameters( ZEND_NUM_ARGS(), "a",
&arr) == FAILURE)
{
RETURN_THROWS();
}
ZEND_PARSE_PARAMETERS_START(1, 1)
Z_PARAM_ARRAY(arr)
ZEND_PARSE_PARAMETERS_END();
hash_arr = Z_ARRVAL_P( arr );
@@ -1125,22 +1116,20 @@ static int add_array_entry(const char* loc_name, zval* hash_arr, char* key_name)
/* {{{ parses a locale-id into an array the different parts of it */
PHP_FUNCTION(locale_parse)
{
const char* loc_name = NULL;
char* loc_name = NULL;
size_t loc_name_len = 0;
int grOffset = 0;
intl_error_reset( NULL );
if(zend_parse_parameters( ZEND_NUM_ARGS(), "s",
&loc_name, &loc_name_len ) == FAILURE)
{
RETURN_THROWS();
}
ZEND_PARSE_PARAMETERS_START(1, 1)
Z_PARAM_STRING(loc_name, loc_name_len)
ZEND_PARSE_PARAMETERS_END();
INTL_CHECK_LOCALE_LEN(strlen(loc_name));
if(loc_name_len == 0) {
loc_name = intl_locale_get_default();
loc_name = (char *)intl_locale_get_default();
}
array_init( return_value );
@@ -1163,7 +1152,7 @@ PHP_FUNCTION(locale_parse)
/* {{{ gets an array containing the list of variants, or null */
PHP_FUNCTION(locale_get_all_variants)
{
const char* loc_name = NULL;
char* loc_name = NULL;
size_t loc_name_len = 0;
int result = 0;
@@ -1173,14 +1162,12 @@ PHP_FUNCTION(locale_get_all_variants)
intl_error_reset( NULL );
if(zend_parse_parameters( ZEND_NUM_ARGS(), "s",
&loc_name, &loc_name_len ) == FAILURE)
{
RETURN_THROWS();
}
ZEND_PARSE_PARAMETERS_START(1, 1)
Z_PARAM_STRING(loc_name, loc_name_len)
ZEND_PARSE_PARAMETERS_END();
if(loc_name_len == 0) {
loc_name = intl_locale_get_default();
loc_name = (char *)intl_locale_get_default();
loc_name_len = strlen(loc_name);
}
@@ -1251,7 +1238,7 @@ PHP_FUNCTION(locale_filter_matches)
{
char* lang_tag = NULL;
size_t lang_tag_len = 0;
const char* loc_range = NULL;
char* loc_range = NULL;
size_t loc_range_len = 0;
int result = 0;
@@ -1269,15 +1256,15 @@ PHP_FUNCTION(locale_filter_matches)
intl_error_reset( NULL );
if(zend_parse_parameters( ZEND_NUM_ARGS(), "ss|b",
&lang_tag, &lang_tag_len , &loc_range , &loc_range_len ,
&boolCanonical) == FAILURE)
{
RETURN_THROWS();
}
ZEND_PARSE_PARAMETERS_START(2, 3)
Z_PARAM_STRING(lang_tag, lang_tag_len)
Z_PARAM_STRING(loc_range, loc_range_len)
Z_PARAM_OPTIONAL
Z_PARAM_BOOL(boolCanonical)
ZEND_PARSE_PARAMETERS_END();
if(loc_range_len == 0) {
loc_range = intl_locale_get_default();
loc_range = (char *)intl_locale_get_default();
loc_range_len = strlen(loc_range);
}
@@ -1532,7 +1519,7 @@ static zend_string* lookup_loc_range(const char* loc_range, HashTable* hash_arr,
PHP_FUNCTION(locale_lookup)
{
zend_string* fallback_loc_str = NULL;
const char* loc_range = NULL;
char* loc_range = NULL;
size_t loc_range_len = 0;
zval* arr = NULL;
@@ -1542,17 +1529,20 @@ PHP_FUNCTION(locale_lookup)
intl_error_reset( NULL );
if(zend_parse_parameters( ZEND_NUM_ARGS(), "as|bS!", &arr, &loc_range, &loc_range_len,
&boolCanonical, &fallback_loc_str) == FAILURE) {
RETURN_THROWS();
}
ZEND_PARSE_PARAMETERS_START(2, 4)
Z_PARAM_ARRAY(arr)
Z_PARAM_STRING(loc_range, loc_range_len)
Z_PARAM_OPTIONAL
Z_PARAM_BOOL(boolCanonical)
Z_PARAM_STR_OR_NULL(fallback_loc_str)
ZEND_PARSE_PARAMETERS_END();
if(loc_range_len == 0) {
if(fallback_loc_str) {
loc_range = ZSTR_VAL(fallback_loc_str);
loc_range_len = ZSTR_LEN(fallback_loc_str);
} else {
loc_range = intl_locale_get_default();
loc_range = (char *)intl_locale_get_default();
loc_range_len = strlen(loc_range);
}
}
@@ -1591,10 +1581,9 @@ PHP_FUNCTION(locale_accept_from_http)
char resultLocale[INTL_MAX_LOCALE_LEN+1];
UAcceptResult outResult;
if(zend_parse_parameters( ZEND_NUM_ARGS(), "s", &http_accept, &http_accept_len) == FAILURE)
{
RETURN_THROWS();
}
ZEND_PARSE_PARAMETERS_START(1, 1)
Z_PARAM_STRING(http_accept, http_accept_len)
ZEND_PARSE_PARAMETERS_END();
if(http_accept_len > ULOC_FULLNAME_CAPACITY) {
/* check each fragment, if any bigger than capacity, can't do it due to bug #72533 */
char *start = http_accept;