From a28497d6e5e17dd6a076e6ad5fd019a8541d6d48 Mon Sep 17 00:00:00 2001 From: Moriyoshi Koizumi Date: Mon, 28 Jul 2008 05:59:17 +0000 Subject: [PATCH] - Fix __halt_compiler() weirdness with zend-mulibyte enabled --- Zend/zend_compile.h | 2 +- Zend/zend_language_scanner.l | 47 +++++++++++++---------- ext/mbstring/tests/zend_multibyte-13.phpt | 22 +++++++++++ 3 files changed, 50 insertions(+), 21 deletions(-) create mode 100644 ext/mbstring/tests/zend_multibyte-13.phpt diff --git a/Zend/zend_compile.h b/Zend/zend_compile.h index da53bb0ddf..3815873285 100644 --- a/Zend/zend_compile.h +++ b/Zend/zend_compile.h @@ -357,7 +357,7 @@ ZEND_API char *zend_set_compiled_filename(char *new_compiled_filename TSRMLS_DC) ZEND_API void zend_restore_compiled_filename(char *original_compiled_filename TSRMLS_DC); ZEND_API char *zend_get_compiled_filename(TSRMLS_D); ZEND_API int zend_get_compiled_lineno(TSRMLS_D); -ZEND_API int zend_get_scanned_file_offset(TSRMLS_D); +ZEND_API size_t zend_get_scanned_file_offset(TSRMLS_D); void zend_resolve_class_name(znode *class_name, ulong *fetch_type, int check_ns_name TSRMLS_DC); ZEND_API char* zend_get_compiled_variable_name(zend_op_array *op_array, zend_uint var, int* name_len); diff --git a/Zend/zend_language_scanner.l b/Zend/zend_language_scanner.l index 7ac4efe353..038b324da5 100644 --- a/Zend/zend_language_scanner.l +++ b/Zend/zend_language_scanner.l @@ -444,9 +444,26 @@ ZEND_API int zend_prepare_string_for_scanning(zval *str, char *filename TSRMLS_D } -ZEND_API int zend_get_scanned_file_offset(TSRMLS_D) +ZEND_API size_t zend_get_scanned_file_offset(TSRMLS_D) { - return SCNG(yy_cursor) - SCNG(yy_start); + size_t offset = SCNG(yy_cursor) - SCNG(yy_start); +#ifdef ZEND_MULTIBYTE + size_t original_offset = offset, length = 0; + do { + unsigned char *p = NULL; + SCNG(input_filter)(&p, &length, SCNG(script_org), offset TSRMLS_CC); + if (!p) { + break; + } + efree(p); + if (length > original_offset) { + offset--; + } else if (length < original_offset) { + offset++; + } + } while (original_offset != length); +#endif + return offset; } @@ -581,29 +598,19 @@ END_EXTERN_C() BEGIN_EXTERN_C() ZEND_API void zend_multibyte_yyinput_again(zend_encoding_filter old_input_filter, zend_encoding *old_encoding TSRMLS_DC) { - size_t offset, original_offset, length, free_flag, new_len; + size_t original_offset, offset, free_flag, new_len, length; unsigned char *p; - zend_encoding *new_encoding; /* calculate current position */ offset = original_offset = YYCURSOR - SCNG(yy_start); - if (old_input_filter && original_offset > 0) { - new_encoding = SCNG(script_encoding); + if (old_input_filter && offset > 0) { + zend_encoding *new_encoding = SCNG(script_encoding); + zend_encoding_filter new_filter = SCNG(input_filter); SCNG(script_encoding) = old_encoding; - do { - (old_input_filter)(&p, &length, SCNG(script_org), offset TSRMLS_CC); - if (!p) { - SCNG(script_encoding) = new_encoding; - return; - } - efree(p); - if (length > original_offset) { - offset--; - } else if (length < original_offset) { - offset++; - } - } while (original_offset != length); + SCNG(input_filter) = new_filter; + offset = zend_get_scanned_file_offset(TSRMLS_C); SCNG(script_encoding) = new_encoding; + SCNG(input_filter) = new_filter; } /* convert and set */ @@ -1926,7 +1933,7 @@ inline_char_handler: /* Check for ending label on the next line */ if (CG(heredoc_len) < YYLIMIT - YYCURSOR && !memcmp(YYCURSOR, s, CG(heredoc_len))) { - char *end = YYCURSOR + CG(heredoc_len); + unsigned char *end = YYCURSOR + CG(heredoc_len); if (*end == ';') { end++; diff --git a/ext/mbstring/tests/zend_multibyte-13.phpt b/ext/mbstring/tests/zend_multibyte-13.phpt new file mode 100644 index 0000000000..d38ab5dce3 --- /dev/null +++ b/ext/mbstring/tests/zend_multibyte-13.phpt @@ -0,0 +1,22 @@ +--TEST-- +zend multibyte (13) +--SKIPIF-- + +--INI-- +mbstring.script_encoding=UTF-8 +mbstring.internal_encoding=ISO-8859-1 +--FILE-- +