diff options
| author | Zeev Suraski <zeev@php.net> | 2000-08-09 19:22:35 +0000 |
|---|---|---|
| committer | Zeev Suraski <zeev@php.net> | 2000-08-09 19:22:35 +0000 |
| commit | c06692e9ec92bdbe22e7a4149b5365635c4ad950 (patch) | |
| tree | fb3e7ccb8c5187dd8d39aacd97d2707739982769 /Zend | |
| parent | 609577d8826e5a23565eb8fdf5033d60ed505c4e (diff) | |
| download | php-git-c06692e9ec92bdbe22e7a4149b5365635c4ad950.tar.gz | |
The patch we promised - redesigned the compilation/execution API:
Advantages:
- Smaller memory footprint for the op arrays
- Slightly faster compilation times (due to saved erealloc() calls and faster zend_op
initialization)
- include_once() & require_once() share the same file list
- Consistency between include() and require() - this mostly means that return()
works inside require()'d files just as it does in include() files (it used to
be meaningless in require()'d files, most of the time (see below))
- Made require() consistent with itself. Before, if the argument was not a constant
string, require() took the include() behavior (with return()).
- Removed lots of duplicate code.
Bottom line - require() and include() are very similar now; require() is simply an include()
which isn't allowed to fail. Due to the erealloc() calls for large op arrays, require()
didn't end up being any faster than include() in the Zend engine.
Diffstat (limited to 'Zend')
| -rw-r--r-- | Zend/zend-parser.y | 10 | ||||
| -rw-r--r-- | Zend/zend-scanner.l | 161 | ||||
| -rw-r--r-- | Zend/zend.c | 34 | ||||
| -rw-r--r-- | Zend/zend_builtin_functions.c | 19 | ||||
| -rw-r--r-- | Zend/zend_compile.c | 30 | ||||
| -rw-r--r-- | Zend/zend_compile.h | 17 | ||||
| -rw-r--r-- | Zend/zend_execute.c | 19 | ||||
| -rw-r--r-- | Zend/zend_execute_API.c | 17 | ||||
| -rw-r--r-- | Zend/zend_globals.h | 4 | ||||
| -rw-r--r-- | Zend/zend_opcode.c | 18 |
10 files changed, 93 insertions, 236 deletions
diff --git a/Zend/zend-parser.y b/Zend/zend-parser.y index 6c62ad78f3..482e72267b 100644 --- a/Zend/zend-parser.y +++ b/Zend/zend-parser.y @@ -47,7 +47,7 @@ %pure_parser %expect 4 -%left T_INCLUDE T_INCLUDE_ONCE T_EVAL +%left T_INCLUDE T_INCLUDE_ONCE T_EVAL T_REQUIRE T_REQUIRE_ONCE %left ',' %left T_LOGICAL_OR %left T_LOGICAL_XOR @@ -105,8 +105,6 @@ %token T_FUNCTION %token T_CONST %token T_RETURN -%token T_REQUIRE -%token T_REQUIRE_ONCE %token T_USE %token T_GLOBAL %token T_STATIC @@ -197,9 +195,7 @@ unticked_statement: | T_ECHO echo_expr_list ';' | T_INLINE_HTML { do_echo(&$1 CLS_CC); } | expr ';' { do_free(&$1 CLS_CC); } - | T_REQUIRE expr ';' { do_require(&$2, 0 CLS_CC); } - | T_REQUIRE_ONCE use_filename ';' { do_require(&$2, 1 CLS_CC); } - | T_USE use_filename ';' { use_filename($2.u.constant.value.str.val, $2.u.constant.value.str.len CLS_CC); zval_dtor(&$2.u.constant); } + | T_USE use_filename ';' { zend_error(E_COMPILE_ERROR,"use: Not yet supported. Please use include_once() or require_once()"); zval_dtor(&$2.u.constant); } | T_UNSET '(' unset_variables ')' ';' | T_FOREACH '(' expr T_AS { do_foreach_begin(&$1, &$3, &$2, &$4 CLS_CC); } w_cvar foreach_optional_arg ')' { do_foreach_cont(&$6, &$7, &$4 CLS_CC); } foreach_statement { do_foreach_end(&$1, &$2 CLS_CC); } | T_DECLARE { do_declare_begin(CLS_C); } '(' declare_list ')' declare_statement { do_declare_end(CLS_C); } @@ -720,6 +716,8 @@ internal_functions_in_yacc: | T_INCLUDE expr { do_include_or_eval(ZEND_INCLUDE, &$$, &$2 CLS_CC); } | T_INCLUDE_ONCE expr { do_include_or_eval(ZEND_INCLUDE_ONCE, &$$, &$2 CLS_CC); } | T_EVAL '(' expr ')' { do_include_or_eval(ZEND_EVAL, &$$, &$3 CLS_CC); } + | T_REQUIRE expr { do_include_or_eval(ZEND_REQUIRE, &$$, &$2 CLS_CC); } + | T_REQUIRE_ONCE use_filename { do_include_or_eval(ZEND_REQUIRE_ONCE, &$$, &$2 CLS_CC); } ; diff --git a/Zend/zend-scanner.l b/Zend/zend-scanner.l index 4619ce4a18..f95d7a13da 100644 --- a/Zend/zend-scanner.l +++ b/Zend/zend-scanner.l @@ -243,7 +243,7 @@ ZEND_API void zend_close_file_handle(zend_file_handle *file_handle CLS_DC) ZEND_API int open_file_for_scanning(zend_file_handle *file_handle CLS_DC) { - char *file_path; + char *file_path=NULL; #ifndef ZTS switch (file_handle->type) { @@ -324,31 +324,16 @@ ZEND_API int open_file_for_scanning(zend_file_handle *file_handle CLS_DC) END_EXTERN_C() -ZEND_API zend_op_array *zend_compile_files(int type CLS_DC, int file_count, ...) -{ - va_list files; - zend_op_array *op_array; - - va_start(files, file_count); - op_array = zend_v_compile_files(type CLS_CC, file_count, files); - va_end(files); - return op_array; -} - - -ZEND_API zend_op_array *v_compile_files(int type CLS_DC, int file_count, va_list files) +ZEND_API zend_op_array *compile_file(zend_file_handle *file_handle CLS_DC) { zend_lex_state original_lex_state; zend_op_array *op_array = (zend_op_array *) emalloc(sizeof(zend_op_array)); zend_op_array *original_active_op_array = CG(active_op_array); zend_op_array *retval=NULL; - int i; int compiler_result; - int compiled_files=0; - int last_file=0; + zend_bool compilation_successful=0; znode retval_znode; zend_bool original_in_compilation = CG(in_compilation); - zend_file_handle **file_handles = (zend_file_handle **) do_alloca(file_count * sizeof(zend_file_handle *)); retval_znode.op_type = IS_CONST; retval_znode.u.constant.type = IS_LONG; @@ -356,55 +341,38 @@ ZEND_API zend_op_array *v_compile_files(int type CLS_DC, int file_count, va_list retval_znode.u.constant.is_ref = 0; retval_znode.u.constant.refcount = 1; - init_op_array(op_array, ZEND_USER_FUNCTION, INITIAL_OP_ARRAY_SIZE); save_lexical_state(&original_lex_state CLS_CC); retval = op_array; /* success oriented */ - for (i=0; i<file_count; i++) { - file_handles[i] = va_arg(files, zend_file_handle *); - if (file_handles[i]) { - last_file = i; - } - } - - for (i=0; i<file_count; i++) { - if (!file_handles[i]) { - continue; - } - if (open_file_for_scanning(file_handles[i] CLS_CC)==FAILURE) { - zend_message_dispatcher(ZMSG_FAILED_INCLUDE_FOPEN, file_handles[i]->filename); - } else { - CG(in_compilation) = 1; - CG(active_op_array) = op_array; - compiler_result = zendparse(CLS_C); - zend_close_file_handle(file_handles[i] CLS_CC); - if (i == last_file) { - do_return(&retval_znode, 0 CLS_CC); - } - restore_lexical_state(&original_lex_state CLS_CC); - CG(in_compilation) = original_in_compilation; - if (compiler_result==1) { /* parser error */ - CG(unclean_shutdown) = 1; - retval = NULL; - break; - } - compiled_files++; + if (open_file_for_scanning(file_handle CLS_CC)==FAILURE) { + zend_message_dispatcher(ZMSG_FAILED_INCLUDE_FOPEN, file_handle->filename); + compilation_successful=0; + } else { + init_op_array(op_array, ZEND_USER_FUNCTION, INITIAL_OP_ARRAY_SIZE CLS_CC); + CG(in_compilation) = 1; + CG(active_op_array) = op_array; + compiler_result = zendparse(CLS_C); + zend_close_file_handle(file_handle CLS_CC); + do_return(&retval_znode, 0 CLS_CC); + restore_lexical_state(&original_lex_state CLS_CC); + CG(in_compilation) = original_in_compilation; + if (compiler_result==1) { /* parser error */ + CG(unclean_shutdown) = 1; + retval = NULL; } + compilation_successful=1; } if (retval) { - if (compiled_files>0) { - CG(active_op_array) = original_active_op_array; + CG(active_op_array) = original_active_op_array; + if (compilation_successful) { pass_two(op_array); } else { - CG(active_op_array) = original_active_op_array; - destroy_op_array(op_array); efree(op_array); retval = NULL; } } - free_alloca(file_handles); return retval; } @@ -435,7 +403,7 @@ zend_op_array *compile_filename(int type, zval *filename CLS_DC ELS_DC) error_reporting = EG(error_reporting); EG(error_reporting) = 0; } - retval = zend_compile_files(type CLS_CC, 1, &file_handle); + retval = zend_compile_file(&file_handle CLS_CC); if (type==ZEND_REQUIRE) { EG(error_reporting) = error_reporting; @@ -496,13 +464,12 @@ zend_op_array *compile_string(zval *source_string CLS_DC) convert_to_string(&tmp); source_string = &tmp; - init_op_array(op_array, ZEND_EVAL_CODE, INITIAL_OP_ARRAY_SIZE); save_lexical_state(&original_lex_state CLS_CC); if (prepare_string_for_scanning(source_string CLS_CC)==FAILURE) { - destroy_op_array(op_array); efree(op_array); retval = NULL; } else { + init_op_array(op_array, ZEND_EVAL_CODE, INITIAL_OP_ARRAY_SIZE CLS_CC); CG(active_op_array) = op_array; #ifndef ZTS BEGIN(ST_IN_SCRIPTING); @@ -520,7 +487,6 @@ zend_op_array *compile_string(zval *source_string CLS_DC) do_return(NULL, 0 CLS_CC); CG(active_op_array) = original_active_op_array; pass_two(op_array); - pass_include_eval(op_array); retval = op_array; } } @@ -531,87 +497,6 @@ zend_op_array *compile_string(zval *source_string CLS_DC) BEGIN_EXTERN_C() -int require_filename(char *filename, zend_bool unique CLS_DC) -{ - zend_file_handle file_handle; - - file_handle.type = ZEND_HANDLE_FILENAME; - file_handle.filename = filename; - file_handle.free_filename = 0; - if (require_file(&file_handle, unique CLS_CC)==FAILURE) { - zend_bailout(); - return FAILURE; /* will never get here */ - } - return SUCCESS; -} - - -int use_filename(char *filename, uint filename_length CLS_DC) -{ - zend_error(E_COMPILE_ERROR,"use: Not yet supported. Please use include_once() or require_once()"); - return FAILURE; - -#if 0 - zend_file_handle file_handle; - - file_handle.filename = (char *) emalloc(filename_length + zend_uv.import_use_extension_length); - memcpy(file_handle.filename, filename, filename_length); - memcpy(file_handle.filename+filename_length, zend_uv.import_use_extension, zend_uv.import_use_extension_length); - file_handle.filename[filename_length+zend_uv.import_use_extension_length] = 0; - file_handle.free_filename = 1; - - file_handle.type = ZEND_HANDLE_FILENAME; - if (require_file(&file_handle, 1 CLS_CC)==FAILURE) { - efree(file_handle.filename); - zend_bailout(); - return FAILURE; /* will never get here */ - } - return SUCCESS; -#endif -} - - -int require_file(zend_file_handle *file_handle, zend_bool unique CLS_DC) -{ - zend_lex_state original_lex_state; - int compiler_result; - - save_lexical_state(&original_lex_state CLS_CC); - if (open_file_for_scanning(file_handle CLS_CC)==FAILURE) { - zend_message_dispatcher(ZMSG_FAILED_REQUIRE_FOPEN, file_handle->filename); - return FAILURE; - } - if (file_handle->opened_path) { - if (unique) { - zend_file_handle *pfh; - - if (zend_hash_add(&CG(used_files), file_handle->opened_path, strlen(file_handle->opened_path)+1, file_handle, sizeof(zend_file_handle), (void **) &pfh)==FAILURE) { - zend_close_file_handle(file_handle CLS_CC); - restore_lexical_state(&original_lex_state CLS_CC); - return SUCCESS; - } else { - /* pfh is a copy we only save for get_used_files() */ - pfh->type = ZEND_HANDLE_FILENAME; - if (pfh->filename) { - pfh->filename = estrdup(pfh->filename); - pfh->free_filename = 1; - } - if (pfh->opened_path) { - pfh->opened_path = strdup(pfh->opened_path); - } - } - } - } - compiler_result = zendparse(CLS_C); - zend_close_file_handle(file_handle CLS_CC); - restore_lexical_state(&original_lex_state CLS_CC); - if (compiler_result==1) { - zend_bailout(); - } - return SUCCESS; -} - - int highlight_file(char *filename, zend_syntax_highlighter_ini *syntax_highlighter_ini) { zend_lex_state original_lex_state; diff --git a/Zend/zend.c b/Zend/zend.c index 7c73765dfd..5a12267e9c 100644 --- a/Zend/zend.c +++ b/Zend/zend.c @@ -357,7 +357,7 @@ int zend_startup(zend_utility_functions *utility_functions, char **extensions, i zend_get_ini_entry_p = utility_functions->get_ini_entry; zend_ticks_function = utility_functions->ticks_function; - zend_v_compile_files = v_compile_files; + zend_compile_file = compile_file; zend_execute = execute; zend_startup_extensions(); @@ -692,3 +692,35 @@ ZEND_API void zend_output_debug_string(zend_bool trigger_break, char *format, .. va_end(args); #endif } + + +ZEND_API int zend_execute_scripts(int type CLS_DC ELS_DC, int file_count, ...) +{ + va_list files; + int i; + zend_file_handle *file_handle; + + va_start(files, file_count); + for (i=0; i<file_count; i++) { + file_handle = va_arg(files, zend_file_handle *); + if (!file_handle) { + continue; + } + EG(active_op_array) = zend_compile_file(file_handle CLS_CC); + if (EG(active_op_array)) { + zend_execute(EG(active_op_array) ELS_CC); + zval_ptr_dtor(EG(return_value_ptr_ptr)); + EG(return_value_ptr_ptr) = &EG(global_return_value_ptr); + EG(global_return_value_ptr) = NULL; + destroy_op_array(EG(active_op_array)); + efree(EG(active_op_array)); + } else if (type==ZEND_REQUIRE) { + va_end(files); + return FAILURE; + } + } + va_end(files); + + return SUCCESS; +} + diff --git a/Zend/zend_builtin_functions.c b/Zend/zend_builtin_functions.c index 4efedd8b08..27564fa5a2 100644 --- a/Zend/zend_builtin_functions.c +++ b/Zend/zend_builtin_functions.c @@ -47,7 +47,6 @@ static ZEND_FUNCTION(leak); #ifdef ZEND_TEST_EXCEPTIONS static ZEND_FUNCTION(crash); #endif -static ZEND_FUNCTION(get_required_files); static ZEND_FUNCTION(get_included_files); static ZEND_FUNCTION(is_subclass_of); static ZEND_FUNCTION(get_class_vars); @@ -91,8 +90,8 @@ static zend_function_entry builtin_functions[] = { #ifdef ZEND_TEST_EXCEPTIONS ZEND_FE(crash, NULL) #endif - ZEND_FE(get_required_files, NULL) ZEND_FE(get_included_files, NULL) + ZEND_FALIAS(get_required_files, get_included_files, NULL) ZEND_FE(is_subclass_of, NULL) ZEND_FE(get_class_vars, NULL) ZEND_FE(get_object_vars, NULL) @@ -713,22 +712,6 @@ static int copy_import_use_file(zend_file_handle *fh, zval *array) } -/* {{{ proto array get_required_files(void) - Returns an array with the file names that were require_once()'d */ -ZEND_FUNCTION(get_required_files) -{ - CLS_FETCH(); - - if (ZEND_NUM_ARGS() != 0) { - ZEND_WRONG_PARAM_COUNT(); - } - - array_init(return_value); - zend_hash_apply_with_argument(&CG(used_files), (apply_func_arg_t) copy_import_use_file, return_value); -} -/* }}} */ - - /* {{{ proto array get_included_files(void) Returns an array with the file names that were include_once()'d */ ZEND_FUNCTION(get_included_files) diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index 2b43e687ff..76d5d4d2b4 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -26,7 +26,7 @@ #include "zend_fast_cache.h" -ZEND_API zend_op_array *(*zend_v_compile_files)(int type CLS_DC, int file_count, va_list files); +ZEND_API zend_op_array *(*zend_compile_file)(zend_file_handle *file_handle CLS_DC); #ifndef ZTS @@ -43,15 +43,15 @@ static void free_filename(void *p) } -static void build_runtime_defined_function_key(zval *result, zval *name, zend_op *opline) +static void build_runtime_defined_function_key(zval *result, zval *name, zend_op *opline CLS_DC) { char lineno_buf[32]; uint lineno_len; char *filename; lineno_len = zend_sprintf(lineno_buf, "%d", opline->lineno); - if (opline->filename) { - filename = opline->filename; + if (CG(active_op_array)->filename) { + filename = CG(active_op_array)->filename; } else { filename = "-"; } @@ -95,7 +95,6 @@ void init_compiler(CLS_D ELS_DC) zend_init_rsrc_list(ELS_C); CG(unclean_shutdown) = 0; zend_llist_init(&CG(open_files), sizeof(zend_file_handle), (void (*)(void *)) zend_open_file_dtor, 0); - zend_hash_init(&CG(used_files), 5, NULL, (void (*)(void *)) zend_open_file_dtor_wrapper, 0); init_compiler_declarables(CLS_C ELS_CC); } @@ -110,7 +109,6 @@ void shutdown_compiler(CLS_D) zend_stack_destroy(&CG(declare_stack)); zend_llist_destroy(&CG(filenames_list)); zend_llist_destroy(&CG(open_files)); - zend_hash_destroy(&CG(used_files)); } @@ -717,7 +715,7 @@ void do_begin_function_declaration(znode *function_token, znode *function_name, function_token->u.op_array = CG(active_op_array); zend_str_tolower(name, name_len); - init_op_array(&op_array, ZEND_USER_FUNCTION, INITIAL_OP_ARRAY_SIZE); + init_op_array(&op_array, ZEND_USER_FUNCTION, INITIAL_OP_ARRAY_SIZE CLS_CC); op_array.function_name = name; op_array.arg_types = NULL; @@ -730,7 +728,7 @@ void do_begin_function_declaration(znode *function_token, znode *function_name, opline->opcode = ZEND_DECLARE_FUNCTION_OR_CLASS; opline->op1.op_type = IS_CONST; - build_runtime_defined_function_key(&opline->op1.u.constant, &function_name->u.constant, opline); + build_runtime_defined_function_key(&opline->op1.u.constant, &function_name->u.constant, opline CLS_CC); opline->op2.op_type = IS_CONST; opline->op2.u.constant.type = IS_STRING; opline->op2.u.constant.value.str.val = estrndup(name, name_len); @@ -1551,7 +1549,7 @@ void do_begin_class_declaration(znode *class_name, znode *parent_class_name CLS_ opline->opcode = ZEND_DECLARE_FUNCTION_OR_CLASS; opline->op1.op_type = IS_CONST; - build_runtime_defined_function_key(&opline->op1.u.constant, &class_name->u.constant, opline); + build_runtime_defined_function_key(&opline->op1.u.constant, &class_name->u.constant, opline CLS_CC); opline->op2.op_type = IS_CONST; opline->op2.u.constant.type = IS_STRING; opline->op2.u.constant.refcount = 1; @@ -1958,20 +1956,6 @@ void do_include_or_eval(int type, znode *result, znode *op1 CLS_DC) } -void do_require(znode *filename, zend_bool unique CLS_DC) -{ - if (filename->op_type==IS_CONST - && filename->u.constant.type==IS_STRING) { - require_filename(filename->u.constant.value.str.val, unique CLS_CC); - zval_dtor(&filename->u.constant); - } else { - znode result; - - do_include_or_eval(ZEND_REQUIRE, &result, filename CLS_CC); - } -} - - void do_indirect_references(znode *result, znode *num_references, znode *variable CLS_DC) { int i; diff --git a/Zend/zend_compile.h b/Zend/zend_compile.h index 648775fb1d..67a49711fe 100644 --- a/Zend/zend_compile.h +++ b/Zend/zend_compile.h @@ -80,7 +80,6 @@ typedef struct _zend_op { znode op1; znode op2; ulong extended_value; - char *filename; uint lineno; } zend_op; @@ -121,6 +120,8 @@ struct _zend_op_array { zend_bool return_reference; zend_bool done_pass_two; + char *filename; + void *reserved[ZEND_MAX_RESERVED_RESOURCES]; }; @@ -211,7 +212,7 @@ BEGIN_EXTERN_C() void init_compiler(CLS_D ELS_DC); void shutdown_compiler(CLS_D); -extern ZEND_API zend_op_array *(*zend_v_compile_files)(int type CLS_DC, int file_count, va_list files); +extern ZEND_API zend_op_array *(*zend_compile_file)(zend_file_handle *file_handle CLS_DC); void zend_activate(CLS_D ELS_DC); void zend_deactivate(CLS_D ELS_DC); @@ -339,7 +340,6 @@ void do_new_list_end(CLS_D); void do_cast(znode *result, znode *expr, int type CLS_DC); void do_include_or_eval(int type, znode *result, znode *op1 CLS_DC); -void do_require(znode *filename, zend_bool unique CLS_DC); void do_unset(znode *variable CLS_DC); void do_isset_or_isempty(int type, znode *result, znode *variable CLS_DC); @@ -375,15 +375,12 @@ ZEND_API void function_add_ref(zend_function *function); /* helper functions in zend-scanner.l */ -ZEND_API int require_file(zend_file_handle *file_handle, zend_bool unique CLS_DC); -ZEND_API int require_filename(char *filename, zend_bool unique CLS_DC); -ZEND_API int use_filename(char *filename, uint filename_length CLS_DC); -ZEND_API zend_op_array *zend_compile_files(int type CLS_DC, int file_count, ...); -ZEND_API zend_op_array *v_compile_files(int type CLS_DC, int file_count, va_list files); +ZEND_API zend_op_array *compile_file(zend_file_handle *file_handle CLS_DC); ZEND_API zend_op_array *compile_string(zval *source_string CLS_DC); ZEND_API zend_op_array *compile_filename(int type, zval *filename CLS_DC ELS_DC); +ZEND_API int zend_execute_scripts(int type CLS_DC ELS_DC, int file_count, ...); ZEND_API int open_file_for_scanning(zend_file_handle *file_handle CLS_DC); -ZEND_API void init_op_array(zend_op_array *op_array, int type, int initial_ops_size); +ZEND_API void init_op_array(zend_op_array *op_array, int type, int initial_ops_size CLS_DC); ZEND_API void destroy_op_array(zend_op_array *op_array); ZEND_API void zend_close_file_handle(zend_file_handle *file_handle CLS_DC); ZEND_API void zend_open_file_dtor(zend_file_handle *fh); @@ -401,7 +398,6 @@ int get_next_op_number(zend_op_array *op_array); int print_class(zend_class_entry *class_entry); void print_op_array(zend_op_array *op_array, int optimizations); int pass_two(zend_op_array *op_array); -ZEND_API void pass_include_eval(zend_op_array *op_array); zend_brk_cont_element *get_next_brk_cont_element(zend_op_array *op_array); ZEND_API zend_bool zend_is_compiling(void); @@ -572,6 +568,7 @@ int zendlex(znode *zendlval CLS_DC); #define ZEND_INCLUDE (1<<1) #define ZEND_INCLUDE_ONCE (1<<2) #define ZEND_REQUIRE (1<<3) +#define ZEND_REQUIRE_ONCE (1<<4) #define ZEND_ISSET (1<<0) #define ZEND_ISEMPTY (1<<1) diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c index d1faef252c..fbb77e3765 100644 --- a/Zend/zend_execute.c +++ b/Zend/zend_execute.c @@ -1720,6 +1720,7 @@ send_by_ref: if (opline->op2.u.constant.type==IS_CONSTANT_ARRAY) { zval_copy_ctor(default_value); } + default_value->refcount=1; zval_update_constant(&default_value, 0); default_value->refcount=0; default_value->is_ref=0; @@ -1969,7 +1970,8 @@ send_by_ref: return_value_used = RETURN_VALUE_USED(opline); switch (opline->op2.u.constant.value.lval) { - case ZEND_INCLUDE_ONCE: { + case ZEND_INCLUDE_ONCE: + case ZEND_REQUIRE_ONCE: { char *opened_path; int dummy = 1; zend_file_handle file_handle; @@ -1986,17 +1988,19 @@ send_by_ref: if (file_handle.handle.fp) { if (!opened_path || zend_hash_add(&EG(included_files), opened_path, strlen(opened_path)+1, (void *)&dummy, sizeof(int), NULL)==SUCCESS) { - new_op_array = zend_compile_files(ZEND_INCLUDE CLS_CC, 1, &file_handle); - if (new_op_array) { - pass_include_eval(new_op_array); - } else { + new_op_array = zend_compile_file(&file_handle CLS_CC); + if (!new_op_array) { fclose(file_handle.handle.fp); } } else { fclose(file_handle.handle.fp); } } else { - zend_message_dispatcher(ZMSG_FAILED_INCLUDE_FOPEN, file_handle.filename); + if (opline->opcode==ZEND_INCLUDE_ONCE) { + zend_message_dispatcher(ZMSG_FAILED_INCLUDE_FOPEN, file_handle.filename); + } else { + zend_message_dispatcher(ZMSG_FAILED_REQUIRE_FOPEN, file_handle.filename); + } } if (opened_path) { free (opened_path); @@ -2008,9 +2012,6 @@ send_by_ref: case ZEND_REQUIRE: { new_op_array = compile_filename(opline->op2.u.constant.value.lval, inc_filename CLS_CC ELS_CC); - if (new_op_array) { - pass_include_eval(new_op_array); - } break; } case ZEND_EVAL: diff --git a/Zend/zend_execute_API.c b/Zend/zend_execute_API.c index 16853bcadb..8a3f147bfb 100644 --- a/Zend/zend_execute_API.c +++ b/Zend/zend_execute_API.c @@ -115,8 +115,7 @@ void init_executor(CLS_D ELS_DC) original_sigsegv_handler = signal(SIGSEGV, zend_handle_sigsegv); #endif EG(return_value_ptr_ptr) = &EG(global_return_value_ptr); - EG(global_return_value_ptr) = &EG(global_return_value); - INIT_ZVAL(EG(global_return_value)); + EG(global_return_value_ptr) = NULL; EG(symtable_cache_ptr) = EG(symtable_cache)-1; EG(symtable_cache_limit)=EG(symtable_cache)+SYMTABLE_CACHE_SIZE-1; @@ -129,7 +128,6 @@ void init_executor(CLS_D ELS_DC) zend_ptr_stack_init(&EG(argument_stack)); - EG(main_op_array) = NULL; zend_hash_init(&EG(symbol_table), 50, NULL, ZVAL_PTR_DTOR, 0); EG(active_symbol_table) = &EG(symbol_table); @@ -155,11 +153,6 @@ void init_executor(CLS_D ELS_DC) void shutdown_executor(ELS_D) { - if (EG(global_return_value_ptr) == &EG(global_return_value)) { - zval_dtor(&EG(global_return_value)); - } else { - zval_ptr_dtor(EG(return_value_ptr_ptr)); - } zend_ptr_stack_destroy(&EG(arg_types_stack)); while (EG(symtable_cache_ptr)>=EG(symtable_cache)) { @@ -180,10 +173,6 @@ void shutdown_executor(ELS_D) zend_ptr_stack_destroy(&EG(argument_stack)); /* Destroy all op arrays */ - if (EG(main_op_array)) { - destroy_op_array(EG(main_op_array)); - efree(EG(main_op_array)); - } zend_hash_apply(EG(function_table), (int (*)(void *)) is_not_internal_function); zend_hash_apply(EG(class_table), (int (*)(void *)) is_not_internal_class); @@ -236,8 +225,8 @@ ZEND_API char *get_active_function_name() ZEND_API char *zend_get_executed_filename(ELS_D) { - if (EG(opline_ptr)) { - return active_opline->filename; + if (EG(active_op_array)) { + return EG(active_op_array)->filename; } else { return "[no active file]"; } diff --git a/Zend/zend_globals.h b/Zend/zend_globals.h index 3223aaa210..0a7c8d3288 100644 --- a/Zend/zend_globals.h +++ b/Zend/zend_globals.h @@ -91,8 +91,6 @@ struct _zend_compiler_globals { HashTable *function_table; /* function symbol table */ HashTable *class_table; /* class table */ - HashTable used_files; /* files already included using 'use' */ - zend_llist filenames_list; zend_bool in_compilation; @@ -133,7 +131,6 @@ struct _zend_executor_globals { /* for global return() support */ zval *global_return_value_ptr; - zval global_return_value; /* symbol table cache */ HashTable *symtable_cache[SYMTABLE_CACHE_SIZE]; @@ -153,7 +150,6 @@ struct _zend_executor_globals { int orig_error_reporting; zend_op_array *active_op_array; - zend_op_array *main_op_array; HashTable *function_table; /* function symbol table */ HashTable *class_table; /* class table */ diff --git a/Zend/zend_opcode.c b/Zend/zend_opcode.c index 294d06cc91..346bd0c7fd 100644 --- a/Zend/zend_opcode.c +++ b/Zend/zend_opcode.c @@ -50,7 +50,7 @@ static void op_array_alloc_ops(zend_op_array *op_array) -void init_op_array(zend_op_array *op_array, int type, int initial_ops_size) +void init_op_array(zend_op_array *op_array, int type, int initial_ops_size CLS_DC) { op_array->type = type; #if SUPPORT_INTERACTIVE @@ -78,6 +78,7 @@ void init_op_array(zend_op_array *op_array, int type, int initial_ops_size) op_array->T = 0; op_array->function_name = NULL; + op_array->filename = zend_get_compiled_filename(CLS_C); op_array->arg_types = NULL; @@ -188,7 +189,6 @@ void init_op(zend_op *op CLS_DC) { memset(&op->result, 0, sizeof(znode)); op->lineno = CG(zend_lineno); - op->filename = zend_get_compiled_filename(CLS_C); op->result.op_type = IS_UNUSED; op->extended_value = 0; memset(&op->op1, 0, sizeof(znode)); @@ -252,7 +252,6 @@ static void zend_update_extended_info(zend_op_array *op_array CLS_DC) continue; } opline->lineno = (opline+1)->lineno; - opline->filename = (opline+1)->filename; } else { opline->opcode = ZEND_NOP; } @@ -264,7 +263,6 @@ static void zend_update_extended_info(zend_op_array *op_array CLS_DC) opline->op1.op_type = IS_UNUSED; opline->op2.op_type = IS_UNUSED; if (op_array->last>0) { - opline->filename = op_array->opcodes[op_array->last-2].filename; opline->lineno= op_array->opcodes[op_array->last-2].lineno; } } @@ -281,6 +279,7 @@ static void zend_extension_op_array_handler(zend_extension *extension, zend_op_a int pass_two(zend_op_array *op_array) { + zend_op *opline=op_array->opcodes, *end=opline+op_array->last; CLS_FETCH(); if (op_array->type!=ZEND_USER_FUNCTION && op_array->type!=ZEND_EVAL_CODE) { @@ -292,15 +291,6 @@ int pass_two(zend_op_array *op_array) if (CG(handle_op_arrays)) { zend_llist_apply_with_argument(&zend_extensions, (void (*)(void *, void *)) zend_extension_op_array_handler, op_array); } - op_array->done_pass_two = 1; - return 0; -} - - -ZEND_API void pass_include_eval(zend_op_array *op_array) -{ - zend_op *opline=op_array->opcodes, *end=opline+op_array->last; - while (opline<end) { if (opline->op1.op_type==IS_CONST) { opline->op1.u.constant.is_ref = 1; @@ -312,6 +302,8 @@ ZEND_API void pass_include_eval(zend_op_array *op_array) } opline++; } + op_array->done_pass_two = 1; + return 0; } |
