]> granicus.if.org Git - php/commitdiff
- Fixed bug #48930 (__COMPILER_HALT_OFFSET__ incorrect in PHP >= 5.3)
authorFelipe Pena <felipe@php.net>
Wed, 30 Jun 2010 02:45:10 +0000 (02:45 +0000)
committerFelipe Pena <felipe@php.net>
Wed, 30 Jun 2010 02:45:10 +0000 (02:45 +0000)
Zend/zend_language_scanner.c
Zend/zend_language_scanner.l

index 7396e4c7be1be104f7ed61167d8741a39f0c56ac..7726001de8250536e9e1b102d9918280a8af2f29 100644 (file)
@@ -1,4 +1,4 @@
-/* Generated by re2c 0.13.5 on Tue Jun 29 22:47:47 2010 */
+/* Generated by re2c 0.13.5 on Tue Jun 29 23:34:41 2010 */
 #line 1 "Zend/zend_language_scanner.l"
 /*
    +----------------------------------------------------------------------+
@@ -141,8 +141,10 @@ static void yy_pop_state(TSRMLS_D)
 static void yy_scan_buffer(char *str, unsigned int len TSRMLS_DC)
 {
        YYCURSOR       = (YYCTYPE*)str;
-       SCNG(yy_start) = YYCURSOR;
        YYLIMIT        = YYCURSOR + len;
+       if (!SCNG(yy_start)) {
+               SCNG(yy_start) = YYCURSOR;
+       }
 }
 
 void startup_scanner(TSRMLS_D)
@@ -243,7 +245,14 @@ ZEND_API void zend_destroy_file_handle(zend_file_handle *file_handle TSRMLS_DC)
 ZEND_API int open_file_for_scanning(zend_file_handle *file_handle TSRMLS_DC)
 {
        char *file_path = NULL, *buf;
-       size_t size;
+       size_t size, offset = 0;
+       
+       /* The shebang line was read, get the current position to obtain the buffer start */
+       if (CG(start_lineno) == 2 && file_handle->type == ZEND_HANDLE_FP && file_handle->handle.fp) {
+               if ((offset = ftell(file_handle->handle.fp)) == -1) {
+                       offset = 0;
+               }
+       }
 
        if (zend_stream_fixup(file_handle, &buf, &size TSRMLS_CC) == FAILURE) {
                return FAILURE;
@@ -259,6 +268,7 @@ ZEND_API int open_file_for_scanning(zend_file_handle *file_handle TSRMLS_DC)
 
        /* Reset the scanner for scanning the new file */
        SCNG(yy_in) = file_handle;
+       SCNG(yy_start) = NULL;
 
        if (size != -1) {
 #ifdef ZEND_MULTIBYTE
@@ -277,9 +287,10 @@ ZEND_API int open_file_for_scanning(zend_file_handle *file_handle TSRMLS_DC)
                } else {
                        SCNG(input_filter)(&SCNG(script_filtered), &SCNG(script_filtered_size), SCNG(script_org), SCNG(script_org_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 {
@@ -421,6 +432,7 @@ ZEND_API int zend_prepare_string_for_scanning(zval *str, char *filename TSRMLS_D
        memset(str->value.str.val + str->value.str.len, 0, ZEND_MMAP_AHEAD);
 
        SCNG(yy_in)=NULL;
+       SCNG(yy_start) = NULL;
 
 #ifdef ZEND_MULTIBYTE
        SCNG(script_org) = (unsigned char *)estrdup(str->value.str.val);
@@ -3514,7 +3526,7 @@ yy245:
                ++YYCURSOR;
                YYDEBUG(246, *YYCURSOR);
                yyleng = YYCURSOR - SCNG(yy_text);
-#line 1291 "Zend/zend_language_scanner.l"
+#line 1303 "Zend/zend_language_scanner.l"
                {
        return T_SR_EQUAL;
 }
index 6622cb3db66df148b5a96b6e8b513d5c70a75d90..0783203cf53c098e864996e7ae5648bb6e81330b 100644 (file)
@@ -139,8 +139,10 @@ static void yy_pop_state(TSRMLS_D)
 static void yy_scan_buffer(char *str, unsigned int len TSRMLS_DC)
 {
        YYCURSOR       = (YYCTYPE*)str;
-       SCNG(yy_start) = YYCURSOR;
        YYLIMIT        = YYCURSOR + len;
+       if (!SCNG(yy_start)) {
+               SCNG(yy_start) = YYCURSOR;
+       }
 }
 
 void startup_scanner(TSRMLS_D)
@@ -241,7 +243,14 @@ ZEND_API void zend_destroy_file_handle(zend_file_handle *file_handle TSRMLS_DC)
 ZEND_API int open_file_for_scanning(zend_file_handle *file_handle TSRMLS_DC)
 {
        char *file_path = NULL, *buf;
-       size_t size;
+       size_t size, offset = 0;
+       
+       /* The shebang line was read, get the current position to obtain the buffer start */
+       if (CG(start_lineno) == 2 && file_handle->type == ZEND_HANDLE_FP && file_handle->handle.fp) {
+               if ((offset = ftell(file_handle->handle.fp)) == -1) {
+                       offset = 0;
+               }
+       }
 
        if (zend_stream_fixup(file_handle, &buf, &size TSRMLS_CC) == FAILURE) {
                return FAILURE;
@@ -257,6 +266,7 @@ ZEND_API int open_file_for_scanning(zend_file_handle *file_handle TSRMLS_DC)
 
        /* Reset the scanner for scanning the new file */
        SCNG(yy_in) = file_handle;
+       SCNG(yy_start) = NULL;
 
        if (size != -1) {
 #ifdef ZEND_MULTIBYTE
@@ -275,9 +285,10 @@ ZEND_API int open_file_for_scanning(zend_file_handle *file_handle TSRMLS_DC)
                } else {
                        SCNG(input_filter)(&SCNG(script_filtered), &SCNG(script_filtered_size), SCNG(script_org), SCNG(script_org_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 {
@@ -419,6 +430,7 @@ ZEND_API int zend_prepare_string_for_scanning(zval *str, char *filename TSRMLS_D
        memset(str->value.str.val + str->value.str.len, 0, ZEND_MMAP_AHEAD);
 
        SCNG(yy_in)=NULL;
+       SCNG(yy_start) = NULL;
 
 #ifdef ZEND_MULTIBYTE
        SCNG(script_org) = (unsigned char *)estrdup(str->value.str.val);