diff --git a/ext/intl/common/common_date.h b/ext/intl/common/common_date.h index ef007c8eee687..988f279294c3c 100644 --- a/ext/intl/common/common_date.h +++ b/ext/intl/common/common_date.h @@ -24,6 +24,9 @@ U_CDECL_END #ifdef __cplusplus +// TODO once C++ migration done we can drop this workaround +#undef U_SHOW_CPLUSPLUS_API +#define U_SHOW_CPLUSPLUS_API 1 #include using icu::TimeZone; diff --git a/ext/intl/config.m4 b/ext/intl/config.m4 index c4c3c9b1d4cea..17b9dbf68d6f3 100644 --- a/ext/intl/config.m4 +++ b/ext/intl/config.m4 @@ -18,19 +18,8 @@ if test "$PHP_INTL" != "no"; then collator/collator_locale.c collator/collator_sort.c common/common_error.c - converter/converter.c - dateformat/dateformat_attr.c dateformat/dateformat_class.c - dateformat/dateformat_data.c - dateformat/dateformat_format.c - dateformat/dateformat_parse.c - dateformat/dateformat.c - formatter/formatter_attr.c formatter/formatter_class.c - formatter/formatter_data.c - formatter/formatter_format.c - formatter/formatter_main.c - formatter/formatter_parse.c grapheme/grapheme_string.c grapheme/grapheme_util.c intl_convert.c @@ -53,10 +42,16 @@ if test "$PHP_INTL" != "no"; then PHP_INTL_CXX_SOURCES="intl_convertcpp.cpp \ common/common_enum.cpp \ common/common_date.cpp \ - dateformat/dateformat_format_object.cpp \ - dateformat/dateformat_create.cpp \ + converter/converter.cpp \ + dateformat/dateformat.cpp \ + dateformat/dateformat_attr.cpp \ dateformat/dateformat_attrcpp.cpp \ + dateformat/dateformat_create.cpp \ + dateformat/dateformat_data.cpp \ + dateformat/dateformat_format.cpp \ + dateformat/dateformat_format_object.cpp \ dateformat/dateformat_helpers.cpp \ + dateformat/dateformat_parse.cpp \ dateformat/datepatterngenerator_class.cpp \ dateformat/datepatterngenerator_methods.cpp \ msgformat/msgformat_helpers.cpp \ @@ -65,6 +60,11 @@ if test "$PHP_INTL" != "no"; then calendar/calendar_class.cpp \ calendar/calendar_methods.cpp \ calendar/gregoriancalendar_methods.cpp \ + formatter/formatter_attr.cpp \ + formatter/formatter_data.cpp \ + formatter/formatter_format.cpp \ + formatter/formatter_main.cpp \ + formatter/formatter_parse.cpp \ msgformat/msgformat_attr.cpp \ msgformat/msgformat_class.cpp \ msgformat/msgformat_data.cpp \ diff --git a/ext/intl/config.w32 b/ext/intl/config.w32 index fb3f0212729dd..f0183d84949fc 100644 --- a/ext/intl/config.w32 +++ b/ext/intl/config.w32 @@ -29,15 +29,15 @@ if (PHP_INTL != "no") { common_date.cpp \ ", "intl"); ADD_SOURCES(configure_module_dirname + "/converter", "\ - converter.c \ + converter.cpp \ ", "intl"); ADD_SOURCES(configure_module_dirname + "/formatter", "\ - formatter_attr.c \ + formatter_attr.cpp \ formatter_class.c \ - formatter_data.c \ - formatter_format.c \ - formatter_main.c \ - formatter_parse.c \ + formatter_data.cpp \ + formatter_format.cpp \ + formatter_main.cpp \ + formatter_parse.cpp \ ", "intl"); ADD_SOURCES(configure_module_dirname + "/listformatter", "\ listformatter_class.c \ @@ -64,13 +64,13 @@ if (PHP_INTL != "no") { normalizer_normalize.cpp \ ", "intl"); ADD_SOURCES(configure_module_dirname + "/dateformat", "\ - dateformat.c \ + dateformat.cpp \ dateformat_class.c \ - dateformat_attr.c \ - dateformat_format.c \ + dateformat_attr.cpp \ + dateformat_format.cpp \ dateformat_format_object.cpp \ - dateformat_parse.c \ - dateformat_data.c \ + dateformat_parse.cpp \ + dateformat_data.cpp \ dateformat_attrcpp.cpp \ dateformat_helpers.cpp \ dateformat_create.cpp \ diff --git a/ext/intl/converter/converter.c b/ext/intl/converter/converter.cpp similarity index 95% rename from ext/intl/converter/converter.c rename to ext/intl/converter/converter.cpp index 759db5e18873a..6123d4b49e614 100644 --- a/ext/intl/converter/converter.c +++ b/ext/intl/converter/converter.cpp @@ -12,7 +12,6 @@ +----------------------------------------------------------------------+ */ -#include "converter.h" #include "zend_exceptions.h" #include @@ -21,10 +20,13 @@ #include #include +extern "C" { +#include "converter.h" +#include "php_intl.h" #include "../intl_error.h" #include "../intl_common.h" +} #include "converter_arginfo.h" -#include "php_intl.h" typedef struct _php_converter_object { UConverter *src, *dest; @@ -238,9 +240,9 @@ static void php_converter_to_u_callback(const void *context, } if (Z_TYPE(zargs[3]) == IS_LONG) { - *pErrorCode = Z_LVAL(zargs[3]); + *pErrorCode = static_cast(Z_LVAL(zargs[3])); } else if (Z_ISREF(zargs[3]) && Z_TYPE_P(Z_REFVAL(zargs[3])) == IS_LONG) { - *pErrorCode = Z_LVAL_P(Z_REFVAL(zargs[3])); + *pErrorCode = static_cast(Z_LVAL_P(Z_REFVAL(zargs[3]))); } zval_ptr_dtor(&zargs[0]); @@ -265,7 +267,7 @@ static void php_converter_append_fromUnicode_target(zval *val, UConverterFromUni { size_t vallen = Z_STRLEN_P(val); if (TARGET_CHECK(args, vallen)) { - args->target = zend_mempcpy(args->target, Z_STRVAL_P(val), vallen); + args->target = reinterpret_cast(zend_mempcpy(args->target, Z_STRVAL_P(val), vallen)); } return; } @@ -315,9 +317,9 @@ static void php_converter_from_u_callback(const void *context, } if (Z_TYPE(zargs[3]) == IS_LONG) { - *pErrorCode = Z_LVAL(zargs[3]); + *pErrorCode = static_cast(Z_LVAL(zargs[3])); } else if (Z_ISREF(zargs[3]) && Z_TYPE_P(Z_REFVAL(zargs[3])) == IS_LONG) { - *pErrorCode = Z_LVAL_P(Z_REFVAL(zargs[3])); + *pErrorCode = static_cast(Z_LVAL_P(Z_REFVAL(zargs[3]))); } zval_ptr_dtor(&zargs[0]); @@ -340,7 +342,7 @@ static inline bool php_converter_set_callbacks(php_converter_object *objval, UCo } ucnv_setToUCallBack(cnv, (UConverterToUCallback)php_converter_to_u_callback, (const void*)objval, - NULL, NULL, &error); + nullptr, nullptr, &error); if (U_FAILURE(error)) { THROW_UFAILURE(objval, error); ret = 0; @@ -348,7 +350,7 @@ static inline bool php_converter_set_callbacks(php_converter_object *objval, UCo error = U_ZERO_ERROR; ucnv_setFromUCallBack(cnv, (UConverterFromUCallback)php_converter_from_u_callback, (const void*)objval, - NULL, NULL, &error); + nullptr, nullptr, &error); if (U_FAILURE(error)) { THROW_UFAILURE(objval, error); ret = 0; @@ -507,14 +509,14 @@ static void php_converter_resolve_callback( const char *callback_name, size_t callback_name_len ) { - zend_function *fn = zend_hash_str_find_ptr_lc(&obj->ce->function_table, callback_name, callback_name_len); - ZEND_ASSERT(fn != NULL); + zend_function *fn = reinterpret_cast(zend_hash_str_find_ptr_lc(&obj->ce->function_table, callback_name, callback_name_len)); + ZEND_ASSERT(fn != nullptr); fcc->function_handler = fn; fcc->object = obj; fcc->called_scope = obj->ce; - fcc->calling_scope = NULL; - fcc->closure = NULL; + fcc->calling_scope = nullptr; + fcc->closure = nullptr; } /* }}} */ @@ -635,16 +637,16 @@ static zend_string* php_converter_do_convert(UConverter *dest_cnv, if (!src_cnv || !dest_cnv) { php_converter_throw_failure(objval, U_INVALID_STATE_ERROR, "Internal converters not initialized"); - return NULL; + return nullptr; } /* Get necessary buffer size first */ temp_len = 1 + ucnv_toUChars(src_cnv, NULL, 0, src, src_len, &error); if (U_FAILURE(error) && error != U_BUFFER_OVERFLOW_ERROR) { THROW_UFAILURE(objval, error); - return NULL; + return nullptr; } - temp = safe_emalloc(sizeof(UChar), temp_len, sizeof(UChar)); + temp = reinterpret_cast(safe_emalloc(sizeof(UChar), temp_len, sizeof(UChar))); /* Convert to intermediate UChar* array */ error = U_ZERO_ERROR; @@ -652,7 +654,7 @@ static zend_string* php_converter_do_convert(UConverter *dest_cnv, if (U_FAILURE(error)) { THROW_UFAILURE(objval, error); efree(temp); - return NULL; + return nullptr; } temp[temp_len] = 0; @@ -661,7 +663,7 @@ static zend_string* php_converter_do_convert(UConverter *dest_cnv, if (U_FAILURE(error) && error != U_BUFFER_OVERFLOW_ERROR) { THROW_UFAILURE(objval, error); efree(temp); - return NULL; + return nullptr; } ret = zend_string_alloc(ret_len, 0); @@ -673,7 +675,7 @@ static zend_string* php_converter_do_convert(UConverter *dest_cnv, if (U_FAILURE(error)) { THROW_UFAILURE(objval, error); zend_string_efree(ret); - return NULL; + return nullptr; } return ret; @@ -735,8 +737,8 @@ PHP_METHOD(UConverter, convert) { PHP_METHOD(UConverter, transcode) { char *str, *src, *dest; size_t str_len, src_len, dest_len; - zval *options = NULL; - UConverter *src_cnv = NULL, *dest_cnv = NULL; + zval *options = nullptr; + UConverter *src_cnv = nullptr, *dest_cnv = nullptr; ZEND_PARSE_PARAMETERS_START(3, 4) Z_PARAM_STRING(str, str_len) @@ -911,7 +913,7 @@ static void php_converter_free_object(zend_object *obj) { static zend_object *php_converter_object_ctor(zend_class_entry *ce, php_converter_object **pobjval) { php_converter_object *objval; - objval = zend_object_alloc(sizeof(php_converter_object), ce); + objval = reinterpret_cast(zend_object_alloc(sizeof(php_converter_object), ce)); zend_object_std_init(&objval->obj, ce); object_properties_init(&objval->obj, ce); @@ -923,7 +925,7 @@ static zend_object *php_converter_object_ctor(zend_class_entry *ce, php_converte } static zend_object *php_converter_create_object(zend_class_entry *ce) { - php_converter_object *objval = NULL; + php_converter_object *objval = nullptr; zend_object *retval = php_converter_object_ctor(ce, &objval); object_properties_init(&(objval->obj), ce); @@ -968,7 +970,7 @@ static zend_object *php_converter_clone_object(zend_object *object) { /* }}} */ /* {{{ php_converter_minit */ -int php_converter_minit(INIT_FUNC_ARGS) { +U_CFUNC int php_converter_minit(INIT_FUNC_ARGS) { php_converter_ce = register_class_UConverter(); php_converter_ce->create_object = php_converter_create_object; php_converter_ce->default_object_handlers = &php_converter_object_handlers; diff --git a/ext/intl/converter/converter.h b/ext/intl/converter/converter.h index f9fb27b82a7d0..5d779560811d0 100644 --- a/ext/intl/converter/converter.h +++ b/ext/intl/converter/converter.h @@ -21,6 +21,12 @@ #include "php.h" +#ifdef __cplusplus +extern "C" { +#endif int php_converter_minit(INIT_FUNC_ARGS); +#ifdef __cplusplus +} +#endif #endif /* PHP_INTL_CONVERTER_H */ diff --git a/ext/intl/dateformat/dateformat.c b/ext/intl/dateformat/dateformat.cpp similarity index 94% rename from ext/intl/dateformat/dateformat.c rename to ext/intl/dateformat/dateformat.cpp index e6ebd5b789649..cf2b445590bb9 100644 --- a/ext/intl/dateformat/dateformat.c +++ b/ext/intl/dateformat/dateformat.cpp @@ -17,12 +17,14 @@ #include +extern "C" { #include "php_intl.h" +} #include "dateformat_class.h" #include "dateformat.h" /* {{{ Get formatter's last error code. */ -PHP_FUNCTION( datefmt_get_error_code ) +U_CFUNC PHP_FUNCTION( datefmt_get_error_code ) { DATE_FORMAT_METHOD_INIT_VARS; @@ -41,7 +43,7 @@ PHP_FUNCTION( datefmt_get_error_code ) /* }}} */ /* {{{ Get text description for formatter's last error code. */ -PHP_FUNCTION( datefmt_get_error_message ) +U_CFUNC PHP_FUNCTION( datefmt_get_error_message ) { zend_string *message = NULL; DATE_FORMAT_METHOD_INIT_VARS; diff --git a/ext/intl/dateformat/dateformat_attr.c b/ext/intl/dateformat/dateformat_attr.cpp similarity index 90% rename from ext/intl/dateformat/dateformat_attr.c rename to ext/intl/dateformat/dateformat_attr.cpp index 8032d758a939b..9c0a1a700be1b 100644 --- a/ext/intl/dateformat/dateformat_attr.c +++ b/ext/intl/dateformat/dateformat_attr.cpp @@ -15,16 +15,18 @@ #include #endif +extern "C" { #include "../php_intl.h" -#include "dateformat_class.h" #include "../intl_convert.h" +} +#include "dateformat_class.h" #include "dateformat_class.h" #include #include /* {{{ Get formatter datetype. */ -PHP_FUNCTION( datefmt_get_datetype ) +U_CFUNC PHP_FUNCTION( datefmt_get_datetype ) { DATE_FORMAT_METHOD_INIT_VARS; @@ -44,7 +46,7 @@ PHP_FUNCTION( datefmt_get_datetype ) /* }}} */ /* {{{ Get formatter timetype. */ -PHP_FUNCTION( datefmt_get_timetype ) +U_CFUNC PHP_FUNCTION( datefmt_get_timetype ) { DATE_FORMAT_METHOD_INIT_VARS; @@ -64,7 +66,7 @@ PHP_FUNCTION( datefmt_get_timetype ) /* }}} */ /* {{{ Get formatter pattern. */ -PHP_FUNCTION( datefmt_get_pattern ) +U_CFUNC PHP_FUNCTION( datefmt_get_pattern ) { UChar value_buf[64]; uint32_t length = USIZE( value_buf ); @@ -100,12 +102,12 @@ PHP_FUNCTION( datefmt_get_pattern ) /* }}} */ /* {{{ Set formatter pattern. */ -PHP_FUNCTION( datefmt_set_pattern ) +U_CFUNC PHP_FUNCTION( datefmt_set_pattern ) { - char* value = NULL; + char* value = nullptr; size_t value_len = 0; int32_t slength = 0; - UChar* svalue = NULL; + UChar* svalue = nullptr; bool is_pattern_localized = false; @@ -136,7 +138,7 @@ PHP_FUNCTION( datefmt_set_pattern ) /* }}} */ /* {{{ Get formatter locale. */ -PHP_FUNCTION( datefmt_get_locale ) +U_CFUNC PHP_FUNCTION( datefmt_get_locale ) { char *loc; zend_long loc_type =ULOC_ACTUAL_LOCALE; @@ -154,14 +156,14 @@ PHP_FUNCTION( datefmt_get_locale ) /* Fetch the object. */ DATE_FORMAT_METHOD_FETCH_OBJECT; - loc = (char *)udat_getLocaleByType(DATE_FORMAT_OBJECT(dfo), loc_type,&INTL_DATA_ERROR_CODE(dfo)); + loc = (char *)udat_getLocaleByType(DATE_FORMAT_OBJECT(dfo), static_cast(loc_type),&INTL_DATA_ERROR_CODE(dfo)); INTL_METHOD_CHECK_STATUS(dfo, "Error getting locale"); RETURN_STRING(loc); } /* }}} */ /* {{{ Get formatter isLenient. */ -PHP_FUNCTION( datefmt_is_lenient ) +U_CFUNC PHP_FUNCTION( datefmt_is_lenient ) { DATE_FORMAT_METHOD_INIT_VARS; @@ -182,7 +184,7 @@ PHP_FUNCTION( datefmt_is_lenient ) /* }}} */ /* {{{ Set formatter lenient. */ -PHP_FUNCTION( datefmt_set_lenient ) +U_CFUNC PHP_FUNCTION( datefmt_set_lenient ) { bool isLenient = false; diff --git a/ext/intl/dateformat/dateformat_class.h b/ext/intl/dateformat/dateformat_class.h index 18afb55023b42..167a777e405fa 100644 --- a/ext/intl/dateformat/dateformat_class.h +++ b/ext/intl/dateformat/dateformat_class.h @@ -35,8 +35,14 @@ static inline IntlDateFormatter_object *php_intl_dateformatter_fetch_object(zend } #define Z_INTL_DATEFORMATTER_P(zv) php_intl_dateformatter_fetch_object(Z_OBJ_P(zv)) +#ifdef __cplusplus +extern "C" { +#endif void dateformat_register_IntlDateFormatter_class( void ); extern zend_class_entry *IntlDateFormatter_ce_ptr; +#ifdef __cplusplus +} +#endif /* Auxiliary macros */ diff --git a/ext/intl/dateformat/dateformat_data.c b/ext/intl/dateformat/dateformat_data.cpp similarity index 91% rename from ext/intl/dateformat/dateformat_data.c rename to ext/intl/dateformat/dateformat_data.cpp index 9c12af6fb6059..42e7c9522055f 100644 --- a/ext/intl/dateformat/dateformat_data.c +++ b/ext/intl/dateformat/dateformat_data.cpp @@ -25,7 +25,7 @@ void dateformat_data_init( dateformat_data* datef_data ) if( !datef_data ) return; - datef_data->udatf = NULL; + datef_data->udatf = nullptr; intl_error_reset( &datef_data->error ); } /* }}} */ @@ -41,7 +41,7 @@ void dateformat_data_free( dateformat_data* datef_data ) if( datef_data->udatf ) udat_close( datef_data->udatf ); - datef_data->udatf = NULL; + datef_data->udatf = nullptr; intl_error_reset( &datef_data->error ); } /* }}} */ @@ -51,7 +51,7 @@ void dateformat_data_free( dateformat_data* datef_data ) */ dateformat_data* dateformat_data_create( void ) { - dateformat_data* datef_data = ecalloc( 1, sizeof(dateformat_data) ); + dateformat_data* datef_data = reinterpret_cast(ecalloc( 1, sizeof(dateformat_data) )); dateformat_data_init( datef_data ); diff --git a/ext/intl/dateformat/dateformat_data.h b/ext/intl/dateformat/dateformat_data.h index 4007d1344fbb6..962ffbade31d8 100644 --- a/ext/intl/dateformat/dateformat_data.h +++ b/ext/intl/dateformat/dateformat_data.h @@ -18,7 +18,13 @@ #include +#ifdef __cplusplus +extern "C" { +#endif #include "intl_error.h" +#ifdef __cplusplus +} +#endif typedef struct { // error handling @@ -28,8 +34,14 @@ typedef struct { UDateFormat * udatf; } dateformat_data; +#ifdef __cplusplus +extern "C" { +#endif dateformat_data* dateformat_data_create( void ); void dateformat_data_init( dateformat_data* datef_data ); void dateformat_data_free( dateformat_data* datef_data ); +#ifdef __cplusplus +} +#endif #endif // DATE_FORMAT_DATA_H diff --git a/ext/intl/dateformat/dateformat_format.c b/ext/intl/dateformat/dateformat_format.cpp similarity index 99% rename from ext/intl/dateformat/dateformat_format.c rename to ext/intl/dateformat/dateformat_format.cpp index ee3abd052d669..4e9531a86ce54 100644 --- a/ext/intl/dateformat/dateformat_format.c +++ b/ext/intl/dateformat/dateformat_format.cpp @@ -16,12 +16,14 @@ #include #endif +extern "C" { #include "../php_intl.h" +#include "../intl_convert.h" +} #include #include -#include "../intl_convert.h" #include "../common/common_date.h" #include "dateformat.h" #include "dateformat_class.h" @@ -137,7 +139,7 @@ static UDate internal_get_timestamp(IntlDateFormatter_object *dfo, /* {{{ Format the time value as a string. */ -PHP_FUNCTION(datefmt_format) +U_CFUNC PHP_FUNCTION(datefmt_format) { UDate timestamp = 0; HashTable *hash_arr = NULL; diff --git a/ext/intl/dateformat/dateformat_parse.c b/ext/intl/dateformat/dateformat_parse.cpp similarity index 96% rename from ext/intl/dateformat/dateformat_parse.c rename to ext/intl/dateformat/dateformat_parse.cpp index b6e9f7c92eb6f..a82a20a42f969 100644 --- a/ext/intl/dateformat/dateformat_parse.c +++ b/ext/intl/dateformat/dateformat_parse.cpp @@ -19,8 +19,10 @@ #include #include +extern "C" { #include "php_intl.h" #include "intl_convert.h" +} #include "dateformat.h" #include "dateformat_class.h" #include "dateformat_data.h" @@ -70,7 +72,7 @@ static void internal_parse_to_timestamp(IntlDateFormatter_object *dfo, char* tex static void add_to_localtime_arr( IntlDateFormatter_object *dfo, zval* return_value, const UCalendar *parsed_calendar, zend_long calendar_field, char* key_name) { - zend_long calendar_field_val = ucal_get( parsed_calendar, calendar_field, &INTL_DATA_ERROR_CODE(dfo)); + zend_long calendar_field_val = ucal_get( parsed_calendar, static_cast(calendar_field), &INTL_DATA_ERROR_CODE(dfo)); INTL_METHOD_CHECK_STATUS( dfo, "Date parsing - localtime failed : could not get a field from calendar" ); if( strcmp(key_name, CALENDAR_YEAR )==0 ){ @@ -126,7 +128,7 @@ static void internal_parse_to_localtime(IntlDateFormatter_object *dfo, char* tex /* {{{ Parse the string $value starting at parse_pos to a Unix timestamp -int */ -PHP_FUNCTION(datefmt_parse) +U_CFUNC PHP_FUNCTION(datefmt_parse) { char* text_to_parse = NULL; size_t text_len =0; @@ -165,7 +167,7 @@ PHP_FUNCTION(datefmt_parse) } /* }}} */ -PHP_METHOD(IntlDateFormatter, parseToCalendar) +U_CFUNC PHP_METHOD(IntlDateFormatter, parseToCalendar) { zend_string *text_to_parse = NULL; zval* z_parse_pos = NULL; @@ -208,7 +210,7 @@ PHP_METHOD(IntlDateFormatter, parseToCalendar) } /* {{{ Parse the string $value to a localtime array */ -PHP_FUNCTION(datefmt_localtime) +U_CFUNC PHP_FUNCTION(datefmt_localtime) { char* text_to_parse = NULL; size_t text_len =0; diff --git a/ext/intl/formatter/formatter_attr.c b/ext/intl/formatter/formatter_attr.cpp similarity index 86% rename from ext/intl/formatter/formatter_attr.c rename to ext/intl/formatter/formatter_attr.cpp index a7cafcf5f9733..06f1023cc585e 100644 --- a/ext/intl/formatter/formatter_attr.c +++ b/ext/intl/formatter/formatter_attr.cpp @@ -16,25 +16,29 @@ #include #endif +extern "C" { #include "php_intl.h" -#include "formatter_class.h" #include "intl_convert.h" +} +#include "formatter_class.h" #include /* {{{ Get formatter attribute value. */ -PHP_FUNCTION( numfmt_get_attribute ) +U_CFUNC PHP_FUNCTION( numfmt_get_attribute ) { - zend_long attribute, value; + zend_long zattribute, value; FORMATTER_METHOD_INIT_VARS; /* Parse parameters. */ if( zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "Ol", - &object, NumberFormatter_ce_ptr, &attribute ) == FAILURE ) + &object, NumberFormatter_ce_ptr, &zattribute ) == FAILURE ) { RETURN_THROWS(); } + UNumberFormatAttribute attribute = static_cast(zattribute); + /* Fetch the object. */ FORMATTER_METHOD_FETCH_OBJECT; @@ -85,9 +89,9 @@ PHP_FUNCTION( numfmt_get_attribute ) /* }}} */ /* {{{ Get formatter attribute value. */ -PHP_FUNCTION( numfmt_get_text_attribute ) +U_CFUNC PHP_FUNCTION( numfmt_get_text_attribute ) { - zend_long attribute; + zend_long zattribute; UChar value_buf[64]; int32_t value_buf_size = USIZE( value_buf ); UChar* value = value_buf; @@ -96,7 +100,7 @@ PHP_FUNCTION( numfmt_get_text_attribute ) /* Parse parameters. */ if( zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "Ol", - &object, NumberFormatter_ce_ptr, &attribute ) == FAILURE ) + &object, NumberFormatter_ce_ptr, &zattribute ) == FAILURE ) { RETURN_THROWS(); } @@ -104,6 +108,8 @@ PHP_FUNCTION( numfmt_get_text_attribute ) /* Fetch the object. */ FORMATTER_METHOD_FETCH_OBJECT; + UNumberFormatTextAttribute attribute = static_cast(zattribute); + length = unum_getTextAttribute( FORMATTER_OBJECT(nfo), attribute, value, value_buf_size, &INTL_DATA_ERROR_CODE(nfo) ); if(INTL_DATA_ERROR_CODE(nfo) == U_BUFFER_OVERFLOW_ERROR && length >= value_buf_size) { ++length; /* to avoid U_STRING_NOT_TERMINATED_WARNING */ @@ -122,15 +128,15 @@ PHP_FUNCTION( numfmt_get_text_attribute ) /* }}} */ /* {{{ Get formatter attribute value. */ -PHP_FUNCTION( numfmt_set_attribute ) +U_CFUNC PHP_FUNCTION( numfmt_set_attribute ) { - zend_long attribute; + zend_long zattribute; zval *value; FORMATTER_METHOD_INIT_VARS; /* Parse parameters. */ if( zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "Oln", - &object, NumberFormatter_ce_ptr, &attribute, &value ) == FAILURE) + &object, NumberFormatter_ce_ptr, &zattribute, &value ) == FAILURE) { RETURN_THROWS(); } @@ -138,6 +144,8 @@ PHP_FUNCTION( numfmt_set_attribute ) /* Fetch the object. */ FORMATTER_METHOD_FETCH_OBJECT; + UNumberFormatAttribute attribute = static_cast(zattribute); + switch(attribute) { case UNUM_PARSE_INT_ONLY: case UNUM_GROUPING_USED: @@ -175,7 +183,7 @@ PHP_FUNCTION( numfmt_set_attribute ) /* }}} */ /* {{{ Get formatter attribute value. */ -PHP_FUNCTION( numfmt_set_text_attribute ) +U_CFUNC PHP_FUNCTION( numfmt_set_text_attribute ) { int32_t slength = 0; UChar *svalue = NULL; @@ -199,7 +207,7 @@ PHP_FUNCTION( numfmt_set_text_attribute ) INTL_METHOD_CHECK_STATUS( nfo, "Error converting attribute value to UTF-16" ); /* Actually set new attribute value. */ - unum_setTextAttribute(FORMATTER_OBJECT(nfo), attribute, svalue, slength, &INTL_DATA_ERROR_CODE(nfo)); + unum_setTextAttribute(FORMATTER_OBJECT(nfo), static_cast(attribute), svalue, slength, &INTL_DATA_ERROR_CODE(nfo)); if (svalue) { efree(svalue); } @@ -210,9 +218,9 @@ PHP_FUNCTION( numfmt_set_text_attribute ) /* }}} */ /* {{{ Get formatter symbol value. */ -PHP_FUNCTION( numfmt_get_symbol ) +U_CFUNC PHP_FUNCTION( numfmt_get_symbol ) { - zend_long symbol; + zend_long zsymbol; UChar value_buf[4]; UChar *value = value_buf; uint32_t length = USIZE(value_buf); @@ -220,11 +228,13 @@ PHP_FUNCTION( numfmt_get_symbol ) /* Parse parameters. */ if( zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "Ol", - &object, NumberFormatter_ce_ptr, &symbol ) == FAILURE ) + &object, NumberFormatter_ce_ptr, &zsymbol ) == FAILURE ) { RETURN_THROWS(); } + UNumberFormatSymbol symbol = static_cast(zsymbol); + if(symbol >= UNUM_FORMAT_SYMBOL_COUNT || symbol < 0) { intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "invalid symbol value"); RETURN_FALSE; @@ -251,9 +261,9 @@ PHP_FUNCTION( numfmt_get_symbol ) /* }}} */ /* {{{ Set formatter symbol value. */ -PHP_FUNCTION( numfmt_set_symbol ) +U_CFUNC PHP_FUNCTION( numfmt_set_symbol ) { - zend_long symbol; + zend_long zsymbol; char* value = NULL; size_t value_len = 0; UChar* svalue = 0; @@ -262,11 +272,13 @@ PHP_FUNCTION( numfmt_set_symbol ) /* Parse parameters. */ if( zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "Ols", - &object, NumberFormatter_ce_ptr, &symbol, &value, &value_len ) == FAILURE ) + &object, NumberFormatter_ce_ptr, &zsymbol, &value, &value_len ) == FAILURE ) { RETURN_THROWS(); } + UNumberFormatSymbol symbol = static_cast(zsymbol); + if (symbol >= UNUM_FORMAT_SYMBOL_COUNT || symbol < 0) { intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "invalid symbol value"); RETURN_FALSE; @@ -291,7 +303,7 @@ PHP_FUNCTION( numfmt_set_symbol ) /* }}} */ /* {{{ Get formatter pattern. */ -PHP_FUNCTION( numfmt_get_pattern ) +U_CFUNC PHP_FUNCTION( numfmt_get_pattern ) { UChar value_buf[64]; uint32_t length = USIZE( value_buf ); @@ -326,7 +338,7 @@ PHP_FUNCTION( numfmt_get_pattern ) /* }}} */ /* {{{ Set formatter pattern. */ -PHP_FUNCTION( numfmt_set_pattern ) +U_CFUNC PHP_FUNCTION( numfmt_set_pattern ) { char* value = NULL; size_t value_len = 0; @@ -365,7 +377,7 @@ PHP_FUNCTION( numfmt_set_pattern ) /* }}} */ /* {{{ Get formatter locale. */ -PHP_FUNCTION( numfmt_get_locale ) +U_CFUNC PHP_FUNCTION( numfmt_get_locale ) { zend_long type = ULOC_ACTUAL_LOCALE; char* loc; @@ -381,7 +393,7 @@ PHP_FUNCTION( numfmt_get_locale ) /* Fetch the object. */ FORMATTER_METHOD_FETCH_OBJECT; - loc = (char *)unum_getLocaleByType(FORMATTER_OBJECT(nfo), type, &INTL_DATA_ERROR_CODE(nfo)); + loc = (char *)unum_getLocaleByType(FORMATTER_OBJECT(nfo), static_cast(type), &INTL_DATA_ERROR_CODE(nfo)); INTL_METHOD_CHECK_STATUS( nfo, "Error getting locale" ); RETURN_STRING(loc); } diff --git a/ext/intl/formatter/formatter_class.h b/ext/intl/formatter/formatter_class.h index f7da2b2201917..aae6131205e3c 100644 --- a/ext/intl/formatter/formatter_class.h +++ b/ext/intl/formatter/formatter_class.h @@ -17,9 +17,15 @@ #include +#ifdef __cplusplus +extern "C" { +#endif #include "intl_common.h" #include "intl_error.h" #include "intl_data.h" +#ifdef __cplusplus +} +#endif #include "formatter_data.h" typedef struct { @@ -32,8 +38,14 @@ static inline NumberFormatter_object *php_intl_number_format_fetch_object(zend_o } #define Z_INTL_NUMBERFORMATTER_P(zv) php_intl_number_format_fetch_object(Z_OBJ_P(zv)) +#ifdef __cplusplus +extern "C" { +#endif void formatter_register_class( void ); extern zend_class_entry *NumberFormatter_ce_ptr; +#ifdef __cplusplus +} +#endif /* Auxiliary macros */ diff --git a/ext/intl/formatter/formatter_data.c b/ext/intl/formatter/formatter_data.cpp similarity index 94% rename from ext/intl/formatter/formatter_data.c rename to ext/intl/formatter/formatter_data.cpp index 57dbc8bde6b5e..095be92ed29e1 100644 --- a/ext/intl/formatter/formatter_data.c +++ b/ext/intl/formatter/formatter_data.cpp @@ -52,7 +52,7 @@ void formatter_data_free( formatter_data* nf_data ) */ formatter_data* formatter_data_create( void ) { - formatter_data* nf_data = ecalloc( 1, sizeof(formatter_data) ); + formatter_data* nf_data = reinterpret_cast(ecalloc( 1, sizeof(formatter_data) )); formatter_data_init( nf_data ); diff --git a/ext/intl/formatter/formatter_data.h b/ext/intl/formatter/formatter_data.h index 817ad0d6055f3..35acc242a8db9 100644 --- a/ext/intl/formatter/formatter_data.h +++ b/ext/intl/formatter/formatter_data.h @@ -19,7 +19,13 @@ #include +#ifdef __cplusplus +extern "C" { +#endif #include "intl_error.h" +#ifdef __cplusplus +} +#endif typedef struct { // error hangling @@ -29,8 +35,14 @@ typedef struct { UNumberFormat* unum; } formatter_data; +#ifdef __cplusplus +extern "C" { +#endif formatter_data* formatter_data_create( void ); void formatter_data_init( formatter_data* nf_data ); void formatter_data_free( formatter_data* nf_data ); +#ifdef __cplusplus +} +#endif #endif // FORMATTER_DATA_H diff --git a/ext/intl/formatter/formatter_format.c b/ext/intl/formatter/formatter_format.cpp similarity index 98% rename from ext/intl/formatter/formatter_format.c rename to ext/intl/formatter/formatter_format.cpp index 5be732dde77e8..f28ea30b9ff8f 100644 --- a/ext/intl/formatter/formatter_format.c +++ b/ext/intl/formatter/formatter_format.cpp @@ -16,16 +16,18 @@ #include #endif +extern "C" { #include "php_intl.h" +#include "intl_convert.h" +} #include #include "formatter_class.h" #include "formatter_format.h" -#include "intl_convert.h" /* {{{ Format a number. */ -PHP_FUNCTION( numfmt_format ) +U_CFUNC PHP_FUNCTION( numfmt_format ) { zval *number; zend_long type = FORMAT_TYPE_DEFAULT; @@ -123,7 +125,7 @@ PHP_FUNCTION( numfmt_format ) /* }}} */ /* {{{ Format a number as currency. */ -PHP_FUNCTION( numfmt_format_currency ) +U_CFUNC PHP_FUNCTION( numfmt_format_currency ) { double number; UChar format_buf[32]; diff --git a/ext/intl/formatter/formatter_main.c b/ext/intl/formatter/formatter_main.cpp similarity index 91% rename from ext/intl/formatter/formatter_main.c rename to ext/intl/formatter/formatter_main.cpp index 6f92b7e787be4..e8bb743f18d07 100644 --- a/ext/intl/formatter/formatter_main.c +++ b/ext/intl/formatter/formatter_main.cpp @@ -19,9 +19,11 @@ #include #include +extern "C" { #include "php_intl.h" -#include "formatter_class.h" #include "intl_convert.h" +} +#include "formatter_class.h" /* {{{ */ static int numfmt_ctor(INTERNAL_FUNCTION_PARAMETERS) @@ -65,7 +67,7 @@ static int numfmt_ctor(INTERNAL_FUNCTION_PARAMETERS) } /* Create an ICU number formatter. */ - FORMATTER_OBJECT(nfo) = unum_open(style, spattern, spattern_len, locale, NULL, &INTL_DATA_ERROR_CODE(nfo)); + FORMATTER_OBJECT(nfo) = unum_open(static_cast(style), spattern, spattern_len, locale, NULL, &INTL_DATA_ERROR_CODE(nfo)); if(spattern) { efree(spattern); @@ -77,7 +79,7 @@ static int numfmt_ctor(INTERNAL_FUNCTION_PARAMETERS) /* }}} */ /* {{{ Create number formatter. */ -PHP_FUNCTION( numfmt_create ) +U_CFUNC PHP_FUNCTION( numfmt_create ) { object_init_ex( return_value, NumberFormatter_ce_ptr ); if (numfmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU) == FAILURE) { @@ -88,7 +90,7 @@ PHP_FUNCTION( numfmt_create ) /* }}} */ /* {{{ NumberFormatter object constructor. */ -PHP_METHOD( NumberFormatter, __construct ) +U_CFUNC PHP_METHOD( NumberFormatter, __construct ) { const bool old_use_exception = INTL_G(use_exceptions); const zend_long old_error_level = INTL_G(error_level); @@ -105,7 +107,7 @@ PHP_METHOD( NumberFormatter, __construct ) /* }}} */ /* {{{ Get formatter's last error code. */ -PHP_FUNCTION( numfmt_get_error_code ) +U_CFUNC PHP_FUNCTION( numfmt_get_error_code ) { FORMATTER_METHOD_INIT_VARS @@ -124,7 +126,7 @@ PHP_FUNCTION( numfmt_get_error_code ) /* }}} */ /* {{{ Get text description for formatter's last error code. */ -PHP_FUNCTION( numfmt_get_error_message ) +U_CFUNC PHP_FUNCTION( numfmt_get_error_message ) { zend_string *message = NULL; FORMATTER_METHOD_INIT_VARS diff --git a/ext/intl/formatter/formatter_parse.c b/ext/intl/formatter/formatter_parse.cpp similarity index 98% rename from ext/intl/formatter/formatter_parse.c rename to ext/intl/formatter/formatter_parse.cpp index ba8307419b4cf..c7d0df8cbda02 100644 --- a/ext/intl/formatter/formatter_parse.c +++ b/ext/intl/formatter/formatter_parse.cpp @@ -16,19 +16,21 @@ #include #endif +extern "C" { #include "php_intl.h" +#include "intl_convert.h" +} #include #include #include "formatter_class.h" #include "formatter_format.h" -#include "intl_convert.h" #define ICU_LOCALE_BUG 1 /* {{{ Parse a number. */ -PHP_FUNCTION( numfmt_parse ) +U_CFUNC PHP_FUNCTION( numfmt_parse ) { zend_long type = FORMAT_TYPE_DOUBLE; UChar* sstr = NULL; @@ -120,7 +122,7 @@ PHP_FUNCTION( numfmt_parse ) /* }}} */ /* {{{ Parse a number as currency. */ -PHP_FUNCTION( numfmt_parse_currency ) +U_CFUNC PHP_FUNCTION( numfmt_parse_currency ) { double number; UChar currency[5] = {0};