diff options
Diffstat (limited to 'Zend')
| -rw-r--r-- | Zend/Zend.m4 | 14 | ||||
| -rw-r--r-- | Zend/tests/declare_001.phpt | 4 | ||||
| -rw-r--r-- | Zend/tests/declare_002.phpt | 28 | ||||
| -rwxr-xr-x | Zend/tests/multibyte/multibyte_encoding_001.phpt | 1 | ||||
| -rwxr-xr-x | Zend/tests/multibyte/multibyte_encoding_002.phpt | 1 | ||||
| -rwxr-xr-x | Zend/tests/multibyte/multibyte_encoding_003.phpt | bin | 469 -> 465 bytes | |||
| -rw-r--r-- | Zend/tests/multibyte/multibyte_encoding_004.phpt | 1 | ||||
| -rw-r--r-- | Zend/tests/multibyte/multibyte_encoding_005.phpt | 1 | ||||
| -rw-r--r-- | Zend/tests/multibyte/multibyte_encoding_006.phpt | bin | 599 -> 624 bytes | |||
| -rw-r--r-- | Zend/zend.c | 3 | ||||
| -rw-r--r-- | Zend/zend_compile.c | 59 | ||||
| -rw-r--r-- | Zend/zend_globals.h | 8 | ||||
| -rw-r--r-- | Zend/zend_highlight.c | 5 | ||||
| -rw-r--r-- | Zend/zend_language_scanner.h | 2 | ||||
| -rw-r--r-- | Zend/zend_language_scanner.l | 150 | ||||
| -rw-r--r-- | Zend/zend_multibyte.c | 43 | ||||
| -rw-r--r-- | Zend/zend_multibyte.h | 4 |
17 files changed, 161 insertions, 163 deletions
diff --git a/Zend/Zend.m4 b/Zend/Zend.m4 index c56b769a99..ececf783b5 100644 --- a/Zend/Zend.m4 +++ b/Zend/Zend.m4 @@ -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]*//` diff --git a/Zend/tests/declare_001.phpt b/Zend/tests/declare_001.phpt index 14c9a453d6..f55566758b 100644 --- a/Zend/tests/declare_001.phpt +++ b/Zend/tests/declare_001.phpt @@ -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-- diff --git a/Zend/tests/declare_002.phpt b/Zend/tests/declare_002.phpt new file mode 100644 index 0000000000..1babdf338b --- /dev/null +++ b/Zend/tests/declare_002.phpt @@ -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 diff --git a/Zend/tests/multibyte/multibyte_encoding_001.phpt b/Zend/tests/multibyte/multibyte_encoding_001.phpt index 19b6064cfa..8c8a1b855e 100755 --- a/Zend/tests/multibyte/multibyte_encoding_001.phpt +++ b/Zend/tests/multibyte/multibyte_encoding_001.phpt @@ -10,6 +10,7 @@ if (!extension_loaded("mbstring")) { } ?> --INI-- +zend.multibyte=1 mbstring.internal_encoding=SJIS --FILE-- <?php diff --git a/Zend/tests/multibyte/multibyte_encoding_002.phpt b/Zend/tests/multibyte/multibyte_encoding_002.phpt index 813222d82d..abf7aef07d 100755 --- a/Zend/tests/multibyte/multibyte_encoding_002.phpt +++ b/Zend/tests/multibyte/multibyte_encoding_002.phpt @@ -10,6 +10,7 @@ if (!extension_loaded("mbstring")) { } ?> --INI-- +zend.multibyte=1 mbstring.internal_encoding=iso-8859-1 --FILE-- <?php diff --git a/Zend/tests/multibyte/multibyte_encoding_003.phpt b/Zend/tests/multibyte/multibyte_encoding_003.phpt Binary files differindex 19b29f209b..08a4d2096c 100755 --- a/Zend/tests/multibyte/multibyte_encoding_003.phpt +++ b/Zend/tests/multibyte/multibyte_encoding_003.phpt diff --git a/Zend/tests/multibyte/multibyte_encoding_004.phpt b/Zend/tests/multibyte/multibyte_encoding_004.phpt index 5a26b7c213..09452113f3 100644 --- a/Zend/tests/multibyte/multibyte_encoding_004.phpt +++ b/Zend/tests/multibyte/multibyte_encoding_004.phpt @@ -10,6 +10,7 @@ if (!extension_loaded("mbstring")) { } ?> --INI-- +zend.multibyte=1 mbstring.script_encoding=Shift_JIS mbstring.internal_encoding=Shift_JIS --FILE-- diff --git a/Zend/tests/multibyte/multibyte_encoding_005.phpt b/Zend/tests/multibyte/multibyte_encoding_005.phpt index 3946238e50..bf88e7ddac 100644 --- a/Zend/tests/multibyte/multibyte_encoding_005.phpt +++ b/Zend/tests/multibyte/multibyte_encoding_005.phpt @@ -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 diff --git a/Zend/tests/multibyte/multibyte_encoding_006.phpt b/Zend/tests/multibyte/multibyte_encoding_006.phpt Binary files differindex da5b8a22b8..680bf00f76 100644 --- a/Zend/tests/multibyte/multibyte_encoding_006.phpt +++ b/Zend/tests/multibyte/multibyte_encoding_006.phpt diff --git a/Zend/zend.c b/Zend/zend.c index a9cfc8f15d..d091593ec4 100644 --- a/Zend/zend.c +++ b/Zend/zend.c @@ -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() diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index ca9dfe1d42..5abb81e8fd 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -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,7 +197,6 @@ 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; @@ -210,7 +204,6 @@ void zend_init_compiler_data_structures(TSRMLS_D) /* {{{ */ 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); diff --git a/Zend/zend_globals.h b/Zend/zend_globals.h index c66ef64c4d..1f6b8d4f1f 100644 --- a/Zend/zend_globals.h +++ b/Zend/zend_globals.h @@ -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 */ diff --git a/Zend/zend_highlight.c b/Zend/zend_highlight.c index 171789b83b..58c83868b1 100644 --- a/Zend/zend_highlight.c +++ b/Zend/zend_highlight.c @@ -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 */ } diff --git a/Zend/zend_language_scanner.h b/Zend/zend_language_scanner.h index ac37c73f68..b0bbfe5b40 100644 --- a/Zend/zend_language_scanner.h +++ b/Zend/zend_language_scanner.h @@ -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; diff --git a/Zend/zend_language_scanner.l b/Zend/zend_language_scanner.l index dedf5d9ba2..b55237db9a 100644 --- a/Zend/zend_language_scanner.l +++ b/Zend/zend_language_scanner.l @@ -181,16 +181,16 @@ ZEND_API void zend_save_lexical_state(zend_lex_state *lex_state TSRMLS_DC) lex_state->filename = zend_get_compiled_filename(TSRMLS_C); lex_state->lineno = CG(zend_lineno); -#ifdef ZEND_MULTIBYTE - lex_state->script_org = SCNG(script_org); - lex_state->script_org_size = SCNG(script_org_size); - lex_state->script_filtered = SCNG(script_filtered); - lex_state->script_filtered_size = SCNG(script_filtered_size); - lex_state->input_filter = SCNG(input_filter); - lex_state->output_filter = SCNG(output_filter); - lex_state->script_encoding = SCNG(script_encoding); - lex_state->internal_encoding = SCNG(internal_encoding); -#endif /* ZEND_MULTIBYTE */ + if (CG(multibyte)) { + lex_state->script_org = SCNG(script_org); + lex_state->script_org_size = SCNG(script_org_size); + lex_state->script_filtered = SCNG(script_filtered); + lex_state->script_filtered_size = SCNG(script_filtered_size); + lex_state->input_filter = SCNG(input_filter); + lex_state->output_filter = SCNG(output_filter); + lex_state->script_encoding = SCNG(script_encoding); + lex_state->internal_encoding = SCNG(internal_encoding); + } } ZEND_API void zend_restore_lexical_state(zend_lex_state *lex_state TSRMLS_DC) @@ -209,24 +209,24 @@ ZEND_API void zend_restore_lexical_state(zend_lex_state *lex_state TSRMLS_DC) YYSETCONDITION(lex_state->yy_state); CG(zend_lineno) = lex_state->lineno; zend_restore_compiled_filename(lex_state->filename TSRMLS_CC); -#ifdef ZEND_MULTIBYTE - if (SCNG(script_org)) { - efree(SCNG(script_org)); - SCNG(script_org) = NULL; - } - if (SCNG(script_filtered)) { - efree(SCNG(script_filtered)); - SCNG(script_filtered) = NULL; + if (CG(multibyte)) { + if (SCNG(script_org)) { + efree(SCNG(script_org)); + SCNG(script_org) = NULL; + } + if (SCNG(script_filtered)) { + efree(SCNG(script_filtered)); + SCNG(script_filtered) = NULL; + } + SCNG(script_org) = lex_state->script_org; + SCNG(script_org_size) = lex_state->script_org_size; + SCNG(script_filtered) = lex_state->script_filtered; + SCNG(script_filtered_size) = lex_state->script_filtered_size; + SCNG(input_filter) = lex_state->input_filter; + SCNG(output_filter) = lex_state->output_filter; + SCNG(script_encoding) = lex_state->script_encoding; + SCNG(internal_encoding) = lex_state->internal_encoding; } - SCNG(script_org) = lex_state->script_org; - SCNG(script_org_size) = lex_state->script_org_size; - SCNG(script_filtered) = lex_state->script_filtered; - SCNG(script_filtered_size) = lex_state->script_filtered_size; - SCNG(input_filter) = lex_state->input_filter; - SCNG(output_filter) = lex_state->output_filter; - SCNG(script_encoding) = lex_state->script_encoding; - SCNG(internal_encoding) = lex_state->internal_encoding; -#endif /* ZEND_MULTIBYTE */ } ZEND_API void zend_destroy_file_handle(zend_file_handle *file_handle TSRMLS_DC) @@ -269,32 +269,32 @@ ZEND_API int open_file_for_scanning(zend_file_handle *file_handle TSRMLS_DC) SCNG(yy_start) = NULL; if (size != -1) { -#ifdef ZEND_MULTIBYTE - if (zend_multibyte_read_script((unsigned char *)buf, size TSRMLS_CC) != 0) { - return FAILURE; - } + if (CG(multibyte)) { + if (zend_multibyte_read_script((unsigned char *)buf, size TSRMLS_CC) != 0) { + return FAILURE; + } - SCNG(yy_in) = NULL; + SCNG(yy_in) = NULL; - zend_multibyte_set_filter(NULL TSRMLS_CC); + zend_multibyte_set_filter(NULL TSRMLS_CC); - if (!SCNG(input_filter)) { - SCNG(script_filtered) = (unsigned char*)emalloc(SCNG(script_org_size)+1); - memcpy(SCNG(script_filtered), SCNG(script_org), SCNG(script_org_size)+1); - SCNG(script_filtered_size) = SCNG(script_org_size); - } else { - SCNG(input_filter)(&SCNG(script_filtered), &SCNG(script_filtered_size), SCNG(script_org), SCNG(script_org_size) TSRMLS_CC); - if (SCNG(script_filtered) == NULL) { - zend_error_noreturn(E_COMPILE_ERROR, "Could not convert the script from the detected " - "encoding \"%s\" to a compatible encoding", LANG_SCNG(script_encoding)->name); + if (!SCNG(input_filter)) { + SCNG(script_filtered) = (unsigned char*)emalloc(SCNG(script_org_size)+1); + memcpy(SCNG(script_filtered), SCNG(script_org), SCNG(script_org_size)+1); + SCNG(script_filtered_size) = SCNG(script_org_size); + } else { + SCNG(input_filter)(&SCNG(script_filtered), &SCNG(script_filtered_size), SCNG(script_org), SCNG(script_org_size) TSRMLS_CC); + if (SCNG(script_filtered) == NULL) { + zend_error_noreturn(E_COMPILE_ERROR, "Could not convert the script from the detected " + "encoding \"%s\" to a compatible encoding", LANG_SCNG(script_encoding)->name); + } } + SCNG(yy_start) = SCNG(script_filtered) - offset; + yy_scan_buffer((char *)SCNG(script_filtered), SCNG(script_filtered_size) TSRMLS_CC); + } else { + SCNG(yy_start) = buf - offset; + yy_scan_buffer(buf, size TSRMLS_CC); } - SCNG(yy_start) = SCNG(script_filtered) - offset; - yy_scan_buffer((char *)SCNG(script_filtered), SCNG(script_filtered_size) TSRMLS_CC); -#else /* !ZEND_MULTIBYTE */ - SCNG(yy_start) = buf - offset; - yy_scan_buffer(buf, size TSRMLS_CC); -#endif /* ZEND_MULTIBYTE */ } else { zend_error_noreturn(E_COMPILE_ERROR, "zend_stream_mmap() failed"); } @@ -437,25 +437,25 @@ ZEND_API int zend_prepare_string_for_scanning(zval *str, char *filename TSRMLS_D SCNG(yy_in)=NULL; SCNG(yy_start) = NULL; -#ifdef ZEND_MULTIBYTE - SCNG(script_org) = (unsigned char *)estrdup(str->value.str.val); - SCNG(script_org_size) = str->value.str.len; + if (CG(multibyte)) { + SCNG(script_org) = (unsigned char *)estrdup(str->value.str.val); + SCNG(script_org_size) = str->value.str.len; - zend_multibyte_set_filter(CG(internal_encoding) TSRMLS_CC); + zend_multibyte_set_filter(CG(internal_encoding) TSRMLS_CC); - if (!SCNG(input_filter)) { - SCNG(script_filtered) = (unsigned char*)emalloc(SCNG(script_org_size)+1); - memcpy(SCNG(script_filtered), SCNG(script_org), SCNG(script_org_size)+1); - SCNG(script_filtered_size) = SCNG(script_org_size); + if (!SCNG(input_filter)) { + SCNG(script_filtered) = (unsigned char*)emalloc(SCNG(script_org_size)+1); + memcpy(SCNG(script_filtered), SCNG(script_org), SCNG(script_org_size)+1); + SCNG(script_filtered_size) = SCNG(script_org_size); + } else { + SCNG(input_filter)(&SCNG(script_filtered), &SCNG(script_filtered_size), SCNG(script_org), SCNG(script_org_size) TSRMLS_CC); + } + + yy_scan_buffer((char *)SCNG(script_filtered), SCNG(script_filtered_size) TSRMLS_CC); } else { - SCNG(input_filter)(&SCNG(script_filtered), &SCNG(script_filtered_size), SCNG(script_org), SCNG(script_org_size) TSRMLS_CC); + yy_scan_buffer(str->value.str.val, str->value.str.len TSRMLS_CC); } - yy_scan_buffer((char *)SCNG(script_filtered), SCNG(script_filtered_size) TSRMLS_CC); -#else /* !ZEND_MULTIBYTE */ - yy_scan_buffer(str->value.str.val, str->value.str.len TSRMLS_CC); -#endif /* ZEND_MULTIBYTE */ - zend_set_compiled_filename(filename TSRMLS_CC); CG(zend_lineno) = 1; CG(increment_lineno) = 0; @@ -466,7 +466,6 @@ ZEND_API int zend_prepare_string_for_scanning(zval *str, char *filename TSRMLS_D ZEND_API size_t zend_get_scanned_file_offset(TSRMLS_D) { size_t offset = SCNG(yy_cursor) - SCNG(yy_start); -#ifdef ZEND_MULTIBYTE if (SCNG(input_filter)) { size_t original_offset = offset, length = 0; do { unsigned char *p = NULL; @@ -482,7 +481,6 @@ ZEND_API size_t zend_get_scanned_file_offset(TSRMLS_D) } } while (original_offset != length); } -#endif return offset; } @@ -524,7 +522,6 @@ zend_op_array *compile_string(zval *source_string, char *filename TSRMLS_DC) BEGIN(ST_IN_SCRIPTING); compiler_result = zendparse(TSRMLS_C); -#ifdef ZEND_MULTIBYTE if (SCNG(script_org)) { efree(SCNG(script_org)); SCNG(script_org) = NULL; @@ -533,7 +530,6 @@ zend_op_array *compile_string(zval *source_string, char *filename TSRMLS_DC) efree(SCNG(script_filtered)); SCNG(script_filtered) = NULL; } -#endif /* ZEND_MULTIBYTE */ if (compiler_result==1) { CG(active_op_array) = original_active_op_array; @@ -571,7 +567,6 @@ int highlight_file(char *filename, zend_syntax_highlighter_ini *syntax_highlight return FAILURE; } zend_highlight(syntax_highlighter_ini TSRMLS_CC); -#ifdef ZEND_MULTIBYTE if (SCNG(script_org)) { efree(SCNG(script_org)); SCNG(script_org) = NULL; @@ -580,7 +575,6 @@ int highlight_file(char *filename, zend_syntax_highlighter_ini *syntax_highlight efree(SCNG(script_filtered)); SCNG(script_filtered) = NULL; } -#endif /* ZEND_MULTIBYTE */ zend_destroy_file_handle(&file_handle TSRMLS_CC); zend_restore_lexical_state(&original_lex_state TSRMLS_CC); return SUCCESS; @@ -600,7 +594,6 @@ int highlight_string(zval *str, zend_syntax_highlighter_ini *syntax_highlighter_ } BEGIN(INITIAL); zend_highlight(syntax_highlighter_ini TSRMLS_CC); -#ifdef ZEND_MULTIBYTE if (SCNG(script_org)) { efree(SCNG(script_org)); SCNG(script_org) = NULL; @@ -609,16 +602,11 @@ int highlight_string(zval *str, zend_syntax_highlighter_ini *syntax_highlighter_ efree(SCNG(script_filtered)); SCNG(script_filtered) = NULL; } -#endif /* ZEND_MULTIBYTE */ zend_restore_lexical_state(&original_lex_state TSRMLS_CC); zval_dtor(str); return SUCCESS; } -END_EXTERN_C() -#ifdef ZEND_MULTIBYTE - -BEGIN_EXTERN_C() ZEND_API void zend_multibyte_yyinput_again(zend_encoding_filter old_input_filter, zend_encoding *old_encoding TSRMLS_DC) { size_t original_offset, offset, free_flag, new_len, length; @@ -728,11 +716,6 @@ ZEND_API int zend_multibyte_read_script(unsigned char *buf, size_t n TSRMLS_DC) zendlval->value.str.val = (char *) estrndup(yytext, yyleng); \ zendlval->value.str.len = yyleng; \ } -#else /* ZEND_MULTIBYTE */ -# define zend_copy_value(zendlval, yytext, yyleng) \ - zendlval->value.str.val = (char *)estrndup(yytext, yyleng); \ - zendlval->value.str.len = yyleng; -#endif /* ZEND_MULTIBYTE */ static void zend_scan_escape_string(zval *zendlval, char *str, int len, char quote_type TSRMLS_DC) { @@ -836,7 +819,6 @@ static void zend_scan_escape_string(zval *zendlval, char *str, int len, char quo s++; } *t = 0; -#ifdef ZEND_MULTIBYTE if (SCNG(output_filter)) { size_t sz = 0; s = zendlval->value.str.val; @@ -844,7 +826,6 @@ static void zend_scan_escape_string(zval *zendlval, char *str, int len, char quo zendlval->value.str.len = sz; efree(s); } -#endif /* ZEND_MULTIBYTE */ } @@ -1690,7 +1671,6 @@ inline_char_handler: inline_html: yyleng = YYCURSOR - SCNG(yy_text); -#ifdef ZEND_MULTIBYTE if (SCNG(output_filter)) { int readsize; size_t sz = 0; @@ -1703,10 +1683,6 @@ inline_html: zendlval->value.str.val = (char *) estrndup(yytext, yyleng); zendlval->value.str.len = yyleng; } -#else /* !ZEND_MULTIBYTE */ - zendlval->value.str.val = (char *) estrndup(yytext, yyleng); - zendlval->value.str.len = yyleng; -#endif zendlval->type = IS_STRING; HANDLE_NEWLINES(yytext, yyleng); return T_INLINE_HTML; @@ -1913,7 +1889,6 @@ inline_html: } *t = 0; -#ifdef ZEND_MULTIBYTE if (SCNG(output_filter)) { size_t sz = 0; s = zendlval->value.str.val; @@ -1921,7 +1896,6 @@ inline_html: zendlval->value.str.len = sz; efree(s); } -#endif /* ZEND_MULTIBYTE */ return T_CONSTANT_ENCAPSED_STRING; } diff --git a/Zend/zend_multibyte.c b/Zend/zend_multibyte.c index d47fa6d83a..33d8688b37 100644 --- a/Zend/zend_multibyte.c +++ b/Zend/zend_multibyte.c @@ -24,7 +24,6 @@ #include "zend_operators.h" #include "zend_multibyte.h" -#ifdef ZEND_MULTIBYTE static size_t zend_multibyte_encoding_filter(unsigned char **to, size_t *to_length, const char *to_encoding, const unsigned char *from, size_t from_length, const char *from_encoding TSRMLS_DC); size_t sjis_input_filter(unsigned char **buf, size_t *length, const unsigned char *sjis, size_t sjis_length TSRMLS_DC); size_t sjis_output_filter(unsigned char **buf, size_t *length, const unsigned char *sjis, size_t sjis_length TSRMLS_DC); @@ -1080,6 +1079,7 @@ static zend_encoding* zend_multibyte_detect_unicode(TSRMLS_D) zend_encoding *script_encoding = NULL; int bom_size; unsigned char *script; + unsigned char *pos1, *pos2; if (LANG_SCNG(script_org_size) < sizeof(BOM_UTF32_LE)-1) { return NULL; @@ -1115,7 +1115,45 @@ static zend_encoding* zend_multibyte_detect_unicode(TSRMLS_D) } /* script contains NULL bytes -> auto-detection */ - if (memchr(LANG_SCNG(script_org), 0, LANG_SCNG(script_org_size))) { + if ((pos1 = memchr(LANG_SCNG(script_org), 0, LANG_SCNG(script_org_size)))) { + /* check if the NULL byte is after the __HALT_COMPILER(); */ + pos2 = LANG_SCNG(script_org); + + while (pos1 - pos2 >= sizeof("__HALT_COMPILER();")-1) { + pos2 = memchr(pos2, '_', pos1 - pos2); + if (!pos2) break; + pos2++; + if (strncasecmp((char*)pos2, "_HALT_COMPILER", sizeof("_HALT_COMPILER")-1) == 0) { + pos2 += sizeof("_HALT_COMPILER")-1; + while (*pos2 == ' ' || + *pos2 == '\t' || + *pos2 == '\r' || + *pos2 == '\n') { + pos2++; + } + if (*pos2 == '(') { + pos2++; + while (*pos2 == ' ' || + *pos2 == '\t' || + *pos2 == '\r' || + *pos2 == '\n') { + pos2++; + } + if (*pos2 == ')') { + pos2++; + while (*pos2 == ' ' || + *pos2 == '\t' || + *pos2 == '\r' || + *pos2 == '\n') { + pos2++; + } + if (*pos2 == ';') { + return NULL; + } + } + } + } + } /* make best effort if BOM is missing */ return zend_multibyte_detect_utf_encoding(LANG_SCNG(script_org), LANG_SCNG(script_org_size) TSRMLS_CC); } @@ -1168,7 +1206,6 @@ static zend_encoding *zend_multibyte_detect_utf_encoding(const unsigned char *sc return NULL; } -#endif /* ZEND_MULTIBYTE */ /* * Local variables: diff --git a/Zend/zend_multibyte.h b/Zend/zend_multibyte.h index 56a70a36ce..02421a8ab5 100644 --- a/Zend/zend_multibyte.h +++ b/Zend/zend_multibyte.h @@ -22,8 +22,6 @@ #ifndef ZEND_MULTIBYTE_H #define ZEND_MULTIBYTE_H -#ifdef ZEND_MULTIBYTE - #define BOM_UTF32_BE "\x00\x00\xfe\xff" #define BOM_UTF32_LE "\xff\xfe\x00\x00" #define BOM_UTF16_BE "\xfe\xff" @@ -67,8 +65,6 @@ ZEND_API int zend_multibyte_yyinput(zend_file_handle *file_handle, char *buf, si ZEND_API int zend_multibyte_read_script(unsigned char *buf, size_t n TSRMLS_DC); END_EXTERN_C() -#endif /* ZEND_MULTIBYTE */ - #endif /* ZEND_MULTIBYTE_H */ /* |
