]> git.donarmstrong.com Git - lilypond.git/commitdiff
* lily/paper-score.cc (process): move gc stat stuff to init.ly
authorHan-Wen Nienhuys <hanwen@xs4all.nl>
Mon, 9 Feb 2004 12:20:34 +0000 (12:20 +0000)
committerHan-Wen Nienhuys <hanwen@xs4all.nl>
Mon, 9 Feb 2004 12:20:34 +0000 (12:20 +0000)
* lily/parser.yy (music_output_def_body): plug memory leak.

* lily/translator-group.cc (add_fresh_group_translator): plug
memory leak: unprotect Translator_group once added.

* lily/span-dynamic-performer.cc (process_music): deprecate span-type.

* scripts/lilypond-book.py (Lilypond_snippet.notice_include):
write .dep file.
(Lilypond_snippet.ly): add \renameinput.

22 files changed:
ChangeLog
input/example-1.ly
lily/accidental-engraver.cc
lily/chord-name-engraver.cc
lily/dynamic-engraver.cc
lily/include/music-output-def.hh
lily/include/source-file.hh
lily/input-file-results.cc
lily/lexer.ll
lily/lily-guile.cc
lily/main.cc
lily/music-output-def.cc
lily/paper-column.cc
lily/paper-score.cc
lily/parser.yy
lily/spacing-spanner.cc
lily/span-dynamic-performer.cc
lily/tie.cc
lily/translator-group.cc
ly/init.ly
scm/lily.scm
scripts/lilypond-book.py

index b896cf54c58bb3dc7dda6d198a4a6f29931db2fe..4c00484346d4dd76e67743580f2707270578ebdf 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2004-02-09  Han-Wen Nienhuys   <hanwen@xs4all.nl>
 
+       * lily/paper-score.cc (process): move gc stat stuff to init.ly 
+
+       * lily/parser.yy (music_output_def_body): plug memory leak.
+
+       * lily/translator-group.cc (add_fresh_group_translator): plug
+       memory leak: unprotect Translator_group once added.   
+
        * lily/span-dynamic-performer.cc (process_music): deprecate span-type.
 
        * scripts/lilypond-book.py (Lilypond_snippet.notice_include):
index 40a817561bd85b17b4fd9747bc01557f078a5287..82095e1b9c6515f98953b89835a97a2fc9062284 100644 (file)
@@ -1,4 +1,5 @@
 \version "2.1.7"
+
 % A simple scale in LilyPond
 %
 % Type:
index c6f1f4ed54caa3aeab6f6cdadb2096fdc7dd263d..770eaa024685b43d8cfcbd733729408c0925c3f6 100644 (file)
@@ -393,6 +393,9 @@ Accidental_engraver::process_acknowledged_grobs ()
 void
 Accidental_engraver::finalize ()
 {
+  /*
+    Must reset, since Accidental_engraver is GCd.
+   */
   last_keysig_ = SCM_EOL;
 }
 
index 95f460823f533c52b1a0de324feb402bb21fbe85..0b8fd2d88d8904ed4161b5e1aa1a349cf448290f 100644 (file)
@@ -26,7 +26,7 @@ protected:
   virtual void stop_translation_timestep ();
   virtual void process_music ();
   virtual bool try_music (Music *);
-
+  virtual void finalize ();
 private:
   void add_note (Music *);
   
@@ -36,6 +36,12 @@ private:
   Protected_scm last_chord_;
 };
 
+void
+Chord_name_engraver::finalize ()
+{
+  last_chord_ = SCM_EOL; 
+}
+
 Chord_name_engraver::Chord_name_engraver ()
 {
   chord_name_ = 0;
index e6498a239c7c7260e5bd384b05770bb98ac74a06..0453cea706cb6cbaad2e1f3ee8b05fcfb5b8af58 100644 (file)
@@ -190,11 +190,10 @@ Dynamic_engraver::process_music ()
     {
       if (current_cresc_ev_)
        {
-         Direction sd = to_dir (current_cresc_ev_->get_mus_property ("span-direction"));
-         String msg = sd == 1
-           ? _ ("already have a crescendo")
-           : _ ("already have a decrescendo");
-      
+         String msg = _ ("already have a decrescendo");
+         if (current_cresc_ev_->is_mus_type ("decrescendo-event"))
+           msg = _ ("already have a crescendo");
+
          accepted_spanreqs_drul_[START]->origin ()->warning (msg);
          current_cresc_ev_->origin ()->warning (_("Cresc started here"));
        }
index 340b47f40ed17209323e79789956688b086bae8e..9a004b389c9fd72356416ce3e23a52f8a03b7749 100644 (file)
@@ -41,8 +41,6 @@ public:
   void set_variable  (SCM, SCM sym);
   
   DECLARE_SMOBS (Music_output_def,);
-
-  
 };
 
 DECLARE_UNSMOB(Music_output_def,music_output_def);
index a41476186b231b9c76e35bf451130488a20d0ad5..18363da1d8f91978128d8fcfbf0d6323890297b6 100644 (file)
@@ -57,7 +57,7 @@ public:
    */
   char const* pos_str0_;
 
-  SCM get_port()const { return str_port_; }
+  SCM get_port () const { return str_port_; }
   String name_;
 
 private:
@@ -69,7 +69,6 @@ private:
   void init_port ();
   
   Protected_scm str_port_;
-  
 };
 
 char * gulp_file (String fn, int *len);
index 938af43ca4bb45f6c2f9045433dff7f40dfe6ed8..a5e7af14df8811b702d878068b5c535716b8374f 100644 (file)
@@ -34,6 +34,9 @@
 
 bool store_locations_global_b;
 
+/*
+  TODO: should merge with My_lily_parser. 
+ */
 
 /*
   no ! suffix since it doesn't modify 1st argument.
index 86b48b218d94feaf35ba3db7a98d1ea5366f865a..7c622accd2600b1f6e8e0a59d7dbabacec79249b 100644 (file)
@@ -180,7 +180,7 @@ HYPHEN              --
 
        yy_pop_state();
        this->here_input().source_file_->name_ = s;
-       progress_indication (_f("\nRenamed input to `%s'", s.to_str0()));
+       progress_indication (_f("\nRenamed input to `%s'\n", s.to_str0()));
        scm_module_define (gh_car (scopes_),
                     ly_symbol2scm ("input-file-name"),
                     scm_makfrom0str (s.to_str0()));
index 4cd7a34554bb2beaa56cbd95e4c34010d31d9d2c..773f072aa350ea52d1e24f651d17fdff1b5359f8 100644 (file)
@@ -785,3 +785,14 @@ alist_to_hashq (SCM alist)
     }
   return tab; 
 }
+
+#if 1
+/*
+  Debugging mem leaks:
+ */
+LY_DEFINE(ly_protects, "ly:protects", 0, 0, 0, (),
+         "Return hash of protected objects.")
+{
+  return scm_protects;
+}
+#endif
index 754b5c4dec1c912e4b5ffaa6a47506de04d85e80..4ad74a0b10ae9a5c50434fa746b7fe9a586d8174 100644 (file)
@@ -363,6 +363,18 @@ main_prog (void *, int, char **)
        init = "init.ly";
        
       do_one_file (init, inpath.to_string (), outpath.to_string ());
+
+#if 0
+      /*
+       Code to debug memory leaks. Cannot call from within .ly since
+       then we get the protects from the parser state too.
+       */
+      static SCM proc ;
+      if (!proc)
+       proc = scm_c_eval_string ("dump-gc-protects");
+      scm_gc ();
+      scm_call_0 (proc);
+#endif
       
       p++;
     } while ((arg  = oparser_p_static->get_next_arg ()));
index ff392eaeeb7bec65fd475d373852880df6c3ac59..04a7b04cd37f6d9727eb3b6d0f27cd361b44e998 100644 (file)
@@ -30,8 +30,6 @@ Music_output_def::Music_output_def ()
   scope_ =   ly_make_anonymous_module();
 }
 
-
-
 Music_output_def::~Music_output_def ()
 {
 }
index eab40b4975caee25fbf3b9c990d5addb0f147d82..64991915cc0420243285e1cb26d0e204d8b3416d 100644 (file)
@@ -95,7 +95,6 @@ Paper_column::is_musical (Grob *me)
       s = *unsmob_moment (m);
     }
   return s != Moment (0);
-  
 }
   
 
index 28962bf440ba36cf670269ab36164ac488d7d034..ac8af7494b60d7d71e3b0261429ee1340daf3dc4 100644 (file)
@@ -83,11 +83,12 @@ Paper_score::process (String outname)
   /*
     Be sure to set breakability on first & last column.
    */
-  Link_array<Grob> pc (system_->columns ());
+  {
+    Link_array<Grob> pc (system_->columns ());
   
-  pc[0]->set_grob_property ("breakable", SCM_BOOL_T);
-  pc.top ()->set_grob_property ("breakable", SCM_BOOL_T);
-
+    pc[0]->set_grob_property ("breakable", SCM_BOOL_T);
+    pc.top ()->set_grob_property ("breakable", SCM_BOOL_T);
+  }
   system_->pre_processing ();
  
   Array<Column_x_positions> breaking = calc_breaking ();
@@ -126,10 +127,4 @@ Paper_score::process (String outname)
   // huh?
   delete outputter_;
   outputter_ = 0;
-  
-  if (verbose_global_b)
-    {
-      scm_write (scm_gc_stats (), scm_current_error_port ());
-      scm_flush (scm_current_error_port ());
-    }
 }
index c9dace074fda70a5b4f69810105a83cfcae349b4..7ea2da8890f891feec0d213ece1f712421fcdbaf 100644 (file)
@@ -677,6 +677,7 @@ music_output_def_body:
                
        }
        | music_output_def_head '{' MUSIC_OUTPUT_DEF_IDENTIFIER         {
+               scm_gc_unprotect_object ($1->self_scm ());
                Music_output_def * o =  unsmob_music_output_def ($3);
                $$ = o;
                THIS->lexer_->remove_scope ();
index 4d1cdd89017955c49812ddc4ff90c8bb8832773d..666253aeebcf0c07a5ebedcea3fab22f175de926 100644 (file)
@@ -121,8 +121,8 @@ loose_column (Grob *l, Grob *c, Grob *r)
     some cases (two isolated, consecutive clef changes) won't be
     nicely folded, but hey, then don't do that.
   */
-  if(!  ((Paper_column::musical_b (l_neighbor) || Item::breakable_b (l_neighbor))
-        && (Paper_column::musical_b (r_neighbor) || Item::breakable_b (r_neighbor))) )
+  if(!  ((Paper_column::is_musical (l_neighbor) || Item::breakable_b (l_neighbor))
+        && (Paper_column::is_musical (r_neighbor) || Item::breakable_b (r_neighbor))) )
     {
       return false;
     }
@@ -167,7 +167,7 @@ Spacing_spanner::prune_loose_columns (Grob*me,Link_array<Grob> *cols, Rational s
   Real increment = robust_scm2double (me->get_grob_property ("spacing-increment"), 1.2);
   for (int i=0; i < cols->size ();  i++)
     {
-      if (Item::breakable_b (cols->elem(i)) || Paper_column::musical_b (cols->elem (i)))
+      if (Item::breakable_b (cols->elem(i)) || Paper_column::is_musical (cols->elem (i)))
        {
          newcols.push (cols->elem(i));
          continue;
@@ -339,7 +339,7 @@ Spacing_spanner::set_implicit_neighbor_columns (Link_array<Grob> cols)
   for (int i = 0; i < cols.size (); i++)
     {
       Item * it = dynamic_cast<Item*>(cols[i]);
-      if (!Item::breakable_b (it) && !Paper_column::musical_b (it))
+      if (!Item::breakable_b (it) && !Paper_column::is_musical (it))
        continue;
 
       // it->breakable || it->musical
@@ -430,7 +430,7 @@ Spacing_spanner::find_shortest (Grob *me, Link_array<Grob> const &cols)
   
   for (int i =0 ; i < cols.size (); i++)  
     {
-      if (Paper_column::musical_b (cols[i]))
+      if (Paper_column::is_musical (cols[i]))
        {
          Moment *when = unsmob_moment (cols[i]->get_grob_property  ("when"));
 
@@ -517,7 +517,7 @@ Spacing_spanner::do_measure (Rational shortest, Grob*me, Link_array<Grob> *cols)
       Paper_column * lc = dynamic_cast<Paper_column*> (l);
       Paper_column * rc = dynamic_cast<Paper_column*> (r);
 
-      if (!Paper_column::musical_b (l))
+      if (!Paper_column::is_musical (l))
        {
          breakable_column_spacing (me, l, r, shortest);
 
@@ -674,7 +674,7 @@ Spacing_spanner::standard_breakable_column_spacing (Grob * me, Item*l, Item*r,
   
   do
     {
-      if (!Paper_column::musical_b (cols[d]))
+      if (!Paper_column::is_musical (cols[d]))
        {
          /*
            Tied accidentals over barlines cause problems, so lets see
@@ -873,7 +873,7 @@ Spacing_spanner::note_spacing (Grob*me, Grob *lc, Grob *rc,
   Moment rwhen =  Paper_column::when_mom (rc);
 
   Moment delta_t = rwhen - lwhen;
-  if (!Paper_column::musical_b (rc ))
+  if (!Paper_column::is_musical (rc ))
     {
       /*
        when toying with mmrests, it is possible to have musical
index f5d24e01be44399791e30d5279bd478276cb49c8..7c2375d90b34b83cccb5577b8dba7e4d9ba4f497 100644 (file)
 #include "event.hh"
 #include "audio-item.hh"
 
+/*
+  TODO: fold this into 1 engraver: \< and \> should also stop when
+  absdyn is encountered.
+ */
+
 struct Audio_dynamic_tuple
 {
   Audio_dynamic* audio_;
@@ -34,8 +39,8 @@ protected:
 private:
   Audio_dynamic* audio_;
   Real last_volume_;
-  Music* span_start_req_;
-  Drul_array<Music*> span_req_l_drul_;
+  Music* span_start_event_;
+  Drul_array<Music*> span_events_;
   Array<Audio_dynamic_tuple> dynamic_tuples_;
   Array<Audio_dynamic_tuple> finished_dynamic_tuples_;
   Direction dir_;
@@ -44,9 +49,9 @@ private:
 
 Span_dynamic_performer::Span_dynamic_performer ()
 {
-  span_req_l_drul_[START] = 0;
-  span_req_l_drul_[STOP] = 0;
-  span_start_req_ = 0;
+  span_events_[START] = 0;
+  span_events_[STOP] = 0;
+  span_start_event_ = 0;
   audio_ = 0;
   last_volume_ = 0;
 }
@@ -63,23 +68,23 @@ Span_dynamic_performer::acknowledge_audio_element (Audio_element_info i)
 void
 Span_dynamic_performer::process_music ()
 {
-  if (span_start_req_ || span_req_l_drul_[START])
+  if (span_start_event_ || span_events_[START])
     {
       audio_ = new Audio_dynamic (0);
-      Audio_element_info info (audio_, span_req_l_drul_[START]
-                              ? span_req_l_drul_[START]
-                              : span_req_l_drul_[STOP]);
+      Audio_element_info info (audio_, span_events_[START]
+                              ? span_events_[START]
+                              : span_events_[STOP]);
       announce_element (info);
       Audio_dynamic_tuple a = { audio_, now_mom () };
       dynamic_tuples_.push (a);
     }
   
-  if (span_req_l_drul_[STOP])
+  if (span_events_[STOP])
     {
-      if (!span_start_req_)
+      if (!span_start_event_)
        {
-         span_req_l_drul_[STOP]->origin ()->warning (_ ("can't find start of (de)crescendo"));
-         span_req_l_drul_[STOP] = 0;
+         span_events_[STOP]->origin ()->warning (_ ("can't find start of (de)crescendo"));
+         span_events_[STOP] = 0;
        }
       else
        {
@@ -87,14 +92,14 @@ Span_dynamic_performer::process_music ()
          finished_dynamic_tuples_ = dynamic_tuples_;
        }
       dynamic_tuples_.clear ();
-      span_start_req_ = 0;
+      span_start_event_ = 0;
     }
 
-  if (span_req_l_drul_[START])
+  if (span_events_[START])
     {
-      String t = ly_scm2string (span_req_l_drul_[START]->get_mus_property ("span-type"));
-      dir_ = (t == "crescendo")        ? RIGHT : LEFT;
-      span_start_req_ = span_req_l_drul_[START];
+      dir_ =  (span_events_[START]->is_mus_type ("crescendo-event"))
+       ? RIGHT : LEFT;
+      span_start_event_ = span_events_[START];
       
       dynamic_tuples_.clear ();
       Audio_dynamic_tuple a = { audio_, now_mom () };
@@ -102,18 +107,18 @@ Span_dynamic_performer::process_music ()
     }
 
 
-  if (span_req_l_drul_[STOP])
+  if (span_events_[STOP])
     { 
       finished_dynamic_tuples_.top ().audio_->volume_ = last_volume_;
     }
   
-  if (span_req_l_drul_[START])
+  if (span_events_[START])
     {
       dynamic_tuples_[0].audio_->volume_ = last_volume_;
     }
-  span_start_req_ = 0;
-  span_req_l_drul_[START] = 0;
-  span_req_l_drul_[STOP] = 0;
+  span_start_event_ = 0;
+  span_events_[START] = 0;
+  span_events_[STOP] = 0;
 }
 
 void
@@ -161,8 +166,8 @@ Span_dynamic_performer::stop_translation_timestep ()
       audio_ = 0;
     }
 
-  span_req_l_drul_[STOP] = 0;
-  span_req_l_drul_[START] = 0;
+  span_events_[STOP] = 0;
+  span_events_[START] = 0;
 
 }
 
@@ -173,7 +178,7 @@ Span_dynamic_performer::try_music (Music* r)
       || r->is_mus_type ("decrescendo-event"))
     {
       Direction d = to_dir (r->get_mus_property ("span-direction"));
-      span_req_l_drul_[d] = r;
+      span_events_[d] = r;
       return true;
     }
   return false;
index debdfc8e2d0b906c7a4092d5710cd376df9fb510..177094443e3a052f039547655f44b76da01050d1 100644 (file)
@@ -59,7 +59,7 @@ Tie::head (Grob*me, Direction d)
 {
   SCM c = me->get_grob_property ("head-pair");
 
-  if (gh_pair_p)
+  if (gh_pair_p (c))
     return unsmob_grob (index_get_cell (c, d));
   else
     return 0;
index ced34587173fcd15fcd8f55ba07dd40d121ae4dc..357e34372f4dd80e2b7a3fa7d4e0c5e7169e6a77 100644 (file)
@@ -89,7 +89,9 @@ void
 Translator_group::add_fresh_group_translator (Translator*t)
 {
   Translator_group*tg = dynamic_cast<Translator_group*> (t);
-  trans_group_list_ = add_translator (trans_group_list_,t); 
+  trans_group_list_ = add_translator (trans_group_list_,t);
+  scm_gc_unprotect_object (t->self_scm ());
+
   Context_def * td = unsmob_context_def (tg->definition_);
 
   /*
@@ -253,7 +255,6 @@ Translator_group::get_default_interpreter ()
        }
       Translator_group *tg = t->instantiate (output_def_, SCM_EOL);
       add_fresh_group_translator (tg);
-
       if (!tg->is_bottom_context ())
        return tg->get_default_interpreter ();
       else
index d640456328324ac32374e2e3da76d5bbd4f79781..7cfe5f3ab7be50755115b55ab463a93ad0c08a26 100644 (file)
   (ly:warn (string-append
            "\n"
            input-file-name ": old relative compatibility was not used.")))
+
+
+#(if (ly:get-option 'verbose)
+  (begin
+   (gc)
+   (write (gc-stats) (current-error-port))
+   (flush-all-ports)))
+
index 5a73f5155371678eb7916e3a04b58c2a77aa90cb..a322713cf11fe5c74d32e3f353b29fcf71fe84fc 100644 (file)
@@ -474,3 +474,33 @@ L1 is copied, L2 not.
    ))
 
 
+;; debug mem leaks
+
+(define gc-protect-stat-count 0)
+(define-public (dump-gc-protects)
+  (set! gc-protect-stat-count (1+ gc-protect-stat-count) )
+  
+  (display 
+   (map (lambda (y)
+         (let
+             ((x (car y))
+              (c (cdr y)))
+
+           (string-append
+            (string-join
+             (map object->string (list (object-address x) c x))
+             " ")
+            "\n")))
+
+         (sort
+          (hash-table->alist (ly:protects))
+          (lambda (a b)
+            (< (object-address (car a))
+               (object-address (car b)))))
+         
+         )
+      (open-file (string-append
+              "gcstat-" (number->string gc-protect-stat-count)
+              ".scm"
+              ) "w")))
+
index 31f81f9b305f07a88a15ddebadee5913fa940667..66db3075b6c3828fb5d4bb4d47551b28b22eea93 100644 (file)
@@ -429,7 +429,8 @@ class Lilypond_snippet (Snippet):
        def ly (self):
                if self.type == 'lilypond_file':
                        name = self.substring ('filename')
-                       return open (find_file (name)).read ()
+                       return '\\renameinput \"%s\"\n' % name\
+                              + open (find_file (name)).read ()
                else:
                        return self.substring ('code')