diff options
Diffstat (limited to 'ext/intl/msgformat')
-rw-r--r-- | ext/intl/msgformat/msgformat.c | 59 | ||||
-rw-r--r-- | ext/intl/msgformat/msgformat.h | 2 | ||||
-rw-r--r-- | ext/intl/msgformat/msgformat_attr.c | 30 | ||||
-rw-r--r-- | ext/intl/msgformat/msgformat_attr.h | 2 | ||||
-rw-r--r-- | ext/intl/msgformat/msgformat_class.c | 64 | ||||
-rw-r--r-- | ext/intl/msgformat/msgformat_class.h | 25 | ||||
-rw-r--r-- | ext/intl/msgformat/msgformat_data.c | 14 | ||||
-rw-r--r-- | ext/intl/msgformat/msgformat_data.h | 10 | ||||
-rw-r--r-- | ext/intl/msgformat/msgformat_format.c | 40 | ||||
-rw-r--r-- | ext/intl/msgformat/msgformat_format.h | 2 | ||||
-rw-r--r-- | ext/intl/msgformat/msgformat_helpers.cpp | 257 | ||||
-rw-r--r-- | ext/intl/msgformat/msgformat_helpers.h | 6 | ||||
-rw-r--r-- | ext/intl/msgformat/msgformat_parse.c | 41 | ||||
-rw-r--r-- | ext/intl/msgformat/msgformat_parse.h | 2 |
14 files changed, 279 insertions, 275 deletions
diff --git a/ext/intl/msgformat/msgformat.c b/ext/intl/msgformat/msgformat.c index 7d8cd958e3..d3f8416c03 100644 --- a/ext/intl/msgformat/msgformat.c +++ b/ext/intl/msgformat/msgformat.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -23,32 +23,33 @@ #include "php_intl.h" #include "msgformat_class.h" +#include "msgformat_data.h" #include "intl_convert.h" /* {{{ */ -static void msgfmt_ctor(INTERNAL_FUNCTION_PARAMETERS) +static int msgfmt_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_constructor) { const char* locale; char* pattern; - int locale_len = 0, pattern_len = 0; + size_t locale_len = 0, pattern_len = 0; UChar* spattern = NULL; int spattern_len = 0; zval* object; MessageFormatter_object* mfo; - intl_error_reset( NULL TSRMLS_CC ); + int zpp_flags = is_constructor ? ZEND_PARSE_PARAMS_THROW : 0; + intl_error_reset( NULL ); object = return_value; /* Parse parameters. */ - if( zend_parse_parameters( ZEND_NUM_ARGS() TSRMLS_CC, "ss", + if( zend_parse_parameters_ex( zpp_flags, ZEND_NUM_ARGS(), "ss", &locale, &locale_len, &pattern, &pattern_len ) == FAILURE ) { intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, - "msgfmt_create: unable to parse input parameters", 0 TSRMLS_CC ); - zval_dtor(return_value); - RETURN_NULL(); + "msgfmt_create: unable to parse input parameters", 0 ); + return FAILURE; } - INTL_CHECK_LOCALE_LEN_OBJ(locale_len, return_value); + INTL_CHECK_LOCALE_LEN_OR_FAILURE(locale_len); MSG_FORMAT_METHOD_FETCH_OBJECT_NO_CHECK; /* Convert pattern (if specified) to UTF-16. */ @@ -61,7 +62,7 @@ static void msgfmt_ctor(INTERNAL_FUNCTION_PARAMETERS) } if(locale_len == 0) { - locale = intl_locale_get_default(TSRMLS_C); + locale = intl_locale_get_default(); } #ifdef MSG_FORMAT_QUOTE_APOS @@ -71,12 +72,12 @@ static void msgfmt_ctor(INTERNAL_FUNCTION_PARAMETERS) #endif if ((mfo)->mf_data.orig_format) { - msgformat_data_free(&mfo->mf_data TSRMLS_CC); + msgformat_data_free(&mfo->mf_data); } (mfo)->mf_data.orig_format = estrndup(pattern, pattern_len); (mfo)->mf_data.orig_format_len = pattern_len; - + /* Create an ICU message formatter. */ MSG_FORMAT_OBJECT(mfo) = umsg_open(spattern, spattern_len, locale, NULL, &INTL_DATA_ERROR_CODE(mfo)); @@ -85,6 +86,7 @@ static void msgfmt_ctor(INTERNAL_FUNCTION_PARAMETERS) } INTL_CTOR_CHECK_STATUS(mfo, "msgfmt_create: message formatter creation failed"); + return SUCCESS; } /* }}} */ @@ -96,7 +98,10 @@ static void msgfmt_ctor(INTERNAL_FUNCTION_PARAMETERS) PHP_FUNCTION( msgfmt_create ) { object_init_ex( return_value, MessageFormatter_ce_ptr ); - msgfmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU); + if (msgfmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0) == FAILURE) { + zval_ptr_dtor(return_value); + RETURN_NULL(); + } } /* }}} */ @@ -105,8 +110,16 @@ PHP_FUNCTION( msgfmt_create ) */ PHP_METHOD( MessageFormatter, __construct ) { + zend_error_handling error_handling; + + zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, &error_handling); return_value = getThis(); - msgfmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU); + if (msgfmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1) == FAILURE) { + if (!EG(exception)) { + zend_throw_exception(IntlException_ce_ptr, "Constructor failed", 0); + } + } + zend_restore_error_handling(&error_handling); } /* }}} */ @@ -121,16 +134,16 @@ PHP_FUNCTION( msgfmt_get_error_code ) MessageFormatter_object* mfo = NULL; /* Parse parameters. */ - if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", + if( zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "O", &object, MessageFormatter_ce_ptr ) == FAILURE ) { intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, - "msgfmt_get_error_code: unable to parse input params", 0 TSRMLS_CC ); + "msgfmt_get_error_code: unable to parse input params", 0 ); RETURN_FALSE; } - mfo = (MessageFormatter_object *) zend_object_store_get_object( object TSRMLS_CC ); + mfo = Z_INTL_MESSAGEFORMATTER_P( object ); /* Return formatter's last error code. */ RETURN_LONG( INTL_DATA_ERROR_CODE(mfo) ); @@ -144,25 +157,25 @@ PHP_FUNCTION( msgfmt_get_error_code ) */ PHP_FUNCTION( msgfmt_get_error_message ) { - char* message = NULL; + zend_string* message = NULL; zval* object = NULL; MessageFormatter_object* mfo = NULL; /* Parse parameters. */ - if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", + if( zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "O", &object, MessageFormatter_ce_ptr ) == FAILURE ) { intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, - "msgfmt_get_error_message: unable to parse input params", 0 TSRMLS_CC ); + "msgfmt_get_error_message: unable to parse input params", 0 ); RETURN_FALSE; } - mfo = (MessageFormatter_object *) zend_object_store_get_object( object TSRMLS_CC ); + mfo = Z_INTL_MESSAGEFORMATTER_P( object ); /* Return last error message. */ - message = intl_error_get_message( &mfo->mf_data.error TSRMLS_CC ); - RETURN_STRING( message, 0); + message = intl_error_get_message( &mfo->mf_data.error ); + RETURN_STR(message); } /* }}} */ diff --git a/ext/intl/msgformat/msgformat.h b/ext/intl/msgformat/msgformat.h index 205c7066fd..a0b2c89644 100644 --- a/ext/intl/msgformat/msgformat.h +++ b/ext/intl/msgformat/msgformat.h @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | diff --git a/ext/intl/msgformat/msgformat_attr.c b/ext/intl/msgformat/msgformat_attr.c index c333a24ee1..78eb727c61 100644 --- a/ext/intl/msgformat/msgformat_attr.c +++ b/ext/intl/msgformat/msgformat_attr.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -21,11 +21,11 @@ #include "php_intl.h" #include "msgformat_class.h" #include "msgformat_attr.h" +#include "msgformat_data.h" #include "intl_convert.h" #include <unicode/ustring.h> - /* {{{ proto string MessageFormatter::getPattern( ) * Get formatter pattern. }}} */ /* {{{ proto string msgfmt_get_pattern( MessageFormatter $mf ) @@ -36,10 +36,10 @@ PHP_FUNCTION( msgfmt_get_pattern ) MSG_FORMAT_METHOD_INIT_VARS; /* Parse parameters. */ - if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &object, MessageFormatter_ce_ptr ) == FAILURE ) + if( zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "O", &object, MessageFormatter_ce_ptr ) == FAILURE ) { - intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, - "msgfmt_get_pattern: unable to parse input params", 0 TSRMLS_CC ); + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "msgfmt_get_pattern: unable to parse input params", 0 ); RETURN_FALSE; } @@ -47,7 +47,7 @@ PHP_FUNCTION( msgfmt_get_pattern ) MSG_FORMAT_METHOD_FETCH_OBJECT; if(mfo->mf_data.orig_format) { - RETURN_STRINGL(mfo->mf_data.orig_format, mfo->mf_data.orig_format_len, 1); + RETURN_STRINGL(mfo->mf_data.orig_format, mfo->mf_data.orig_format_len); } RETURN_FALSE; @@ -62,17 +62,17 @@ PHP_FUNCTION( msgfmt_get_pattern ) PHP_FUNCTION( msgfmt_set_pattern ) { char* value = NULL; - int value_len = 0; - int spattern_len = 0; + size_t value_len = 0; + int32_t spattern_len = 0; UChar* spattern = NULL; MSG_FORMAT_METHOD_INIT_VARS; /* Parse parameters. */ - if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os", + if( zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "Os", &object, MessageFormatter_ce_ptr, &value, &value_len ) == FAILURE ) { - intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, - "msgfmt_set_pattern: unable to parse input params", 0 TSRMLS_CC); + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "msgfmt_set_pattern: unable to parse input params", 0); RETURN_FALSE; } @@ -85,7 +85,7 @@ PHP_FUNCTION( msgfmt_set_pattern ) #ifdef MSG_FORMAT_QUOTE_APOS if(msgformat_fix_quotes(&spattern, &spattern_len, &INTL_DATA_ERROR_CODE(mfo)) != SUCCESS) { intl_error_set( NULL, U_INVALID_FORMAT_ERROR, - "msgfmt_set_pattern: error converting pattern to quote-friendly format", 0 TSRMLS_CC ); + "msgfmt_set_pattern: error converting pattern to quote-friendly format", 0 ); RETURN_FALSE; } #endif @@ -124,11 +124,11 @@ PHP_FUNCTION( msgfmt_get_locale ) MSG_FORMAT_METHOD_INIT_VARS; /* Parse parameters. */ - if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", + if( zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "O", &object, MessageFormatter_ce_ptr ) == FAILURE ) { intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, - "msgfmt_get_locale: unable to parse input params", 0 TSRMLS_CC ); + "msgfmt_get_locale: unable to parse input params", 0 ); RETURN_FALSE; } @@ -137,7 +137,7 @@ PHP_FUNCTION( msgfmt_get_locale ) MSG_FORMAT_METHOD_FETCH_OBJECT; loc = (char *)umsg_getLocale(MSG_FORMAT_OBJECT(mfo)); - RETURN_STRING(loc, 1); + RETURN_STRING(loc); } /* }}} */ diff --git a/ext/intl/msgformat/msgformat_attr.h b/ext/intl/msgformat/msgformat_attr.h index 898c4451e1..891f44c073 100644 --- a/ext/intl/msgformat/msgformat_attr.h +++ b/ext/intl/msgformat/msgformat_attr.h @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | diff --git a/ext/intl/msgformat/msgformat_class.c b/ext/intl/msgformat/msgformat_class.c index bb3b55f39c..8d464c6ca4 100644 --- a/ext/intl/msgformat/msgformat_class.c +++ b/ext/intl/msgformat/msgformat_class.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -34,60 +34,50 @@ static zend_object_handlers MessageFormatter_handlers; */ /* {{{ MessageFormatter_objects_dtor */ -static void MessageFormatter_object_dtor(void *object, zend_object_handle handle TSRMLS_DC ) +static void MessageFormatter_object_dtor(zend_object *object ) { - zend_objects_destroy_object( object, handle TSRMLS_CC ); + zend_objects_destroy_object( object ); } /* }}} */ /* {{{ MessageFormatter_objects_free */ -void MessageFormatter_object_free( zend_object *object TSRMLS_DC ) +void MessageFormatter_object_free( zend_object *object ) { - MessageFormatter_object* mfo = (MessageFormatter_object*)object; + MessageFormatter_object* mfo = php_intl_messageformatter_fetch_object(object); - zend_object_std_dtor( &mfo->zo TSRMLS_CC ); + zend_object_std_dtor( &mfo->zo ); - msgformat_data_free( &mfo->mf_data TSRMLS_CC ); - - efree( mfo ); + msgformat_data_free( &mfo->mf_data ); } /* }}} */ /* {{{ MessageFormatter_object_create */ -zend_object_value MessageFormatter_object_create(zend_class_entry *ce TSRMLS_DC) +zend_object *MessageFormatter_object_create(zend_class_entry *ce) { - zend_object_value retval; MessageFormatter_object* intern; - intern = ecalloc( 1, sizeof(MessageFormatter_object) ); - msgformat_data_init( &intern->mf_data TSRMLS_CC ); - zend_object_std_init( &intern->zo, ce TSRMLS_CC ); + intern = ecalloc( 1, sizeof(MessageFormatter_object) + zend_object_properties_size(ce)); + msgformat_data_init( &intern->mf_data ); + zend_object_std_init( &intern->zo, ce ); object_properties_init(&intern->zo, ce); - retval.handle = zend_objects_store_put( - intern, - MessageFormatter_object_dtor, - (zend_objects_free_object_storage_t)MessageFormatter_object_free, - NULL TSRMLS_CC ); - - retval.handlers = &MessageFormatter_handlers; + intern->zo.handlers = &MessageFormatter_handlers; - return retval; + return &intern->zo; } /* }}} */ /* {{{ MessageFormatter_object_clone */ -zend_object_value MessageFormatter_object_clone(zval *object TSRMLS_DC) +zend_object *MessageFormatter_object_clone(zval *object) { - zend_object_value new_obj_val; - zend_object_handle handle = Z_OBJ_HANDLE_P(object); MessageFormatter_object *mfo, *new_mfo; + zend_object *new_obj; MSG_FORMAT_METHOD_FETCH_OBJECT_NO_CHECK; - new_obj_val = MessageFormatter_ce_ptr->create_object(Z_OBJCE_P(object) TSRMLS_CC); - new_mfo = (MessageFormatter_object *)zend_object_store_get_object_by_handle(new_obj_val.handle TSRMLS_CC); - /* clone standard parts */ - zend_objects_clone_members(&new_mfo->zo, new_obj_val, &mfo->zo, handle TSRMLS_CC); + new_obj = MessageFormatter_ce_ptr->create_object(Z_OBJCE_P(object)); + new_mfo = php_intl_messageformatter_fetch_object(new_obj); + /* clone standard parts */ + zend_objects_clone_members(&new_mfo->zo, &mfo->zo); /* clone formatter object */ if (MSG_FORMAT_OBJECT(mfo) != NULL) { @@ -96,13 +86,13 @@ zend_object_value MessageFormatter_object_clone(zval *object TSRMLS_DC) if (U_FAILURE(INTL_DATA_ERROR_CODE(mfo))) { intl_errors_set(INTL_DATA_ERROR_P(mfo), INTL_DATA_ERROR_CODE(mfo), - "Failed to clone MessageFormatter object", 0 TSRMLS_CC); - zend_throw_exception_ex(NULL, 0 TSRMLS_CC, "Failed to clone MessageFormatter object"); + "Failed to clone MessageFormatter object", 0); + zend_throw_exception_ex(NULL, 0, "Failed to clone MessageFormatter object"); } } else { - zend_throw_exception_ex(NULL, 0 TSRMLS_CC, "Cannot clone unconstructed MessageFormatter"); + zend_throw_exception_ex(NULL, 0, "Cannot clone unconstructed MessageFormatter"); } - return new_obj_val; + return new_obj; } /* }}} */ @@ -160,18 +150,22 @@ static zend_function_entry MessageFormatter_class_functions[] = { /* {{{ msgformat_register_class * Initialize 'MessageFormatter' class */ -void msgformat_register_class( TSRMLS_D ) +void msgformat_register_class( void ) { zend_class_entry ce; /* Create and register 'MessageFormatter' class. */ INIT_CLASS_ENTRY( ce, "MessageFormatter", MessageFormatter_class_functions ); ce.create_object = MessageFormatter_object_create; - MessageFormatter_ce_ptr = zend_register_internal_class( &ce TSRMLS_CC ); + MessageFormatter_ce_ptr = zend_register_internal_class( &ce ); memcpy(&MessageFormatter_handlers, zend_get_std_object_handlers(), sizeof MessageFormatter_handlers); + MessageFormatter_handlers.offset = XtOffsetOf(MessageFormatter_object, zo); MessageFormatter_handlers.clone_obj = MessageFormatter_object_clone; + MessageFormatter_handlers.dtor_obj = MessageFormatter_object_dtor; + MessageFormatter_handlers.free_obj = MessageFormatter_object_free; + /* Declare 'MessageFormatter' class properties. */ if( !MessageFormatter_ce_ptr ) diff --git a/ext/intl/msgformat/msgformat_class.h b/ext/intl/msgformat/msgformat_class.h index 337e04e647..6823595f6d 100644 --- a/ext/intl/msgformat/msgformat_class.h +++ b/ext/intl/msgformat/msgformat_class.h @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -24,32 +24,39 @@ #include "../intl_common.h" #include "../intl_error.h" #include "../intl_data.h" + +#if U_ICU_VERSION_MAJOR_NUM * 10 + U_ICU_VERSION_MINOR_NUM < 48 +# define MSG_FORMAT_QUOTE_APOS 1 +#endif + #include "msgformat_data.h" typedef struct { - zend_object zo; msgformat_data mf_data; + zend_object zo; } MessageFormatter_object; -void msgformat_register_class( TSRMLS_D ); + +static inline MessageFormatter_object *php_intl_messageformatter_fetch_object(zend_object *obj) { + return (MessageFormatter_object *)((char*)(obj) - XtOffsetOf(MessageFormatter_object, zo)); +} +#define Z_INTL_MESSAGEFORMATTER_P(zv) php_intl_messageformatter_fetch_object(Z_OBJ_P(zv)) + +void msgformat_register_class( void ); extern zend_class_entry *MessageFormatter_ce_ptr; /* Auxiliary macros */ #define MSG_FORMAT_METHOD_INIT_VARS INTL_METHOD_INIT_VARS(MessageFormatter, mfo) -#define MSG_FORMAT_METHOD_FETCH_OBJECT_NO_CHECK INTL_METHOD_FETCH_OBJECT(MessageFormatter, mfo) +#define MSG_FORMAT_METHOD_FETCH_OBJECT_NO_CHECK INTL_METHOD_FETCH_OBJECT(INTL_MESSAGEFORMATTER, mfo) #define MSG_FORMAT_METHOD_FETCH_OBJECT \ MSG_FORMAT_METHOD_FETCH_OBJECT_NO_CHECK; \ if (MSG_FORMAT_OBJECT(mfo) == NULL) { \ intl_errors_set(&mfo->mf_data.error, U_ILLEGAL_ARGUMENT_ERROR, \ - "Found unconstructed MessageFormatter", 0 TSRMLS_CC); \ + "Found unconstructed MessageFormatter", 0); \ RETURN_FALSE; \ } #define MSG_FORMAT_OBJECT(mfo) (mfo)->mf_data.umsgf -#if U_ICU_VERSION_MAJOR_NUM * 10 + U_ICU_VERSION_MINOR_NUM < 48 -# define MSG_FORMAT_QUOTE_APOS 1 -#endif - #endif // #ifndef MSG_FORMAT_CLASS_H diff --git a/ext/intl/msgformat/msgformat_data.c b/ext/intl/msgformat/msgformat_data.c index 9e967daf4d..e2510e16b8 100644 --- a/ext/intl/msgformat/msgformat_data.c +++ b/ext/intl/msgformat/msgformat_data.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -26,7 +26,7 @@ /* {{{ void msgformat_data_init( msgformat_data* mf_data ) * Initialize internals of msgformat_data. */ -void msgformat_data_init( msgformat_data* mf_data TSRMLS_DC ) +void msgformat_data_init( msgformat_data* mf_data ) { if( !mf_data ) return; @@ -35,14 +35,14 @@ void msgformat_data_init( msgformat_data* mf_data TSRMLS_DC ) mf_data->orig_format = NULL; mf_data->arg_types = NULL; mf_data->tz_set = 0; - intl_error_reset( &mf_data->error TSRMLS_CC ); + intl_error_reset( &mf_data->error ); } /* }}} */ /* {{{ void msgformat_data_free( msgformat_data* mf_data ) * Clean up memory allocated for msgformat_data */ -void msgformat_data_free(msgformat_data* mf_data TSRMLS_DC) +void msgformat_data_free(msgformat_data* mf_data) { if (!mf_data) return; @@ -62,18 +62,18 @@ void msgformat_data_free(msgformat_data* mf_data TSRMLS_DC) } mf_data->umsgf = NULL; - intl_error_reset(&mf_data->error TSRMLS_CC); + intl_error_reset(&mf_data->error); } /* }}} */ /* {{{ msgformat_data* msgformat_data_create() * Allocate memory for msgformat_data and initialize it with default values. */ -msgformat_data* msgformat_data_create( TSRMLS_D ) +msgformat_data* msgformat_data_create( void ) { msgformat_data* mf_data = ecalloc( 1, sizeof(msgformat_data) ); - msgformat_data_init( mf_data TSRMLS_CC ); + msgformat_data_init( mf_data ); return mf_data; } diff --git a/ext/intl/msgformat/msgformat_data.h b/ext/intl/msgformat/msgformat_data.h index 51d7687a3a..a4226664ae 100644 --- a/ext/intl/msgformat/msgformat_data.h +++ b/ext/intl/msgformat/msgformat_data.h @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -30,14 +30,14 @@ typedef struct { // formatter handling UMessageFormat* umsgf; char* orig_format; - ulong orig_format_len; + zend_ulong orig_format_len; HashTable* arg_types; int tz_set; /* if we've already the time zone in sub-formats */ } msgformat_data; -msgformat_data* msgformat_data_create( TSRMLS_D ); -void msgformat_data_init( msgformat_data* mf_data TSRMLS_DC ); -void msgformat_data_free( msgformat_data* mf_data TSRMLS_DC ); +msgformat_data* msgformat_data_create( void ); +void msgformat_data_init( msgformat_data* mf_data ); +void msgformat_data_free( msgformat_data* mf_data ); #ifdef MSG_FORMAT_QUOTE_APOS int msgformat_fix_quotes(UChar **spattern, uint32_t *spattern_len, UErrorCode *ec); diff --git a/ext/intl/msgformat/msgformat_format.c b/ext/intl/msgformat/msgformat_format.c index 9b6df38ee3..cb74a3fb1b 100644 --- a/ext/intl/msgformat/msgformat_format.c +++ b/ext/intl/msgformat/msgformat_format.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -32,21 +32,20 @@ #endif /* {{{ */ -static void msgfmt_do_format(MessageFormatter_object *mfo, zval *args, zval *return_value TSRMLS_DC) +static void msgfmt_do_format(MessageFormatter_object *mfo, zval *args, zval *return_value) { int count; UChar* formatted = NULL; - int formatted_len = 0; + int32_t formatted_len = 0; HashTable *args_copy; count = zend_hash_num_elements(Z_ARRVAL_P(args)); ALLOC_HASHTABLE(args_copy); zend_hash_init(args_copy, count, NULL, ZVAL_PTR_DTOR, 0); - zend_hash_copy(args_copy, Z_ARRVAL_P(args), (copy_ctor_func_t)zval_add_ref, - NULL, sizeof(zval*)); + zend_hash_copy(args_copy, Z_ARRVAL_P(args), (copy_ctor_func_t)zval_add_ref); - umsg_format_helper(mfo, args_copy, &formatted, &formatted_len TSRMLS_CC); + umsg_format_helper(mfo, args_copy, &formatted, &formatted_len); zend_hash_destroy(args_copy); efree(args_copy); @@ -74,11 +73,11 @@ PHP_FUNCTION( msgfmt_format ) /* Parse parameters. */ - if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oa", + if( zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "Oa", &object, MessageFormatter_ce_ptr, &args ) == FAILURE ) { intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, - "msgfmt_format: unable to parse input params", 0 TSRMLS_CC ); + "msgfmt_format: unable to parse input params", 0 ); RETURN_FALSE; } @@ -86,7 +85,7 @@ PHP_FUNCTION( msgfmt_format ) /* Fetch the object. */ MSG_FORMAT_METHOD_FETCH_OBJECT; - msgfmt_do_format(mfo, args, return_value TSRMLS_CC); + msgfmt_do_format(mfo, args, return_value); } /* }}} */ @@ -101,32 +100,33 @@ PHP_FUNCTION( msgfmt_format_message ) UChar *spattern = NULL; int spattern_len = 0; char *pattern = NULL; - int pattern_len = 0; + size_t pattern_len = 0; const char *slocale = NULL; - int slocale_len = 0; - MessageFormatter_object mf = {0}; + size_t slocale_len = 0; + MessageFormatter_object mf; MessageFormatter_object *mfo = &mf; /* Parse parameters. */ - if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "ssa", + if( zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "ssa", &slocale, &slocale_len, &pattern, &pattern_len, &args ) == FAILURE ) { intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, - "msgfmt_format_message: unable to parse input params", 0 TSRMLS_CC ); + "msgfmt_format_message: unable to parse input params", 0 ); RETURN_FALSE; } INTL_CHECK_LOCALE_LEN(slocale_len); - msgformat_data_init(&mfo->mf_data TSRMLS_CC); + memset(mfo, 0, sizeof(*mfo)); + msgformat_data_init(&mfo->mf_data); if(pattern && pattern_len) { intl_convert_utf8_to_utf16(&spattern, &spattern_len, pattern, pattern_len, &INTL_DATA_ERROR_CODE(mfo)); if( U_FAILURE(INTL_DATA_ERROR_CODE((mfo))) ) { intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, - "msgfmt_format_message: error converting pattern to UTF-16", 0 TSRMLS_CC ); + "msgfmt_format_message: error converting pattern to UTF-16", 0 ); RETURN_FALSE; } } else { @@ -135,13 +135,13 @@ PHP_FUNCTION( msgfmt_format_message ) } if(slocale_len == 0) { - slocale = intl_locale_get_default(TSRMLS_C); + slocale = intl_locale_get_default(); } #ifdef MSG_FORMAT_QUOTE_APOS if(msgformat_fix_quotes(&spattern, &spattern_len, &INTL_DATA_ERROR_CODE(mfo)) != SUCCESS) { intl_error_set( NULL, U_INVALID_FORMAT_ERROR, - "msgfmt_format_message: error converting pattern to quote-friendly format", 0 TSRMLS_CC ); + "msgfmt_format_message: error converting pattern to quote-friendly format", 0 ); RETURN_FALSE; } #endif @@ -153,10 +153,10 @@ PHP_FUNCTION( msgfmt_format_message ) } INTL_METHOD_CHECK_STATUS(mfo, "Creating message formatter failed"); - msgfmt_do_format(mfo, args, return_value TSRMLS_CC); + msgfmt_do_format(mfo, args, return_value); /* drop the temporary formatter */ - msgformat_data_free(&mfo->mf_data TSRMLS_CC); + msgformat_data_free(&mfo->mf_data); } /* }}} */ diff --git a/ext/intl/msgformat/msgformat_format.h b/ext/intl/msgformat/msgformat_format.h index b74deab8ff..12b0e4a283 100644 --- a/ext/intl/msgformat/msgformat_format.h +++ b/ext/intl/msgformat/msgformat_format.h @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | diff --git a/ext/intl/msgformat/msgformat_helpers.cpp b/ext/intl/msgformat/msgformat_helpers.cpp index cc38cf0dc9..ce7899edd9 100644 --- a/ext/intl/msgformat/msgformat_helpers.cpp +++ b/ext/intl/msgformat/msgformat_helpers.cpp @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -83,8 +83,12 @@ U_CFUNC int32_t umsg_format_arg_count(UMessageFormat *fmt) return fmt_count; } +static void arg_types_dtor(zval *el) { + efree(Z_PTR_P(el)); +} + static HashTable *umsg_get_numeric_types(MessageFormatter_object *mfo, - intl_error& err TSRMLS_DC) + intl_error& err) { HashTable *ret; int32_t parts_count; @@ -104,14 +108,13 @@ static HashTable *umsg_get_numeric_types(MessageFormatter_object *mfo, /* Hash table will store Formattable::Type objects directly, * so no need for destructor */ ALLOC_HASHTABLE(ret); - zend_hash_init(ret, parts_count, NULL, NULL, 0); + zend_hash_init(ret, parts_count, NULL, arg_types_dtor, 0); for (int i = 0; i < parts_count; i++) { const Formattable::Type t = types[i]; - if (zend_hash_index_update(ret, (ulong)i, (void*)&t, sizeof(t), NULL) - == FAILURE) { + if (zend_hash_index_update_mem(ret, (zend_ulong)i, (void*)&t, sizeof(t)) == NULL) { intl_errors_set(&err, U_MEMORY_ALLOCATION_ERROR, - "Write to argument types hash table failed", 0 TSRMLS_CC); + "Write to argument types hash table failed", 0); break; } } @@ -131,7 +134,7 @@ static HashTable *umsg_get_numeric_types(MessageFormatter_object *mfo, #ifdef HAS_MESSAGE_PATTERN static HashTable *umsg_parse_format(MessageFormatter_object *mfo, const MessagePattern& mp, - intl_error& err TSRMLS_DC) + intl_error& err) { HashTable *ret; int32_t parts_count; @@ -141,7 +144,7 @@ static HashTable *umsg_parse_format(MessageFormatter_object *mfo, } if (!((MessageFormat *)mfo->mf_data.umsgf)->usesNamedArguments()) { - return umsg_get_numeric_types(mfo, err TSRMLS_CC); + return umsg_get_numeric_types(mfo, err); } if (mfo->mf_data.arg_types) { @@ -152,7 +155,7 @@ static HashTable *umsg_parse_format(MessageFormatter_object *mfo, /* Hash table will store Formattable::Type objects directly, * so no need for destructor */ ALLOC_HASHTABLE(ret); - zend_hash_init(ret, 32, NULL, NULL, 0); + zend_hash_init(ret, 32, NULL, arg_types_dtor, 0); parts_count = mp.countParts(); @@ -180,14 +183,13 @@ static HashTable *umsg_parse_format(MessageFormatter_object *mfo, if (name_part.getType() == UMSGPAT_PART_TYPE_ARG_NAME) { UnicodeString argName = mp.getSubstring(name_part); - if (zend_hash_find(ret, (char*)argName.getBuffer(), argName.length(), - (void**)&storedType) == FAILURE) { + if ((storedType = (Formattable::Type*)zend_hash_str_find_ptr(ret, (char*)argName.getBuffer(), argName.length())) == NULL) { /* not found already; create new entry in HT */ Formattable::Type bogusType = Formattable::kObject; - if (zend_hash_update(ret, (char*)argName.getBuffer(), argName.length(), - (void*)&bogusType, sizeof(bogusType), (void**)&storedType) == FAILURE) { + if ((storedType = (Formattable::Type*)zend_hash_str_update_mem(ret, (char*)argName.getBuffer(), argName.length(), + (void*)&bogusType, sizeof(bogusType))) == NULL) { intl_errors_set(&err, U_MEMORY_ALLOCATION_ERROR, - "Write to argument types hash table failed", 0 TSRMLS_CC); + "Write to argument types hash table failed", 0); continue; } } @@ -195,22 +197,20 @@ static HashTable *umsg_parse_format(MessageFormatter_object *mfo, int32_t argNumber = name_part.getValue(); if (argNumber < 0) { intl_errors_set(&err, U_INVALID_FORMAT_ERROR, - "Found part with negative number", 0 TSRMLS_CC); + "Found part with negative number", 0); continue; } - if (zend_hash_index_find(ret, (ulong)argNumber, (void**)&storedType) - == FAILURE) { + if ((storedType = (Formattable::Type*)zend_hash_index_find_ptr(ret, (zend_ulong)argNumber)) == NULL) { /* not found already; create new entry in HT */ Formattable::Type bogusType = Formattable::kObject; - if (zend_hash_index_update(ret, (ulong)argNumber, (void*)&bogusType, - sizeof(bogusType), (void**)&storedType) == FAILURE) { + if ((storedType = (Formattable::Type*)zend_hash_index_update_mem(ret, (zend_ulong)argNumber, (void*)&bogusType, sizeof(bogusType))) == NULL) { intl_errors_set(&err, U_MEMORY_ALLOCATION_ERROR, - "Write to argument types hash table failed", 0 TSRMLS_CC); + "Write to argument types hash table failed", 0); continue; } } } else { - intl_errors_set(&err, U_INVALID_FORMAT_ERROR, "Invalid part type encountered", 0 TSRMLS_CC); + intl_errors_set(&err, U_INVALID_FORMAT_ERROR, "Invalid part type encountered", 0); continue; } @@ -255,7 +255,7 @@ static HashTable *umsg_parse_format(MessageFormatter_object *mfo, * is broken. */ intl_errors_set(&err, U_PARSE_ERROR, "Expected UMSGPAT_PART_TYPE_ARG_TYPE part following " - "UMSGPAT_ARG_TYPE_SIMPLE part", 0 TSRMLS_CC); + "UMSGPAT_ARG_TYPE_SIMPLE part", 0); continue; } } else if (argType == UMSGPAT_ARG_TYPE_PLURAL) { @@ -276,7 +276,7 @@ static HashTable *umsg_parse_format(MessageFormatter_object *mfo, /* We found a different type for the same arg! */ if (*storedType != Formattable::kObject && *storedType != type) { intl_errors_set(&err, U_ARGUMENT_TYPE_MISMATCH, - "Inconsistent types declared for an argument", 0 TSRMLS_CC); + "Inconsistent types declared for an argument", 0); continue; } @@ -297,27 +297,27 @@ static HashTable *umsg_parse_format(MessageFormatter_object *mfo, #endif static HashTable *umsg_get_types(MessageFormatter_object *mfo, - intl_error& err TSRMLS_DC) + intl_error& err) { MessageFormat *mf = (MessageFormat *)mfo->mf_data.umsgf; #ifdef HAS_MESSAGE_PATTERN const MessagePattern mp = MessageFormatAdapter::getMessagePattern(mf); - return umsg_parse_format(mfo, mp, err TSRMLS_CC); + return umsg_parse_format(mfo, mp, err); #else if (mf->usesNamedArguments()) { intl_errors_set(&err, U_UNSUPPORTED_ERROR, "This extension supports named arguments only on ICU 4.8+", - 0 TSRMLS_CC); + 0); return NULL; } - return umsg_get_numeric_types(mfo, err TSRMLS_CC); + return umsg_get_numeric_types(mfo, err); #endif } static void umsg_set_timezone(MessageFormatter_object *mfo, - intl_error& err TSRMLS_DC) + intl_error& err) { MessageFormat *mf = (MessageFormat *)mfo->mf_data.umsgf; TimeZone *used_tz = NULL; @@ -328,16 +328,16 @@ static void umsg_set_timezone(MessageFormatter_object *mfo, * appear inside complex formats because ::getFormats() returns NULL * for all uncached formats, which is the case for complex formats * unless they were set via one of the ::setFormat() methods */ - + if (mfo->mf_data.tz_set) { return; /* already done */ } formats = mf->getFormats(count); - + if (formats == NULL) { intl_errors_set(&err, U_MEMORY_ALLOCATION_ERROR, - "Out of memory retrieving subformats", 0 TSRMLS_CC); + "Out of memory retrieving subformats", 0); } for (int i = 0; U_SUCCESS(err.code) && i < count; i++) { @@ -346,17 +346,16 @@ static void umsg_set_timezone(MessageFormatter_object *mfo, if (df == NULL) { continue; } - + if (used_tz == NULL) { - zval nullzv = zval_used_for_init, - *zvptr = &nullzv; - used_tz = timezone_process_timezone_argument(&zvptr, &err, - "msgfmt_format" TSRMLS_CC); + zval nullzv, *zvptr = &nullzv; + ZVAL_NULL(zvptr); + used_tz = timezone_process_timezone_argument(zvptr, &err, "msgfmt_format"); if (used_tz == NULL) { continue; } } - + df->setTimeZone(*used_tz); } @@ -368,7 +367,7 @@ static void umsg_set_timezone(MessageFormatter_object *mfo, U_CFUNC void umsg_format_helper(MessageFormatter_object *mfo, HashTable *args, UChar **formatted, - int *formatted_len TSRMLS_DC) + int32_t *formatted_len) { int arg_count = zend_hash_num_elements(args); std::vector<Formattable> fargs; @@ -381,42 +380,34 @@ U_CFUNC void umsg_format_helper(MessageFormatter_object *mfo, return; } - types = umsg_get_types(mfo, err TSRMLS_CC); - - umsg_set_timezone(mfo, err TSRMLS_CC); + types = umsg_get_types(mfo, err); + + umsg_set_timezone(mfo, err); fargs.resize(arg_count); farg_names.resize(arg_count); int argNum = 0; - HashPosition pos; - zval **elem; + zval *elem; // Key related variables - int key_type; - char *str_index; - uint str_len; - ulong num_index; - - for (zend_hash_internal_pointer_reset_ex(args, &pos); - U_SUCCESS(err.code) && - (key_type = zend_hash_get_current_key_ex( - args, &str_index, &str_len, &num_index, 0, &pos), - zend_hash_get_current_data_ex(args, (void **)&elem, &pos) - ) == SUCCESS; - zend_hash_move_forward_ex(args, &pos), argNum++) - { + zend_string *str_index; + zend_ulong num_index; + + ZEND_HASH_FOREACH_KEY_VAL(args, num_index, str_index, elem) { Formattable& formattable = fargs[argNum]; UnicodeString& key = farg_names[argNum]; Formattable::Type argType = Formattable::kObject, //unknown *storedArgType = NULL; - + if (!U_SUCCESS(err.code)) { + break; + } /* Process key and retrieve type */ - if (key_type == HASH_KEY_IS_LONG) { + if (str_index == NULL) { /* includes case where index < 0 because it's exposed as unsigned */ - if (num_index > (ulong)INT32_MAX) { + if (num_index > (zend_ulong)INT32_MAX) { intl_errors_set(&err, U_ILLEGAL_ARGUMENT_ERROR, - "Found negative or too large array key", 0 TSRMLS_CC); + "Found negative or too large array key", 0); continue; } @@ -424,21 +415,20 @@ U_CFUNC void umsg_format_helper(MessageFormatter_object *mfo, int32_t len = u_sprintf(temp, "%u", (uint32_t)num_index); key.append(temp, len); - zend_hash_index_find(types, (ulong)num_index, (void**)&storedArgType); + storedArgType = (Formattable::Type*)zend_hash_index_find_ptr(types, (zend_ulong)num_index); } else { //string; assumed to be in UTF-8 - intl_stringFromChar(key, str_index, str_len-1, &err.code); + intl_stringFromChar(key, ZSTR_VAL(str_index), ZSTR_LEN(str_index), &err.code); if (U_FAILURE(err.code)) { char *message; spprintf(&message, 0, - "Invalid UTF-8 data in argument key: '%s'", str_index); - intl_errors_set(&err, err.code, message, 1 TSRMLS_CC); + "Invalid UTF-8 data in argument key: '%s'", ZSTR_VAL(str_index)); + intl_errors_set(&err, err.code, message, 1); efree(message); continue; } - zend_hash_find(types, (char*)key.getBuffer(), key.length(), - (void**)&storedArgType); + storedArgType = (Formattable::Type*)zend_hash_str_find_ptr(types, (char*)key.getBuffer(), key.length()); } if (storedArgType != NULL) { @@ -461,13 +451,13 @@ U_CFUNC void umsg_format_helper(MessageFormatter_object *mfo, UnicodeString *text = new UnicodeString(); intl_stringFromChar(*text, - Z_STRVAL_PP(elem), Z_STRLEN_PP(elem), &err.code); + Z_STRVAL_P(elem), Z_STRLEN_P(elem), &err.code); if (U_FAILURE(err.code)) { char *message; spprintf(&message, 0, "Invalid UTF-8 data in string argument: " - "'%s'", Z_STRVAL_PP(elem)); - intl_errors_set(&err, err.code, message, 1 TSRMLS_CC); + "'%s'", Z_STRVAL_P(elem)); + intl_errors_set(&err, err.code, message, 1); efree(message); delete text; continue; @@ -478,16 +468,16 @@ U_CFUNC void umsg_format_helper(MessageFormatter_object *mfo, case Formattable::kDouble: { double d; - if (Z_TYPE_PP(elem) == IS_DOUBLE) { - d = Z_DVAL_PP(elem); - } else if (Z_TYPE_PP(elem) == IS_LONG) { - d = (double)Z_LVAL_PP(elem); + if (Z_TYPE_P(elem) == IS_DOUBLE) { + d = Z_DVAL_P(elem); + } else if (Z_TYPE_P(elem) == IS_LONG) { + d = (double)Z_LVAL_P(elem); } else { SEPARATE_ZVAL_IF_NOT_REF(elem); - convert_scalar_to_number(*elem TSRMLS_CC); - d = (Z_TYPE_PP(elem) == IS_DOUBLE) - ? Z_DVAL_PP(elem) - : (double)Z_LVAL_PP(elem); + convert_scalar_to_number(elem); + d = (Z_TYPE_P(elem) == IS_DOUBLE) + ? Z_DVAL_P(elem) + : (double)Z_LVAL_P(elem); } formattable.setDouble(d); break; @@ -496,27 +486,27 @@ U_CFUNC void umsg_format_helper(MessageFormatter_object *mfo, { int32_t tInt32 = 0; retry_klong: - if (Z_TYPE_PP(elem) == IS_DOUBLE) { - if (Z_DVAL_PP(elem) > (double)INT32_MAX || - Z_DVAL_PP(elem) < (double)INT32_MIN) { + if (Z_TYPE_P(elem) == IS_DOUBLE) { + if (Z_DVAL_P(elem) > (double)INT32_MAX || + Z_DVAL_P(elem) < (double)INT32_MIN) { intl_errors_set(&err, U_ILLEGAL_ARGUMENT_ERROR, "Found PHP float with absolute value too large for " - "32 bit integer argument", 0 TSRMLS_CC); + "32 bit integer argument", 0); } else { - tInt32 = (int32_t)Z_DVAL_PP(elem); + tInt32 = (int32_t)Z_DVAL_P(elem); } - } else if (Z_TYPE_PP(elem) == IS_LONG) { - if (Z_LVAL_PP(elem) > INT32_MAX || - Z_LVAL_PP(elem) < INT32_MIN) { + } else if (Z_TYPE_P(elem) == IS_LONG) { + if (Z_LVAL_P(elem) > INT32_MAX || + Z_LVAL_P(elem) < INT32_MIN) { intl_errors_set(&err, U_ILLEGAL_ARGUMENT_ERROR, "Found PHP integer with absolute value too large " - "for 32 bit integer argument", 0 TSRMLS_CC); + "for 32 bit integer argument", 0); } else { - tInt32 = (int32_t)Z_LVAL_PP(elem); + tInt32 = (int32_t)Z_LVAL_P(elem); } } else { SEPARATE_ZVAL_IF_NOT_REF(elem); - convert_scalar_to_number(*elem TSRMLS_CC); + convert_scalar_to_number(elem); goto retry_klong; } formattable.setLong(tInt32); @@ -526,21 +516,21 @@ retry_klong: { int64_t tInt64 = 0; retry_kint64: - if (Z_TYPE_PP(elem) == IS_DOUBLE) { - if (Z_DVAL_PP(elem) > (double)U_INT64_MAX || - Z_DVAL_PP(elem) < (double)U_INT64_MIN) { + if (Z_TYPE_P(elem) == IS_DOUBLE) { + if (Z_DVAL_P(elem) > (double)U_INT64_MAX || + Z_DVAL_P(elem) < (double)U_INT64_MIN) { intl_errors_set(&err, U_ILLEGAL_ARGUMENT_ERROR, "Found PHP float with absolute value too large for " - "64 bit integer argument", 0 TSRMLS_CC); + "64 bit integer argument", 0); } else { - tInt64 = (int64_t)Z_DVAL_PP(elem); + tInt64 = (int64_t)Z_DVAL_P(elem); } - } else if (Z_TYPE_PP(elem) == IS_LONG) { + } else if (Z_TYPE_P(elem) == IS_LONG) { /* assume long is not wider than 64 bits */ - tInt64 = (int64_t)Z_LVAL_PP(elem); + tInt64 = (int64_t)Z_LVAL_P(elem); } else { SEPARATE_ZVAL_IF_NOT_REF(elem); - convert_scalar_to_number(*elem TSRMLS_CC); + convert_scalar_to_number(elem); goto retry_kint64; } formattable.setInt64(tInt64); @@ -548,17 +538,17 @@ retry_kint64: } case Formattable::kDate: { - double dd = intl_zval_to_millis(*elem, &err, "msgfmt_format" TSRMLS_CC); + double dd = intl_zval_to_millis(elem, &err, "msgfmt_format"); if (U_FAILURE(err.code)) { - char *message, *key_char; - int key_len; + char *message; + zend_string *u8key; UErrorCode status = UErrorCode(); - if (intl_charFromString(key, &key_char, &key_len, - &status) == SUCCESS) { + u8key = intl_charFromString(key, &status); + if (u8key) { spprintf(&message, 0, "The argument for key '%s' " - "cannot be used as a date or time", key_char); - intl_errors_set(&err, err.code, message, 1 TSRMLS_CC); - efree(key_char); + "cannot be used as a date or time", ZSTR_VAL(u8key)); + intl_errors_set(&err, err.code, message, 1); + zend_string_release(u8key); efree(message); } continue; @@ -568,22 +558,23 @@ retry_kint64: } default: intl_errors_set(&err, U_ILLEGAL_ARGUMENT_ERROR, - "Found unsupported argument type", 0 TSRMLS_CC); + "Found unsupported argument type", 0); break; } } else { /* We couldn't find any information about the argument in the pattern, this * means it's an extra argument. So convert it to a number if it's a number or * bool or null and to a string if it's anything else except arrays . */ - switch (Z_TYPE_PP(elem)) { + switch (Z_TYPE_P(elem)) { case IS_DOUBLE: - formattable.setDouble(Z_DVAL_PP(elem)); + formattable.setDouble(Z_DVAL_P(elem)); break; - case IS_BOOL: + case IS_TRUE: + case IS_FALSE: convert_to_long_ex(elem); /* Intentional fallthrough */ case IS_LONG: - formattable.setInt64((int64_t)Z_LVAL_PP(elem)); + formattable.setInt64((int64_t)Z_LVAL_P(elem)); break; case IS_NULL: formattable.setInt64((int64_t)0); @@ -593,23 +584,24 @@ retry_kint64: goto string_arg; default: { - char *message, *key_char; - int key_len; + char *message; + zend_string *u8key; UErrorCode status = UErrorCode(); - if (intl_charFromString(key, &key_char, &key_len, - &status) == SUCCESS) { + u8key = intl_charFromString(key, &status); + if (u8key) { spprintf(&message, 0, "No strategy to convert the " "value given for the argument with key '%s' " - "is available", key_char); + "is available", ZSTR_VAL(u8key)); intl_errors_set(&err, - U_ILLEGAL_ARGUMENT_ERROR, message, 1 TSRMLS_CC); - efree(key_char); + U_ILLEGAL_ARGUMENT_ERROR, message, 1); + zend_string_release(u8key); efree(message); } } } } - } // visiting each argument + argNum++; + } ZEND_HASH_FOREACH_END(); // visiting each argument if (U_FAILURE(err.code)) { return; @@ -624,7 +616,7 @@ retry_kint64: if (U_FAILURE(err.code)) { intl_errors_set(&err, err.code, - "Call to ICU MessageFormat::format() has failed", 0 TSRMLS_CC); + "Call to ICU MessageFormat::format() has failed", 0); return; } @@ -633,14 +625,14 @@ retry_kint64: resultStr.extract(*formatted, *formatted_len+1, err.code); if (U_FAILURE(err.code)) { intl_errors_set(&err, err.code, - "Error copying format() result", 0 TSRMLS_CC); + "Error copying format() result", 0); return; } } #define cleanup_zvals() for(int j=i;j>=0;j--) { zval_ptr_dtor((*args)+i); } -U_CFUNC void umsg_parse_helper(UMessageFormat *fmt, int *count, zval ***args, UChar *source, int source_len, UErrorCode *status) +U_CFUNC void umsg_parse_helper(UMessageFormat *fmt, int *count, zval **args, UChar *source, int32_t source_len, UErrorCode *status) { UnicodeString srcString(source, source_len); Formattable *fargs = ((const MessageFormat*)fmt)->parse(srcString, *count, *status); @@ -649,49 +641,46 @@ U_CFUNC void umsg_parse_helper(UMessageFormat *fmt, int *count, zval ***args, UC return; } - *args = (zval **)safe_emalloc(*count, sizeof(zval *), 0); + *args = (zval *)safe_emalloc(*count, sizeof(zval), 0); // assign formattables to varargs for(int32_t i = 0; i < *count; i++) { int64_t aInt64; double aDate; UnicodeString temp; - char *stmp; - int stmp_len; - - ALLOC_INIT_ZVAL((*args)[i]); + zend_string *u8str; switch(fargs[i].getType()) { case Formattable::kDate: aDate = ((double)fargs[i].getDate())/U_MILLIS_PER_SECOND; - ZVAL_DOUBLE((*args)[i], aDate); + ZVAL_DOUBLE(&(*args)[i], aDate); break; case Formattable::kDouble: - ZVAL_DOUBLE((*args)[i], (double)fargs[i].getDouble()); + ZVAL_DOUBLE(&(*args)[i], (double)fargs[i].getDouble()); break; case Formattable::kLong: - ZVAL_LONG((*args)[i], fargs[i].getLong()); + ZVAL_LONG(&(*args)[i], fargs[i].getLong()); break; case Formattable::kInt64: aInt64 = fargs[i].getInt64(); - if(aInt64 > LONG_MAX || aInt64 < -LONG_MAX) { - ZVAL_DOUBLE((*args)[i], (double)aInt64); + if(aInt64 > ZEND_LONG_MAX || aInt64 < -ZEND_LONG_MAX) { + ZVAL_DOUBLE(&(*args)[i], (double)aInt64); } else { - ZVAL_LONG((*args)[i], (long)aInt64); + ZVAL_LONG(&(*args)[i], (zend_long)aInt64); } break; case Formattable::kString: fargs[i].getString(temp); - intl_convert_utf16_to_utf8(&stmp, &stmp_len, temp.getBuffer(), temp.length(), status); - if(U_FAILURE(*status)) { + u8str = intl_convert_utf16_to_utf8(temp.getBuffer(), temp.length(), status); + if(!u8str) { cleanup_zvals(); return; } - ZVAL_STRINGL((*args)[i], stmp, stmp_len, 0); + ZVAL_NEW_STR(&(*args)[i], u8str); break; case Formattable::kObject: diff --git a/ext/intl/msgformat/msgformat_helpers.h b/ext/intl/msgformat/msgformat_helpers.h index e6eda087d2..df05259574 100644 --- a/ext/intl/msgformat/msgformat_helpers.h +++ b/ext/intl/msgformat/msgformat_helpers.h @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -19,7 +19,7 @@ int32_t umsg_format_arg_count(UMessageFormat *fmt); void umsg_format_helper(MessageFormatter_object *mfo, HashTable *args, - UChar **formatted, int *formatted_len TSRMLS_DC); -void umsg_parse_helper(UMessageFormat *fmt, int *count, zval ***args, + UChar **formatted, int *formatted_len); +void umsg_parse_helper(UMessageFormat *fmt, int *count, zval **args, UChar *source, int source_len, UErrorCode *status); #endif // MSG_FORMAT_HELPERS_H diff --git a/ext/intl/msgformat/msgformat_parse.c b/ext/intl/msgformat/msgformat_parse.c index 14a6363424..349633912b 100644 --- a/ext/intl/msgformat/msgformat_parse.c +++ b/ext/intl/msgformat/msgformat_parse.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -28,9 +28,9 @@ #include "intl_convert.h" /* {{{ */ -static void msgfmt_do_parse(MessageFormatter_object *mfo, char *source, int src_len, zval *return_value TSRMLS_DC) +static void msgfmt_do_parse(MessageFormatter_object *mfo, char *source, size_t src_len, zval *return_value) { - zval **fargs; + zval *fargs; int count = 0; int i; UChar *usource = NULL; @@ -47,7 +47,7 @@ static void msgfmt_do_parse(MessageFormatter_object *mfo, char *source, int src_ array_init(return_value); for(i=0;i<count;i++) { - add_next_index_zval(return_value, fargs[i]); + add_next_index_zval(return_value, &fargs[i]); } efree(fargs); } @@ -61,16 +61,16 @@ static void msgfmt_do_parse(MessageFormatter_object *mfo, char *source, int src_ PHP_FUNCTION( msgfmt_parse ) { char *source; - int source_len; + size_t source_len; MSG_FORMAT_METHOD_INIT_VARS; /* Parse parameters. */ - if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os", + if( zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "Os", &object, MessageFormatter_ce_ptr, &source, &source_len ) == FAILURE ) { intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, - "msgfmt_parse: unable to parse input params", 0 TSRMLS_CC ); + "msgfmt_parse: unable to parse input params", 0 ); RETURN_FALSE; } @@ -78,7 +78,7 @@ PHP_FUNCTION( msgfmt_parse ) /* Fetch the object. */ MSG_FORMAT_METHOD_FETCH_OBJECT; - msgfmt_do_parse(mfo, source, source_len, return_value TSRMLS_CC); + msgfmt_do_parse(mfo, source, source_len, return_value); } /* }}} */ @@ -92,32 +92,33 @@ PHP_FUNCTION( msgfmt_parse_message ) UChar *spattern = NULL; int spattern_len = 0; char *pattern = NULL; - int pattern_len = 0; + size_t pattern_len = 0; const char *slocale = NULL; - int slocale_len = 0; + size_t slocale_len = 0; char *source = NULL; - int src_len = 0; - MessageFormatter_object mf = {0}; + size_t src_len = 0; + MessageFormatter_object mf; MessageFormatter_object *mfo = &mf; /* Parse parameters. */ - if( zend_parse_parameters( ZEND_NUM_ARGS() TSRMLS_CC, "sss", + if( zend_parse_parameters( ZEND_NUM_ARGS(), "sss", &slocale, &slocale_len, &pattern, &pattern_len, &source, &src_len ) == FAILURE ) { intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, - "msgfmt_parse_message: unable to parse input params", 0 TSRMLS_CC ); + "msgfmt_parse_message: unable to parse input params", 0 ); RETURN_FALSE; } - msgformat_data_init(&mfo->mf_data TSRMLS_CC); + memset(mfo, 0, sizeof(*mfo)); + msgformat_data_init(&mfo->mf_data); if(pattern && pattern_len) { intl_convert_utf8_to_utf16(&spattern, &spattern_len, pattern, pattern_len, &INTL_DATA_ERROR_CODE(mfo)); if( U_FAILURE(INTL_DATA_ERROR_CODE((mfo))) ) { intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, - "msgfmt_parse_message: error converting pattern to UTF-16", 0 TSRMLS_CC ); + "msgfmt_parse_message: error converting pattern to UTF-16", 0 ); RETURN_FALSE; } } else { @@ -126,13 +127,13 @@ PHP_FUNCTION( msgfmt_parse_message ) } if(slocale_len == 0) { - slocale = intl_locale_get_default(TSRMLS_C); + slocale = intl_locale_get_default(); } #ifdef MSG_FORMAT_QUOTE_APOS if(msgformat_fix_quotes(&spattern, &spattern_len, &INTL_DATA_ERROR_CODE(mfo)) != SUCCESS) { intl_error_set( NULL, U_INVALID_FORMAT_ERROR, - "msgfmt_parse_message: error converting pattern to quote-friendly format", 0 TSRMLS_CC ); + "msgfmt_parse_message: error converting pattern to quote-friendly format", 0 ); RETURN_FALSE; } #endif @@ -144,10 +145,10 @@ PHP_FUNCTION( msgfmt_parse_message ) } INTL_METHOD_CHECK_STATUS(mfo, "Creating message formatter failed"); - msgfmt_do_parse(mfo, source, src_len, return_value TSRMLS_CC); + msgfmt_do_parse(mfo, source, src_len, return_value); /* drop the temporary formatter */ - msgformat_data_free(&mfo->mf_data TSRMLS_CC); + msgformat_data_free(&mfo->mf_data); } /* }}} */ diff --git a/ext/intl/msgformat/msgformat_parse.h b/ext/intl/msgformat/msgformat_parse.h index a937235839..4a86403a48 100644 --- a/ext/intl/msgformat/msgformat_parse.h +++ b/ext/intl/msgformat/msgformat_parse.h @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | |