From 5286b3971cbe7763f1f5aa918a5a909f61968fe8 Mon Sep 17 00:00:00 2001 From: Zeev Suraski Date: Tue, 12 Sep 2000 19:47:25 +0000 Subject: [PATCH] Make compile_string() accept a description of the code --- Zend/zend-scanner.l | 19 +++++++++---------- Zend/zend.c | 26 ++++++++++++++++++++++++++ Zend/zend_builtin_functions.c | 6 +++++- Zend/zend_compile.h | 3 ++- Zend/zend_execute.c | 10 ++++++---- Zend/zend_execute.h | 2 +- Zend/zend_execute_API.c | 4 ++-- Zend/zend_highlight.h | 2 +- 8 files changed, 52 insertions(+), 20 deletions(-) diff --git a/Zend/zend-scanner.l b/Zend/zend-scanner.l index 99feccfceb..0e0a670fd5 100644 --- a/Zend/zend-scanner.l +++ b/Zend/zend-scanner.l @@ -410,9 +410,9 @@ zend_op_array *compile_filename(int type, zval *filename CLS_DC ELS_DC) } #ifndef ZTS -static inline int prepare_string_for_scanning(zval *str) +static inline int prepare_string_for_scanning(zval *str, char *filename) #else -static inline int prepare_string_for_scanning(zval *str, istrstream **input_stream CLS_DC) +static inline int prepare_string_for_scanning(zval *str, istrstream **input_stream, char *filename CLS_DC) #endif { #ifndef ZTS @@ -429,13 +429,13 @@ static inline int prepare_string_for_scanning(zval *str, istrstream **input_stre CG(ZFL)->switch_streams(*input_stream, &cout); #endif - zend_set_compiled_filename("Eval code"); + zend_set_compiled_filename(filename); CG(zend_lineno) = 1; return SUCCESS; } -zend_op_array *compile_string(zval *source_string CLS_DC) +zend_op_array *compile_string(zval *source_string, char *filename CLS_DC) { zend_lex_state original_lex_state; zend_op_array *op_array = (zend_op_array *) emalloc(sizeof(zend_op_array)); @@ -462,9 +462,9 @@ zend_op_array *compile_string(zval *source_string CLS_DC) save_lexical_state(&original_lex_state CLS_CC); #ifndef ZTS - if (prepare_string_for_scanning(source_string)==FAILURE) { + if (prepare_string_for_scanning(source_string, filename)==FAILURE) { #else - if (prepare_string_for_scanning(source_string, &input_stream CLS_CC)==FAILURE) { + if (prepare_string_for_scanning(source_string, &input_stream, filename CLS_CC)==FAILURE) { #endif efree(op_array); retval = NULL; @@ -521,8 +521,7 @@ int highlight_file(char *filename, zend_syntax_highlighter_ini *syntax_highlight return SUCCESS; } - -int highlight_string(zval *str, zend_syntax_highlighter_ini *syntax_highlighter_ini) +int highlight_string(zval *str, zend_syntax_highlighter_ini *syntax_highlighter_ini, char *str_name) { zend_lex_state original_lex_state; zval tmp = *str; @@ -535,9 +534,9 @@ int highlight_string(zval *str, zend_syntax_highlighter_ini *syntax_highlighter_ zval_copy_ctor(str); save_lexical_state(&original_lex_state CLS_CC); #ifndef ZTS - if (prepare_string_for_scanning(str)==FAILURE) { + if (prepare_string_for_scanning(str, str_name)==FAILURE) { #else - if (prepare_string_for_scanning(str, &input_stream CLS_CC)==FAILURE) { + if (prepare_string_for_scanning(str, &input_stream, str_name CLS_CC)==FAILURE) { #endif return FAILURE; } diff --git a/Zend/zend.c b/Zend/zend.c index 2c2fa082ae..01737f8946 100644 --- a/Zend/zend.c +++ b/Zend/zend.c @@ -730,3 +730,29 @@ ZEND_API int zend_execute_scripts(int type CLS_DC ELS_DC, int file_count, ...) return SUCCESS; } +#define COMPILED_STRING_DESCRIPTION_FORMAT "%s(%d) : %s" + +ZEND_API char *zend_make_compiled_string_description(char *name) +{ + char *cur_filename; + int cur_lineno; + char *compiled_string_description; + CLS_FETCH(); + ELS_FETCH(); + + if (zend_is_compiling()) { + cur_filename = zend_get_compiled_filename(CLS_C); + cur_lineno = zend_get_compiled_lineno(CLS_C); + } else if (zend_is_executing()) { + cur_filename = zend_get_executed_filename(ELS_C); + cur_lineno = zend_get_executed_lineno(ELS_C); + } else { + cur_filename = "Unknown"; + cur_lineno = 0; + } + + compiled_string_description = emalloc(sizeof(COMPILED_STRING_DESCRIPTION_FORMAT)+strlen(name)+strlen(cur_filename)+MAX_LENGTH_OF_LONG); + sprintf(compiled_string_description, COMPILED_STRING_DESCRIPTION_FORMAT, cur_filename, cur_lineno, name); + return compiled_string_description; +} + diff --git a/Zend/zend_builtin_functions.c b/Zend/zend_builtin_functions.c index f4e25a6f2a..7c0941186a 100644 --- a/Zend/zend_builtin_functions.c +++ b/Zend/zend_builtin_functions.c @@ -855,6 +855,7 @@ ZEND_FUNCTION(create_function) int eval_code_length, function_name_length; zval **z_function_args, **z_function_code; int retval; + char *eval_name; CLS_FETCH(); if (ZEND_NUM_ARGS()!=2 || zend_get_parameters_ex(2, &z_function_args, &z_function_code)==FAILURE) { @@ -873,8 +874,11 @@ ZEND_FUNCTION(create_function) eval_code = (char *) emalloc(eval_code_length); sprintf(eval_code, "function " LAMBDA_TEMP_FUNCNAME "(%s){%s}", Z_STRVAL_PP(z_function_args), Z_STRVAL_PP(z_function_code)); - retval = zend_eval_string(eval_code, NULL CLS_CC ELS_CC); + eval_name = zend_make_compiled_string_description("runtime-created function"); + retval = zend_eval_string(eval_code, NULL, eval_name CLS_CC ELS_CC); efree(eval_code); + efree(eval_name); + if (retval==SUCCESS) { zend_function *func; diff --git a/Zend/zend_compile.h b/Zend/zend_compile.h index 64b54ff0bc..57d90be57e 100644 --- a/Zend/zend_compile.h +++ b/Zend/zend_compile.h @@ -376,7 +376,7 @@ ZEND_API void function_add_ref(zend_function *function); /* helper functions in zend-scanner.l */ ZEND_API zend_op_array *compile_file(zend_file_handle *file_handle, int type CLS_DC); -ZEND_API zend_op_array *compile_string(zval *source_string CLS_DC); +ZEND_API zend_op_array *compile_string(zval *source_string, char *filename 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); @@ -400,6 +400,7 @@ void print_op_array(zend_op_array *op_array, int optimizations); int pass_two(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); +ZEND_API char *zend_make_compiled_string_description(char *name); int zendlex(znode *zendlval CLS_DC); diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c index 6232490bf3..4faf7f0c2b 100644 --- a/Zend/zend_execute.c +++ b/Zend/zend_execute.c @@ -2007,12 +2007,14 @@ send_by_ref: break; case ZEND_INCLUDE: case ZEND_REQUIRE: - { new_op_array = compile_filename(opline->op2.u.constant.value.lval, inc_filename CLS_CC ELS_CC); break; - } - case ZEND_EVAL: - new_op_array = compile_string(inc_filename CLS_CC); + case ZEND_EVAL: { + char *eval_desc = zend_make_compiled_string_description("eval()'d code"); + + new_op_array = compile_string(inc_filename, eval_desc CLS_CC); + efree(eval_desc); + } break; EMPTY_SWITCH_DEFAULT_CASE() } diff --git a/Zend/zend_execute.h b/Zend/zend_execute.h index 8fcd5c0ea9..5e733de798 100644 --- a/Zend/zend_execute.h +++ b/Zend/zend_execute.h @@ -67,7 +67,7 @@ ZEND_API inline void safe_free_zval_ptr(zval *p) ; #endif -ZEND_API int zend_eval_string(char *str, zval *retval_ptr CLS_DC ELS_DC); +ZEND_API int zend_eval_string(char *str, zval *retval_ptr, char *string_name CLS_DC ELS_DC); ZEND_API inline int i_zend_is_true(zval *op) #if defined(C9X_INLINE_SEMANTICS) { diff --git a/Zend/zend_execute_API.c b/Zend/zend_execute_API.c index d67c98395a..fc17c591bd 100644 --- a/Zend/zend_execute_API.c +++ b/Zend/zend_execute_API.c @@ -457,7 +457,7 @@ int call_user_function_ex(HashTable *function_table, zval *object, zval *functio } -ZEND_API int zend_eval_string(char *str, zval *retval_ptr CLS_DC ELS_DC) +ZEND_API int zend_eval_string(char *str, zval *retval_ptr, char *string_name CLS_DC ELS_DC) { zval pv; zend_op_array *new_op_array; @@ -482,7 +482,7 @@ ZEND_API int zend_eval_string(char *str, zval *retval_ptr CLS_DC ELS_DC) original_handle_op_arrays = CG(handle_op_arrays); CG(handle_op_arrays) = 0; - new_op_array = compile_string(&pv CLS_CC); + new_op_array = compile_string(&pv, string_name CLS_CC); CG(handle_op_arrays) = original_handle_op_arrays; if (new_op_array) { diff --git a/Zend/zend_highlight.h b/Zend/zend_highlight.h index e9dff976f0..e2b5553bd3 100644 --- a/Zend/zend_highlight.h +++ b/Zend/zend_highlight.h @@ -41,7 +41,7 @@ typedef struct _zend_syntax_highlighter_ini { BEGIN_EXTERN_C() ZEND_API void zend_highlight(zend_syntax_highlighter_ini *syntax_highlighter_ini); int highlight_file(char *filename, zend_syntax_highlighter_ini *syntax_highlighter_ini); -int highlight_string(zval *str, zend_syntax_highlighter_ini *syntax_highlighter_ini); +int highlight_string(zval *str, zend_syntax_highlighter_ini *syntax_highlighter_ini, char *str_name); ZEND_API void zend_html_putc(char c); ZEND_API void zend_html_puts(char *s, uint len); END_EXTERN_C() -- 2.40.0