From a6028240bd3a9aa58ceffaeb1dbbda7dd191a76c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1t=C3=A9=20Kocsis?= <kocsismate@woohoolabs.com> Date: Sat, 30 Jul 2022 15:17:07 +0200 Subject: [PATCH] Declare ext/intl constants in stubs - part 1 --- ext/intl/locale/locale.c | 35 ---------------- ext/intl/locale/locale.h | 2 - ext/intl/locale/locale.stub.php | 48 ++++++++++++++++++++++ ext/intl/locale/locale_arginfo.h | 69 +++++++++++++++++++++++++++++++- ext/intl/php_intl.c | 3 -- 5 files changed, 116 insertions(+), 41 deletions(-) diff --git a/ext/intl/locale/locale.c b/ext/intl/locale/locale.c index 6feb67fff789d..cb7afabe2b700 100644 --- a/ext/intl/locale/locale.c +++ b/ext/intl/locale/locale.c @@ -22,38 +22,3 @@ #include <unicode/utypes.h> #include <unicode/uloc.h> #include <unicode/ustring.h> - -/* {{{ locale_register_constants - * Register constants common for the both (OO and procedural) - * APIs. - */ -void locale_register_constants( INIT_FUNC_ARGS ) -{ - if( !Locale_ce_ptr ) - { - zend_error( E_ERROR, "Locale class not defined" ); - return; - } - - #define LOCALE_EXPOSE_CONST(x) REGISTER_LONG_CONSTANT(#x, x, CONST_PERSISTENT | CONST_CS) - #define LOCALE_EXPOSE_CLASS_CONST(x) zend_declare_class_constant_long( Locale_ce_ptr, ZEND_STRS( #x ) - 1, ULOC_##x ); - #define LOCALE_EXPOSE_CUSTOM_CLASS_CONST_STR(name, value) zend_declare_class_constant_string( Locale_ce_ptr, ZEND_STRS( name ) - 1, value ); - - LOCALE_EXPOSE_CLASS_CONST( ACTUAL_LOCALE ); - LOCALE_EXPOSE_CLASS_CONST( VALID_LOCALE ); - - zend_declare_class_constant_null(Locale_ce_ptr, ZEND_STRS("DEFAULT_LOCALE") - 1); - - LOCALE_EXPOSE_CUSTOM_CLASS_CONST_STR( "LANG_TAG", LOC_LANG_TAG); - LOCALE_EXPOSE_CUSTOM_CLASS_CONST_STR( "EXTLANG_TAG", LOC_EXTLANG_TAG); - LOCALE_EXPOSE_CUSTOM_CLASS_CONST_STR( "SCRIPT_TAG", LOC_SCRIPT_TAG); - LOCALE_EXPOSE_CUSTOM_CLASS_CONST_STR( "REGION_TAG", LOC_REGION_TAG); - LOCALE_EXPOSE_CUSTOM_CLASS_CONST_STR( "VARIANT_TAG",LOC_VARIANT_TAG); - LOCALE_EXPOSE_CUSTOM_CLASS_CONST_STR( "GRANDFATHERED_LANG_TAG",LOC_GRANDFATHERED_LANG_TAG); - LOCALE_EXPOSE_CUSTOM_CLASS_CONST_STR( "PRIVATE_TAG",LOC_PRIVATE_TAG); - - #undef LOCALE_EXPOSE_CUSTOM_CLASS_CONST_STR - #undef LOCALE_EXPOSE_CLASS_CONST - #undef LOCALE_EXPOSE_CONST -} -/* }}} */ diff --git a/ext/intl/locale/locale.h b/ext/intl/locale/locale.h index 39b3f92695828..31aef035050d1 100644 --- a/ext/intl/locale/locale.h +++ b/ext/intl/locale/locale.h @@ -17,8 +17,6 @@ #include <php.h> -void locale_register_constants( INIT_FUNC_ARGS ); - #define OPTION_DEFAULT NULL #define LOC_LANG_TAG "language" #define LOC_SCRIPT_TAG "script" diff --git a/ext/intl/locale/locale.stub.php b/ext/intl/locale/locale.stub.php index e5a4194a261ac..afb73ce125943 100644 --- a/ext/intl/locale/locale.stub.php +++ b/ext/intl/locale/locale.stub.php @@ -4,6 +4,54 @@ class Locale { + /** + * @var int + * @cvalue ULOC_ACTUAL_LOCALE + */ + public const ACTUAL_LOCALE = UNKNOWN; + /** + * @var int + * @cvalue ULOC_VALID_LOCALE + */ + public const VALID_LOCALE = UNKNOWN; + /** @var null */ + public const DEFAULT_LOCALE = null; + /** + * @var string + * @cvalue LOC_LANG_TAG + */ + public const LANG_TAG = UNKNOWN; + /** + * @var string + * @cvalue LOC_EXTLANG_TAG + */ + public const EXTLANG_TAG = UNKNOWN; + /** + * @var string + * @cvalue LOC_SCRIPT_TAG + */ + public const SCRIPT_TAG = UNKNOWN; + /** + * @var string + * @cvalue LOC_REGION_TAG + */ + public const REGION_TAG = UNKNOWN; + /** + * @var string + * @cvalue LOC_VARIANT_TAG + */ + public const VARIANT_TAG = UNKNOWN; + /** + * @var string + * @cvalue LOC_GRANDFATHERED_LANG_TAG + */ + public const GRANDFATHERED_LANG_TAG = UNKNOWN; + /** + * @var string + * @cvalue LOC_PRIVATE_TAG + */ + public const PRIVATE_TAG = UNKNOWN; + /** * @tentative-return-type * @alias locale_get_default diff --git a/ext/intl/locale/locale_arginfo.h b/ext/intl/locale/locale_arginfo.h index 679a4ca9d9034..891fa7e004418 100644 --- a/ext/intl/locale/locale_arginfo.h +++ b/ext/intl/locale/locale_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: 539e559bc038e18358540b3b3f4db7b09e532dae */ + * Stub hash: ada449c81e2e3657dbbff7b77ce2410f9f5b1a9a */ ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_Locale_getDefault, 0, 0, IS_STRING, 0) ZEND_END_ARG_INFO() @@ -112,5 +112,72 @@ static zend_class_entry *register_class_Locale(void) INIT_CLASS_ENTRY(ce, "Locale", class_Locale_methods); class_entry = zend_register_internal_class_ex(&ce, NULL); + zval const_ACTUAL_LOCALE_value; + ZVAL_LONG(&const_ACTUAL_LOCALE_value, ULOC_ACTUAL_LOCALE); + zend_string *const_ACTUAL_LOCALE_name = zend_string_init_interned("ACTUAL_LOCALE", sizeof("ACTUAL_LOCALE") - 1, 1); + zend_declare_class_constant_ex(class_entry, const_ACTUAL_LOCALE_name, &const_ACTUAL_LOCALE_value, ZEND_ACC_PUBLIC, NULL); + zend_string_release(const_ACTUAL_LOCALE_name); + + zval const_VALID_LOCALE_value; + ZVAL_LONG(&const_VALID_LOCALE_value, ULOC_VALID_LOCALE); + zend_string *const_VALID_LOCALE_name = zend_string_init_interned("VALID_LOCALE", sizeof("VALID_LOCALE") - 1, 1); + zend_declare_class_constant_ex(class_entry, const_VALID_LOCALE_name, &const_VALID_LOCALE_value, ZEND_ACC_PUBLIC, NULL); + zend_string_release(const_VALID_LOCALE_name); + + zval const_DEFAULT_LOCALE_value; + ZVAL_NULL(&const_DEFAULT_LOCALE_value); + zend_string *const_DEFAULT_LOCALE_name = zend_string_init_interned("DEFAULT_LOCALE", sizeof("DEFAULT_LOCALE") - 1, 1); + zend_declare_class_constant_ex(class_entry, const_DEFAULT_LOCALE_name, &const_DEFAULT_LOCALE_value, ZEND_ACC_PUBLIC, NULL); + zend_string_release(const_DEFAULT_LOCALE_name); + + zval const_LANG_TAG_value; + zend_string *const_LANG_TAG_value_str = zend_string_init(LOC_LANG_TAG, sizeof(LOC_LANG_TAG) - 1, 1); + ZVAL_STR(&const_LANG_TAG_value, const_LANG_TAG_value_str); + zend_string *const_LANG_TAG_name = zend_string_init_interned("LANG_TAG", sizeof("LANG_TAG") - 1, 1); + zend_declare_class_constant_ex(class_entry, const_LANG_TAG_name, &const_LANG_TAG_value, ZEND_ACC_PUBLIC, NULL); + zend_string_release(const_LANG_TAG_name); + + zval const_EXTLANG_TAG_value; + zend_string *const_EXTLANG_TAG_value_str = zend_string_init(LOC_EXTLANG_TAG, sizeof(LOC_EXTLANG_TAG) - 1, 1); + ZVAL_STR(&const_EXTLANG_TAG_value, const_EXTLANG_TAG_value_str); + zend_string *const_EXTLANG_TAG_name = zend_string_init_interned("EXTLANG_TAG", sizeof("EXTLANG_TAG") - 1, 1); + zend_declare_class_constant_ex(class_entry, const_EXTLANG_TAG_name, &const_EXTLANG_TAG_value, ZEND_ACC_PUBLIC, NULL); + zend_string_release(const_EXTLANG_TAG_name); + + zval const_SCRIPT_TAG_value; + zend_string *const_SCRIPT_TAG_value_str = zend_string_init(LOC_SCRIPT_TAG, sizeof(LOC_SCRIPT_TAG) - 1, 1); + ZVAL_STR(&const_SCRIPT_TAG_value, const_SCRIPT_TAG_value_str); + zend_string *const_SCRIPT_TAG_name = zend_string_init_interned("SCRIPT_TAG", sizeof("SCRIPT_TAG") - 1, 1); + zend_declare_class_constant_ex(class_entry, const_SCRIPT_TAG_name, &const_SCRIPT_TAG_value, ZEND_ACC_PUBLIC, NULL); + zend_string_release(const_SCRIPT_TAG_name); + + zval const_REGION_TAG_value; + zend_string *const_REGION_TAG_value_str = zend_string_init(LOC_REGION_TAG, sizeof(LOC_REGION_TAG) - 1, 1); + ZVAL_STR(&const_REGION_TAG_value, const_REGION_TAG_value_str); + zend_string *const_REGION_TAG_name = zend_string_init_interned("REGION_TAG", sizeof("REGION_TAG") - 1, 1); + zend_declare_class_constant_ex(class_entry, const_REGION_TAG_name, &const_REGION_TAG_value, ZEND_ACC_PUBLIC, NULL); + zend_string_release(const_REGION_TAG_name); + + zval const_VARIANT_TAG_value; + zend_string *const_VARIANT_TAG_value_str = zend_string_init(LOC_VARIANT_TAG, sizeof(LOC_VARIANT_TAG) - 1, 1); + ZVAL_STR(&const_VARIANT_TAG_value, const_VARIANT_TAG_value_str); + zend_string *const_VARIANT_TAG_name = zend_string_init_interned("VARIANT_TAG", sizeof("VARIANT_TAG") - 1, 1); + zend_declare_class_constant_ex(class_entry, const_VARIANT_TAG_name, &const_VARIANT_TAG_value, ZEND_ACC_PUBLIC, NULL); + zend_string_release(const_VARIANT_TAG_name); + + zval const_GRANDFATHERED_LANG_TAG_value; + zend_string *const_GRANDFATHERED_LANG_TAG_value_str = zend_string_init(LOC_GRANDFATHERED_LANG_TAG, sizeof(LOC_GRANDFATHERED_LANG_TAG) - 1, 1); + ZVAL_STR(&const_GRANDFATHERED_LANG_TAG_value, const_GRANDFATHERED_LANG_TAG_value_str); + zend_string *const_GRANDFATHERED_LANG_TAG_name = zend_string_init_interned("GRANDFATHERED_LANG_TAG", sizeof("GRANDFATHERED_LANG_TAG") - 1, 1); + zend_declare_class_constant_ex(class_entry, const_GRANDFATHERED_LANG_TAG_name, &const_GRANDFATHERED_LANG_TAG_value, ZEND_ACC_PUBLIC, NULL); + zend_string_release(const_GRANDFATHERED_LANG_TAG_name); + + zval const_PRIVATE_TAG_value; + zend_string *const_PRIVATE_TAG_value_str = zend_string_init(LOC_PRIVATE_TAG, sizeof(LOC_PRIVATE_TAG) - 1, 1); + ZVAL_STR(&const_PRIVATE_TAG_value, const_PRIVATE_TAG_value_str); + zend_string *const_PRIVATE_TAG_name = zend_string_init_interned("PRIVATE_TAG", sizeof("PRIVATE_TAG") - 1, 1); + zend_declare_class_constant_ex(class_entry, const_PRIVATE_TAG_name, &const_PRIVATE_TAG_value, ZEND_ACC_PUBLIC, NULL); + zend_string_release(const_PRIVATE_TAG_name); + return class_entry; } diff --git a/ext/intl/php_intl.c b/ext/intl/php_intl.c index 5826c2e3372f1..a76472f19f2e9 100644 --- a/ext/intl/php_intl.c +++ b/ext/intl/php_intl.c @@ -175,9 +175,6 @@ PHP_MINIT_FUNCTION( intl ) /* Register 'Locale' PHP class */ locale_register_Locale_class( ); - /* Expose Locale constants to PHP scripts */ - locale_register_constants( INIT_FUNC_ARGS_PASSTHRU ); - msgformat_register_class(); grapheme_register_constants( INIT_FUNC_ARGS_PASSTHRU );