Skip to content

Commit 140fc69

Browse files
authored
ext/intl: update from C to C++ step2. (#19294)
1 parent c5143c0 commit 140fc69

13 files changed

+87
-41
lines changed

ext/intl/config.m4

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,6 @@ if test "$PHP_INTL" != "no"; then
3636
intl_convert.c
3737
intl_error.c
3838
listformatter/listformatter_class.c
39-
msgformat/msgformat_attr.c
40-
msgformat/msgformat_class.c
41-
msgformat/msgformat_data.c
42-
msgformat/msgformat_format.c
43-
msgformat/msgformat_parse.c
44-
msgformat/msgformat.c
45-
normalizer/normalizer_class.c
46-
normalizer/normalizer_normalize.c
4739
php_intl.c
4840
resourcebundle/resourcebundle_class.c
4941
resourcebundle/resourcebundle_iterator.c
@@ -73,6 +65,14 @@ if test "$PHP_INTL" != "no"; then
7365
calendar/calendar_class.cpp \
7466
calendar/calendar_methods.cpp \
7567
calendar/gregoriancalendar_methods.cpp \
68+
msgformat/msgformat_attr.cpp \
69+
msgformat/msgformat_class.cpp \
70+
msgformat/msgformat_data.cpp \
71+
msgformat/msgformat_format.cpp \
72+
msgformat/msgformat_parse.cpp \
73+
msgformat/msgformat.cpp \
74+
normalizer/normalizer_class.cpp \
75+
normalizer/normalizer_normalize.cpp \
7676
breakiterator/breakiterator_class.cpp \
7777
breakiterator/breakiterator_iterators.cpp \
7878
breakiterator/breakiterator_methods.cpp \

ext/intl/config.w32

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,20 @@ if (PHP_INTL != "no") {
4848
locale_methods.cpp \
4949
", "intl");
5050
ADD_SOURCES(configure_module_dirname + "/msgformat", "\
51-
msgformat.c \
52-
msgformat_attr.c \
53-
msgformat_class.c \
54-
msgformat_data.c \
55-
msgformat_format.c \
51+
msgformat.cpp \
52+
msgformat_attr.cpp \
53+
msgformat_class.cpp \
54+
msgformat_data.cpp \
55+
msgformat_format.cpp \
5656
msgformat_helpers.cpp \
57-
msgformat_parse.c \
57+
msgformat_parse.cpp \
5858
", "intl");
5959
ADD_SOURCES(configure_module_dirname + "/grapheme", "\
6060
grapheme_string.c grapheme_util.c \
6161
", "intl");
6262
ADD_SOURCES(configure_module_dirname + "/normalizer", "\
63-
normalizer_class.c \
64-
normalizer_normalize.c \
63+
normalizer_class.cpp \
64+
normalizer_normalize.cpp \
6565
", "intl");
6666
ADD_SOURCES(configure_module_dirname + "/dateformat", "\
6767
dateformat.c \

ext/intl/locale/locale_methods.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -936,7 +936,7 @@ static int handleAppendResult( int result, smart_str* loc_name)
936936
* }}} */
937937
U_CFUNC PHP_FUNCTION(locale_compose)
938938
{
939-
smart_str loc_name_s = {0};
939+
smart_str loc_name_s = {NULL, 0};
940940
smart_str *loc_name = &loc_name_s;
941941
zval* arr = NULL;
942942
HashTable* hash_arr = NULL;

ext/intl/msgformat/msgformat.c renamed to ext/intl/msgformat/msgformat.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@
1919
#include <unicode/ustring.h>
2020
#include <unicode/umsg.h>
2121

22+
extern "C" {
2223
#include "php_intl.h"
2324
#include "msgformat_class.h"
2425
#include "msgformat_data.h"
2526
#include "intl_convert.h"
27+
}
2628

2729
/* {{{ */
2830
static int msgfmt_ctor(INTERNAL_FUNCTION_PARAMETERS)
@@ -99,7 +101,7 @@ static int msgfmt_ctor(INTERNAL_FUNCTION_PARAMETERS)
99101
/* }}} */
100102

101103
/* {{{ Create formatter. */
102-
PHP_FUNCTION( msgfmt_create )
104+
U_CFUNC PHP_FUNCTION( msgfmt_create )
103105
{
104106
object_init_ex( return_value, MessageFormatter_ce_ptr );
105107
if (msgfmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU) == FAILURE) {
@@ -110,7 +112,7 @@ PHP_FUNCTION( msgfmt_create )
110112
/* }}} */
111113

112114
/* {{{ MessageFormatter object constructor. */
113-
PHP_METHOD( MessageFormatter, __construct )
115+
U_CFUNC PHP_METHOD( MessageFormatter, __construct )
114116
{
115117
const bool old_use_exception = INTL_G(use_exceptions);
116118
const zend_long old_error_level = INTL_G(error_level);
@@ -127,7 +129,7 @@ PHP_METHOD( MessageFormatter, __construct )
127129
/* }}} */
128130

129131
/* {{{ Get formatter's last error code. */
130-
PHP_FUNCTION( msgfmt_get_error_code )
132+
U_CFUNC PHP_FUNCTION( msgfmt_get_error_code )
131133
{
132134
zval* object = NULL;
133135
MessageFormatter_object* mfo = NULL;
@@ -147,7 +149,7 @@ PHP_FUNCTION( msgfmt_get_error_code )
147149
/* }}} */
148150

149151
/* {{{ Get text description for formatter's last error code. */
150-
PHP_FUNCTION( msgfmt_get_error_message )
152+
U_CFUNC PHP_FUNCTION( msgfmt_get_error_message )
151153
{
152154
zend_string* message = NULL;
153155
zval* object = NULL;

ext/intl/msgformat/msgformat_attr.c renamed to ext/intl/msgformat/msgformat_attr.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,17 @@
1616
#include <config.h>
1717
#endif
1818

19+
extern "C" {
1920
#include "php_intl.h"
2021
#include "msgformat_class.h"
2122
#include "msgformat_data.h"
2223
#include "intl_convert.h"
24+
}
2325

2426
#include <unicode/ustring.h>
2527

2628
/* {{{ Get formatter pattern. */
27-
PHP_FUNCTION( msgfmt_get_pattern )
29+
U_CFUNC PHP_FUNCTION( msgfmt_get_pattern )
2830
{
2931
MSG_FORMAT_METHOD_INIT_VARS;
3032

@@ -46,7 +48,7 @@ PHP_FUNCTION( msgfmt_get_pattern )
4648
/* }}} */
4749

4850
/* {{{ Set formatter pattern. */
49-
PHP_FUNCTION( msgfmt_set_pattern )
51+
U_CFUNC PHP_FUNCTION( msgfmt_set_pattern )
5052
{
5153
char* value = NULL;
5254
size_t value_len = 0;
@@ -105,7 +107,7 @@ PHP_FUNCTION( msgfmt_set_pattern )
105107
/* }}} */
106108

107109
/* {{{ Get formatter locale. */
108-
PHP_FUNCTION( msgfmt_get_locale )
110+
U_CFUNC PHP_FUNCTION( msgfmt_get_locale )
109111
{
110112
char *loc;
111113
MSG_FORMAT_METHOD_INIT_VARS;

ext/intl/msgformat/msgformat_class.c renamed to ext/intl/msgformat/msgformat_class.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@
1414

1515
#include <unicode/unum.h>
1616

17+
extern "C" {
1718
#include "msgformat_class.h"
1819
#include "php_intl.h"
1920
#include "msgformat_data.h"
2021
#include "msgformat_arginfo.h"
22+
}
2123

2224
#include <zend_exceptions.h>
2325

@@ -29,7 +31,7 @@ static zend_object_handlers MessageFormatter_handlers;
2931
*/
3032

3133
/* {{{ MessageFormatter_objects_free */
32-
void MessageFormatter_object_free( zend_object *object )
34+
U_CFUNC void MessageFormatter_object_free( zend_object *object )
3335
{
3436
MessageFormatter_object* mfo = php_intl_messageformatter_fetch_object(object);
3537

@@ -40,11 +42,11 @@ void MessageFormatter_object_free( zend_object *object )
4042
/* }}} */
4143

4244
/* {{{ MessageFormatter_object_create */
43-
zend_object *MessageFormatter_object_create(zend_class_entry *ce)
45+
U_CFUNC zend_object *MessageFormatter_object_create(zend_class_entry *ce)
4446
{
4547
MessageFormatter_object* intern;
4648

47-
intern = zend_object_alloc(sizeof(MessageFormatter_object), ce);
49+
intern = reinterpret_cast<MessageFormatter_object *>(zend_object_alloc(sizeof(MessageFormatter_object), ce));
4850
msgformat_data_init( &intern->mf_data );
4951
zend_object_std_init( &intern->zo, ce );
5052
object_properties_init(&intern->zo, ce);
@@ -54,7 +56,7 @@ zend_object *MessageFormatter_object_create(zend_class_entry *ce)
5456
/* }}} */
5557

5658
/* {{{ MessageFormatter_object_clone */
57-
zend_object *MessageFormatter_object_clone(zend_object *object)
59+
U_CFUNC zend_object *MessageFormatter_object_clone(zend_object *object)
5860
{
5961
MessageFormatter_object *mfo = php_intl_messageformatter_fetch_object(object);
6062
zend_object *new_obj = MessageFormatter_ce_ptr->create_object(object->ce);
@@ -66,7 +68,7 @@ zend_object *MessageFormatter_object_clone(zend_object *object)
6668
/* clone formatter object */
6769
if (MSG_FORMAT_OBJECT(mfo) != NULL) {
6870
UErrorCode error = U_ZERO_ERROR;
69-
MSG_FORMAT_OBJECT(new_mfo) = umsg_clone(MSG_FORMAT_OBJECT(mfo), &error);
71+
MSG_FORMAT_OBJECT(new_mfo) = reinterpret_cast<UMessageFormat *>(umsg_clone(MSG_FORMAT_OBJECT(mfo), &error));
7072

7173
if (U_FAILURE(error)) {
7274
zend_throw_error(NULL, "Failed to clone MessageFormatter");

ext/intl/msgformat/msgformat_data.c renamed to ext/intl/msgformat/msgformat_data.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
/* {{{ void msgformat_data_init( msgformat_data* mf_data )
2525
* Initialize internals of msgformat_data.
2626
*/
27-
void msgformat_data_init( msgformat_data* mf_data )
27+
U_CFUNC void msgformat_data_init( msgformat_data* mf_data )
2828
{
2929
if( !mf_data )
3030
return;
@@ -40,7 +40,7 @@ void msgformat_data_init( msgformat_data* mf_data )
4040
/* {{{ void msgformat_data_free( msgformat_data* mf_data )
4141
* Clean up memory allocated for msgformat_data
4242
*/
43-
void msgformat_data_free(msgformat_data* mf_data)
43+
U_CFUNC void msgformat_data_free(msgformat_data* mf_data)
4444
{
4545
if (!mf_data)
4646
return;
@@ -69,7 +69,7 @@ void msgformat_data_free(msgformat_data* mf_data)
6969
*/
7070
msgformat_data* msgformat_data_create( void )
7171
{
72-
msgformat_data* mf_data = ecalloc( 1, sizeof(msgformat_data) );
72+
msgformat_data* mf_data = reinterpret_cast<msgformat_data *>(ecalloc( 1, sizeof(msgformat_data) ));
7373

7474
msgformat_data_init( mf_data );
7575

ext/intl/msgformat/msgformat_data.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,13 @@
1717

1818
#include <php.h>
1919

20+
#ifdef __cplusplus
21+
extern "C" {
22+
#endif
2023
#include "../intl_error.h"
24+
#ifdef __cplusplus
25+
}
26+
#endif
2127

2228
#include <unicode/umsg.h>
2329

@@ -26,16 +32,22 @@ typedef struct {
2632
intl_error error;
2733

2834
// formatter handling
29-
UMessageFormat* umsgf;
35+
UMessageFormat *umsgf;
3036
char* orig_format;
3137
zend_ulong orig_format_len;
3238
HashTable* arg_types;
3339
int tz_set; /* if we've already the time zone in sub-formats */
3440
} msgformat_data;
3541

42+
#ifdef __cplusplus
43+
extern "C" {
44+
#endif
3645
msgformat_data* msgformat_data_create( void );
3746
void msgformat_data_init( msgformat_data* mf_data );
3847
void msgformat_data_free( msgformat_data* mf_data );
48+
#ifdef __cplusplus
49+
}
50+
#endif
3951

4052
#ifdef MSG_FORMAT_QUOTE_APOS
4153
int msgformat_fix_quotes(UChar **spattern, uint32_t *spattern_len, UErrorCode *ec);

ext/intl/msgformat/msgformat_format.c renamed to ext/intl/msgformat/msgformat_format.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@
1818

1919
#include <unicode/ustring.h>
2020

21+
extern "C" {
2122
#include "php_intl.h"
2223
#include "msgformat_class.h"
2324
#include "msgformat_data.h"
2425
#include "msgformat_helpers.h"
2526
#include "intl_convert.h"
27+
}
2628

2729
#ifndef Z_ADDREF_P
2830
#define Z_ADDREF_P(z) ((z)->refcount++)
@@ -48,7 +50,7 @@ static void msgfmt_do_format(MessageFormatter_object *mfo, zval *args, zval *ret
4850
/* }}} */
4951

5052
/* {{{ Format a message. */
51-
PHP_FUNCTION( msgfmt_format )
53+
U_CFUNC PHP_FUNCTION( msgfmt_format )
5254
{
5355
zval *args;
5456
MSG_FORMAT_METHOD_INIT_VARS;
@@ -69,7 +71,7 @@ PHP_FUNCTION( msgfmt_format )
6971
/* }}} */
7072

7173
/* {{{ Format a message. */
72-
PHP_FUNCTION( msgfmt_format_message )
74+
U_CFUNC PHP_FUNCTION( msgfmt_format_message )
7375
{
7476
zval *args;
7577
UChar *spattern = NULL;

ext/intl/msgformat/msgformat_parse.c renamed to ext/intl/msgformat/msgformat_parse.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@
1818

1919
#include <unicode/ustring.h>
2020

21+
extern "C" {
2122
#include "php_intl.h"
2223
#include "msgformat_class.h"
2324
#include "msgformat_data.h"
2425
#include "msgformat_helpers.h"
2526
#include "intl_convert.h"
27+
}
2628

2729
/* {{{ */
2830
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
5254
/* }}} */
5355

5456
/* {{{ Parse a message */
55-
PHP_FUNCTION( msgfmt_parse )
57+
U_CFUNC PHP_FUNCTION( msgfmt_parse )
5658
{
5759
char *source;
5860
size_t source_len;
@@ -74,7 +76,7 @@ PHP_FUNCTION( msgfmt_parse )
7476
/* }}} */
7577

7678
/* {{{ Parse a message. */
77-
PHP_FUNCTION( msgfmt_parse_message )
79+
U_CFUNC PHP_FUNCTION( msgfmt_parse_message )
7880
{
7981
UChar *spattern = NULL;
8082
int spattern_len = 0;

0 commit comments

Comments
 (0)