diff options
author | Moriyoshi Koizumi <moriyoshi@php.net> | 2008-07-28 05:59:17 +0000 |
---|---|---|
committer | Moriyoshi Koizumi <moriyoshi@php.net> | 2008-07-28 05:59:17 +0000 |
commit | a28497d6e5e17dd6a076e6ad5fd019a8541d6d48 (patch) | |
tree | 153ecf87dbca37758ce96e93c0f232c18296f755 | |
parent | f24a083dfee137f7640e3c6de51d9973101826b0 (diff) | |
download | php-git-a28497d6e5e17dd6a076e6ad5fd019a8541d6d48.tar.gz |
- Fix __halt_compiler() weirdness with zend-mulibyte enabled
-rw-r--r-- | Zend/zend_compile.h | 2 | ||||
-rw-r--r-- | Zend/zend_language_scanner.l | 47 | ||||
-rw-r--r-- | ext/mbstring/tests/zend_multibyte-13.phpt | 22 |
3 files changed, 50 insertions, 21 deletions
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-- +<?php +ini_set("mbstring.script_encoding", "SJIS"); +ini_set("mbstring.script_encoding", "***") != "SJIS" and + 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 +" +areinf(12) "e4ebfce1e9fa" |