From: Han-Wen Nienhuys Date: Tue, 2 Jan 2007 21:49:12 +0000 (+0100) Subject: Allow --safe testing as a snippet. X-Git-Tag: release/2.11.8-1~25 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=666c669990584a38b18cd00f50f22d93959d4f18;p=lilypond.git Allow --safe testing as a snippet. Add ly:lexer-set-safe!, which sets safety for the rest of the file. --- diff --git a/input/no-notation/README b/input/no-notation/README deleted file mode 100644 index d162aad83c..0000000000 --- a/input/no-notation/README +++ /dev/null @@ -1,9 +0,0 @@ -These examples test various non-typesetting things. Since they -do not generate output, they are not in test/ or regression/ - -Some (notably parse*.ly) are just error/warning generation tests -and should remain here. - -Some (notably midi-*.ly) test midi output, which does not usually -get tested in ../regression files. - diff --git a/input/no-notation/safe-guile.ly b/input/no-notation/safe-guile.ly deleted file mode 100644 index eeaf1f2efc..0000000000 --- a/input/no-notation/safe-guile.ly +++ /dev/null @@ -1,14 +0,0 @@ -\version "2.10.0" - -\header{ - - texidoc = "This should not survive lilypond --safe-mode, and - certainly not write /tmp/safe-guile.scm" - -} - -#(write "hallo" (open-file "/tmp/safe-guile.scm" "w")) - -\score{ - c'' -} \ No newline at end of file diff --git a/input/no-notation/safe-include.ly b/input/no-notation/safe-include.ly deleted file mode 100644 index aa26b22239..0000000000 --- a/input/no-notation/safe-include.ly +++ /dev/null @@ -1,13 +0,0 @@ -\version "2.10.0" - -\header{ - - texidoc = "This should not survive lilypond --safe-mode" - -} - -\include "safe-ps.ly" - -\score{ - c'' -} \ No newline at end of file diff --git a/input/no-notation/safe.ly b/input/no-notation/safe.ly new file mode 100644 index 0000000000..88d54bd279 --- /dev/null +++ b/input/no-notation/safe.ly @@ -0,0 +1,19 @@ +\version "2.10.0" + +"expect-error" = ##t + +#(ly:lexer-set-safe! (ly:parser-lexer parser)) + +"force-finish" = ##t + +\header{ + texidoc = "This should not survive lilypond --safe-mode" + + #(open-file "w") +} + + +#(open-file "/tmp/safe-guile.scm" "r") + +\include "this-should-fail.ly" + diff --git a/lily/include/lily-lexer.hh b/lily/include/lily-lexer.hh index 994d185f6f..e8a9c998d1 100644 --- a/lily/include/lily-lexer.hh +++ b/lily/include/lily-lexer.hh @@ -42,6 +42,7 @@ public: void *lexval; Input *lexloc; bool is_main_input_; + bool be_safe_; Sources *sources_; diff --git a/lily/include/lily-parser.hh b/lily/include/lily-parser.hh index b07734769a..3acfd8a596 100644 --- a/lily/include/lily-parser.hh +++ b/lily/include/lily-parser.hh @@ -57,6 +57,8 @@ public: void parser_error (string); void parser_error (Input const &, string); void set_yydebug (bool); + + SCM make_scope () const; }; DECLARE_UNSMOB (Lily_parser, lily_parser); diff --git a/lily/lexer.ll b/lily/lexer.ll index 9cb2cac0c6..d20b075eb4 100644 --- a/lily/lexer.ll +++ b/lily/lexer.ll @@ -271,7 +271,7 @@ BOM_UTF8 \357\273\277 } <> { LexerError (_ ("EOF found inside a comment").c_str ()); - is_main_input_ = false; + is_main_input_ = false; // should be safe , can't have \include in --safe. if (! close_input ()) yyterminate (); // can't move this, since it actually rets a YY_NULL } @@ -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_global && is_main_input_); + be_safe_ && is_main_input_); if (sval == SCM_UNDEFINED) { diff --git a/lily/lily-lexer-scheme.cc b/lily/lily-lexer-scheme.cc index 66e47d3d6b..424b4fa816 100644 --- a/lily/lily-lexer-scheme.cc +++ b/lily/lily-lexer-scheme.cc @@ -10,7 +10,7 @@ #include "lily-lexer.hh" LY_DEFINE(ly_lexer_keywords, "ly:lexer-keywords", - 1,0,0, (SCM lexer), + 1, 0, 0, (SCM lexer), "Return a list of (KEY . CODE) pairs, signifying the lilypond reserved words list.") { Lily_lexer * lex = Lily_lexer::unsmob (lexer); @@ -18,3 +18,16 @@ LY_DEFINE(ly_lexer_keywords, "ly:lexer-keywords", 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-parser.cc b/lily/lily-parser.cc index ae3943dbdb..708b10659d 100644 --- a/lily/lily-parser.cc +++ b/lily/lily-parser.cc @@ -140,8 +140,7 @@ Lily_parser::parse_string (string ly_code) self_scm ()); lexer_->main_input_name_ = ""; - lexer_->is_main_input_ = true; - + lexer_->is_main_input_ = true; lexer_->new_input (lexer_->main_input_name_, ly_code, sources_); SCM mod = lexer_->set_current_scope (); @@ -241,13 +240,19 @@ get_header (Lily_parser *parser) { SCM id = parser->lexer_->lookup_identifier ("$defaultheader"); if (!ly_is_module (id)) - id = ly_make_anonymous_module (be_safe_global); + id = parser->make_scope (); else { - SCM nid = ly_make_anonymous_module (false); - ly_module_copy(nid,id); + SCM nid = parser->make_scope (); + ly_module_copy (nid, id); id = nid; } return id; } + +SCM +Lily_parser::make_scope () const +{ + return ly_make_anonymous_module (lexer_->be_safe_); +} diff --git a/ly/init.ly b/ly/init.ly index 102233c5a4..091ae68194 100644 --- a/ly/init.ly +++ b/ly/init.ly @@ -4,11 +4,6 @@ #(if (and #t (defined? 'set-debug-cell-accesses!)) (set-debug-cell-accesses! 5000)) -#(define-public midi-debug #f) - - - - \version "2.10.0" \include "declarations-init.ly"