]> granicus.if.org Git - php/commitdiff
- Fix __halt_compiler() weirdness with zend-mulibyte enabled
authorMoriyoshi Koizumi <moriyoshi@php.net>
Mon, 28 Jul 2008 05:59:17 +0000 (05:59 +0000)
committerMoriyoshi Koizumi <moriyoshi@php.net>
Mon, 28 Jul 2008 05:59:17 +0000 (05:59 +0000)
Zend/zend_compile.h
Zend/zend_language_scanner.l
ext/mbstring/tests/zend_multibyte-13.phpt [new file with mode: 0644]

index da53bb0ddfcf975873ede2a2b1d7bd9f9b6f742e..38158732852636ed8f26c00b5676343a1d3f5b65 100644 (file)
@@ -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);
index 7ac4efe353a740c77d084336a5a7714c98cbbea3..038b324da511c998c34c2a89dd6215fa6c80facd 100644 (file)
@@ -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 (file)
index 0000000..d38ab5d
--- /dev/null
@@ -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"