summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZeev Suraski <zeev@php.net>2000-02-04 14:45:58 +0000
committerZeev Suraski <zeev@php.net>2000-02-04 14:45:58 +0000
commitb6197bcf902373c481eac2c5484954c3b3bd5f85 (patch)
tree75dcf52ac6d07dab7be506edf2e0d39505e32a29
parent2e90a7a368c54f1b2596caac67c325a97121b584 (diff)
downloadphp-git-b6197bcf902373c481eac2c5484954c3b3bd5f85.tar.gz
Maintain a state of whether we're compiling and/or executing
-rw-r--r--Zend/zend-scanner.l12
-rw-r--r--Zend/zend_compile.c18
-rw-r--r--Zend/zend_compile.h4
-rw-r--r--Zend/zend_execute.c3
-rw-r--r--Zend/zend_execute.h1
-rw-r--r--Zend/zend_execute_API.c10
-rw-r--r--Zend/zend_globals.h3
-rw-r--r--Zend/zend_opcode.c2
8 files changed, 47 insertions, 6 deletions
diff --git a/Zend/zend-scanner.l b/Zend/zend-scanner.l
index fe3d868dd5..5b7c25749b 100644
--- a/Zend/zend-scanner.l
+++ b/Zend/zend-scanner.l
@@ -150,7 +150,7 @@ static inline void save_lexical_state(zend_lex_state *lex_state CLS_DC)
lex_state->in = yyin;
lex_state->lineno = CG(zend_lineno);
lex_state->state = YYSTATE;
- lex_state->filename = zend_get_compiled_filename();
+ lex_state->filename = zend_get_compiled_filename(CLS_C);
#else
lex_state->ZFL = CG(ZFL);
#endif
@@ -338,7 +338,9 @@ ZEND_API zend_op_array *v_compile_files(int mark_as_ref CLS_DC, int file_count,
int i;
int compiler_result;
int compiled_files=0;
+ zend_bool original_in_compilation = CG(in_compilation);
+ CG(in_compilation) = 1;
init_op_array(op_array, INITIAL_OP_ARRAY_SIZE);
save_lexical_state(&original_lex_state CLS_CC);
@@ -379,6 +381,7 @@ ZEND_API zend_op_array *v_compile_files(int mark_as_ref CLS_DC, int file_count,
retval = NULL;
}
}
+ CG(in_compilation) = original_in_compilation;
return retval;
}
@@ -454,11 +457,15 @@ zend_op_array *compile_string(zval *source_string CLS_DC)
zend_op_array *retval;
zval tmp;
int compiler_result;
+ zend_bool original_in_compilation = CG(in_compilation);
if (source_string->value.str.len==0) {
efree(op_array);
return NULL;
}
+
+ CG(in_compilation) = 1;
+
tmp = *source_string;
zval_copy_ctor(&tmp);
convert_to_string(&tmp);
@@ -494,6 +501,7 @@ zend_op_array *compile_string(zval *source_string CLS_DC)
}
}
zval_dtor(&tmp);
+ CG(in_compilation) = original_in_compilation;
return retval;
}
@@ -1125,7 +1133,7 @@ ESCAPED_AND_WHITESPACE [\n\t\r #'.:;,()|^&+-/*=%!~<>?@]+
}
<ST_IN_SCRIPTING>"__FILE__" {
- char *filename = zend_get_compiled_filename();
+ char *filename = zend_get_compiled_filename(CLS_C);
if (!filename) {
filename = "";
diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c
index f97d825979..f25eb3337b 100644
--- a/Zend/zend_compile.c
+++ b/Zend/zend_compile.c
@@ -108,6 +108,7 @@ void init_compiler(CLS_D ELS_DC)
CG(asp_tags) = ZEND_UV(asp_tags);
CG(allow_call_time_pass_reference) = ZEND_UV(allow_call_time_pass_reference);
CG(handle_op_arrays) = 1;
+ CG(in_compilation) = 0;
init_resource_list(ELS_C);
CG(unclean_shutdown) = 0;
zend_llist_init(&CG(open_files), sizeof(zend_file_handle), (void (*)(void *)) zend_open_file_dtor, 0);
@@ -150,11 +151,24 @@ ZEND_API void zend_restore_compiled_filename(char *original_compiled_filename)
CG(compiled_filename) = original_compiled_filename;
}
-ZEND_API char *zend_get_compiled_filename()
+
+ZEND_API char *zend_get_compiled_filename(CLS_D)
+{
+ return CG(compiled_filename);
+}
+
+
+ZEND_API int zend_get_compiled_lineno(CLS_D)
+{
+ return CG(zend_lineno);
+}
+
+
+ZEND_API zend_bool zend_is_compiling()
{
CLS_FETCH();
- return CG(compiled_filename);
+ return CG(in_compilation);
}
diff --git a/Zend/zend_compile.h b/Zend/zend_compile.h
index 3f304892b0..45ce3719fc 100644
--- a/Zend/zend_compile.h
+++ b/Zend/zend_compile.h
@@ -208,7 +208,8 @@ void shutdown_scanner(CLS_D);
ZEND_API char *zend_set_compiled_filename(char *new_compiled_filename);
ZEND_API void zend_restore_compiled_filename(char *original_compiled_filename);
-ZEND_API char *zend_get_compiled_filename(void);
+ZEND_API char *zend_get_compiled_filename(CLS_D);
+ZEND_API int zend_get_compiled_lineno(CLS_D);
#ifdef ZTS
const char *zend_get_zendtext(CLS_D);
@@ -382,6 +383,7 @@ void print_op_array(zend_op_array *op_array, int optimizations);
int pass_two(zend_op_array *op_array);
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);
int zendlex(znode *zendlval CLS_DC);
diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c
index 2407e4768f..7b4e912af7 100644
--- a/Zend/zend_execute.c
+++ b/Zend/zend_execute.c
@@ -967,7 +967,9 @@ void execute(zend_op_array *op_array ELS_DC)
#else
temp_variable Ts[op_array->T];
#endif
+ zend_bool original_in_execution=EG(in_execution);
+ EG(in_execution) = 1;
#if SUPPORT_INTERACTIVE
if (EG(interactive)) {
opline = op_array->opcodes + op_array->start_op_number;
@@ -1649,6 +1651,7 @@ do_fcall_common:
op_array->last_executed_op_number = opline-op_array->opcodes;
#endif
free_alloca(Ts);
+ EG(in_execution) = original_in_execution;
return;
}
break;
diff --git a/Zend/zend_execute.h b/Zend/zend_execute.h
index 0eb61c0771..84208fd7ac 100644
--- a/Zend/zend_execute.h
+++ b/Zend/zend_execute.h
@@ -65,6 +65,7 @@ void execute_new_code(CLS_D);
ZEND_API char *get_active_function_name(void);
ZEND_API char *zend_get_executed_filename(ELS_D);
ZEND_API uint zend_get_executed_lineno(ELS_D);
+ZEND_API zend_bool zend_is_executing(void);
#define zendi_zval_copy_ctor(p) zval_copy_ctor(&(p))
#define zendi_zval_dtor(p) zval_dtor(&(p))
diff --git a/Zend/zend_execute_API.c b/Zend/zend_execute_API.c
index ba97c18410..a5e1d0c996 100644
--- a/Zend/zend_execute_API.c
+++ b/Zend/zend_execute_API.c
@@ -103,6 +103,8 @@ void init_executor(CLS_D ELS_DC)
EG(function_table) = CG(function_table);
EG(class_table) = CG(class_table);
+ EG(in_execution) = 0;
+
zend_ptr_stack_init(&EG(argument_stack));
EG(main_op_array) = NULL;
@@ -201,6 +203,14 @@ ZEND_API uint zend_get_executed_lineno(ELS_D)
}
+ZEND_API zend_bool zend_is_executing()
+{
+ ELS_FETCH();
+
+ return EG(in_execution);
+}
+
+
ZEND_API inline void safe_free_zval_ptr(zval *p)
{
ELS_FETCH();
diff --git a/Zend/zend_globals.h b/Zend/zend_globals.h
index 4f7ba35c9d..7abd6b135f 100644
--- a/Zend/zend_globals.h
+++ b/Zend/zend_globals.h
@@ -96,6 +96,7 @@ struct _zend_compiler_globals {
zend_llist filenames_list;
+ zend_bool in_compilation;
zend_bool short_tags;
zend_bool asp_tags;
zend_bool allow_call_time_pass_reference;
@@ -163,6 +164,8 @@ struct _zend_executor_globals {
int ticks_count;
+ zend_bool in_execution;
+
/* for extended information support */
zend_bool no_extensions;
diff --git a/Zend/zend_opcode.c b/Zend/zend_opcode.c
index a80aa26bc7..7f680f3ec1 100644
--- a/Zend/zend_opcode.c
+++ b/Zend/zend_opcode.c
@@ -194,7 +194,7 @@ ZEND_API void destroy_op_array(zend_op_array *op_array)
void init_op(zend_op *op CLS_DC)
{
op->lineno = CG(zend_lineno);
- op->filename = zend_get_compiled_filename();
+ op->filename = zend_get_compiled_filename(CLS_C);
op->result.op_type = IS_UNUSED;
op->extended_value = 0;
op->op1.u.EA.var = 0;