From: Han-Wen Nienhuys Date: Thu, 2 Nov 2006 15:02:12 +0000 (+0100) Subject: clear lexer scopes after parsing file. Plugs pseudo memory leak X-Git-Tag: release/2.10.0-2~34^2~25 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=621e7e7fadf18a606275cb0c7619009423b56667;p=lilypond.git clear lexer scopes after parsing file. Plugs pseudo memory leak --- diff --git a/lily/include/lily-lexer.hh b/lily/include/lily-lexer.hh index ff95d83b39..7d51b8a640 100644 --- a/lily/include/lily-lexer.hh +++ b/lily/include/lily-lexer.hh @@ -63,6 +63,7 @@ public: void add_scope (SCM); SCM set_current_scope (); + bool has_scope () const; SCM remove_scope (); void start_main_input (); diff --git a/lily/include/lily-parser.hh b/lily/include/lily-parser.hh index 4fa354d280..d4557e3688 100644 --- a/lily/include/lily-parser.hh +++ b/lily/include/lily-parser.hh @@ -50,6 +50,7 @@ public: DECLARE_SCHEME_CALLBACK (layout_description, ()); + void clear (); void do_init_file (); void do_yyparse (); void parse_file (string init, string name, string out_name); diff --git a/lily/lily-lexer.cc b/lily/lily-lexer.cc index 2392f47b36..b7460bb609 100644 --- a/lily/lily-lexer.cc +++ b/lily/lily-lexer.cc @@ -145,6 +145,11 @@ Lily_lexer::add_scope (SCM module) set_current_scope (); } +bool +Lily_lexer::has_scope () const +{ + return scm_is_pair (scopes_); +} SCM Lily_lexer::remove_scope () @@ -294,6 +299,8 @@ IMPLEMENT_DEFAULT_EQUAL_P (Lily_lexer); SCM Lily_lexer::mark_smob (SCM s) { + ASSERT_LIVE_IS_ALLOWED(); + Lily_lexer *lexer = (Lily_lexer *) SCM_CELL_WORD_1 (s); scm_gc_mark (lexer->chordmodifier_tab_); diff --git a/lily/lily-parser-scheme.cc b/lily/lily-parser-scheme.cc index 3092c6ca9d..a1cdfa3c03 100644 --- a/lily/lily-parser-scheme.cc +++ b/lily/lily-parser-scheme.cc @@ -132,6 +132,7 @@ LY_DEFINE (ly_parse_file, "ly:parse-file", error = parser->error_level_; + parser->clear (); parser->unprotect (); } diff --git a/lily/lily-parser.cc b/lily/lily-parser.cc index 1f073fb07a..d1c94b0c19 100644 --- a/lily/lily-parser.cc +++ b/lily/lily-parser.cc @@ -128,7 +128,7 @@ Lily_parser::parse_file (string init, string name, string out_name) } error_level_ = error_level_ | lexer_->error_level_; - lexer_ = 0; + clear (); } void @@ -157,6 +157,19 @@ Lily_parser::parse_string (string ly_code) error_level_ = error_level_ | lexer_->error_level_; } +void +Lily_parser::clear () +{ + if (lexer_) + { + while (lexer_->has_scope ()) + lexer_->remove_scope (); + + + } + lexer_ = 0; +} + char const * Lily_parser::here_str0 () const {