From: Han-Wen Nienhuys Date: Thu, 29 May 2008 02:44:39 +0000 (-0300) Subject: Fix #268. X-Git-Tag: release/2.11.48-1~24^2~1 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=a7aa39d18a9b432e0df3a419fc65887c00b749d5;p=lilypond.git Fix #268. Define 'parser in anonymous modules, so trusted functions (that have access to ly:parser-XXX functions) can access the toplevel module. --- diff --git a/lily/include/parse-scm.hh b/lily/include/parse-scm.hh index 2939bc2f5c..3e3f956634 100644 --- a/lily/include/parse-scm.hh +++ b/lily/include/parse-scm.hh @@ -21,10 +21,18 @@ struct Parse_start int nchars; Input start_location_; bool safe_; + Lily_parser *parser_; + + Parse_start() { + str = 0; + nchars = 0; + safe_ = false; + parser_ = 0; + } }; SCM catch_protected_parse_body (void *); SCM protected_ly_parse_scm (Parse_start *, bool); -SCM ly_parse_scm (char const *, int *, Input, bool); +SCM ly_parse_scm (char const *, int *, Input, bool, Lily_parser *); #endif /* PARSE_SCM_HH */ diff --git a/lily/lexer.ll b/lily/lexer.ll index b444704ea5..bec065347b 100644 --- a/lily/lexer.ll +++ b/lily/lexer.ll @@ -337,7 +337,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_global && is_main_input_, parser_); if (sval == SCM_UNDEFINED) { diff --git a/lily/lily-parser.cc b/lily/lily-parser.cc index b508860efa..13d62ebc5c 100644 --- a/lily/lily-parser.cc +++ b/lily/lily-parser.cc @@ -15,6 +15,7 @@ #include "international.hh" #include "lily-lexer.hh" #include "lily-version.hh" +#include "ly-module.hh" #include "main.hh" #include "output-def.hh" #include "paper-book.hh" @@ -250,5 +251,6 @@ get_header (Lily_parser *parser) SCM Lily_parser::make_scope () const { - return ly_make_anonymous_module (be_safe_global); + SCM module = ly_make_anonymous_module (be_safe_global); + return module; } diff --git a/lily/parse-scm.cc b/lily/parse-scm.cc index 51acd6e6ca..087d2e5951 100644 --- a/lily/parse-scm.cc +++ b/lily/parse-scm.cc @@ -11,6 +11,7 @@ #include using namespace std; +#include "lily-parser.hh" #include "international.hh" #include "main.hh" #include "paper-book.hh" @@ -37,7 +38,6 @@ internal_ly_parse_scm (Parse_start *ps) SCM answer = SCM_UNSPECIFIED; SCM form = scm_read (port); - /* Reset read_buf for scm_ftell. Shouldn't scm_read () do this for us? */ scm_fill_input (port); @@ -56,6 +56,12 @@ internal_ly_parse_scm (Parse_start *ps) SCM function = ly_lily_module_constant ("make-safe-lilypond-module"); module = scm_call_0 (function); } + + // We define the parser so trusted Scheme functions can + // access the real namespace underlying the parser. + if (ps->parser_) + scm_module_define (module, ly_symbol2scm ("parser"), + ps->parser_->self_scm()); answer = scm_eval (form, module); } else @@ -113,12 +119,13 @@ bool parsed_objects_should_be_dead = false; /* Try parsing. Upon failure return SCM_UNDEFINED. FIXME: shouldn't we return SCM_UNSCPECIFIED -- jcn */ SCM -ly_parse_scm (char const *s, int *n, Input i, bool safe) +ly_parse_scm (char const *s, int *n, Input i, bool safe, Lily_parser *parser) { Parse_start ps; ps.str = s; ps.start_location_ = i; ps.safe_ = safe; + ps.parser_ = parser; SCM ans = parse_protect_global ? protected_ly_parse_scm (&ps) : internal_ly_parse_scm (&ps); diff --git a/scm/paper.scm b/scm/paper.scm index 8c2b5dc710..8acf4e8d10 100644 --- a/scm/paper.scm +++ b/scm/paper.scm @@ -70,7 +70,8 @@ size. SZ is in points" (define-safe-public (set-global-staff-size sz) "Set the default staff size, where SZ is thought to be in PT." (let* ((current-mod (current-module)) - (pap (eval '$defaultpaper current-mod)) + (parser (eval 'parser current-mod)) + (pap (ly:parser-lookup parser '$defaultpaper)) (in-layout? (or (module-defined? current-mod 'is-paper) (module-defined? current-mod 'is-layout)))