Permalink
Browse files

Added multibyte suppport by default. Previosly php had to be compiled…

… with --enable-zend-multibyte. Now it can be enabled or disabled throug zend.multibyte directive in php.ini
  • Loading branch information...
1 parent 011fd80 commit ab93d8c621645e05d6a6a431d52ac64eda956673 Dmitry Stogov committed Nov 24, 2010
View
@@ -28,6 +28,9 @@ PHP NEWS
- Changed third parameter of preg_match_all() to optional. FR #53238. (Adam)
- General improvements:
+ . Added multibyte suppport by default. Previosly php had to be compiled
+ with --enable-zend-multibyte. Now it can be enabled or disabled throug
+ zend.multibyte directive in php.ini (Dmitry)
. Added scalar typehints to the parser and the reflection API. (Ilia, Derick)
. Added support for Traits. (Stefan)
. Added closure $this support back. (Stas)
View
@@ -235,6 +235,11 @@ UPGRADE NOTES - PHP X.Y
- Added session.upload_progress.enabled, session.upload_progress.cleanup,
session.upload_progress.prefix, session.upload_progress.name,
session.upload_progress.freq, session.upload_progress.min_freq.
+- Added zend.multibyte directive as a replacement of PHP compile time
+ configuration option --enable-zend-multibyte. Now ZE always contains code for
+ multibyte support, but may enable or disable it by zend.multibyte. It doesn't
+ make a lot of sense to enable this option without ext/mbstring, because the
+ most functionality is implemented by mbstrings callbacks.
====================
11. Syntax additions
View
@@ -176,13 +176,6 @@ AC_ARG_ENABLE(inline-optimization,
ZEND_INLINE_OPTIMIZATION=yes
])
-AC_ARG_ENABLE(zend-multibyte,
-[ --enable-zend-multibyte Compile with zend multibyte support], [
- ZEND_MULTIBYTE=$enableval
-],[
- ZEND_MULTIBYTE=no
-])
-
AC_MSG_CHECKING([virtual machine dispatch method])
AC_MSG_RESULT($PHP_ZEND_VM)
@@ -195,9 +188,6 @@ AC_MSG_RESULT($ZEND_INLINE_OPTIMIZATION)
AC_MSG_CHECKING(whether to enable Zend debugging)
AC_MSG_RESULT($ZEND_DEBUG)
-AC_MSG_CHECKING(whether to enable Zend multibyte)
-AC_MSG_RESULT($ZEND_MULTIBYTE)
-
case $PHP_ZEND_VM in
SWITCH)
AC_DEFINE(ZEND_VM_KIND,ZEND_VM_KIND_SWITCH,[virtual machine dispatch method])
@@ -232,10 +222,6 @@ if test "$ZEND_MAINTAINER_ZTS" = "yes"; then
LIBZEND_CPLUSPLUS_CHECKS
fi
-if test "$ZEND_MULTIBYTE" = "yes"; then
- AC_DEFINE(ZEND_MULTIBYTE, 1, [ ])
-fi
-
changequote({,})
if test -n "$GCC" && test "$ZEND_INLINE_OPTIMIZATION" != "yes"; then
INLINE_CFLAGS=`echo $ac_n "$CFLAGS $ac_c" | sed s/-O[0-9s]*//`
@@ -2,8 +2,8 @@
Testing declare statement with several type values
--SKIPIF--
<?php
-if (in_array("detect_unicode", array_keys(ini_get_all()))) {
- die("skip");
+if (ini_get("zend.multibyte")) {
+ die("skip Requires zend.multibyte=0");
}
?>
--FILE--
@@ -0,0 +1,28 @@
+--TEST--
+Testing declare statement with several type values
+--SKIPIF--
+<?php
+if (!ini_get("zend.multibyte")) {
+ die("skip Requires zend.multibyte=1");
+}
+?>
+--FILE--
+<?php
+
+declare(encoding = 1);
+declare(encoding = 1123131232131312321);
+declare(encoding = NULL);
+declare(encoding = 'utf-8');
+declare(encoding = M_PI);
+
+print 'DONE';
+
+?>
+--EXPECTF--
+Warning: Unsupported encoding [%d] in %sdeclare_002.php on line 3
+
+Warning: Unsupported encoding [%f] in %sdeclare_002.php on line 4
+
+Warning: Unsupported encoding [] in %sdeclare_002.php on line 5
+
+Fatal error: Cannot use constants as encoding in %sdeclare_002.php on line 7
@@ -10,6 +10,7 @@ if (!extension_loaded("mbstring")) {
}
?>
--INI--
+zend.multibyte=1
mbstring.internal_encoding=SJIS
--FILE--
<?php
@@ -10,6 +10,7 @@ if (!extension_loaded("mbstring")) {
}
?>
--INI--
+zend.multibyte=1
mbstring.internal_encoding=iso-8859-1
--FILE--
<?php
Binary file not shown.
@@ -10,6 +10,7 @@ if (!extension_loaded("mbstring")) {
}
?>
--INI--
+zend.multibyte=1
mbstring.script_encoding=Shift_JIS
mbstring.internal_encoding=Shift_JIS
--FILE--
@@ -10,6 +10,7 @@ if (!extension_loaded("mbstring")) {
}
?>
--INI--
+zend.multibyte=1
mbstring.encoding_translation = On
mbstring.script_encoding=Shift_JIS
mbstring.internal_encoding=UTF-8
Binary file not shown.
View
@@ -92,9 +92,8 @@ static ZEND_INI_MH(OnUpdateGCEnabled) /* {{{ */
ZEND_INI_BEGIN()
ZEND_INI_ENTRY("error_reporting", NULL, ZEND_INI_ALL, OnUpdateErrorReporting)
STD_ZEND_INI_BOOLEAN("zend.enable_gc", "1", ZEND_INI_ALL, OnUpdateGCEnabled, gc_enabled, zend_gc_globals, gc_globals)
-#ifdef ZEND_MULTIBYTE
+ STD_ZEND_INI_BOOLEAN("zend.multibyte", "0", ZEND_INI_PERDIR, OnUpdateBool, multibyte, zend_compiler_globals, compiler_globals)
STD_ZEND_INI_BOOLEAN("detect_unicode", "1", ZEND_INI_ALL, OnUpdateBool, detect_unicode, zend_compiler_globals, compiler_globals)
-#endif
ZEND_INI_END()
View
@@ -27,10 +27,7 @@
#include "zend_API.h"
#include "zend_exceptions.h"
#include "tsrm_virtual_cwd.h"
-
-#ifdef ZEND_MULTIBYTE
#include "zend_multibyte.h"
-#endif /* ZEND_MULTIBYTE */
#define CONSTANT_EX(op_array, op) \
(op_array)->literals[op].constant
@@ -149,14 +146,12 @@ static void build_runtime_defined_function_key(zval *result, const char *name, i
/* NULL, name length, filename length, last accepting char position length */
result->value.str.len = 1+name_length+strlen(filename)+char_pos_len;
-#ifdef ZEND_MULTIBYTE
+
/* must be binary safe */
result->value.str.val = (char *) safe_emalloc(result->value.str.len, 1, 1);
result->value.str.val[0] = '\0';
sprintf(result->value.str.val+1, "%s%s%s", name, filename, char_pos_buf);
-#else
- zend_spprintf(&result->value.str.val, 0, "%c%s%s%s", '\0', name, filename, char_pos_buf);
-#endif /* ZEND_MULTIBYTE */
+
result->type = IS_STRING;
Z_SET_REFCOUNT_P(result, 1);
}
@@ -202,15 +197,13 @@ void zend_init_compiler_data_structures(TSRMLS_D) /* {{{ */
init_compiler_declarables(TSRMLS_C);
zend_stack_init(&CG(context_stack));
-#ifdef ZEND_MULTIBYTE
CG(script_encoding_list) = NULL;
CG(script_encoding_list_size) = 0;
CG(internal_encoding) = NULL;
CG(encoding_detector) = NULL;
CG(encoding_converter) = NULL;
CG(encoding_oddlen) = NULL;
CG(encoding_declared) = 0;
-#endif /* ZEND_MULTIBYTE */
}
/* }}} */
@@ -249,11 +242,9 @@ void shutdown_compiler(TSRMLS_D) /* {{{ */
zend_llist_destroy(&CG(open_files));
zend_stack_destroy(&CG(context_stack));
-#ifdef ZEND_MULTIBYTE
if (CG(script_encoding_list)) {
efree(CG(script_encoding_list));
}
-#endif /* ZEND_MULTIBYTE */
}
/* }}} */
@@ -5835,11 +5826,7 @@ void zend_do_declare_stmt(znode *var, znode *val TSRMLS_DC) /* {{{ */
if (!zend_binary_strcasecmp(var->u.constant.value.str.val, var->u.constant.value.str.len, "ticks", sizeof("ticks")-1)) {
convert_to_long(&val->u.constant);
CG(declarables).ticks = val->u.constant;
-#ifdef ZEND_MULTIBYTE
} else if (!zend_binary_strcasecmp(var->u.constant.value.str.val, var->u.constant.value.str.len, "encoding", sizeof("encoding")-1)) {
- zend_encoding *new_encoding, *old_encoding;
- zend_encoding_filter old_input_filter;
-
if ((Z_TYPE(val->u.constant) & IS_CONSTANT_TYPE_MASK) == IS_CONSTANT) {
zend_error(E_COMPILE_ERROR, "Cannot use constants as encoding");
}
@@ -5863,31 +5850,31 @@ void zend_do_declare_stmt(znode *var, znode *val TSRMLS_DC) /* {{{ */
zend_error(E_COMPILE_ERROR, "Encoding declaration pragma must be the very first statement in the script");
}
}
- CG(encoding_declared) = 1;
- convert_to_string(&val->u.constant);
- new_encoding = zend_multibyte_fetch_encoding(val->u.constant.value.str.val);
- if (!new_encoding) {
- zend_error(E_COMPILE_WARNING, "Unsupported encoding [%s]", val->u.constant.value.str.val);
- } else {
- old_input_filter = LANG_SCNG(input_filter);
- old_encoding = LANG_SCNG(script_encoding);
- zend_multibyte_set_filter(new_encoding TSRMLS_CC);
-
- /* need to re-scan if input filter changed */
- if (old_input_filter != LANG_SCNG(input_filter) ||
- ((old_input_filter == zend_multibyte_script_encoding_filter) &&
- (new_encoding != old_encoding))) {
- zend_multibyte_yyinput_again(old_input_filter, old_encoding TSRMLS_CC);
+ if (CG(multibyte)) {
+ zend_encoding *new_encoding, *old_encoding;
+ zend_encoding_filter old_input_filter;
+
+ CG(encoding_declared) = 1;
+
+ convert_to_string(&val->u.constant);
+ new_encoding = zend_multibyte_fetch_encoding(val->u.constant.value.str.val);
+ if (!new_encoding) {
+ zend_error(E_COMPILE_WARNING, "Unsupported encoding [%s]", val->u.constant.value.str.val);
+ } else {
+ old_input_filter = LANG_SCNG(input_filter);
+ old_encoding = LANG_SCNG(script_encoding);
+ zend_multibyte_set_filter(new_encoding TSRMLS_CC);
+
+ /* need to re-scan if input filter changed */
+ if (old_input_filter != LANG_SCNG(input_filter) ||
+ ((old_input_filter == zend_multibyte_script_encoding_filter) &&
+ (new_encoding != old_encoding))) {
+ zend_multibyte_yyinput_again(old_input_filter, old_encoding TSRMLS_CC);
+ }
}
}
- efree(val->u.constant.value.str.val);
-#else /* !ZEND_MULTIBYTE */
- } else if (!zend_binary_strcasecmp(var->u.constant.value.str.val, var->u.constant.value.str.len, "encoding", sizeof("encoding")-1)) {
- /* Do not generate any kind of warning for encoding declares */
- /* zend_error(E_COMPILE_WARNING, "Declare encoding [%s] not supported", val->u.constant.value.str.val); */
zval_dtor(&val->u.constant);
-#endif /* ZEND_MULTIBYTE */
} else {
zend_error(E_COMPILE_WARNING, "Unsupported declare '%s'", var->u.constant.value.str.val);
zval_dtor(&val->u.constant);
View
@@ -35,10 +35,7 @@
#include "zend_objects_API.h"
#include "zend_modules.h"
#include "zend_float.h"
-
-#ifdef ZEND_MULTIBYTE
#include "zend_multibyte.h"
-#endif /* ZEND_MULTIBYTE */
/* Define ZTS if you want a thread-safe Zend */
/*#undef ZTS*/
@@ -150,9 +147,9 @@ struct _zend_compiler_globals {
HashTable interned_strings;
-#ifdef ZEND_MULTIBYTE
zend_encoding **script_encoding_list;
size_t script_encoding_list_size;
+ zend_bool multibyte;
zend_bool detect_unicode;
zend_bool encoding_declared;
@@ -162,7 +159,6 @@ struct _zend_compiler_globals {
zend_encoding_detector encoding_detector;
zend_encoding_converter encoding_converter;
zend_encoding_oddlen encoding_oddlen;
-#endif /* ZEND_MULTIBYTE */
#ifdef ZTS
zval ***static_members_table;
@@ -308,7 +304,6 @@ struct _zend_php_scanner_globals {
int yy_state;
zend_stack state_stack;
-#ifdef ZEND_MULTIBYTE
/* original (unfiltered) script */
unsigned char *script_org;
size_t script_org_size;
@@ -322,7 +317,6 @@ struct _zend_php_scanner_globals {
zend_encoding_filter output_filter;
zend_encoding *script_encoding;
zend_encoding *internal_encoding;
-#endif /* ZEND_MULTIBYTE */
};
#endif /* ZEND_GLOBALS_H */
@@ -57,8 +57,6 @@ ZEND_API void zend_html_putc(char c)
ZEND_API void zend_html_puts(const char *s, uint len TSRMLS_DC)
{
const char *ptr=s, *end=s+len;
-
-#ifdef ZEND_MULTIBYTE
char *filtered;
int filtered_len;
@@ -67,7 +65,6 @@ ZEND_API void zend_html_puts(const char *s, uint len TSRMLS_DC)
ptr = filtered;
end = filtered + filtered_len;
}
-#endif /* ZEND_MULTIBYTE */
while (ptr<end) {
if (*ptr==' ') {
@@ -79,11 +76,9 @@ ZEND_API void zend_html_puts(const char *s, uint len TSRMLS_DC)
}
}
-#ifdef ZEND_MULTIBYTE
if (LANG_SCNG(output_filter)) {
efree(filtered);
}
-#endif /* ZEND_MULTIBYTE */
}
@@ -36,7 +36,6 @@ typedef struct _zend_lex_state {
uint lineno;
char *filename;
-#ifdef ZEND_MULTIBYTE
/* original (unfiltered) script */
unsigned char *script_org;
size_t script_org_size;
@@ -50,7 +49,6 @@ typedef struct _zend_lex_state {
zend_encoding_filter output_filter;
zend_encoding *script_encoding;
zend_encoding *internal_encoding;
-#endif /* ZEND_MULTIBYTE */
} zend_lex_state;
Oops, something went wrong.

0 comments on commit ab93d8c

Please sign in to comment.