From 8dcbb3e4512c184369eb4ada2c9a7bb9fb7b96ee Mon Sep 17 00:00:00 2001 From: David Carlier Date: Sat, 8 Nov 2025 12:50:45 +0000 Subject: [PATCH] ext/intl: migrate C to C++ code step 5. --- .../{common_error.c => common_error.cpp} | 14 +++++----- ext/intl/config.m4 | 18 ++++++------- ext/intl/config.w32 | 18 ++++++------- ...ateformat_class.c => dateformat_class.cpp} | 6 +++-- ext/intl/dateformat/dateformat_class.h | 6 +++++ ext/intl/dateformat/dateformat_format.cpp | 2 +- ...{formatter_class.c => formatter_class.cpp} | 14 ++++++---- ext/intl/formatter/formatter_class.h | 2 +- .../{resourcebundle.c => resourcebundle.cpp} | 4 ++- ext/intl/resourcebundle/resourcebundle.h | 6 +++++ ...undle_class.c => resourcebundle_class.cpp} | 27 +++++++++++-------- .../resourcebundle/resourcebundle_class.h | 13 ++++++++- ...iterator.c => resourcebundle_iterator.cpp} | 6 +++-- .../resourcebundle/resourcebundle_iterator.h | 6 +++++ ...checker_class.c => spoofchecker_class.cpp} | 14 +++++----- ext/intl/spoofchecker/spoofchecker_class.h | 12 +++++++++ ...ecker_create.c => spoofchecker_create.cpp} | 11 ++++++-- ...ofchecker_main.c => spoofchecker_main.cpp} | 19 ++++++++----- 18 files changed, 136 insertions(+), 62 deletions(-) rename ext/intl/common/{common_error.c => common_error.cpp} (84%) rename ext/intl/dateformat/{dateformat_class.c => dateformat_class.cpp} (95%) rename ext/intl/formatter/{formatter_class.c => formatter_class.cpp} (89%) rename ext/intl/resourcebundle/{resourcebundle.c => resourcebundle.cpp} (96%) rename ext/intl/resourcebundle/{resourcebundle_class.c => resourcebundle_class.cpp} (95%) rename ext/intl/resourcebundle/{resourcebundle_iterator.c => resourcebundle_iterator.cpp} (95%) rename ext/intl/spoofchecker/{spoofchecker_class.c => spoofchecker_class.cpp} (90%) rename ext/intl/spoofchecker/{spoofchecker_create.c => spoofchecker_create.cpp} (94%) rename ext/intl/spoofchecker/{spoofchecker_main.c => spoofchecker_main.cpp} (95%) diff --git a/ext/intl/common/common_error.c b/ext/intl/common/common_error.cpp similarity index 84% rename from ext/intl/common/common_error.c rename to ext/intl/common/common_error.cpp index 733a1913ad08f..cb12d8dff8f3d 100644 --- a/ext/intl/common/common_error.c +++ b/ext/intl/common/common_error.cpp @@ -17,11 +17,13 @@ #include #endif +extern "C" { #include "php_intl.h" #include "intl_error.h" +} /* {{{ Get code of the last occurred error. */ -PHP_FUNCTION( intl_get_error_code ) +U_CFUNC PHP_FUNCTION( intl_get_error_code ) { ZEND_PARSE_PARAMETERS_NONE(); @@ -30,7 +32,7 @@ PHP_FUNCTION( intl_get_error_code ) /* }}} */ /* {{{ Get text description of the last occurred error. */ -PHP_FUNCTION( intl_get_error_message ) +U_CFUNC PHP_FUNCTION( intl_get_error_message ) { ZEND_PARSE_PARAMETERS_NONE(); @@ -42,7 +44,7 @@ PHP_FUNCTION( intl_get_error_message ) * Returns true if it does, and false if the code * indicates success or a warning. */ -PHP_FUNCTION( intl_is_failure ) +U_CFUNC PHP_FUNCTION( intl_is_failure ) { zend_long err_code; @@ -50,14 +52,14 @@ PHP_FUNCTION( intl_is_failure ) Z_PARAM_LONG(err_code) ZEND_PARSE_PARAMETERS_END(); - RETURN_BOOL( U_FAILURE( err_code ) ); + RETURN_BOOL( U_FAILURE( static_cast(err_code) ) ); } /* }}} */ /* {{{ Return a string for a given error code. * The string will be the same as the name of the error code constant. */ -PHP_FUNCTION( intl_error_name ) +U_CFUNC PHP_FUNCTION( intl_error_name ) { zend_long err_code; @@ -65,6 +67,6 @@ PHP_FUNCTION( intl_error_name ) Z_PARAM_LONG(err_code) ZEND_PARSE_PARAMETERS_END(); - RETURN_STRING( (char*)u_errorName( err_code ) ); + RETURN_STRING( (char*)u_errorName( static_cast(err_code) ) ); } /* }}} */ diff --git a/ext/intl/config.m4 b/ext/intl/config.m4 index aa1348029fa7d..7251f22835349 100644 --- a/ext/intl/config.m4 +++ b/ext/intl/config.m4 @@ -8,18 +8,9 @@ if test "$PHP_INTL" != "no"; then PHP_SUBST([INTL_SHARED_LIBADD]) INTL_COMMON_FLAGS="$ICU_CFLAGS -Wno-write-strings -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1" PHP_NEW_EXTENSION([intl], m4_normalize([ - common/common_error.c - dateformat/dateformat_class.c - formatter/formatter_class.c intl_convert.c intl_error.c php_intl.c - resourcebundle/resourcebundle_class.c - resourcebundle/resourcebundle_iterator.c - resourcebundle/resourcebundle.c - spoofchecker/spoofchecker_class.c - spoofchecker/spoofchecker_create.c - spoofchecker/spoofchecker_main.c ]), [$ext_shared],, [$INTL_COMMON_FLAGS], @@ -37,6 +28,8 @@ if test "$PHP_INTL" != "no"; then collator/collator_sort.cpp \ common/common_enum.cpp \ common/common_date.cpp \ + common/common_error.cpp \ + dateformat/dateformat_class.cpp \ converter/converter.cpp \ dateformat/dateformat.cpp \ dateformat/dateformat_attr.cpp \ @@ -49,6 +42,7 @@ if test "$PHP_INTL" != "no"; then dateformat/dateformat_parse.cpp \ dateformat/datepatterngenerator_class.cpp \ dateformat/datepatterngenerator_methods.cpp \ + formatter/formatter_class.cpp \ grapheme/grapheme_string.cpp \ grapheme/grapheme_util.cpp \ msgformat/msgformat_helpers.cpp \ @@ -84,6 +78,12 @@ if test "$PHP_INTL" != "no"; then locale/locale_class.cpp \ locale/locale_methods.cpp \ locale/locale.cpp \ + resourcebundle/resourcebundle_class.cpp \ + resourcebundle/resourcebundle_iterator.cpp \ + resourcebundle/resourcebundle.cpp \ + spoofchecker/spoofchecker_class.cpp \ + spoofchecker/spoofchecker_create.cpp \ + spoofchecker/spoofchecker_main.cpp \ uchar/uchar.cpp" PHP_REQUIRE_CXX() diff --git a/ext/intl/config.w32 b/ext/intl/config.w32 index d0720ff1af18b..d5c86d1236712 100644 --- a/ext/intl/config.w32 +++ b/ext/intl/config.w32 @@ -24,7 +24,7 @@ if (PHP_INTL != "no") { collator_sort.cpp \ ", "intl"); ADD_SOURCES(configure_module_dirname + "/common", "\ - common_error.c \ + common_error.cpp \ common_enum.cpp \ common_date.cpp \ ", "intl"); @@ -33,7 +33,7 @@ if (PHP_INTL != "no") { ", "intl"); ADD_SOURCES(configure_module_dirname + "/formatter", "\ formatter_attr.cpp \ - formatter_class.c \ + formatter_class.cpp \ formatter_data.cpp \ formatter_format.cpp \ formatter_main.cpp \ @@ -68,7 +68,7 @@ if (PHP_INTL != "no") { ", "intl"); ADD_SOURCES(configure_module_dirname + "/dateformat", "\ dateformat.cpp \ - dateformat_class.c \ + dateformat_class.cpp \ dateformat_attr.cpp \ dateformat_format.cpp \ dateformat_format_object.cpp \ @@ -87,16 +87,16 @@ if (PHP_INTL != "no") { idn.cpp", "intl"); ADD_SOURCES(configure_module_dirname + "/resourcebundle", "\ - resourcebundle.c \ - resourcebundle_class.c \ - resourcebundle_iterator.c", + resourcebundle.cpp \ + resourcebundle_class.cpp \ + resourcebundle_iterator.cpp", "intl"); if (CHECK_HEADER_ADD_INCLUDE("unicode/uspoof.h", "CFLAGS_INTL")) { ADD_SOURCES(configure_module_dirname + "/spoofchecker", "\ - spoofchecker_class.c \ - spoofchecker_create.c \ - spoofchecker_main.c", + spoofchecker_class.cpp \ + spoofchecker_create.cpp \ + spoofchecker_main.cpp", "intl"); } diff --git a/ext/intl/dateformat/dateformat_class.c b/ext/intl/dateformat/dateformat_class.cpp similarity index 95% rename from ext/intl/dateformat/dateformat_class.c rename to ext/intl/dateformat/dateformat_class.cpp index 15bf5bf23ce57..b6ccf97990073 100644 --- a/ext/intl/dateformat/dateformat_class.c +++ b/ext/intl/dateformat/dateformat_class.cpp @@ -11,13 +11,15 @@ | Authors: Kirti Velankar | +----------------------------------------------------------------------+ */ -#include +#include +extern "C" { #include "dateformat_class.h" #include "php_intl.h" #include "dateformat_data.h" #include "dateformat.h" #include "dateformat_arginfo.h" +} #include @@ -48,7 +50,7 @@ zend_object *IntlDateFormatter_object_create(zend_class_entry *ce) { IntlDateFormatter_object* intern; - intern = zend_object_alloc(sizeof(IntlDateFormatter_object), ce); + intern = reinterpret_cast(zend_object_alloc(sizeof(IntlDateFormatter_object), ce)); dateformat_data_init( &intern->datef_data ); zend_object_std_init( &intern->zo, ce ); object_properties_init(&intern->zo, ce); diff --git a/ext/intl/dateformat/dateformat_class.h b/ext/intl/dateformat/dateformat_class.h index 167a777e405fa..e722c40b4bd9f 100644 --- a/ext/intl/dateformat/dateformat_class.h +++ b/ext/intl/dateformat/dateformat_class.h @@ -16,9 +16,15 @@ #include +#ifdef __cplusplus +extern "C" { +#endif #include "intl_common.h" #include "intl_error.h" #include "intl_data.h" +#ifdef __cplusplus +} +#endif #include "dateformat_data.h" typedef struct { diff --git a/ext/intl/dateformat/dateformat_format.cpp b/ext/intl/dateformat/dateformat_format.cpp index 72fbd5f34ae7f..30570a5887c17 100644 --- a/ext/intl/dateformat/dateformat_format.cpp +++ b/ext/intl/dateformat/dateformat_format.cpp @@ -17,7 +17,7 @@ #endif #include -#include +#include extern "C" { #include "../php_intl.h" diff --git a/ext/intl/formatter/formatter_class.c b/ext/intl/formatter/formatter_class.cpp similarity index 89% rename from ext/intl/formatter/formatter_class.c rename to ext/intl/formatter/formatter_class.cpp index 7832824c94e1c..214e1e57dae8a 100644 --- a/ext/intl/formatter/formatter_class.c +++ b/ext/intl/formatter/formatter_class.cpp @@ -15,15 +15,19 @@ #include #include "formatter_class.h" +extern "C" { #include "php_intl.h" #include "formatter_data.h" #include "formatter_format.h" +} #include #include "Zend/zend_attributes.h" #include "Zend/zend_interfaces.h" +extern "C" { #include "formatter_arginfo.h" +} zend_class_entry *NumberFormatter_ce_ptr = NULL; static zend_object_handlers NumberFormatter_handlers; @@ -33,7 +37,7 @@ static zend_object_handlers NumberFormatter_handlers; */ /* {{{ NumberFormatter_objects_free */ -void NumberFormatter_object_free( zend_object *object ) +U_CFUNC void NumberFormatter_object_free( zend_object *object ) { NumberFormatter_object* nfo = php_intl_number_format_fetch_object(object); @@ -44,11 +48,11 @@ void NumberFormatter_object_free( zend_object *object ) /* }}} */ /* {{{ NumberFormatter_object_create */ -zend_object *NumberFormatter_object_create(zend_class_entry *ce) +U_CFUNC zend_object *NumberFormatter_object_create(zend_class_entry *ce) { NumberFormatter_object* intern; - intern = zend_object_alloc(sizeof(NumberFormatter_object), ce); + intern = reinterpret_cast(zend_object_alloc(sizeof(NumberFormatter_object), ce)); formatter_data_init( &intern->nf_data ); zend_object_std_init( &intern->zo, ce ); object_properties_init(&intern->zo, ce); @@ -58,7 +62,7 @@ zend_object *NumberFormatter_object_create(zend_class_entry *ce) /* }}} */ /* {{{ NumberFormatter_object_clone */ -zend_object *NumberFormatter_object_clone(zend_object *object) +U_CFUNC zend_object *NumberFormatter_object_clone(zend_object *object) { NumberFormatter_object *nfo = php_intl_number_format_fetch_object(object); zend_object *new_obj = NumberFormatter_ce_ptr->create_object(object->ce); @@ -88,7 +92,7 @@ zend_object *NumberFormatter_object_clone(zend_object *object) /* {{{ formatter_register_class * Initialize 'NumberFormatter' class */ -void formatter_register_class( void ) +U_CFUNC void formatter_register_class( void ) { /* Create and register 'NumberFormatter' class. */ NumberFormatter_ce_ptr = register_class_NumberFormatter(); diff --git a/ext/intl/formatter/formatter_class.h b/ext/intl/formatter/formatter_class.h index aae6131205e3c..bf21825b5f5f4 100644 --- a/ext/intl/formatter/formatter_class.h +++ b/ext/intl/formatter/formatter_class.h @@ -23,10 +23,10 @@ extern "C" { #include "intl_common.h" #include "intl_error.h" #include "intl_data.h" +#include "formatter_data.h" #ifdef __cplusplus } #endif -#include "formatter_data.h" typedef struct { formatter_data nf_data; diff --git a/ext/intl/resourcebundle/resourcebundle.c b/ext/intl/resourcebundle/resourcebundle.cpp similarity index 96% rename from ext/intl/resourcebundle/resourcebundle.c rename to ext/intl/resourcebundle/resourcebundle.cpp index e29596f01872e..b8c5c00efaba6 100644 --- a/ext/intl/resourcebundle/resourcebundle.c +++ b/ext/intl/resourcebundle/resourcebundle.cpp @@ -17,12 +17,14 @@ #include #include +extern "C" { #include "intl_convert.h" #include "intl_data.h" #include "resourcebundle/resourcebundle_class.h" +} /* {{{ ResourceBundle_extract_value */ -void resourcebundle_extract_value( zval *return_value, ResourceBundle_object *source ) +U_CFUNC void resourcebundle_extract_value( zval *return_value, ResourceBundle_object *source ) { UResType restype; const UChar* ufield; diff --git a/ext/intl/resourcebundle/resourcebundle.h b/ext/intl/resourcebundle/resourcebundle.h index ddcf75b8c50ac..c46908a8edff2 100644 --- a/ext/intl/resourcebundle/resourcebundle.h +++ b/ext/intl/resourcebundle/resourcebundle.h @@ -21,6 +21,12 @@ #include "resourcebundle/resourcebundle_class.h" +#ifdef __cplusplus +extern "C" { +#endif void resourcebundle_extract_value( zval *target, ResourceBundle_object *source); +#ifdef __cplusplus +} +#endif #endif // #ifndef RESOURCEBUNDLE_CLASS_H diff --git a/ext/intl/resourcebundle/resourcebundle_class.c b/ext/intl/resourcebundle/resourcebundle_class.cpp similarity index 95% rename from ext/intl/resourcebundle/resourcebundle_class.c rename to ext/intl/resourcebundle/resourcebundle_class.cpp index 165e60cc1d3a1..d88ba2ad13170 100644 --- a/ext/intl/resourcebundle/resourcebundle_class.c +++ b/ext/intl/resourcebundle/resourcebundle_class.cpp @@ -16,19 +16,24 @@ #include #include + +extern "C" { #include +#include +} + #include #include -#include +extern "C" { #include "php_intl.h" #include "intl_data.h" #include "intl_common.h" - #include "resourcebundle/resourcebundle.h" #include "resourcebundle/resourcebundle_iterator.h" #include "resourcebundle/resourcebundle_class.h" #include "resourcebundle/resourcebundle_arginfo.h" +} zend_class_entry *ResourceBundle_ce_ptr = NULL; @@ -58,7 +63,7 @@ static zend_object *ResourceBundle_object_create( zend_class_entry *ce ) { ResourceBundle_object *rb; - rb = zend_object_alloc(sizeof(ResourceBundle_object), ce); + rb = reinterpret_cast(zend_object_alloc(sizeof(ResourceBundle_object), ce)); zend_object_std_init( &rb->zend, ce ); object_properties_init( &rb->zend, ce); @@ -152,7 +157,7 @@ PHP_METHOD( ResourceBundle, __construct ) /* }}} */ /* {{{ */ -PHP_FUNCTION( resourcebundle_create ) +U_CFUNC PHP_FUNCTION( resourcebundle_create ) { object_init_ex( return_value, ResourceBundle_ce_ptr ); if (resourcebundle_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU) == FAILURE) { @@ -234,7 +239,7 @@ static zval *resource_bundle_array_fetch( /* }}} */ /* {{{ resourcebundle_array_get */ -zval *resourcebundle_array_get(zend_object *object, zval *offset, int type, zval *rv) +U_CFUNC zval *resourcebundle_array_get(zend_object *object, zval *offset, int type, zval *rv) { if (offset == NULL) { zend_throw_error(NULL, "Cannot apply [] to ResourceBundle object"); @@ -254,7 +259,7 @@ zval *resourcebundle_array_get(zend_object *object, zval *offset, int type, zval /* }}} */ /* {{{ Get resource identified by numerical index or key name. */ -PHP_FUNCTION( resourcebundle_get ) +U_CFUNC PHP_FUNCTION( resourcebundle_get ) { bool fallback = true; zend_object *resource_bundle = NULL; @@ -312,7 +317,7 @@ static zend_result resourcebundle_array_count(zend_object *object, zend_long *co /* }}} */ /* {{{ Get resources count */ -PHP_FUNCTION( resourcebundle_count ) +U_CFUNC PHP_FUNCTION( resourcebundle_count ) { int32_t len; RESOURCEBUNDLE_METHOD_INIT_VARS; @@ -328,7 +333,7 @@ PHP_FUNCTION( resourcebundle_count ) } /* {{{ Get available locales from ResourceBundle name */ -PHP_FUNCTION( resourcebundle_locales ) +U_CFUNC PHP_FUNCTION( resourcebundle_locales ) { char * bundlename; size_t bundlename_len = 0; @@ -368,7 +373,7 @@ PHP_FUNCTION( resourcebundle_locales ) /* }}} */ /* {{{ Get text description for ResourceBundle's last error code. */ -PHP_FUNCTION( resourcebundle_get_error_code ) +U_CFUNC PHP_FUNCTION( resourcebundle_get_error_code ) { RESOURCEBUNDLE_METHOD_INIT_VARS; @@ -385,7 +390,7 @@ PHP_FUNCTION( resourcebundle_get_error_code ) /* }}} */ /* {{{ Get text description for ResourceBundle's last error. */ -PHP_FUNCTION( resourcebundle_get_error_message ) +U_CFUNC PHP_FUNCTION( resourcebundle_get_error_message ) { zend_string* message = NULL; RESOURCEBUNDLE_METHOD_INIT_VARS; @@ -411,7 +416,7 @@ PHP_METHOD(ResourceBundle, getIterator) { /* {{{ resourcebundle_register_class * Initialize 'ResourceBundle' class */ -void resourcebundle_register_class( void ) +U_CFUNC void resourcebundle_register_class( void ) { ResourceBundle_ce_ptr = register_class_ResourceBundle(zend_ce_aggregate, zend_ce_countable); ResourceBundle_ce_ptr->create_object = ResourceBundle_object_create; diff --git a/ext/intl/resourcebundle/resourcebundle_class.h b/ext/intl/resourcebundle/resourcebundle_class.h index be397c8d47601..334532bde99b7 100644 --- a/ext/intl/resourcebundle/resourcebundle_class.h +++ b/ext/intl/resourcebundle/resourcebundle_class.h @@ -18,9 +18,14 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif #include "php.h" - #include "intl_error.h" +#ifdef __cplusplus +} +#endif typedef struct { intl_error error; @@ -46,7 +51,13 @@ static inline ResourceBundle_object *php_intl_resourcebundle_fetch_object(zend_o #define RESOURCEBUNDLE_OBJECT(rb) (rb)->me +#ifdef __cplusplus +extern "C" { +#endif void resourcebundle_register_class( void ); extern zend_class_entry *ResourceBundle_ce_ptr; +#ifdef __cplusplus +} +#endif #endif // #ifndef RESOURCEBUNDLE_CLASS_H diff --git a/ext/intl/resourcebundle/resourcebundle_iterator.c b/ext/intl/resourcebundle/resourcebundle_iterator.cpp similarity index 95% rename from ext/intl/resourcebundle/resourcebundle_iterator.c rename to ext/intl/resourcebundle/resourcebundle_iterator.cpp index c79269e475070..7747b34adbd4c 100644 --- a/ext/intl/resourcebundle/resourcebundle_iterator.c +++ b/ext/intl/resourcebundle/resourcebundle_iterator.cpp @@ -12,9 +12,11 @@ +----------------------------------------------------------------------+ */ +extern "C" { #include #include #include +} #include "resourcebundle/resourcebundle.h" #include "resourcebundle/resourcebundle_class.h" @@ -145,7 +147,7 @@ static const zend_object_iterator_funcs resourcebundle_iterator_funcs = { /* }}} */ /* {{{ resourcebundle_get_iterator */ -zend_object_iterator *resourcebundle_get_iterator( zend_class_entry *ce, zval *object, int byref ) +U_CFUNC zend_object_iterator *resourcebundle_get_iterator( zend_class_entry *ce, zval *object, int byref ) { if (byref) { zend_throw_error(NULL, "An iterator cannot be used with foreach by reference"); @@ -153,7 +155,7 @@ zend_object_iterator *resourcebundle_get_iterator( zend_class_entry *ce, zval *o } ResourceBundle_object *rb = Z_INTL_RESOURCEBUNDLE_P(object ); - ResourceBundle_iterator *iterator = emalloc( sizeof( ResourceBundle_iterator ) ); + ResourceBundle_iterator *iterator = reinterpret_cast(emalloc( sizeof( ResourceBundle_iterator )) ); zend_iterator_init(&iterator->intern); Z_ADDREF_P(object); diff --git a/ext/intl/resourcebundle/resourcebundle_iterator.h b/ext/intl/resourcebundle/resourcebundle_iterator.h index 1ad948723160f..c323d4e17b4c9 100644 --- a/ext/intl/resourcebundle/resourcebundle_iterator.h +++ b/ext/intl/resourcebundle/resourcebundle_iterator.h @@ -29,6 +29,12 @@ typedef struct { zend_long i; } ResourceBundle_iterator; +#ifdef __cplusplus +extern "C" { +#endif zend_object_iterator *resourcebundle_get_iterator( zend_class_entry *ce, zval *object, int byref ); +#ifdef __cplusplus +} +#endif #endif // #ifndef RESOURCEBUNDLE_ITERATOR_H diff --git a/ext/intl/spoofchecker/spoofchecker_class.c b/ext/intl/spoofchecker/spoofchecker_class.cpp similarity index 90% rename from ext/intl/spoofchecker/spoofchecker_class.c rename to ext/intl/spoofchecker/spoofchecker_class.cpp index 6fa59edd47b00..ba4c64321f14e 100644 --- a/ext/intl/spoofchecker/spoofchecker_class.c +++ b/ext/intl/spoofchecker/spoofchecker_class.cpp @@ -13,9 +13,11 @@ */ #include "spoofchecker_class.h" +extern "C" { #include "spoofchecker_arginfo.h" #include "php_intl.h" #include "intl_error.h" +} #include @@ -27,7 +29,7 @@ static zend_object_handlers Spoofchecker_handlers; */ /* {{{ Spoofchecker_objects_free */ -void Spoofchecker_objects_free(zend_object *object) +U_CFUNC void Spoofchecker_objects_free(zend_object *object) { Spoofchecker_object* co = php_intl_spoofchecker_fetch_object(object); @@ -38,11 +40,11 @@ void Spoofchecker_objects_free(zend_object *object) /* }}} */ /* {{{ Spoofchecker_object_create */ -zend_object *Spoofchecker_object_create(zend_class_entry *ce) +U_CFUNC zend_object *Spoofchecker_object_create(zend_class_entry *ce) { Spoofchecker_object* intern; - intern = zend_object_alloc(sizeof(Spoofchecker_object), ce); + intern = reinterpret_cast(zend_object_alloc(sizeof(Spoofchecker_object), ce)); intl_error_init(SPOOFCHECKER_ERROR_P(intern)); zend_object_std_init(&intern->zo, ce); object_properties_init(&intern->zo, ce); @@ -87,7 +89,7 @@ static zend_object *spoofchecker_clone_obj(zend_object *object) /* {{{ */ /* {{{ spoofchecker_register_Spoofchecker_class * Initialize 'Spoofchecker' class */ -void spoofchecker_register_Spoofchecker_class(void) +U_CFUNC void spoofchecker_register_Spoofchecker_class(void) { /* Create and register 'Spoofchecker' class. */ Spoofchecker_ce_ptr = register_class_Spoofchecker(); @@ -106,7 +108,7 @@ void spoofchecker_register_Spoofchecker_class(void) * Initialize internals of Spoofchecker_object. * Must be called before any other call to 'spoofchecker_object_...' functions. */ -void spoofchecker_object_init(Spoofchecker_object* co) +U_CFUNC void spoofchecker_object_init(Spoofchecker_object* co) { if (!co) { return; @@ -119,7 +121,7 @@ void spoofchecker_object_init(Spoofchecker_object* co) /* {{{ void spoofchecker_object_destroy( Spoofchecker_object* co ) * Clean up mem allocted by internals of Spoofchecker_object */ -void spoofchecker_object_destroy(Spoofchecker_object* co) +U_CFUNC void spoofchecker_object_destroy(Spoofchecker_object* co) { if (!co) { return; diff --git a/ext/intl/spoofchecker/spoofchecker_class.h b/ext/intl/spoofchecker/spoofchecker_class.h index a471c055c2ce6..06701eb60e36e 100644 --- a/ext/intl/spoofchecker/spoofchecker_class.h +++ b/ext/intl/spoofchecker/spoofchecker_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 @@ -47,10 +53,16 @@ static inline Spoofchecker_object *php_intl_spoofchecker_fetch_object(zend_objec #define SPOOFCHECKER_ERROR_CODE(co) INTL_ERROR_CODE(SPOOFCHECKER_ERROR(co)) #define SPOOFCHECKER_ERROR_CODE_P(co) &(INTL_ERROR_CODE(SPOOFCHECKER_ERROR(co))) +#ifdef __cplusplus +extern "C" { +#endif void spoofchecker_register_Spoofchecker_class(void); void spoofchecker_object_init(Spoofchecker_object* co); void spoofchecker_object_destroy(Spoofchecker_object* co); +#ifdef __cplusplus +} +#endif extern zend_class_entry *Spoofchecker_ce_ptr; diff --git a/ext/intl/spoofchecker/spoofchecker_create.c b/ext/intl/spoofchecker/spoofchecker_create.cpp similarity index 94% rename from ext/intl/spoofchecker/spoofchecker_create.c rename to ext/intl/spoofchecker/spoofchecker_create.cpp index 7cb51adef4e24..1ed4055cccd10 100644 --- a/ext/intl/spoofchecker/spoofchecker_create.c +++ b/ext/intl/spoofchecker/spoofchecker_create.cpp @@ -16,12 +16,19 @@ #include #endif +#if __cplusplus >= 201703L +#include +#include +#endif + +extern "C" { #include "php_intl.h" -#include "spoofchecker_class.h" #include "intl_data.h" +} +#include "spoofchecker_class.h" /* {{{ Spoofchecker object constructor. */ -PHP_METHOD(Spoofchecker, __construct) +U_CFUNC PHP_METHOD(Spoofchecker, __construct) { #if U_ICU_VERSION_MAJOR_NUM < 58 int checks; diff --git a/ext/intl/spoofchecker/spoofchecker_main.c b/ext/intl/spoofchecker/spoofchecker_main.cpp similarity index 95% rename from ext/intl/spoofchecker/spoofchecker_main.c rename to ext/intl/spoofchecker/spoofchecker_main.cpp index a4b1ad591fdd6..ddbf02a0d3ded 100644 --- a/ext/intl/spoofchecker/spoofchecker_main.c +++ b/ext/intl/spoofchecker/spoofchecker_main.cpp @@ -16,12 +16,19 @@ #include #endif +#if __cplusplus >= 201703L +#include +#include +#endif + +extern "C" { #include "php_intl.h" #include "intl_convert.h" +} #include "spoofchecker_class.h" /* {{{ Checks if a given text contains any suspicious characters */ -PHP_METHOD(Spoofchecker, isSuspicious) +U_CFUNC PHP_METHOD(Spoofchecker, isSuspicious) { int32_t ret, errmask; zend_string *text; @@ -62,7 +69,7 @@ PHP_METHOD(Spoofchecker, isSuspicious) /* }}} */ /* {{{ Checks if a given text contains any confusable characters */ -PHP_METHOD(Spoofchecker, areConfusable) +U_CFUNC PHP_METHOD(Spoofchecker, areConfusable) { int ret; zend_string *s1, *s2; @@ -95,7 +102,7 @@ PHP_METHOD(Spoofchecker, areConfusable) /* }}} */ /* {{{ Locales to use when running checks */ -PHP_METHOD(Spoofchecker, setAllowedLocales) +U_CFUNC PHP_METHOD(Spoofchecker, setAllowedLocales) { zend_string *locales; SPOOFCHECKER_METHOD_INIT_VARS; @@ -116,7 +123,7 @@ PHP_METHOD(Spoofchecker, setAllowedLocales) /* }}} */ /* {{{ Set the checks to run */ -PHP_METHOD(Spoofchecker, setChecks) +U_CFUNC PHP_METHOD(Spoofchecker, setChecks) { zend_long checks; SPOOFCHECKER_METHOD_INIT_VARS; @@ -137,7 +144,7 @@ PHP_METHOD(Spoofchecker, setChecks) #if U_ICU_VERSION_MAJOR_NUM >= 58 /* {{{ Set the loosest restriction level allowed for strings. */ -PHP_METHOD(Spoofchecker, setRestrictionLevel) +U_CFUNC PHP_METHOD(Spoofchecker, setRestrictionLevel) { zend_long level; SPOOFCHECKER_METHOD_INIT_VARS; @@ -165,7 +172,7 @@ PHP_METHOD(Spoofchecker, setRestrictionLevel) /* }}} */ #endif -PHP_METHOD(Spoofchecker, setAllowedChars) +U_CFUNC PHP_METHOD(Spoofchecker, setAllowedChars) { zend_string *pattern; UChar *upattern = NULL;