From: Han-Wen Nienhuys Date: Tue, 2 Jan 2007 22:41:38 +0000 (+0100) Subject: Use be_safe_global for determining whether file inclusion X-Git-Tag: release/2.11.8-1~22 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=14ee7d1ba5ac5b0e0722ef98b7de223168f5da58;p=lilypond.git Use be_safe_global for determining whether file inclusion is allowed. --- diff --git a/lily/includable-lexer.cc b/lily/includable-lexer.cc index 0668b91d81..29b7d9e5f3 100644 --- a/lily/includable-lexer.cc +++ b/lily/includable-lexer.cc @@ -41,19 +41,12 @@ Includable_lexer::Includable_lexer () #if HAVE_FLEXLEXER_YY_CURRENT_BUFFER yy_current_buffer = 0; #endif - allow_includes_ = true; } /** Set the new input file to NAME, remember old file. */ void Includable_lexer::new_input (string name, Sources *sources) { - if (!allow_includes_) - { - LexerError (_ ("include files are not allowed in safe mode").c_str ()); - return; - } - Source_file *file = sources->get_file (&name); if (!file) { diff --git a/lily/include/includable-lexer.hh b/lily/include/includable-lexer.hh index 4b992b8714..c103ba97f5 100644 --- a/lily/include/includable-lexer.hh +++ b/lily/include/includable-lexer.hh @@ -33,7 +33,6 @@ protected: vector char_count_stack_; public: - bool allow_includes_; Includable_lexer (); ~Includable_lexer (); @@ -42,9 +41,10 @@ public: vector file_name_strings_; Source_file *get_source_file () const; - void new_input (string s, Sources *); + virtual void new_input (string s, Sources *); + void new_input (string name, string data, Sources *); - + char const *here_str0 () const; }; diff --git a/lily/include/lily-lexer.hh b/lily/include/lily-lexer.hh index e8a9c998d1..5609f53f4d 100644 --- a/lily/include/lily-lexer.hh +++ b/lily/include/lily-lexer.hh @@ -42,7 +42,6 @@ public: void *lexval; Input *lexloc; bool is_main_input_; - bool be_safe_; Sources *sources_; @@ -56,7 +55,7 @@ public: Lily_lexer (Sources *, Lily_parser *); Lily_lexer (Lily_lexer const &, Lily_parser *); int yylex (); - + void add_lexed_char (int); void prepare_for_next_token (); @@ -70,6 +69,9 @@ public: void start_main_input (); + virtual void new_input (string s, Sources *); + virtual void new_input (string s, string d, Sources *); + SCM keyword_list () const; SCM lookup_identifier (string s); SCM lookup_identifier_symbol (SCM s); diff --git a/lily/lexer.ll b/lily/lexer.ll index d20b075eb4..b6fb615bd2 100644 --- a/lily/lexer.ll +++ b/lily/lexer.ll @@ -334,7 +334,7 @@ BOM_UTF8 \357\273\277 Input hi = here_input(); hi.step_forward (); SCM sval = ly_parse_scm (hi.start (), &n, hi, - be_safe_ && is_main_input_); + be_safe_global && is_main_input_); if (sval == SCM_UNDEFINED) { diff --git a/lily/lily-lexer-scheme.cc b/lily/lily-lexer-scheme.cc index 424b4fa816..7cb6d53691 100644 --- a/lily/lily-lexer-scheme.cc +++ b/lily/lily-lexer-scheme.cc @@ -17,17 +17,3 @@ LY_DEFINE(ly_lexer_keywords, "ly:lexer-keywords", SCM_ASSERT_TYPE(lex, lexer, SCM_ARG1, __FUNCTION__, "lily lexer"); return lex->keyword_list (); } - - -LY_DEFINE(ly_lexer_set_safe, "ly:lexer-set-safe!", - 1, 0, 0, (SCM lexer), - "Switch on safe mode for the rest of the file.") -{ - Lily_lexer * lex = Lily_lexer::unsmob (lexer); - SCM_ASSERT_TYPE(lex, lexer, SCM_ARG1, __FUNCTION__, "lily lexer"); - - lex->be_safe_ = true; - lex->allow_includes_ = false; - - return SCM_UNSPECIFIED; -} diff --git a/lily/lily-lexer.cc b/lily/lily-lexer.cc index 72e8bb8661..cd0c42eaa4 100644 --- a/lily/lily-lexer.cc +++ b/lily/lily-lexer.cc @@ -231,14 +231,29 @@ Lily_lexer::start_main_input () new_input (main_input_name_, sources_); - /* Do not allow \include in --safe-mode */ - allow_includes_ = allow_includes_ && !be_safe_global; - scm_module_define (scm_car (scopes_), ly_symbol2scm ("input-file-name"), scm_makfrom0str (main_input_name_.c_str ())); } +void +Lily_lexer::new_input (string str, string d, Sources *ss) +{ + Includable_lexer::new_input (str, d, ss); +} + +void +Lily_lexer::new_input (string str, Sources *ss) +{ + if (is_main_input_ && be_safe_global) + { + LexerError (_ ("include files are not allowed in safe mode").c_str ()); + return; + } + + Includable_lexer::new_input (str, ss); +} + void Lily_lexer::set_identifier (SCM name, SCM s) { diff --git a/lily/lily-parser.cc b/lily/lily-parser.cc index 708b10659d..15cb06c4d7 100644 --- a/lily/lily-parser.cc +++ b/lily/lily-parser.cc @@ -254,5 +254,5 @@ get_header (Lily_parser *parser) SCM Lily_parser::make_scope () const { - return ly_make_anonymous_module (lexer_->be_safe_); + return ly_make_anonymous_module (be_safe_global); }