Browse files

- Fix __halt_compiler() weirdness with zend-mulibyte enabled

  • Loading branch information...
1 parent f24a083 commit a28497d6e5e17dd6a076e6ad5fd019a8541d6d48 Moriyoshi Koizumi committed Jul 28, 2008
Showing with 50 additions and 21 deletions.
  1. +1 −1 Zend/zend_compile.h
  2. +27 −20 Zend/zend_language_scanner.l
  3. +22 −0 ext/mbstring/tests/zend_multibyte-13.phpt
View
2 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);
View
47 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++;
View
22 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"

0 comments on commit a28497d

Please sign in to comment.