cvs: ZendEngine2 / zend_compile.c zend_compile.h zend_constants.c zend_language_parser.y /tests halt_compiler1.phpt halt_compiler2.phpt
halt_compiler3.phpt halt_compiler4.phpt
| From: | Stanislav Malyshev | Date: | Thu, 28 Jun 2007 00:01:59 +0000 |
| Subject: | cvs: ZendEngine2 / zend_compile.c zend_compile.h zend_constants.c zend_language_parser.y /tests halt_compiler1.phpt halt_compiler2.phpt halt_compiler3.phpt halt_compiler4.phpt |
||
| Groups: | php.zend-engine.cvs | ||
| Request: | Send a blank email to php-zend-engine-cvs+get-5867@lists.php.net to get a copy of this message | ||
stas Thu Jun 28 00:01:59 2007 UTC
Modified files:
/ZendEngine2 zend_compile.c zend_compile.h zend_constants.c
zend_language_parser.y
/ZendEngine2/tests halt_compiler1.phpt halt_compiler2.phpt
halt_compiler3.phpt halt_compiler4.phpt
Log:
MF5 __HALT_COMPILER fix:
Remove limitation of __HALT_COMPILER() that allowed only one instance
per request.
# Patch by Gregory Beaver
http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_compile.c?r1=1.749&r2=1.750&diff_format=u Index: ZendEngine2/zend_compile.c diff -u ZendEngine2/zend_compile.c:1.749 ZendEngine2/zend_compile.c:1.750 --- ZendEngine2/zend_compile.c:1.749 Fri May 18 13:12:47 2007 +++ ZendEngine2/zend_compile.c Thu Jun 28 00:01:57 2007 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_compile.c,v 1.749 2007/05/18 13:12:47 dmitry Exp $ */ +/* $Id: zend_compile.c,v 1.750 2007/06/28 00:01:57 stas Exp $ */ #include <zend_language_parser.h> #include "zend.h" @@ -3338,6 +3338,18 @@ zend_llist_add_element(fetch_list_ptr, &opline); } +void zend_do_halt_compiler_register(TSRMLS_D) +{ + char *name, *cfilename; + char haltoff[] = "__COMPILER_HALT_OFFSET__"; + int len, clen; + cfilename = zend_get_compiled_filename(TSRMLS_C); + clen = strlen(cfilename); + zend_mangle_property_name(&name, &len, haltoff, + sizeof("__COMPILER_HALT_OFFSET__") - 1, cfilename, clen, 0); + zend_register_long_constant(name, len+1, zend_get_scanned_file_offset(TSRMLS_C), CONST_CS, 0 TSRMLS_CC); + pefree(name, 0); +} void zend_do_declare_implicit_property(TSRMLS_D) http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_compile.h?r1=1.357&r2=1.358&diff_format=u Index: ZendEngine2/zend_compile.h diff -u ZendEngine2/zend_compile.h:1.357 ZendEngine2/zend_compile.h:1.358 --- ZendEngine2/zend_compile.h:1.357 Fri May 18 13:12:47 2007 +++ ZendEngine2/zend_compile.h Thu Jun 28 00:01:57 2007 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_compile.h,v 1.357 2007/05/18 13:12:47 dmitry Exp $ */ +/* $Id: zend_compile.h,v 1.358 2007/06/28 00:01:57 stas Exp $ */ #ifndef ZEND_COMPILE_H #define ZEND_COMPILE_H @@ -456,6 +456,7 @@ void zend_do_begin_class_declaration(znode *class_token, znode *class_name, znode *parent_class_name TSRMLS_DC); void zend_do_end_class_declaration(znode *class_token, znode *parent_token TSRMLS_DC); void zend_do_declare_property(znode *var_name, znode *value, zend_uint access_type TSRMLS_DC); +void zend_do_halt_compiler_register(TSRMLS_D); void zend_do_declare_implicit_property(TSRMLS_D); void zend_do_declare_class_constant(znode *var_name, znode *value TSRMLS_DC); http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_constants.c?r1=1.91&r2=1.92&diff_format=u Index: ZendEngine2/zend_constants.c diff -u ZendEngine2/zend_constants.c:1.91 ZendEngine2/zend_constants.c:1.92 --- ZendEngine2/zend_constants.c:1.91 Mon Jun 4 08:24:32 2007 +++ ZendEngine2/zend_constants.c Thu Jun 28 00:01:57 2007 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_constants.c,v 1.91 2007/06/04 08:24:32 tony2001 Exp $ */ +/* $Id: zend_constants.c,v 1.92 2007/06/28 00:01:57 stas Exp $ */ #include "zend.h" #include "zend_constants.h" @@ -348,7 +348,27 @@ retval=0; } } else { - retval=0; + char haltoff[] = "__COMPILER_HALT_OFFSET__"; + if (!EG(in_execution)) { + retval = 0; + } else if (name_len == sizeof("__COMPILER_HALT_OFFSET__") - 1 && memcmp(haltoff, name.s, name_len) == 0) { + char *cfilename; + zstr haltname; + int len, clen; + cfilename = zend_get_executed_filename(TSRMLS_C); + clen = strlen(cfilename); + /* check for __COMPILER_HALT_OFFSET__ */ + zend_mangle_property_name(&haltname.s, &len, haltoff, + sizeof("__COMPILER_HALT_OFFSET__") - 1, cfilename, clen, 0); + if (zend_u_hash_find(EG(zend_constants), IS_STRING, haltname, len+1, (void **) &c) == SUCCESS) { + retval=1; + } else { + retval=0; + } + pefree(haltname.s, 0); + } else { + retval=0; + } } efree(lookup_name.v); } @@ -374,6 +394,7 @@ zstr lookup_name; zstr name; int ret = SUCCESS; + static char haltoff[] = "__COMPILER_HALT_OFFSET__"; #if 0 printf("Registering constant for module %d\n", c->module_number); @@ -389,6 +410,13 @@ lookup_name = NULL_ZSTR; } + if (EG(in_execution) && lookup_name_len == sizeof("__COMPILER_HALT_OFFSET__") && memcmp(haltoff, name.s, lookup_name_len) == 0) { + zend_error(E_NOTICE,"Constant %R already defined", type, name); + if (lookup_name.v) { + efree(lookup_name.v); + } + ret = FAILURE; + } if (zend_u_hash_add(EG(zend_constants), type, name, lookup_name_len, (void *) c, sizeof(zend_constant), NULL)==FAILURE) { zend_error(E_NOTICE,"Constant %R already defined", type, name); free(c->name.v); http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_language_parser.y?r1=1.183&r2=1.184&diff_format=u Index: ZendEngine2/zend_language_parser.y diff -u ZendEngine2/zend_language_parser.y:1.183 ZendEngine2/zend_language_parser.y:1.184 --- ZendEngine2/zend_language_parser.y:1.183 Fri May 18 20:48:19 2007 +++ ZendEngine2/zend_language_parser.y Thu Jun 28 00:01:57 2007 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_language_parser.y,v 1.183 2007/05/18 20:48:19 stas Exp $ */ +/* $Id: zend_language_parser.y,v 1.184 2007/06/28 00:01:57 stas Exp $ */ /* * LALR shift/reduce conflicts and how they are resolved: @@ -163,7 +163,7 @@ statement | function_declaration_statement { zend_do_early_binding(TSRMLS_C); } | class_declaration_statement { zend_do_early_binding(TSRMLS_C); } - | T_HALT_COMPILER '(' ')' ';' { zval c; if (zend_get_constant("__COMPILER_HALT_OFFSET__", sizeof("__COMPILER_HALT_OFFSET__") - 1, &c TSRMLS_CC)) { zval_dtor(&c); zend_error(E_COMPILE_ERROR, "__HALT_COMPILER() can only be used once per request"); } else { REGISTER_MAIN_LONG_CONSTANT("__COMPILER_HALT_OFFSET__", zend_get_scanned_file_offset(TSRMLS_C), CONST_CS); } YYACCEPT; } + | T_HALT_COMPILER '(' ')' ';' { zend_do_halt_compiler_register(TSRMLS_C); YYACCEPT; } ; http://cvs.php.net/viewvc.cgi/ZendEngine2/tests/halt_compiler1.phpt?r1=1.1&r2=1.2&diff_format=u Index: ZendEngine2/tests/halt_compiler1.phpt diff -u /dev/null ZendEngine2/tests/halt_compiler1.phpt:1.2 --- /dev/null Thu Jun 28 00:01:58 2007 +++ ZendEngine2/tests/halt_compiler1.phpt Thu Jun 28 00:01:58 2007 @@ -0,0 +1,8 @@ +--TEST-- +__HALT_COMPILER(); +--FILE-- +<?php echo 'test'; var_dump(__COMPILER_HALT_OFFSET__); __HALT_COMPILER(); +?> +===DONE=== +--EXPECT-- +testint(73) \ No newline at end of file http://cvs.php.net/viewvc.cgi/ZendEngine2/tests/halt_compiler2.phpt?r1=1.1&r2=1.2&diff_format=u Index: ZendEngine2/tests/halt_compiler2.phpt diff -u /dev/null ZendEngine2/tests/halt_compiler2.phpt:1.2 --- /dev/null Thu Jun 28 00:01:58 2007 +++ ZendEngine2/tests/halt_compiler2.phpt Thu Jun 28 00:01:58 2007 @@ -0,0 +1,23 @@ +--TEST-- +__HALT_COMPILER(); 2 files +--FILE-- +<?php +$text = "<?php echo 'test'; var_dump(__COMPILER_HALT_OFFSET__); __HALT_COMPILER(); ?> +hi there"; +file_put_contents(dirname(__FILE__) . '/test1.php', $text); +$text = "<?php echo 'test2'; var_dump(__COMPILER_HALT_OFFSET__); __HALT_COMPILER(); ?> +hi there 2"; +file_put_contents(dirname(__FILE__) . '/test2.php', $text); +include dirname(__FILE__) . '/test1.php'; +include dirname(__FILE__) . '/test2.php'; +?> +==DONE== +--CLEAN-- +<?php +unlink(dirname(__FILE__) . '/test1.php'); +unlink(dirname(__FILE__) . '/test2.php'); +?> +--EXPECT-- +testint(73) +test2int(74) +==DONE== \ No newline at end of file http://cvs.php.net/viewvc.cgi/ZendEngine2/tests/halt_compiler3.phpt?r1=1.1&r2=1.2&diff_format=u Index: ZendEngine2/tests/halt_compiler3.phpt diff -u /dev/null ZendEngine2/tests/halt_compiler3.phpt:1.2 --- /dev/null Thu Jun 28 00:01:58 2007 +++ ZendEngine2/tests/halt_compiler3.phpt Thu Jun 28 00:01:58 2007 @@ -0,0 +1,10 @@ +--TEST-- +__HALT_COMPILER(); bad define() of __COMPILER_HALT_OFFSET__ 1 +--FILE-- +<?php +define ('__COMPILER_HALT_OFFSET__', 1); +?> +==DONE== +--EXPECTF-- +Notice: Constant __COMPILER_HALT_OFFSET__ already defined in %s on line %d +==DONE== \ No newline at end of file http://cvs.php.net/viewvc.cgi/ZendEngine2/tests/halt_compiler4.phpt?r1=1.1&r2=1.2&diff_format=u Index: ZendEngine2/tests/halt_compiler4.phpt diff -u /dev/null ZendEngine2/tests/halt_compiler4.phpt:1.2 --- /dev/null Thu Jun 28 00:01:59 2007 +++ ZendEngine2/tests/halt_compiler4.phpt Thu Jun 28 00:01:58 2007 @@ -0,0 +1,10 @@ +--TEST-- +__HALT_COMPILER(); bad define() of __COMPILER_HALT_OFFSET__ 2 +--FILE-- +<?php +define ('__COMPILER_HALT_OFFSET__', 1); +__HALT_COMPILER(); +?> +==DONE== +--EXPECTF-- +Notice: Constant __COMPILER_HALT_OFFSET__ already defined in %s on line %d \ No newline at end of file
http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_compile.c?r1=1.749&r2=1.750&diff_format=u Index: ZendEngine2/zend_compile.c diff -u ZendEngine2/zend_compile.c:1.749 ZendEngine2/zend_compile.c:1.750 --- ZendEngine2/zend_compile.c:1.749 Fri May 18 13:12:47 2007 +++ ZendEngine2/zend_compile.c Thu Jun 28 00:01:57 2007 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_compile.c,v 1.749 2007/05/18 13:12:47 dmitry Exp $ */ +/* $Id: zend_compile.c,v 1.750 2007/06/28 00:01:57 stas Exp $ */ #include <zend_language_parser.h> #include "zend.h" @@ -3338,6 +3338,18 @@ zend_llist_add_element(fetch_list_ptr, &opline); } +void zend_do_halt_compiler_register(TSRMLS_D) +{ + char *name, *cfilename; + char haltoff[] = "__COMPILER_HALT_OFFSET__"; + int len, clen; + cfilename = zend_get_compiled_filename(TSRMLS_C); + clen = strlen(cfilename); + zend_mangle_property_name(&name, &len, haltoff, + sizeof("__COMPILER_HALT_OFFSET__") - 1, cfilename, clen, 0); + zend_register_long_constant(name, len+1, zend_get_scanned_file_offset(TSRMLS_C), CONST_CS, 0 TSRMLS_CC); + pefree(name, 0); +} void zend_do_declare_implicit_property(TSRMLS_D) http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_compile.h?r1=1.357&r2=1.358&diff_format=u Index: ZendEngine2/zend_compile.h diff -u ZendEngine2/zend_compile.h:1.357 ZendEngine2/zend_compile.h:1.358 --- ZendEngine2/zend_compile.h:1.357 Fri May 18 13:12:47 2007 +++ ZendEngine2/zend_compile.h Thu Jun 28 00:01:57 2007 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_compile.h,v 1.357 2007/05/18 13:12:47 dmitry Exp $ */ +/* $Id: zend_compile.h,v 1.358 2007/06/28 00:01:57 stas Exp $ */ #ifndef ZEND_COMPILE_H #define ZEND_COMPILE_H @@ -456,6 +456,7 @@ void zend_do_begin_class_declaration(znode *class_token, znode *class_name, znode *parent_class_name TSRMLS_DC); void zend_do_end_class_declaration(znode *class_token, znode *parent_token TSRMLS_DC); void zend_do_declare_property(znode *var_name, znode *value, zend_uint access_type TSRMLS_DC); +void zend_do_halt_compiler_register(TSRMLS_D); void zend_do_declare_implicit_property(TSRMLS_D); void zend_do_declare_class_constant(znode *var_name, znode *value TSRMLS_DC); http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_constants.c?r1=1.91&r2=1.92&diff_format=u Index: ZendEngine2/zend_constants.c diff -u ZendEngine2/zend_constants.c:1.91 ZendEngine2/zend_constants.c:1.92 --- ZendEngine2/zend_constants.c:1.91 Mon Jun 4 08:24:32 2007 +++ ZendEngine2/zend_constants.c Thu Jun 28 00:01:57 2007 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_constants.c,v 1.91 2007/06/04 08:24:32 tony2001 Exp $ */ +/* $Id: zend_constants.c,v 1.92 2007/06/28 00:01:57 stas Exp $ */ #include "zend.h" #include "zend_constants.h" @@ -348,7 +348,27 @@ retval=0; } } else { - retval=0; + char haltoff[] = "__COMPILER_HALT_OFFSET__"; + if (!EG(in_execution)) { + retval = 0; + } else if (name_len == sizeof("__COMPILER_HALT_OFFSET__") - 1 && memcmp(haltoff, name.s, name_len) == 0) { + char *cfilename; + zstr haltname; + int len, clen; + cfilename = zend_get_executed_filename(TSRMLS_C); + clen = strlen(cfilename); + /* check for __COMPILER_HALT_OFFSET__ */ + zend_mangle_property_name(&haltname.s, &len, haltoff, + sizeof("__COMPILER_HALT_OFFSET__") - 1, cfilename, clen, 0); + if (zend_u_hash_find(EG(zend_constants), IS_STRING, haltname, len+1, (void **) &c) == SUCCESS) { + retval=1; + } else { + retval=0; + } + pefree(haltname.s, 0); + } else { + retval=0; + } } efree(lookup_name.v); } @@ -374,6 +394,7 @@ zstr lookup_name; zstr name; int ret = SUCCESS; + static char haltoff[] = "__COMPILER_HALT_OFFSET__"; #if 0 printf("Registering constant for module %d\n", c->module_number); @@ -389,6 +410,13 @@ lookup_name = NULL_ZSTR; } + if (EG(in_execution) && lookup_name_len == sizeof("__COMPILER_HALT_OFFSET__") && memcmp(haltoff, name.s, lookup_name_len) == 0) { + zend_error(E_NOTICE,"Constant %R already defined", type, name); + if (lookup_name.v) { + efree(lookup_name.v); + } + ret = FAILURE; + } if (zend_u_hash_add(EG(zend_constants), type, name, lookup_name_len, (void *) c, sizeof(zend_constant), NULL)==FAILURE) { zend_error(E_NOTICE,"Constant %R already defined", type, name); free(c->name.v); http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_language_parser.y?r1=1.183&r2=1.184&diff_format=u Index: ZendEngine2/zend_language_parser.y diff -u ZendEngine2/zend_language_parser.y:1.183 ZendEngine2/zend_language_parser.y:1.184 --- ZendEngine2/zend_language_parser.y:1.183 Fri May 18 20:48:19 2007 +++ ZendEngine2/zend_language_parser.y Thu Jun 28 00:01:57 2007 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_language_parser.y,v 1.183 2007/05/18 20:48:19 stas Exp $ */ +/* $Id: zend_language_parser.y,v 1.184 2007/06/28 00:01:57 stas Exp $ */ /* * LALR shift/reduce conflicts and how they are resolved: @@ -163,7 +163,7 @@ statement | function_declaration_statement { zend_do_early_binding(TSRMLS_C); } | class_declaration_statement { zend_do_early_binding(TSRMLS_C); } - | T_HALT_COMPILER '(' ')' ';' { zval c; if (zend_get_constant("__COMPILER_HALT_OFFSET__", sizeof("__COMPILER_HALT_OFFSET__") - 1, &c TSRMLS_CC)) { zval_dtor(&c); zend_error(E_COMPILE_ERROR, "__HALT_COMPILER() can only be used once per request"); } else { REGISTER_MAIN_LONG_CONSTANT("__COMPILER_HALT_OFFSET__", zend_get_scanned_file_offset(TSRMLS_C), CONST_CS); } YYACCEPT; } + | T_HALT_COMPILER '(' ')' ';' { zend_do_halt_compiler_register(TSRMLS_C); YYACCEPT; } ; http://cvs.php.net/viewvc.cgi/ZendEngine2/tests/halt_compiler1.phpt?r1=1.1&r2=1.2&diff_format=u Index: ZendEngine2/tests/halt_compiler1.phpt diff -u /dev/null ZendEngine2/tests/halt_compiler1.phpt:1.2 --- /dev/null Thu Jun 28 00:01:58 2007 +++ ZendEngine2/tests/halt_compiler1.phpt Thu Jun 28 00:01:58 2007 @@ -0,0 +1,8 @@ +--TEST-- +__HALT_COMPILER(); +--FILE-- +<?php echo 'test'; var_dump(__COMPILER_HALT_OFFSET__); __HALT_COMPILER(); +?> +===DONE=== +--EXPECT-- +testint(73) \ No newline at end of file http://cvs.php.net/viewvc.cgi/ZendEngine2/tests/halt_compiler2.phpt?r1=1.1&r2=1.2&diff_format=u Index: ZendEngine2/tests/halt_compiler2.phpt diff -u /dev/null ZendEngine2/tests/halt_compiler2.phpt:1.2 --- /dev/null Thu Jun 28 00:01:58 2007 +++ ZendEngine2/tests/halt_compiler2.phpt Thu Jun 28 00:01:58 2007 @@ -0,0 +1,23 @@ +--TEST-- +__HALT_COMPILER(); 2 files +--FILE-- +<?php +$text = "<?php echo 'test'; var_dump(__COMPILER_HALT_OFFSET__); __HALT_COMPILER(); ?> +hi there"; +file_put_contents(dirname(__FILE__) . '/test1.php', $text); +$text = "<?php echo 'test2'; var_dump(__COMPILER_HALT_OFFSET__); __HALT_COMPILER(); ?> +hi there 2"; +file_put_contents(dirname(__FILE__) . '/test2.php', $text); +include dirname(__FILE__) . '/test1.php'; +include dirname(__FILE__) . '/test2.php'; +?> +==DONE== +--CLEAN-- +<?php +unlink(dirname(__FILE__) . '/test1.php'); +unlink(dirname(__FILE__) . '/test2.php'); +?> +--EXPECT-- +testint(73) +test2int(74) +==DONE== \ No newline at end of file http://cvs.php.net/viewvc.cgi/ZendEngine2/tests/halt_compiler3.phpt?r1=1.1&r2=1.2&diff_format=u Index: ZendEngine2/tests/halt_compiler3.phpt diff -u /dev/null ZendEngine2/tests/halt_compiler3.phpt:1.2 --- /dev/null Thu Jun 28 00:01:58 2007 +++ ZendEngine2/tests/halt_compiler3.phpt Thu Jun 28 00:01:58 2007 @@ -0,0 +1,10 @@ +--TEST-- +__HALT_COMPILER(); bad define() of __COMPILER_HALT_OFFSET__ 1 +--FILE-- +<?php +define ('__COMPILER_HALT_OFFSET__', 1); +?> +==DONE== +--EXPECTF-- +Notice: Constant __COMPILER_HALT_OFFSET__ already defined in %s on line %d +==DONE== \ No newline at end of file http://cvs.php.net/viewvc.cgi/ZendEngine2/tests/halt_compiler4.phpt?r1=1.1&r2=1.2&diff_format=u Index: ZendEngine2/tests/halt_compiler4.phpt diff -u /dev/null ZendEngine2/tests/halt_compiler4.phpt:1.2 --- /dev/null Thu Jun 28 00:01:59 2007 +++ ZendEngine2/tests/halt_compiler4.phpt Thu Jun 28 00:01:58 2007 @@ -0,0 +1,10 @@ +--TEST-- +__HALT_COMPILER(); bad define() of __COMPILER_HALT_OFFSET__ 2 +--FILE-- +<?php +define ('__COMPILER_HALT_OFFSET__', 1); +__HALT_COMPILER(); +?> +==DONE== +--EXPECTF-- +Notice: Constant __COMPILER_HALT_OFFSET__ already defined in %s on line %d \ No newline at end of file