]> git.donarmstrong.com Git - lilypond.git/commitdiff
(ly_make_anonymous_module): call make-module
authorhanwen <hanwen>
Fri, 10 Jun 2005 00:36:22 +0000 (00:36 +0000)
committerhanwen <hanwen>
Fri, 10 Jun 2005 00:36:22 +0000 (00:36 +0000)
directly. This fixes a massive memory leak, provided you use CVS
GUILE.

ChangeLog
lily/include/lily-lexer.hh
lily/lily-lexer.cc
lily/lily-parser.cc
lily/ly-module.cc
lily/output-def.cc
scm/lily.scm

index c49ac73986ec82841836f9ad9088d718a70cff2a..f6654afcb659d2d7449a64da56c45842d5561f81 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2005-06-10  Han-Wen Nienhuys  <hanwen@xs4all.nl>
+
+       * lily/ly-module.cc (ly_make_anonymous_module): call make-module
+       directly. This fixes a massive memory leak, provided you use CVS
+       GUILE.
+
 2005-06-10  Erik Sandberg  <ersa9195@student.uu.se>
 
        * ly/property-init.ly: Added tieDashed.
index 37e25fa10176dfef285d04c9bd9e30b6492bc123..cfc09af6bff4a290a2368c566a217c37aaf5339a 100644 (file)
@@ -22,8 +22,6 @@ void set_lexer ();
 class Lily_lexer : public Includable_lexer
 {
   DECLARE_SMOBS (Lily_lexer,);
-public:
-  SCM scopes_;
 
 private:
   int lookup_keyword (String);
@@ -34,7 +32,8 @@ private:
   char escaped_char (char) const;
 
   Keyword_table *keytable_;
-
+  SCM scopes_;
+  SCM start_module_;
 public:
   String main_input_name_;
   void *lexval;
@@ -61,6 +60,7 @@ public:
   Input here_input () const;
 
   void add_scope (SCM);
+  void set_current_scope ();
   SCM remove_scope ();
 
   void start_main_input ();
index 455bbfaea06c6ad645ed442496f0d982f136d89f..6194400ab0bb0bb8db5cf69aabcb71fdccc6de8d 100644 (file)
@@ -93,7 +93,7 @@ Lily_lexer::Lily_lexer (Sources *sources)
   scopes_ = SCM_EOL;
   error_level_ = 0;
   is_main_input_ = false;
-
+  start_module_ = SCM_EOL;
   smobify_self ();
 
   add_scope (ly_make_anonymous_module (false));
@@ -108,7 +108,8 @@ Lily_lexer::Lily_lexer (Lily_lexer const &src)
   chordmodifier_tab_ = src.chordmodifier_tab_;
   pitchname_tab_stack_ = src.pitchname_tab_stack_;
   sources_ = src.sources_;
-
+  start_module_ = SCM_EOL;
+  
   error_level_ = src.error_level_;
   is_main_input_ = src.is_main_input_;
 
@@ -139,6 +140,9 @@ void
 Lily_lexer::add_scope (SCM module)
 {
   ly_reexport_module (scm_current_module ());
+  if (!scm_is_pair (scopes_))
+    start_module_ = scm_current_module ();
+  
   scm_set_current_module (module);
   for (SCM s = scopes_; scm_is_pair (s); s = scm_cdr (s))
     {
@@ -147,16 +151,25 @@ Lily_lexer::add_scope (SCM module)
   scopes_ = scm_cons (module, scopes_);
 }
 
+
 SCM
 Lily_lexer::remove_scope ()
 {
   SCM sc = scm_car (scopes_);
   scopes_ = scm_cdr (scopes_);
-  scm_set_current_module (scm_car (scopes_));
-
+  set_current_scope ();
   return sc;
 }
 
+void
+Lily_lexer::set_current_scope ()
+{
+  if (scm_is_pair (scopes_))
+    scm_set_current_module (scm_car (scopes_));
+  else
+    scm_set_current_module (start_module_);
+}
+
 int
 Lily_lexer::lookup_keyword (String s)
 {
index 1c284b4138f71989dbebe8bd9ab60a1b0e2c1e73..76915d07e8664763310621d56aab6c0e3d7c93f3 100644 (file)
@@ -87,6 +87,8 @@ Lily_parser::parse_file (String init, String name, String out_name)
       try_load_text_metrics (out_name);
     }
 
+  SCM oldmod = scm_current_module ();
+
   lexer_ = new Lily_lexer (sources_);
   scm_gc_unprotect_object (lexer_->self_scm ());
   // TODO: use $parser 
@@ -120,6 +122,8 @@ Lily_parser::parse_file (String init, String name, String out_name)
 
   error_level_ = error_level_ | lexer_->error_level_;
   lexer_ = 0;
+
+  scm_set_current_module (oldmod);
 }
 
 void
@@ -131,12 +135,10 @@ Lily_parser::parse_string (String ly_code)
   scm_gc_unprotect_object (lexer_->self_scm ());
 
   SCM oldmod = scm_current_module ();
-  scm_set_current_module (scm_car (lexer_->scopes_));
-
   // TODO: use $parser 
   lexer_->set_identifier (ly_symbol2scm ("parser"),
                          self_scm ());
-
+  
   lexer_->main_input_name_ = "<string>";
   lexer_->is_main_input_ = true;
 
index 2cd0403e28d76c2c4d3b8681fae11233c2be4de3..6a6e5d58c6d853cf2d470135dc5dd66a920d5521 100644 (file)
 
 #define FUNC_NAME __FUNCTION__
 
-static int module_count;
-
-void
-ly_init_anonymous_module (void *data)
-{
-  (void) data;
-}
-
 SCM
 ly_make_anonymous_module (bool safe)
 {
   SCM mod = SCM_EOL;
   if (!safe)
     {
-      String s = "*anonymous-ly-" + to_string (module_count++) + "*";
-      mod = scm_c_define_module (s.to_str0 (), ly_init_anonymous_module, 0);
+      SCM maker = ly_lily_module_constant ("make-module");
+      SCM scm_module = ly_lily_module_constant ("the-scm-module");
+      
+      mod = scm_call_0 (maker);
+      ly_use_module (mod, scm_module);
       ly_use_module (mod, global_lily_module);
     }
   else
index eedf75c9881e1c6a8fe775bd2fe1e2edbf820d6f..e08816a7b80e6ab435b39fb481fba4949c7cd6b1 100644 (file)
 
 #include "ly-smobs.icc"
 
+#include "program-option.hh"
+
+#include "string-convert.hh"
+
 Output_def::Output_def ()
 {
   scope_ = SCM_EOL;
index 6fd1db2d5ec52fc3e3deed710a53028560040efc..82aea7b532a9a6aba58036635831e5fa1a6c4f98 100644 (file)
@@ -268,7 +268,7 @@ The syntax is the same as `define*-public'."
                    (lambda (a b)
                      (< (object-address (car a))
                         (object-address (car b))))))
-        
+
         (out-file-name (string-append
                         "gcstat-" (number->string gc-protect-stat-count)
                         ".scm"))
@@ -288,7 +288,24 @@ The syntax is the same as `define*-public'."
                 " ")
                "\n")))
           protects))
-     outfile)))
+     outfile)
+
+    (if (defined? 'gc-live-object-stats)
+       (let*
+           ((dummy (gc))
+            (dummy2 (gc))
+            (stats (gc-live-object-stats))
+            )
+
+         (for-each
+          (lambda (x)
+            (format outfile "~a: ~a\n" (car x) (cdr x)))
+          (sort (gc-live-object-stats)
+                (lambda (x y)
+                  (string<? (car x) (car y)))))
+          ))
+
+    ))
 
 (define-public (tweak-grob-property grob sym val)
   (set! (ly:grob-property grob sym) val))