- Fixed bug #48930 (__COMPILER_HALT_OFFSET__ incorrect in PHP >= 5.3)

This commit is contained in:
Felipe Pena 2010-06-27 21:46:16 +00:00
parent cb6bf19bfa
commit 3396a6d185
6 changed files with 26 additions and 3 deletions

16
Zend/tests/bug48930.phpt Normal file
View File

@ -0,0 +1,16 @@
--TEST--
Bug #48930 (__COMPILER_HALT_OFFSET__ incorrect in PHP>=5.3)
--FILE--
#!php
<?php
/*
* Test
*/
printf("__COMPILER_HALT_OFFSET__ is %d\n",__COMPILER_HALT_OFFSET__);
__halt_compiler();
?>
--EXPECT--
__COMPILER_HALT_OFFSET__ is 116

View File

@ -88,6 +88,7 @@ struct _zend_compiler_globals {
char *compiled_filename;
int zend_lineno;
int shebang_len;
char *heredoc;
int heredoc_len;

View File

@ -301,6 +301,7 @@ ZEND_API int open_file_for_scanning(zend_file_handle *file_handle TSRMLS_DC)
CG(start_lineno) = 0;
} else {
CG(zend_lineno) = 1;
CG(shebang_len) = 0;
}
CG(increment_lineno) = 0;
@ -450,7 +451,7 @@ ZEND_API int zend_prepare_string_for_scanning(zval *str, char *filename TSRMLS_D
ZEND_API size_t zend_get_scanned_file_offset(TSRMLS_D)
{
size_t offset = SCNG(yy_cursor) - SCNG(yy_start);
size_t offset = (SCNG(yy_cursor) - SCNG(yy_start)) + CG(shebang_len);
#ifdef ZEND_MULTIBYTE
if (SCNG(input_filter)) {
size_t original_offset = offset, length = 0; do {
@ -3514,7 +3515,7 @@ yy245:
++YYCURSOR;
YYDEBUG(246, *YYCURSOR);
yyleng = YYCURSOR - SCNG(yy_text);
#line 1291 "Zend/zend_language_scanner.l"
#line 1292 "Zend/zend_language_scanner.l"
{
return T_SR_EQUAL;
}

View File

@ -299,6 +299,7 @@ ZEND_API int open_file_for_scanning(zend_file_handle *file_handle TSRMLS_DC)
CG(start_lineno) = 0;
} else {
CG(zend_lineno) = 1;
CG(shebang_len) = 0;
}
CG(increment_lineno) = 0;
@ -448,7 +449,7 @@ ZEND_API int zend_prepare_string_for_scanning(zval *str, char *filename TSRMLS_D
ZEND_API size_t zend_get_scanned_file_offset(TSRMLS_D)
{
size_t offset = SCNG(yy_cursor) - SCNG(yy_start);
size_t offset = (SCNG(yy_cursor) - SCNG(yy_start)) + CG(shebang_len);
#ifdef ZEND_MULTIBYTE
if (SCNG(input_filter)) {
size_t original_offset = offset, length = 0; do {

View File

@ -2093,8 +2093,10 @@ consult the installation file that came with this distribution, or visit \n\
fseek(file_handle.handle.fp, pos - 1, SEEK_SET);
}
}
CG(shebang_len) = ftell(file_handle.handle.fp);
CG(start_lineno) = 2;
} else {
CG(shebang_len) = 0;
rewind(file_handle.handle.fp);
}
}

View File

@ -652,8 +652,10 @@ static int cli_seek_file_begin(zend_file_handle *file_handle, char *script_file,
fseek(file_handle->handle.fp, pos - 1, SEEK_SET);
}
}
CG(shebang_len) = ftell(file_handle->handle.fp);
*lineno = 2;
} else {
CG(shebang_len) = 0;
rewind(file_handle->handle.fp);
}