diff options
Diffstat (limited to 'ext/intl/msgformat')
-rw-r--r-- | ext/intl/msgformat/msgformat.c | 29 | ||||
-rw-r--r-- | ext/intl/msgformat/msgformat.h | 2 | ||||
-rw-r--r-- | ext/intl/msgformat/msgformat_attr.c | 8 | ||||
-rw-r--r-- | ext/intl/msgformat/msgformat_attr.h | 2 | ||||
-rw-r--r-- | ext/intl/msgformat/msgformat_class.c | 42 | ||||
-rw-r--r-- | ext/intl/msgformat/msgformat_class.h | 12 | ||||
-rw-r--r-- | ext/intl/msgformat/msgformat_data.c | 2 | ||||
-rw-r--r-- | ext/intl/msgformat/msgformat_data.h | 4 | ||||
-rw-r--r-- | ext/intl/msgformat/msgformat_format.c | 11 | ||||
-rw-r--r-- | ext/intl/msgformat/msgformat_format.h | 2 | ||||
-rw-r--r-- | ext/intl/msgformat/msgformat_helpers.cpp | 161 | ||||
-rw-r--r-- | ext/intl/msgformat/msgformat_helpers.h | 4 | ||||
-rw-r--r-- | ext/intl/msgformat/msgformat_parse.c | 18 | ||||
-rw-r--r-- | ext/intl/msgformat/msgformat_parse.h | 2 |
14 files changed, 152 insertions, 147 deletions
diff --git a/ext/intl/msgformat/msgformat.c b/ext/intl/msgformat/msgformat.c index 6a9f04f32b..2ca8ed9186 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 | @@ -28,9 +28,9 @@ /* {{{ */ static void msgfmt_ctor(INTERNAL_FUNCTION_PARAMETERS) { - char* locale; + 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; @@ -44,8 +44,8 @@ static void msgfmt_ctor(INTERNAL_FUNCTION_PARAMETERS) { intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "msgfmt_create: unable to parse input parameters", 0 TSRMLS_CC ); - zval_dtor(return_value); - RETURN_NULL(); + Z_OBJ_P(return_value) = NULL; + return; } INTL_CHECK_LOCALE_LEN_OBJ(locale_len, return_value); @@ -97,6 +97,9 @@ PHP_FUNCTION( msgfmt_create ) { object_init_ex( return_value, MessageFormatter_ce_ptr ); msgfmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU); + if (Z_TYPE_P(return_value) == IS_OBJECT && Z_OBJ_P(return_value) == NULL) { + RETURN_NULL(); + } } /* }}} */ @@ -105,8 +108,16 @@ PHP_FUNCTION( msgfmt_create ) */ PHP_METHOD( MessageFormatter, __construct ) { + zval orig_this = *getThis(); + return_value = getThis(); msgfmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU); + + if (Z_TYPE_P(return_value) == IS_OBJECT && Z_OBJ_P(return_value) == NULL) { + zend_object_store_ctor_failed(Z_OBJ(orig_this) TSRMLS_CC); + zval_dtor(&orig_this); + ZEND_CTOR_MAKE_NULL(); + } } /* }}} */ @@ -130,7 +141,7 @@ PHP_FUNCTION( msgfmt_get_error_code ) 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,7 +155,7 @@ 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; @@ -158,11 +169,11 @@ PHP_FUNCTION( msgfmt_get_error_message ) 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); + 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..79c04266e0 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 | @@ -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,7 +62,7 @@ PHP_FUNCTION( msgfmt_get_pattern ) PHP_FUNCTION( msgfmt_set_pattern ) { char* value = NULL; - int value_len = 0; + size_t value_len = 0; int spattern_len = 0; UChar* spattern = NULL; MSG_FORMAT_METHOD_INIT_VARS; @@ -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..65f32bf683 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 TSRMLS_DC ) { - zend_objects_destroy_object( object, handle TSRMLS_CC ); + zend_objects_destroy_object( object TSRMLS_CC ); } /* }}} */ /* {{{ MessageFormatter_objects_free */ void MessageFormatter_object_free( zend_object *object TSRMLS_DC ) { - MessageFormatter_object* mfo = (MessageFormatter_object*)object; + MessageFormatter_object* mfo = php_intl_messageformatter_fetch_object(object); zend_object_std_dtor( &mfo->zo TSRMLS_CC ); msgformat_data_free( &mfo->mf_data TSRMLS_CC ); - - efree( mfo ); } /* }}} */ /* {{{ MessageFormatter_object_create */ -zend_object_value MessageFormatter_object_create(zend_class_entry *ce TSRMLS_DC) +zend_object *MessageFormatter_object_create(zend_class_entry *ce TSRMLS_DC) { - zend_object_value retval; MessageFormatter_object* intern; - intern = ecalloc( 1, sizeof(MessageFormatter_object) ); + intern = ecalloc( 1, sizeof(MessageFormatter_object) + sizeof(zval) * (ce->default_properties_count - 1)); msgformat_data_init( &intern->mf_data TSRMLS_CC ); zend_object_std_init( &intern->zo, ce TSRMLS_CC ); 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 TSRMLS_DC) { - 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); + new_obj = MessageFormatter_ce_ptr->create_object(Z_OBJCE_P(object) TSRMLS_CC); + new_mfo = php_intl_messageformatter_fetch_object(new_obj); /* clone standard parts */ - zend_objects_clone_members(&new_mfo->zo, new_obj_val, &mfo->zo, handle TSRMLS_CC); + zend_objects_clone_members(&new_mfo->zo, &mfo->zo TSRMLS_CC); /* clone formatter object */ if (MSG_FORMAT_OBJECT(mfo) != NULL) { @@ -102,7 +92,7 @@ zend_object_value MessageFormatter_object_clone(zval *object TSRMLS_DC) } else { zend_throw_exception_ex(NULL, 0 TSRMLS_CC, "Cannot clone unconstructed MessageFormatter"); } - return new_obj_val; + return new_obj; } /* }}} */ @@ -171,7 +161,11 @@ void msgformat_register_class( TSRMLS_D ) 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..8c2c29a7dd 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 | @@ -27,17 +27,23 @@ #include "msgformat_data.h" typedef struct { - zend_object zo; msgformat_data mf_data; + zend_object zo; } MessageFormatter_object; + +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( TSRMLS_D ); 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) { \ diff --git a/ext/intl/msgformat/msgformat_data.c b/ext/intl/msgformat/msgformat_data.c index 5d49054473..f94920d3e8 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 | diff --git a/ext/intl/msgformat/msgformat_data.h b/ext/intl/msgformat/msgformat_data.h index 51d7687a3a..f3a594d25a 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,7 +30,7 @@ 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; diff --git a/ext/intl/msgformat/msgformat_format.c b/ext/intl/msgformat/msgformat_format.c index 4b81cfe2b4..36cd61c685 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 | @@ -43,8 +43,7 @@ static void msgfmt_do_format(MessageFormatter_object *mfo, zval *args, zval *ret 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); @@ -102,9 +101,9 @@ PHP_FUNCTION( msgfmt_format_message ) UChar *spattern = NULL; int spattern_len = 0; char *pattern = NULL; - int pattern_len = 0; - char *slocale = NULL; - int slocale_len = 0; + size_t pattern_len = 0; + const char *slocale = NULL; + size_t slocale_len = 0; MessageFormatter_object mf = {0}; MessageFormatter_object *mfo = &mf; 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 c4456d54f3..46ebe25a17 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,6 +83,10 @@ 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) { @@ -104,12 +108,11 @@ 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); break; @@ -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,12 +183,11 @@ 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); continue; @@ -198,17 +200,18 @@ static HashTable *umsg_parse_format(MessageFormatter_object *mfo, "Found part with negative number", 0 TSRMLS_CC); 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); continue; } } + } else { + intl_errors_set(&err, U_INVALID_FORMAT_ERROR, "Invalid part type encountered", 0 TSRMLS_CC); + continue; } UMessagePatternArgType argType = p.getArgType(); @@ -341,10 +344,9 @@ static void umsg_set_timezone(MessageFormatter_object *mfo, } 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" TSRMLS_CC); if (used_tz == NULL) { continue; } @@ -382,32 +384,24 @@ U_CFUNC void umsg_format_helper(MessageFormatter_object *mfo, 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); continue; @@ -417,21 +411,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, str_index->val, str_index->len, &err.code); if (U_FAILURE(err.code)) { char *message; spprintf(&message, 0, - "Invalid UTF-8 data in argument key: '%s'", str_index); + "Invalid UTF-8 data in argument key: '%s'", str_index->val); intl_errors_set(&err, err.code, message, 1 TSRMLS_CC); 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) { @@ -454,12 +447,12 @@ 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)); + "'%s'", Z_STRVAL_P(elem)); intl_errors_set(&err, err.code, message, 1 TSRMLS_CC); efree(message); delete text; @@ -471,16 +464,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 TSRMLS_CC); + d = (Z_TYPE_P(elem) == IS_DOUBLE) + ? Z_DVAL_P(elem) + : (double)Z_LVAL_P(elem); } formattable.setDouble(d); break; @@ -489,27 +482,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); } 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); } 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 TSRMLS_CC); goto retry_klong; } formattable.setLong(tInt32); @@ -519,21 +512,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); } 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 TSRMLS_CC); goto retry_kint64; } formattable.setInt64(tInt64); @@ -541,7 +534,7 @@ 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" TSRMLS_CC); if (U_FAILURE(err.code)) { char *message, *key_char; int key_len; @@ -568,15 +561,16 @@ retry_kint64: /* 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); @@ -602,7 +596,8 @@ retry_kint64: } } } - } // visiting each argument + argNum++; + } ZEND_HASH_FOREACH_END(); // visiting each argument if (U_FAILURE(err.code)) { return; @@ -633,7 +628,7 @@ retry_kint64: #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, int source_len, UErrorCode *status) { UnicodeString srcString(source, source_len); Formattable *fargs = ((const MessageFormat*)fmt)->parse(srcString, *count, *status); @@ -642,7 +637,7 @@ 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++) { @@ -652,28 +647,26 @@ U_CFUNC void umsg_parse_helper(UMessageFormat *fmt, int *count, zval ***args, UC char *stmp; int stmp_len; - ALLOC_INIT_ZVAL((*args)[i]); - 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; @@ -684,7 +677,9 @@ U_CFUNC void umsg_parse_helper(UMessageFormat *fmt, int *count, zval ***args, UC cleanup_zvals(); return; } - ZVAL_STRINGL((*args)[i], stmp, stmp_len, 0); + ZVAL_STRINGL(&(*args)[i], stmp, stmp_len); + //??? + efree(stmp); break; case Formattable::kObject: diff --git a/ext/intl/msgformat/msgformat_helpers.h b/ext/intl/msgformat/msgformat_helpers.h index e6eda087d2..41d179f8d0 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 | @@ -20,6 +20,6 @@ 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, +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 413d3b1f15..add2f901eb 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 TSRMLS_DC) { - 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,7 +61,7 @@ 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; @@ -92,11 +92,11 @@ PHP_FUNCTION( msgfmt_parse_message ) UChar *spattern = NULL; int spattern_len = 0; char *pattern = NULL; - int pattern_len = 0; - char *slocale = NULL; - int slocale_len = 0; + size_t pattern_len = 0; + const char *slocale = NULL; + size_t slocale_len = 0; char *source = NULL; - int src_len = 0; + size_t src_len = 0; MessageFormatter_object mf = {0}; MessageFormatter_object *mfo = &mf; 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 | |