diff --git a/ext/intl/config.m4 b/ext/intl/config.m4 index d60068e5ad4..c4c3c9b1d4c 100644 --- a/ext/intl/config.m4 +++ b/ext/intl/config.m4 @@ -36,14 +36,6 @@ if test "$PHP_INTL" != "no"; then intl_convert.c intl_error.c listformatter/listformatter_class.c - msgformat/msgformat_attr.c - msgformat/msgformat_class.c - msgformat/msgformat_data.c - msgformat/msgformat_format.c - msgformat/msgformat_parse.c - msgformat/msgformat.c - normalizer/normalizer_class.c - normalizer/normalizer_normalize.c php_intl.c resourcebundle/resourcebundle_class.c resourcebundle/resourcebundle_iterator.c @@ -73,6 +65,14 @@ if test "$PHP_INTL" != "no"; then calendar/calendar_class.cpp \ calendar/calendar_methods.cpp \ calendar/gregoriancalendar_methods.cpp \ + msgformat/msgformat_attr.cpp \ + msgformat/msgformat_class.cpp \ + msgformat/msgformat_data.cpp \ + msgformat/msgformat_format.cpp \ + msgformat/msgformat_parse.cpp \ + msgformat/msgformat.cpp \ + normalizer/normalizer_class.cpp \ + normalizer/normalizer_normalize.cpp \ breakiterator/breakiterator_class.cpp \ breakiterator/breakiterator_iterators.cpp \ breakiterator/breakiterator_methods.cpp \ diff --git a/ext/intl/config.w32 b/ext/intl/config.w32 index dcec448c462..fb3f0212729 100644 --- a/ext/intl/config.w32 +++ b/ext/intl/config.w32 @@ -48,20 +48,20 @@ if (PHP_INTL != "no") { locale_methods.cpp \ ", "intl"); ADD_SOURCES(configure_module_dirname + "/msgformat", "\ - msgformat.c \ - msgformat_attr.c \ - msgformat_class.c \ - msgformat_data.c \ - msgformat_format.c \ + msgformat.cpp \ + msgformat_attr.cpp \ + msgformat_class.cpp \ + msgformat_data.cpp \ + msgformat_format.cpp \ msgformat_helpers.cpp \ - msgformat_parse.c \ + msgformat_parse.cpp \ ", "intl"); ADD_SOURCES(configure_module_dirname + "/grapheme", "\ grapheme_string.c grapheme_util.c \ ", "intl"); ADD_SOURCES(configure_module_dirname + "/normalizer", "\ - normalizer_class.c \ - normalizer_normalize.c \ + normalizer_class.cpp \ + normalizer_normalize.cpp \ ", "intl"); ADD_SOURCES(configure_module_dirname + "/dateformat", "\ dateformat.c \ diff --git a/ext/intl/locale/locale_methods.cpp b/ext/intl/locale/locale_methods.cpp index 2cc47d5cc4e..fd8712b3b46 100644 --- a/ext/intl/locale/locale_methods.cpp +++ b/ext/intl/locale/locale_methods.cpp @@ -936,7 +936,7 @@ static int handleAppendResult( int result, smart_str* loc_name) * }}} */ U_CFUNC PHP_FUNCTION(locale_compose) { - smart_str loc_name_s = {0}; + smart_str loc_name_s = {NULL, 0}; smart_str *loc_name = &loc_name_s; zval* arr = NULL; HashTable* hash_arr = NULL; diff --git a/ext/intl/msgformat/msgformat.c b/ext/intl/msgformat/msgformat.cpp similarity index 96% rename from ext/intl/msgformat/msgformat.c rename to ext/intl/msgformat/msgformat.cpp index 4f0beaf2c05..a9e1f71bfc6 100644 --- a/ext/intl/msgformat/msgformat.c +++ b/ext/intl/msgformat/msgformat.cpp @@ -19,10 +19,12 @@ #include #include +extern "C" { #include "php_intl.h" #include "msgformat_class.h" #include "msgformat_data.h" #include "intl_convert.h" +} /* {{{ */ static int msgfmt_ctor(INTERNAL_FUNCTION_PARAMETERS) @@ -99,7 +101,7 @@ static int msgfmt_ctor(INTERNAL_FUNCTION_PARAMETERS) /* }}} */ /* {{{ Create formatter. */ -PHP_FUNCTION( msgfmt_create ) +U_CFUNC PHP_FUNCTION( msgfmt_create ) { object_init_ex( return_value, MessageFormatter_ce_ptr ); if (msgfmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU) == FAILURE) { @@ -110,7 +112,7 @@ PHP_FUNCTION( msgfmt_create ) /* }}} */ /* {{{ MessageFormatter object constructor. */ -PHP_METHOD( MessageFormatter, __construct ) +U_CFUNC PHP_METHOD( MessageFormatter, __construct ) { const bool old_use_exception = INTL_G(use_exceptions); const zend_long old_error_level = INTL_G(error_level); @@ -127,7 +129,7 @@ PHP_METHOD( MessageFormatter, __construct ) /* }}} */ /* {{{ Get formatter's last error code. */ -PHP_FUNCTION( msgfmt_get_error_code ) +U_CFUNC PHP_FUNCTION( msgfmt_get_error_code ) { zval* object = NULL; MessageFormatter_object* mfo = NULL; @@ -147,7 +149,7 @@ PHP_FUNCTION( msgfmt_get_error_code ) /* }}} */ /* {{{ Get text description for formatter's last error code. */ -PHP_FUNCTION( msgfmt_get_error_message ) +U_CFUNC PHP_FUNCTION( msgfmt_get_error_message ) { zend_string* message = NULL; zval* object = NULL; diff --git a/ext/intl/msgformat/msgformat_attr.c b/ext/intl/msgformat/msgformat_attr.cpp similarity index 96% rename from ext/intl/msgformat/msgformat_attr.c rename to ext/intl/msgformat/msgformat_attr.cpp index 6d1813f4608..e7ec006e5e7 100644 --- a/ext/intl/msgformat/msgformat_attr.c +++ b/ext/intl/msgformat/msgformat_attr.cpp @@ -16,15 +16,17 @@ #include #endif +extern "C" { #include "php_intl.h" #include "msgformat_class.h" #include "msgformat_data.h" #include "intl_convert.h" +} #include /* {{{ Get formatter pattern. */ -PHP_FUNCTION( msgfmt_get_pattern ) +U_CFUNC PHP_FUNCTION( msgfmt_get_pattern ) { MSG_FORMAT_METHOD_INIT_VARS; @@ -46,7 +48,7 @@ PHP_FUNCTION( msgfmt_get_pattern ) /* }}} */ /* {{{ Set formatter pattern. */ -PHP_FUNCTION( msgfmt_set_pattern ) +U_CFUNC PHP_FUNCTION( msgfmt_set_pattern ) { char* value = NULL; size_t value_len = 0; @@ -105,7 +107,7 @@ PHP_FUNCTION( msgfmt_set_pattern ) /* }}} */ /* {{{ Get formatter locale. */ -PHP_FUNCTION( msgfmt_get_locale ) +U_CFUNC PHP_FUNCTION( msgfmt_get_locale ) { char *loc; MSG_FORMAT_METHOD_INIT_VARS; diff --git a/ext/intl/msgformat/msgformat_class.c b/ext/intl/msgformat/msgformat_class.cpp similarity index 87% rename from ext/intl/msgformat/msgformat_class.c rename to ext/intl/msgformat/msgformat_class.cpp index 4e0766a911b..e762febf0d1 100644 --- a/ext/intl/msgformat/msgformat_class.c +++ b/ext/intl/msgformat/msgformat_class.cpp @@ -14,10 +14,12 @@ #include +extern "C" { #include "msgformat_class.h" #include "php_intl.h" #include "msgformat_data.h" #include "msgformat_arginfo.h" +} #include @@ -29,7 +31,7 @@ static zend_object_handlers MessageFormatter_handlers; */ /* {{{ MessageFormatter_objects_free */ -void MessageFormatter_object_free( zend_object *object ) +U_CFUNC void MessageFormatter_object_free( zend_object *object ) { MessageFormatter_object* mfo = php_intl_messageformatter_fetch_object(object); @@ -40,11 +42,11 @@ void MessageFormatter_object_free( zend_object *object ) /* }}} */ /* {{{ MessageFormatter_object_create */ -zend_object *MessageFormatter_object_create(zend_class_entry *ce) +U_CFUNC zend_object *MessageFormatter_object_create(zend_class_entry *ce) { MessageFormatter_object* intern; - intern = zend_object_alloc(sizeof(MessageFormatter_object), ce); + intern = reinterpret_cast(zend_object_alloc(sizeof(MessageFormatter_object), ce)); msgformat_data_init( &intern->mf_data ); zend_object_std_init( &intern->zo, ce ); object_properties_init(&intern->zo, ce); @@ -54,7 +56,7 @@ zend_object *MessageFormatter_object_create(zend_class_entry *ce) /* }}} */ /* {{{ MessageFormatter_object_clone */ -zend_object *MessageFormatter_object_clone(zend_object *object) +U_CFUNC zend_object *MessageFormatter_object_clone(zend_object *object) { MessageFormatter_object *mfo = php_intl_messageformatter_fetch_object(object); zend_object *new_obj = MessageFormatter_ce_ptr->create_object(object->ce); @@ -66,7 +68,7 @@ zend_object *MessageFormatter_object_clone(zend_object *object) /* clone formatter object */ if (MSG_FORMAT_OBJECT(mfo) != NULL) { UErrorCode error = U_ZERO_ERROR; - MSG_FORMAT_OBJECT(new_mfo) = umsg_clone(MSG_FORMAT_OBJECT(mfo), &error); + MSG_FORMAT_OBJECT(new_mfo) = reinterpret_cast(umsg_clone(MSG_FORMAT_OBJECT(mfo), &error)); if (U_FAILURE(error)) { zend_throw_error(NULL, "Failed to clone MessageFormatter"); diff --git a/ext/intl/msgformat/msgformat_data.c b/ext/intl/msgformat/msgformat_data.cpp similarity index 92% rename from ext/intl/msgformat/msgformat_data.c rename to ext/intl/msgformat/msgformat_data.cpp index 5d170d25945..f8b7ec39601 100644 --- a/ext/intl/msgformat/msgformat_data.c +++ b/ext/intl/msgformat/msgformat_data.cpp @@ -24,7 +24,7 @@ /* {{{ void msgformat_data_init( msgformat_data* mf_data ) * Initialize internals of msgformat_data. */ -void msgformat_data_init( msgformat_data* mf_data ) +U_CFUNC void msgformat_data_init( msgformat_data* mf_data ) { if( !mf_data ) return; @@ -40,7 +40,7 @@ void msgformat_data_init( msgformat_data* mf_data ) /* {{{ void msgformat_data_free( msgformat_data* mf_data ) * Clean up memory allocated for msgformat_data */ -void msgformat_data_free(msgformat_data* mf_data) +U_CFUNC void msgformat_data_free(msgformat_data* mf_data) { if (!mf_data) return; @@ -69,7 +69,7 @@ void msgformat_data_free(msgformat_data* mf_data) */ msgformat_data* msgformat_data_create( void ) { - msgformat_data* mf_data = ecalloc( 1, sizeof(msgformat_data) ); + msgformat_data* mf_data = reinterpret_cast(ecalloc( 1, sizeof(msgformat_data) )); msgformat_data_init( mf_data ); diff --git a/ext/intl/msgformat/msgformat_data.h b/ext/intl/msgformat/msgformat_data.h index 539c7d6d925..bac94cbec34 100644 --- a/ext/intl/msgformat/msgformat_data.h +++ b/ext/intl/msgformat/msgformat_data.h @@ -17,7 +17,13 @@ #include +#ifdef __cplusplus +extern "C" { +#endif #include "../intl_error.h" +#ifdef __cplusplus +} +#endif #include @@ -26,16 +32,22 @@ typedef struct { intl_error error; // formatter handling - UMessageFormat* umsgf; + UMessageFormat *umsgf; char* orig_format; zend_ulong orig_format_len; HashTable* arg_types; int tz_set; /* if we've already the time zone in sub-formats */ } msgformat_data; +#ifdef __cplusplus +extern "C" { +#endif msgformat_data* msgformat_data_create( void ); void msgformat_data_init( msgformat_data* mf_data ); void msgformat_data_free( msgformat_data* mf_data ); +#ifdef __cplusplus +} +#endif #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.cpp similarity index 97% rename from ext/intl/msgformat/msgformat_format.c rename to ext/intl/msgformat/msgformat_format.cpp index 54babc98396..8e3ec28b389 100644 --- a/ext/intl/msgformat/msgformat_format.c +++ b/ext/intl/msgformat/msgformat_format.cpp @@ -18,11 +18,13 @@ #include +extern "C" { #include "php_intl.h" #include "msgformat_class.h" #include "msgformat_data.h" #include "msgformat_helpers.h" #include "intl_convert.h" +} #ifndef Z_ADDREF_P #define Z_ADDREF_P(z) ((z)->refcount++) @@ -48,7 +50,7 @@ static void msgfmt_do_format(MessageFormatter_object *mfo, zval *args, zval *ret /* }}} */ /* {{{ Format a message. */ -PHP_FUNCTION( msgfmt_format ) +U_CFUNC PHP_FUNCTION( msgfmt_format ) { zval *args; MSG_FORMAT_METHOD_INIT_VARS; @@ -69,7 +71,7 @@ PHP_FUNCTION( msgfmt_format ) /* }}} */ /* {{{ Format a message. */ -PHP_FUNCTION( msgfmt_format_message ) +U_CFUNC PHP_FUNCTION( msgfmt_format_message ) { zval *args; UChar *spattern = NULL; diff --git a/ext/intl/msgformat/msgformat_parse.c b/ext/intl/msgformat/msgformat_parse.cpp similarity index 97% rename from ext/intl/msgformat/msgformat_parse.c rename to ext/intl/msgformat/msgformat_parse.cpp index 5c4f0443981..28d7ce71080 100644 --- a/ext/intl/msgformat/msgformat_parse.c +++ b/ext/intl/msgformat/msgformat_parse.cpp @@ -18,11 +18,13 @@ #include +extern "C" { #include "php_intl.h" #include "msgformat_class.h" #include "msgformat_data.h" #include "msgformat_helpers.h" #include "intl_convert.h" +} /* {{{ */ static void msgfmt_do_parse(MessageFormatter_object *mfo, char *source, size_t src_len, zval *return_value) @@ -52,7 +54,7 @@ static void msgfmt_do_parse(MessageFormatter_object *mfo, char *source, size_t s /* }}} */ /* {{{ Parse a message */ -PHP_FUNCTION( msgfmt_parse ) +U_CFUNC PHP_FUNCTION( msgfmt_parse ) { char *source; size_t source_len; @@ -74,7 +76,7 @@ PHP_FUNCTION( msgfmt_parse ) /* }}} */ /* {{{ Parse a message. */ -PHP_FUNCTION( msgfmt_parse_message ) +U_CFUNC PHP_FUNCTION( msgfmt_parse_message ) { UChar *spattern = NULL; int spattern_len = 0; diff --git a/ext/intl/normalizer/normalizer_class.c b/ext/intl/normalizer/normalizer_class.cpp similarity index 86% rename from ext/intl/normalizer/normalizer_class.c rename to ext/intl/normalizer/normalizer_class.cpp index d9e413d5e51..3838f754632 100644 --- a/ext/intl/normalizer/normalizer_class.c +++ b/ext/intl/normalizer/normalizer_class.cpp @@ -12,11 +12,22 @@ +----------------------------------------------------------------------+ */ +#if __cplusplus >= 201703L +#include +#endif +#include + #include "normalizer.h" #include "normalizer_class.h" #include "php_intl.h" +#ifdef __cplusplus +extern "C" { +#endif #include "normalizer_arginfo.h" #include "intl_error.h" +#ifdef __cplusplus +} +#endif #include @@ -29,7 +40,7 @@ zend_class_entry *Normalizer_ce_ptr = NULL; /* {{{ normalizer_register_Normalizer_class * Initialize 'Normalizer' class */ -void normalizer_register_Normalizer_class( void ) +U_CFUNC void normalizer_register_Normalizer_class( void ) { /* Create and register 'Normalizer' class. */ Normalizer_ce_ptr = register_class_Normalizer(); diff --git a/ext/intl/normalizer/normalizer_class.h b/ext/intl/normalizer/normalizer_class.h index 6e57cae40ba..8f88f215abc 100644 --- a/ext/intl/normalizer/normalizer_class.h +++ b/ext/intl/normalizer/normalizer_class.h @@ -36,6 +36,12 @@ typedef struct { #define NORMALIZER_ERROR_CODE(co) INTL_ERROR_CODE(NORMALIZER_ERROR(co)) #define NORMALIZER_ERROR_CODE_P(co) &(INTL_ERROR_CODE(NORMALIZER_ERROR(co))) +#ifdef __cplusplus +extern "C" { +#endif void normalizer_register_Normalizer_class( void ); +#ifdef __cplusplus +} +#endif extern zend_class_entry *Normalizer_ce_ptr; #endif // #ifndef NORMALIZER_CLASS_H diff --git a/ext/intl/normalizer/normalizer_normalize.c b/ext/intl/normalizer/normalizer_normalize.cpp similarity index 97% rename from ext/intl/normalizer/normalizer_normalize.c rename to ext/intl/normalizer/normalizer_normalize.cpp index 670042f34d2..92e8f1166ad 100644 --- a/ext/intl/normalizer/normalizer_normalize.c +++ b/ext/intl/normalizer/normalizer_normalize.cpp @@ -16,11 +16,18 @@ #include #endif +#if __cplusplus >= 201703L +#include +#include +#endif + +extern "C" { #include "php_intl.h" #include #include "normalizer.h" #include "normalizer_class.h" #include "intl_convert.h" +} #include @@ -71,7 +78,7 @@ static UBool intl_is_normalized(zend_long form, const UChar *uinput, int32_t uin }/*}}}*/ /* {{{ Normalize a string. */ -PHP_FUNCTION( normalizer_normalize ) +U_CFUNC PHP_FUNCTION( normalizer_normalize ) { char* input = NULL; /* form is optional, defaults to FORM_C */ @@ -200,7 +207,7 @@ PHP_FUNCTION( normalizer_normalize ) /* }}} */ /* {{{ Test if a string is in a given normalization form. */ -PHP_FUNCTION( normalizer_is_normalized ) +U_CFUNC PHP_FUNCTION( normalizer_is_normalized ) { char* input = NULL; /* form is optional, defaults to FORM_C */ @@ -276,7 +283,7 @@ PHP_FUNCTION( normalizer_is_normalized ) /* }}} */ /* {{{ Returns the Decomposition_Mapping property for the given UTF-8 encoded code point. */ -PHP_FUNCTION( normalizer_get_raw_decomposition ) +U_CFUNC PHP_FUNCTION( normalizer_get_raw_decomposition ) { char* input = NULL; size_t input_length = 0;