]> git.donarmstrong.com Git - lilypond.git/commitdiff
clear lexer scopes after parsing file. Plugs pseudo memory leak
authorHan-Wen Nienhuys <hanwen@xs4all.nl>
Thu, 2 Nov 2006 15:02:12 +0000 (16:02 +0100)
committerHan-Wen Nienhuys <hanwen@xs4all.nl>
Thu, 2 Nov 2006 15:02:12 +0000 (16:02 +0100)
lily/include/lily-lexer.hh
lily/include/lily-parser.hh
lily/lily-lexer.cc
lily/lily-parser-scheme.cc
lily/lily-parser.cc

index ff95d83b3957b17b5ca83823d4afa65cd29ce975..7d51b8a64027e5d850edfb214918c3a917f56ff2 100644 (file)
@@ -63,6 +63,7 @@ public:
 
   void add_scope (SCM);
   SCM set_current_scope ();
+  bool has_scope () const;
   SCM remove_scope ();
 
   void start_main_input ();
index 4fa354d2803a31358049419f6054873da4a6bcc9..d4557e368826cfb7a195070c89303b794cf9e755 100644 (file)
@@ -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);
index 2392f47b363d63917061b20583dd43ec9a18b01b..b7460bb609f093dc0b18d3deb7d980cc8f7de0b0 100644 (file)
@@ -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_);
index 3092c6ca9d610d32e4c8a2da18a2222bdecdee94..a1cdfa3c035f9b5d7d26db9f3d81f7928f9930bd 100644 (file)
@@ -132,6 +132,7 @@ LY_DEFINE (ly_parse_file, "ly:parse-file",
 
       error = parser->error_level_;
 
+      parser->clear ();
       parser->unprotect ();
     }
 
index 1f073fb07a3b7cff5a0bf60efe519fd16b3b46bf..d1c94b0c1906b125177138712f45d79777e40d40 100644 (file)
@@ -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
 {