Permalink
Browse files

Maintain a state of whether we're compiling and/or executing

  • Loading branch information...
1 parent 2e90a7a commit b6197bcf902373c481eac2c5484954c3b3bd5f85 @zsuraski zsuraski committed Feb 4, 2000
Showing with 47 additions and 6 deletions.
  1. +10 −2 Zend/zend-scanner.l
  2. +16 −2 Zend/zend_compile.c
  3. +3 −1 Zend/zend_compile.h
  4. +3 −0 Zend/zend_execute.c
  5. +1 −0 Zend/zend_execute.h
  6. +10 −0 Zend/zend_execute_API.c
  7. +3 −0 Zend/zend_globals.h
  8. +1 −1 Zend/zend_opcode.c
View
@@ -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 = "";
View
@@ -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);
}
View
@@ -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);
View
@@ -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 @@ binary_assign_op_addr: {
op_array->last_executed_op_number = opline-op_array->opcodes;
#endif
free_alloca(Ts);
+ EG(in_execution) = original_in_execution;
return;
}
break;
View
@@ -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))
@@ -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();
View
@@ -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;
View
@@ -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;

0 comments on commit b6197bc

Please sign in to comment.