]> granicus.if.org Git - php/commitdiff
Maintain a state of whether we're compiling and/or executing
authorZeev Suraski <zeev@php.net>
Fri, 4 Feb 2000 14:45:58 +0000 (14:45 +0000)
committerZeev Suraski <zeev@php.net>
Fri, 4 Feb 2000 14:45:58 +0000 (14:45 +0000)
Zend/zend-scanner.l
Zend/zend_compile.c
Zend/zend_compile.h
Zend/zend_execute.c
Zend/zend_execute.h
Zend/zend_execute_API.c
Zend/zend_globals.h
Zend/zend_opcode.c

index fe3d868dd5701914fdce151dc87e1b026fe144fe..5b7c25749be8ac54dce5c4b10d9d226010a6185e 100644 (file)
@@ -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 = "";
index f97d8259790bf442897fefa5a80e924e302e75fc..f25eb3337b9a80f1f7fa930808f972db43a659c1 100644 (file)
@@ -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);
 }
 
 
index 3f304892b07638f959945bc94432c7369b97de97..45ce3719fc4ff1ae21649a86f6d30f1be0b2fd5c 100644 (file)
@@ -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);
 
index 2407e4768f4d5cc264e423391ed547ac89747019..7b4e912af7ae0dfbd9186658e900a4e29ab00b52 100644 (file)
@@ -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;
index 0eb61c077179b45d46918a55528d1634bcd4fd74..84208fd7acbcc0e8b328f069fe3d8ea16ca1c352 100644 (file)
@@ -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))
index ba97c184103ceb08d1a68c13de7f612f73c5d0f1..a5e1d0c9967eebf3c1f1bdb887f310ea7bdcee46 100644 (file)
@@ -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();
index 4f7ba35c9d78335050d046cba6b3434d1457a8d8..7abd6b135f94b0e449c3ed21c5878d6737c19010 100644 (file)
@@ -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;
 
index a80aa26bc700aceac771f4aeed9bb57c412ff014..7f680f3ec1f6e1fcfe6709ef288f67a3ca25701f 100644 (file)
@@ -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;