]> granicus.if.org Git - php/commitdiff
- Fixed bug #48200 (compile failure with mbstring.c when --enable-zend-multibyte...
authorJani Taskinen <jani@php.net>
Sun, 10 May 2009 21:04:26 +0000 (21:04 +0000)
committerJani Taskinen <jani@php.net>
Sun, 10 May 2009 21:04:26 +0000 (21:04 +0000)
15 files changed:
ext/mbstring/mbstring.c
ext/mbstring/tests/zend_multibyte-01.phpt [new file with mode: 0644]
ext/mbstring/tests/zend_multibyte-02.phpt [new file with mode: 0644]
ext/mbstring/tests/zend_multibyte-03.phpt [new file with mode: 0644]
ext/mbstring/tests/zend_multibyte-04.phpt [new file with mode: 0644]
ext/mbstring/tests/zend_multibyte-05.phpt [new file with mode: 0644]
ext/mbstring/tests/zend_multibyte-06.phpt [new file with mode: 0644]
ext/mbstring/tests/zend_multibyte-07.phpt [new file with mode: 0644]
ext/mbstring/tests/zend_multibyte-08.phpt [new file with mode: 0644]
ext/mbstring/tests/zend_multibyte-09.phpt [new file with mode: 0644]
ext/mbstring/tests/zend_multibyte-10.phpt [new file with mode: 0644]
ext/mbstring/tests/zend_multibyte-11.phpt [new file with mode: 0644]
ext/mbstring/tests/zend_multibyte-12.phpt [new file with mode: 0644]
ext/mbstring/tests/zend_multibyte-13.phpt [new file with mode: 0644]
ext/mbstring/tests/zend_multibyte-14.phpt [new file with mode: 0644]

index c73b9d8f936ca5defee1ad34b9af3e137012d4c5..f8ca92a920e54dccbf1d09e66d53f19c4c235b9d 100644 (file)
 
 /* {{{ prototypes */
 ZEND_DECLARE_MODULE_GLOBALS(mbstring)
+
 static PHP_GINIT_FUNCTION(mbstring);
 static PHP_GSHUTDOWN_FUNCTION(mbstring);
+
+static size_t php_mb_oddlen(const unsigned char *string, size_t length, const char *encoding TSRMLS_DC);
+static int php_mb_encoding_converter(unsigned char **to, size_t *to_length, const unsigned char *from, size_t from_length, const char *encoding_to, const char *encoding_from TSRMLS_DC);
+static char* php_mb_encoding_detector(const unsigned char *arg_string, size_t arg_length, char *arg_list TSRMLS_DC);
+static int php_mb_set_zend_encoding(TSRMLS_D);
 /* }}} */
 
 /* {{{ php_mb_default_identify_list */
@@ -866,7 +872,7 @@ static void _php_mb_free_regex(void *opaque);
 
 #if HAVE_ONIG
 /* {{{ _php_mb_compile_regex */
-void *_php_mb_compile_regex(const char *pattern TSRMLS_DC)
+static void *_php_mb_compile_regex(const char *pattern TSRMLS_DC)
 {
        php_mb_regex_t *retval;
        OnigErrorInfo err_info;
@@ -887,7 +893,7 @@ void *_php_mb_compile_regex(const char *pattern TSRMLS_DC)
 /* }}} */
 
 /* {{{ _php_mb_match_regex */
-int _php_mb_match_regex(void *opaque, const char *str, size_t str_len)
+static int _php_mb_match_regex(void *opaque, const char *str, size_t str_len)
 {
        return onig_search((php_mb_regex_t *)opaque, (const OnigUChar *)str,
                        (const OnigUChar*)str + str_len, (const OnigUChar *)str,
@@ -896,14 +902,14 @@ int _php_mb_match_regex(void *opaque, const char *str, size_t str_len)
 /* }}} */
 
 /* {{{ _php_mb_free_regex */
-void _php_mb_free_regex(void *opaque)
+static void _php_mb_free_regex(void *opaque)
 {
        onig_free((php_mb_regex_t *)opaque);
 }
 /* }}} */
 #elif HAVE_PCRE || HAVE_BUNDLED_PCRE
 /* {{{ _php_mb_compile_regex */
-void *_php_mb_compile_regex(const char *pattern TSRMLS_DC)
+static void *_php_mb_compile_regex(const char *pattern TSRMLS_DC)
 {
        pcre *retval;
        const char *err_str;
@@ -918,7 +924,7 @@ void *_php_mb_compile_regex(const char *pattern TSRMLS_DC)
 /* }}} */
 
 /* {{{ _php_mb_match_regex */
-int _php_mb_match_regex(void *opaque, const char *str, size_t str_len)
+static int _php_mb_match_regex(void *opaque, const char *str, size_t str_len)
 {
        return pcre_exec((pcre *)opaque, NULL, str, (int)str_len, 0,
                        0, NULL, 0) >= 0;
@@ -926,7 +932,7 @@ int _php_mb_match_regex(void *opaque, const char *str, size_t str_len)
 /* }}} */
 
 /* {{{ _php_mb_free_regex */
-void _php_mb_free_regex(void *opaque)
+static void _php_mb_free_regex(void *opaque)
 {
        pcre_free(opaque);
 }
@@ -4714,7 +4720,6 @@ MBSTRING_API int php_mb_stripos(int mode, const char *old_haystack, unsigned int
 /* }}} */
 
 #ifdef ZEND_MULTIBYTE
-
 /* {{{ php_mb_set_zend_encoding() */
 static int php_mb_set_zend_encoding(TSRMLS_D)
 {
@@ -4806,9 +4811,7 @@ static char* php_mb_encoding_detector(const unsigned char *arg_string, size_t ar
 /* }}} */
 
 /*     {{{ int php_mb_encoding_converter() */
-static int php_mb_encoding_converter(unsigned char **to, size_t *to_length,
-               const unsigned char *from, size_t from_length,
-               const char *encoding_to, const char *encoding_from TSRMLS_DC)
+static int php_mb_encoding_converter(unsigned char **to, size_t *to_length, const unsigned char *from, size_t from_length, const char *encoding_to, const char *encoding_from TSRMLS_DC)
 {
        mbfl_string string, result, *ret;
        enum mbfl_no_encoding from_encoding, to_encoding;
diff --git a/ext/mbstring/tests/zend_multibyte-01.phpt b/ext/mbstring/tests/zend_multibyte-01.phpt
new file mode 100644 (file)
index 0000000..d96e0f0
--- /dev/null
@@ -0,0 +1,23 @@
+--TEST--
+zend multibyte (1)
+--SKIPIF--
+<?php
+ini_set("mbstring.script_encoding","SJIS");
+if (ini_set("mbstring.script_encoding","SJIS") != "SJIS") {
+       die("skip zend-multibyte is not available");
+}
+?>
+--INI--
+mbstring.script_encoding=Shift_JIS
+mbstring.internal_encoding=Shift_JIS
+--FILE--
+<?php
+       function \97\\8e\\94\($\88ø\90\94)
+       {
+               echo $\88ø\90\94;
+       }
+
+       \97\\8e\\94\("\83h\83\8c\83~\83t\83@\83\");
+?>
+--EXPECT--
+\83h\83\8c\83~\83t\83@\83\
diff --git a/ext/mbstring/tests/zend_multibyte-02.phpt b/ext/mbstring/tests/zend_multibyte-02.phpt
new file mode 100644 (file)
index 0000000..c94dee5
--- /dev/null
@@ -0,0 +1,18 @@
+--TEST--
+zend multibyte (2)
+--SKIPIF--
+<?php
+ini_set("mbstring.script_encoding","SJIS");
+if (ini_set("mbstring.script_encoding","SJIS") != "SJIS") {
+       die("skip zend-multibyte is not available");
+}
+?>
+--INI--
+mbstring.script_encoding=UTF-8
+mbstring.internal_encoding=CP932
+--FILE--
+<?php
+var_dump(bin2hex("テスト"));
+?>
+--EXPECT--
+string(12) "836583588367"
diff --git a/ext/mbstring/tests/zend_multibyte-03.phpt b/ext/mbstring/tests/zend_multibyte-03.phpt
new file mode 100644 (file)
index 0000000..46a262c
--- /dev/null
@@ -0,0 +1,18 @@
+--TEST--
+zend multibyte (3)
+--SKIPIF--
+<?php
+ini_set("mbstring.script_encoding","SJIS");
+if (ini_set("mbstring.script_encoding","SJIS") != "SJIS") {
+       die("skip zend-multibyte is not available");
+}
+?>
+--INI--
+mbstring.script_encoding=UTF-8
+mbstring.internal_encoding=EUC-JP
+--FILE--
+<?php
+var_dump(bin2hex("テスト"));
+?>
+--EXPECT--
+string(12) "a5c6a5b9a5c8"
diff --git a/ext/mbstring/tests/zend_multibyte-04.phpt b/ext/mbstring/tests/zend_multibyte-04.phpt
new file mode 100644 (file)
index 0000000..f1295b6
--- /dev/null
@@ -0,0 +1,18 @@
+--TEST--
+zend multibyte (4)
+--SKIPIF--
+<?php
+ini_set("mbstring.script_encoding","SJIS");
+if (ini_set("mbstring.script_encoding","SJIS") != "SJIS") {
+       die("skip zend-multibyte is not available");
+}
+?>
+--INI--
+mbstring.script_encoding=CP932
+mbstring.internal_encoding=UTF-8
+--FILE--
+<?php
+var_dump(bin2hex("\83e\83X\83g"));
+?>
+--EXPECT--
+string(18) "e38386e382b9e38388"
diff --git a/ext/mbstring/tests/zend_multibyte-05.phpt b/ext/mbstring/tests/zend_multibyte-05.phpt
new file mode 100644 (file)
index 0000000..0a01c23
--- /dev/null
@@ -0,0 +1,21 @@
+--TEST--
+zend multibyte (5)
+--SKIPIF--
+<?php
+ini_set("mbstring.script_encoding","SJIS");
+if (ini_set("mbstring.script_encoding","SJIS") != "SJIS") {
+       die("skip zend-multibyte is not available");
+}
+?>
+--INI--
+mbstring.script_encoding=EUC-JP
+mbstring.internal_encoding=UTF-8
+--FILE--
+<?php
+// forcefully interpret an UTF-8 encoded string as EUC-JP and then convert it
+// back to UTF-8. There should be only a pair of consecutive bytes that is
+// valid EUC-encoded character "鴻".
+var_dump(bin2hex("テスト"));
+?>
+--EXPECT--
+string(16) "3f3f3fe9b4bb3f3f"
diff --git a/ext/mbstring/tests/zend_multibyte-06.phpt b/ext/mbstring/tests/zend_multibyte-06.phpt
new file mode 100644 (file)
index 0000000..9acd6a9
--- /dev/null
@@ -0,0 +1,19 @@
+--TEST--
+zend multibyte (6)
+--SKIPIF--
+<?php
+ini_set("mbstring.script_encoding","SJIS");
+if (ini_set("mbstring.script_encoding","SJIS") != "SJIS") {
+       die("skip zend-multibyte is not available");
+}
+?>
+--INI--
+mbstring.script_encoding=EUC-JP
+mbstring.internal_encoding=CP932
+--FILE--
+<?php
+declare(encoding="UTF-8");
+var_dump(bin2hex("テスト"));
+?>
+--EXPECT--
+string(12) "836583588367"
diff --git a/ext/mbstring/tests/zend_multibyte-07.phpt b/ext/mbstring/tests/zend_multibyte-07.phpt
new file mode 100644 (file)
index 0000000..30305f5
--- /dev/null
@@ -0,0 +1,19 @@
+--TEST--
+zend multibyte (7)
+--SKIPIF--
+<?php
+ini_set("mbstring.script_encoding","SJIS");
+if (ini_set("mbstring.script_encoding","SJIS") != "SJIS") {
+       die("skip zend-multibyte is not available");
+}
+?>
+--INI--
+mbstring.script_encoding=ISO-8859-1
+mbstring.internal_encoding=EUC-JP
+--FILE--
+<?php
+declare(encoding="UTF-8");
+var_dump(bin2hex("テスト"));
+?>
+--EXPECT--
+string(12) "a5c6a5b9a5c8"
diff --git a/ext/mbstring/tests/zend_multibyte-08.phpt b/ext/mbstring/tests/zend_multibyte-08.phpt
new file mode 100644 (file)
index 0000000..ab27461
--- /dev/null
@@ -0,0 +1,19 @@
+--TEST--
+zend multibyte (8)
+--SKIPIF--
+<?php
+ini_set("mbstring.script_encoding","SJIS");
+if (ini_set("mbstring.script_encoding","SJIS") != "SJIS") {
+       die("skip zend-multibyte is not available");
+}
+?>
+--INI--
+mbstring.script_encoding=ISO-8859-1
+mbstring.internal_encoding=UTF-8
+--FILE--
+<?php
+declare(encoding="CP932");
+var_dump(bin2hex("\83e\83X\83g"));
+?>
+--EXPECT--
+string(18) "e38386e382b9e38388"
diff --git a/ext/mbstring/tests/zend_multibyte-09.phpt b/ext/mbstring/tests/zend_multibyte-09.phpt
new file mode 100644 (file)
index 0000000..79ee435
--- /dev/null
@@ -0,0 +1,22 @@
+--TEST--
+zend multibyte (9)
+--SKIPIF--
+<?php
+ini_set("mbstring.script_encoding","SJIS");
+if (ini_set("mbstring.script_encoding","SJIS") != "SJIS") {
+       die("skip zend-multibyte is not available");
+}
+?>
+--INI--
+mbstring.script_encoding=cp1251
+mbstring.internal_encoding=UTF-8
+--FILE--
+<?php
+declare(encoding="EUC-JP");
+// forcefully interpret an UTF-8 encoded string as EUC-JP and then convert it
+// back to UTF-8. There should be only a pair of consecutive bytes that is
+// valid EUC-encoded character "鴻".
+var_dump(bin2hex("テスト"));
+?>
+--EXPECT--
+string(16) "3f3f3fe9b4bb3f3f"
diff --git a/ext/mbstring/tests/zend_multibyte-10.phpt b/ext/mbstring/tests/zend_multibyte-10.phpt
new file mode 100644 (file)
index 0000000..c3543c9
--- /dev/null
@@ -0,0 +1,16 @@
+--TEST--
+zend multibyte (10)
+--SKIPIF--
+<?php
+ini_set("mbstring.script_encoding","SJIS");
+if (ini_set("mbstring.script_encoding","SJIS") != "SJIS") {
+       die("skip zend-multibyte is not available");
+}
+?>
+--FILE--
+<?php
+declare(encoding="ISO-8859-15");
+declare(encoding="ISO-8859-1");
+?>
+--EXPECTF--
+Fatal error: Encoding declaration pragma must be the very first statement in the script in %s on line 3
diff --git a/ext/mbstring/tests/zend_multibyte-11.phpt b/ext/mbstring/tests/zend_multibyte-11.phpt
new file mode 100644 (file)
index 0000000..84e16ae
--- /dev/null
@@ -0,0 +1,17 @@
+--TEST--
+zend multibyte (11)
+--SKIPIF--
+<?php
+ini_set("mbstring.script_encoding","SJIS");
+if (ini_set("mbstring.script_encoding","SJIS") != "SJIS") {
+       die("skip zend-multibyte is not available");
+}
+?>
+--FILE--
+<?php
+declare(encoding="ISO-8859-15") {
+       declare(encoding="ISO-8859-1");
+}
+?>
+--EXPECTF--
+Fatal error: Encoding declaration pragma must be the very first statement in the script in %s on line 3
diff --git a/ext/mbstring/tests/zend_multibyte-12.phpt b/ext/mbstring/tests/zend_multibyte-12.phpt
new file mode 100644 (file)
index 0000000..e1c8ce5
--- /dev/null
@@ -0,0 +1,17 @@
+--TEST--
+zend multibyte (12)
+--SKIPIF--
+<?php
+ini_set("mbstring.script_encoding","SJIS");
+if (ini_set("mbstring.script_encoding","SJIS") != "SJIS") {
+       die("skip zend-multibyte is not available");
+}
+?>
+--FILE--
+<?php
+declare(encoding="ISO-8859-15");
+echo 1;
+declare(encoding="ISO-8859-1");
+?>
+--EXPECTF--
+Fatal error: Encoding declaration pragma must be the very first statement in the script in %s on line 4
diff --git a/ext/mbstring/tests/zend_multibyte-13.phpt b/ext/mbstring/tests/zend_multibyte-13.phpt
new file mode 100644 (file)
index 0000000..e601a6c
--- /dev/null
@@ -0,0 +1,23 @@
+--TEST--
+zend multibyte (13)
+--SKIPIF--
+<?php
+ini_set("mbstring.script_encoding","SJIS");
+if (ini_set("mbstring.script_encoding","SJIS") != "SJIS") {
+       die("skip zend-multibyte is not available");
+}
+?>
+--INI--
+mbstring.script_encoding=UTF-8
+mbstring.internal_encoding=ISO-8859-1
+--FILE--
+<?php
+var_dump(substr(file_get_contents(__FILE__), __COMPILER_HALT_OFFSET__));
+var_dump(bin2hex("äëüáéú"));
+__halt_compiler();test
+test
+--EXPECT--
+string(10) "test
+test
+"
+string(12) "e4ebfce1e9fa"
diff --git a/ext/mbstring/tests/zend_multibyte-14.phpt b/ext/mbstring/tests/zend_multibyte-14.phpt
new file mode 100644 (file)
index 0000000..04bc409
--- /dev/null
@@ -0,0 +1,23 @@
+--TEST--
+zend multibyte (14)
+--SKIPIF--
+<?php
+ini_set("mbstring.script_encoding","SJIS");
+if (ini_set("mbstring.script_encoding","SJIS") != "SJIS") {
+       die("skip zend-multibyte is not available");
+}
+?>
+--INI--
+mbstring.script_encoding=UTF-8
+mbstring.internal_encoding=UTF-8
+--FILE--
+<?php
+var_dump(substr(file_get_contents(__FILE__), __COMPILER_HALT_OFFSET__));
+var_dump(bin2hex("äëüáéú"));
+__halt_compiler();test
+test
+--EXPECT--
+string(10) "test
+test
+"
+string(24) "c3a4c3abc3bcc3a1c3a9c3ba"