Skip to content

Commit 4c29f86

Browse files
committed
ext/intl: migrate C to C++ code step 5.
1 parent 5ab594c commit 4c29f86

18 files changed

+136
-62
lines changed

ext/intl/common/common_error.c renamed to ext/intl/common/common_error.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@
1717
#include <config.h>
1818
#endif
1919

20+
extern "C" {
2021
#include "php_intl.h"
2122
#include "intl_error.h"
23+
}
2224

2325
/* {{{ Get code of the last occurred error. */
24-
PHP_FUNCTION( intl_get_error_code )
26+
U_CFUNC PHP_FUNCTION( intl_get_error_code )
2527
{
2628
ZEND_PARSE_PARAMETERS_NONE();
2729

@@ -30,7 +32,7 @@ PHP_FUNCTION( intl_get_error_code )
3032
/* }}} */
3133

3234
/* {{{ Get text description of the last occurred error. */
33-
PHP_FUNCTION( intl_get_error_message )
35+
U_CFUNC PHP_FUNCTION( intl_get_error_message )
3436
{
3537
ZEND_PARSE_PARAMETERS_NONE();
3638

@@ -42,29 +44,29 @@ PHP_FUNCTION( intl_get_error_message )
4244
* Returns true if it does, and false if the code
4345
* indicates success or a warning.
4446
*/
45-
PHP_FUNCTION( intl_is_failure )
47+
U_CFUNC PHP_FUNCTION( intl_is_failure )
4648
{
4749
zend_long err_code;
4850

4951
ZEND_PARSE_PARAMETERS_START(1, 1)
5052
Z_PARAM_LONG(err_code)
5153
ZEND_PARSE_PARAMETERS_END();
5254

53-
RETURN_BOOL( U_FAILURE( err_code ) );
55+
RETURN_BOOL( U_FAILURE( static_cast<UErrorCode>(err_code) ) );
5456
}
5557
/* }}} */
5658

5759
/* {{{ Return a string for a given error code.
5860
* The string will be the same as the name of the error code constant.
5961
*/
60-
PHP_FUNCTION( intl_error_name )
62+
U_CFUNC PHP_FUNCTION( intl_error_name )
6163
{
6264
zend_long err_code;
6365

6466
ZEND_PARSE_PARAMETERS_START(1, 1)
6567
Z_PARAM_LONG(err_code)
6668
ZEND_PARSE_PARAMETERS_END();
6769

68-
RETURN_STRING( (char*)u_errorName( err_code ) );
70+
RETURN_STRING( (char*)u_errorName( static_cast<UErrorCode>(err_code) ) );
6971
}
7072
/* }}} */

ext/intl/config.m4

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,9 @@ if test "$PHP_INTL" != "no"; then
88
PHP_SUBST([INTL_SHARED_LIBADD])
99
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"
1010
PHP_NEW_EXTENSION([intl], m4_normalize([
11-
common/common_error.c
12-
dateformat/dateformat_class.c
13-
formatter/formatter_class.c
1411
intl_convert.c
1512
intl_error.c
1613
php_intl.c
17-
resourcebundle/resourcebundle_class.c
18-
resourcebundle/resourcebundle_iterator.c
19-
resourcebundle/resourcebundle.c
20-
spoofchecker/spoofchecker_class.c
21-
spoofchecker/spoofchecker_create.c
22-
spoofchecker/spoofchecker_main.c
2314
]),
2415
[$ext_shared],,
2516
[$INTL_COMMON_FLAGS],
@@ -37,6 +28,8 @@ if test "$PHP_INTL" != "no"; then
3728
collator/collator_sort.cpp \
3829
common/common_enum.cpp \
3930
common/common_date.cpp \
31+
common/common_error.cpp \
32+
dateformat/dateformat_class.cpp \
4033
converter/converter.cpp \
4134
dateformat/dateformat.cpp \
4235
dateformat/dateformat_attr.cpp \
@@ -49,6 +42,7 @@ if test "$PHP_INTL" != "no"; then
4942
dateformat/dateformat_parse.cpp \
5043
dateformat/datepatterngenerator_class.cpp \
5144
dateformat/datepatterngenerator_methods.cpp \
45+
formatter/formatter_class.cpp \
5246
grapheme/grapheme_string.cpp \
5347
grapheme/grapheme_util.cpp \
5448
msgformat/msgformat_helpers.cpp \
@@ -84,6 +78,12 @@ if test "$PHP_INTL" != "no"; then
8478
locale/locale_class.cpp \
8579
locale/locale_methods.cpp \
8680
locale/locale.cpp \
81+
resourcebundle/resourcebundle_class.cpp \
82+
resourcebundle/resourcebundle_iterator.cpp \
83+
resourcebundle/resourcebundle.cpp \
84+
spoofchecker/spoofchecker_class.cpp \
85+
spoofchecker/spoofchecker_create.cpp \
86+
spoofchecker/spoofchecker_main.cpp \
8787
uchar/uchar.cpp"
8888

8989
PHP_REQUIRE_CXX()

ext/intl/config.w32

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ if (PHP_INTL != "no") {
2424
collator_sort.cpp \
2525
", "intl");
2626
ADD_SOURCES(configure_module_dirname + "/common", "\
27-
common_error.c \
27+
common_error.cpp \
2828
common_enum.cpp \
2929
common_date.cpp \
3030
", "intl");
@@ -33,7 +33,7 @@ if (PHP_INTL != "no") {
3333
", "intl");
3434
ADD_SOURCES(configure_module_dirname + "/formatter", "\
3535
formatter_attr.cpp \
36-
formatter_class.c \
36+
formatter_class.cpp \
3737
formatter_data.cpp \
3838
formatter_format.cpp \
3939
formatter_main.cpp \
@@ -68,7 +68,7 @@ if (PHP_INTL != "no") {
6868
", "intl");
6969
ADD_SOURCES(configure_module_dirname + "/dateformat", "\
7070
dateformat.cpp \
71-
dateformat_class.c \
71+
dateformat_class.cpp \
7272
dateformat_attr.cpp \
7373
dateformat_format.cpp \
7474
dateformat_format_object.cpp \
@@ -87,16 +87,16 @@ if (PHP_INTL != "no") {
8787
idn.cpp",
8888
"intl");
8989
ADD_SOURCES(configure_module_dirname + "/resourcebundle", "\
90-
resourcebundle.c \
91-
resourcebundle_class.c \
92-
resourcebundle_iterator.c",
90+
resourcebundle.cpp \
91+
resourcebundle_class.cpp \
92+
resourcebundle_iterator.cpp",
9393
"intl");
9494

9595
if (CHECK_HEADER_ADD_INCLUDE("unicode/uspoof.h", "CFLAGS_INTL")) {
9696
ADD_SOURCES(configure_module_dirname + "/spoofchecker", "\
97-
spoofchecker_class.c \
98-
spoofchecker_create.c \
99-
spoofchecker_main.c",
97+
spoofchecker_class.cpp \
98+
spoofchecker_create.cpp \
99+
spoofchecker_main.cpp",
100100
"intl");
101101
}
102102

ext/intl/dateformat/dateformat_class.c renamed to ext/intl/dateformat/dateformat_class.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@
1111
| Authors: Kirti Velankar <kirtig@yahoo-inc.com> |
1212
+----------------------------------------------------------------------+
1313
*/
14-
#include <unicode/unum.h>
14+
#include <unicode/udat.h>
1515

16+
extern "C" {
1617
#include "dateformat_class.h"
1718
#include "php_intl.h"
1819
#include "dateformat_data.h"
1920
#include "dateformat.h"
2021
#include "dateformat_arginfo.h"
22+
}
2123

2224
#include <zend_exceptions.h>
2325

@@ -48,7 +50,7 @@ zend_object *IntlDateFormatter_object_create(zend_class_entry *ce)
4850
{
4951
IntlDateFormatter_object* intern;
5052

51-
intern = zend_object_alloc(sizeof(IntlDateFormatter_object), ce);
53+
intern = reinterpret_cast<IntlDateFormatter_object *>(zend_object_alloc(sizeof(IntlDateFormatter_object), ce));
5254
dateformat_data_init( &intern->datef_data );
5355
zend_object_std_init( &intern->zo, ce );
5456
object_properties_init(&intern->zo, ce);

ext/intl/dateformat/dateformat_class.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,15 @@
1616

1717
#include <php.h>
1818

19+
#ifdef __cplusplus
20+
extern "C" {
21+
#endif
1922
#include "intl_common.h"
2023
#include "intl_error.h"
2124
#include "intl_data.h"
25+
#ifdef __cplusplus
26+
}
27+
#endif
2228
#include "dateformat_data.h"
2329

2430
typedef struct {

ext/intl/dateformat/dateformat_format.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#endif
1818

1919
#include <unicode/ustring.h>
20-
#include <unicode/ucal.h>
20+
#include <unicode/unum.h>
2121

2222
extern "C" {
2323
#include "../php_intl.h"

ext/intl/formatter/formatter_class.c renamed to ext/intl/formatter/formatter_class.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,19 @@
1515
#include <unicode/unum.h>
1616

1717
#include "formatter_class.h"
18+
extern "C" {
1819
#include "php_intl.h"
1920
#include "formatter_data.h"
2021
#include "formatter_format.h"
22+
}
2123

2224
#include <zend_exceptions.h>
2325
#include "Zend/zend_attributes.h"
2426
#include "Zend/zend_interfaces.h"
2527

28+
extern "C" {
2629
#include "formatter_arginfo.h"
30+
}
2731

2832
zend_class_entry *NumberFormatter_ce_ptr = NULL;
2933
static zend_object_handlers NumberFormatter_handlers;
@@ -33,7 +37,7 @@ static zend_object_handlers NumberFormatter_handlers;
3337
*/
3438

3539
/* {{{ NumberFormatter_objects_free */
36-
void NumberFormatter_object_free( zend_object *object )
40+
U_CFUNC void NumberFormatter_object_free( zend_object *object )
3741
{
3842
NumberFormatter_object* nfo = php_intl_number_format_fetch_object(object);
3943

@@ -44,11 +48,11 @@ void NumberFormatter_object_free( zend_object *object )
4448
/* }}} */
4549

4650
/* {{{ NumberFormatter_object_create */
47-
zend_object *NumberFormatter_object_create(zend_class_entry *ce)
51+
U_CFUNC zend_object *NumberFormatter_object_create(zend_class_entry *ce)
4852
{
4953
NumberFormatter_object* intern;
5054

51-
intern = zend_object_alloc(sizeof(NumberFormatter_object), ce);
55+
intern = reinterpret_cast<NumberFormatter_object *>(zend_object_alloc(sizeof(NumberFormatter_object), ce));
5256
formatter_data_init( &intern->nf_data );
5357
zend_object_std_init( &intern->zo, ce );
5458
object_properties_init(&intern->zo, ce);
@@ -58,7 +62,7 @@ zend_object *NumberFormatter_object_create(zend_class_entry *ce)
5862
/* }}} */
5963

6064
/* {{{ NumberFormatter_object_clone */
61-
zend_object *NumberFormatter_object_clone(zend_object *object)
65+
U_CFUNC zend_object *NumberFormatter_object_clone(zend_object *object)
6266
{
6367
NumberFormatter_object *nfo = php_intl_number_format_fetch_object(object);
6468
zend_object *new_obj = NumberFormatter_ce_ptr->create_object(object->ce);
@@ -88,7 +92,7 @@ zend_object *NumberFormatter_object_clone(zend_object *object)
8892
/* {{{ formatter_register_class
8993
* Initialize 'NumberFormatter' class
9094
*/
91-
void formatter_register_class( void )
95+
U_CFUNC void formatter_register_class( void )
9296
{
9397
/* Create and register 'NumberFormatter' class. */
9498
NumberFormatter_ce_ptr = register_class_NumberFormatter();

ext/intl/formatter/formatter_class.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ extern "C" {
2323
#include "intl_common.h"
2424
#include "intl_error.h"
2525
#include "intl_data.h"
26+
#include "formatter_data.h"
2627
#ifdef __cplusplus
2728
}
2829
#endif
29-
#include "formatter_data.h"
3030

3131
typedef struct {
3232
formatter_data nf_data;

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@
1717
#include <zend.h>
1818
#include <zend_API.h>
1919

20+
extern "C" {
2021
#include "intl_convert.h"
2122
#include "intl_data.h"
2223
#include "resourcebundle/resourcebundle_class.h"
24+
}
2325

2426
/* {{{ ResourceBundle_extract_value */
25-
void resourcebundle_extract_value( zval *return_value, ResourceBundle_object *source )
27+
U_CFUNC void resourcebundle_extract_value( zval *return_value, ResourceBundle_object *source )
2628
{
2729
UResType restype;
2830
const UChar* ufield;

ext/intl/resourcebundle/resourcebundle.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@
2121

2222
#include "resourcebundle/resourcebundle_class.h"
2323

24+
#ifdef __cplusplus
25+
extern "C" {
26+
#endif
2427
void resourcebundle_extract_value( zval *target, ResourceBundle_object *source);
28+
#ifdef __cplusplus
29+
}
30+
#endif
2531

2632
#endif // #ifndef RESOURCEBUNDLE_CLASS_H

0 commit comments

Comments
 (0)