From e783d9a1c681e62c649604f7155945271d610ec7 Mon Sep 17 00:00:00 2001 From: hanwen Date: Mon, 9 Feb 2004 12:20:34 +0000 Subject: [PATCH] * 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): write .dep file. (Lilypond_snippet.ly): add \renameinput. --- ChangeLog | 7 ++++ input/example-1.ly | 1 + lily/accidental-engraver.cc | 3 ++ lily/chord-name-engraver.cc | 8 ++++- lily/dynamic-engraver.cc | 9 +++-- lily/include/music-output-def.hh | 2 -- lily/include/source-file.hh | 3 +- lily/input-file-results.cc | 3 ++ lily/lexer.ll | 2 +- lily/lily-guile.cc | 11 ++++++ lily/main.cc | 12 +++++++ lily/music-output-def.cc | 2 -- lily/paper-column.cc | 1 - lily/paper-score.cc | 15 +++------ lily/parser.yy | 1 + lily/spacing-spanner.cc | 16 ++++----- lily/span-dynamic-performer.cc | 57 +++++++++++++++++--------------- lily/tie.cc | 2 +- lily/translator-group.cc | 5 +-- ly/init.ly | 8 +++++ scm/lily.scm | 30 +++++++++++++++++ scripts/lilypond-book.py | 3 +- 22 files changed, 139 insertions(+), 62 deletions(-) diff --git a/ChangeLog b/ChangeLog index b896cf54c5..4c00484346 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,12 @@ 2004-02-09 Han-Wen Nienhuys + * 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): diff --git a/input/example-1.ly b/input/example-1.ly index 40a817561b..82095e1b9c 100644 --- a/input/example-1.ly +++ b/input/example-1.ly @@ -1,4 +1,5 @@ \version "2.1.7" + % A simple scale in LilyPond % % Type: diff --git a/lily/accidental-engraver.cc b/lily/accidental-engraver.cc index c6f1f4ed54..770eaa0246 100644 --- a/lily/accidental-engraver.cc +++ b/lily/accidental-engraver.cc @@ -393,6 +393,9 @@ Accidental_engraver::process_acknowledged_grobs () void Accidental_engraver::finalize () { + /* + Must reset, since Accidental_engraver is GCd. + */ last_keysig_ = SCM_EOL; } diff --git a/lily/chord-name-engraver.cc b/lily/chord-name-engraver.cc index 95f460823f..0b8fd2d88d 100644 --- a/lily/chord-name-engraver.cc +++ b/lily/chord-name-engraver.cc @@ -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; diff --git a/lily/dynamic-engraver.cc b/lily/dynamic-engraver.cc index e6498a239c..0453cea706 100644 --- a/lily/dynamic-engraver.cc +++ b/lily/dynamic-engraver.cc @@ -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")); } diff --git a/lily/include/music-output-def.hh b/lily/include/music-output-def.hh index 340b47f40e..9a004b389c 100644 --- a/lily/include/music-output-def.hh +++ b/lily/include/music-output-def.hh @@ -41,8 +41,6 @@ public: void set_variable (SCM, SCM sym); DECLARE_SMOBS (Music_output_def,); - - }; DECLARE_UNSMOB(Music_output_def,music_output_def); diff --git a/lily/include/source-file.hh b/lily/include/source-file.hh index a41476186b..18363da1d8 100644 --- a/lily/include/source-file.hh +++ b/lily/include/source-file.hh @@ -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); diff --git a/lily/input-file-results.cc b/lily/input-file-results.cc index 938af43ca4..a5e7af14df 100644 --- a/lily/input-file-results.cc +++ b/lily/input-file-results.cc @@ -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. diff --git a/lily/lexer.ll b/lily/lexer.ll index 86b48b218d..7c622accd2 100644 --- a/lily/lexer.ll +++ b/lily/lexer.ll @@ -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())); diff --git a/lily/lily-guile.cc b/lily/lily-guile.cc index 4cd7a34554..773f072aa3 100644 --- a/lily/lily-guile.cc +++ b/lily/lily-guile.cc @@ -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 diff --git a/lily/main.cc b/lily/main.cc index 754b5c4dec..4ad74a0b10 100644 --- a/lily/main.cc +++ b/lily/main.cc @@ -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 ())); diff --git a/lily/music-output-def.cc b/lily/music-output-def.cc index ff392eaeeb..04a7b04cd3 100644 --- a/lily/music-output-def.cc +++ b/lily/music-output-def.cc @@ -30,8 +30,6 @@ Music_output_def::Music_output_def () scope_ = ly_make_anonymous_module(); } - - Music_output_def::~Music_output_def () { } diff --git a/lily/paper-column.cc b/lily/paper-column.cc index eab40b4975..64991915cc 100644 --- a/lily/paper-column.cc +++ b/lily/paper-column.cc @@ -95,7 +95,6 @@ Paper_column::is_musical (Grob *me) s = *unsmob_moment (m); } return s != Moment (0); - } diff --git a/lily/paper-score.cc b/lily/paper-score.cc index 28962bf440..ac8af7494b 100644 --- a/lily/paper-score.cc +++ b/lily/paper-score.cc @@ -83,11 +83,12 @@ Paper_score::process (String outname) /* Be sure to set breakability on first & last column. */ - Link_array pc (system_->columns ()); + { + Link_array 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 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 ()); - } } diff --git a/lily/parser.yy b/lily/parser.yy index c9dace074f..7ea2da8890 100644 --- a/lily/parser.yy +++ b/lily/parser.yy @@ -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 (); diff --git a/lily/spacing-spanner.cc b/lily/spacing-spanner.cc index 4d1cdd8901..666253aeeb 100644 --- a/lily/spacing-spanner.cc +++ b/lily/spacing-spanner.cc @@ -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 *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 cols) for (int i = 0; i < cols.size (); i++) { Item * it = dynamic_cast(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 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 *cols) Paper_column * lc = dynamic_cast (l); Paper_column * rc = dynamic_cast (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 diff --git a/lily/span-dynamic-performer.cc b/lily/span-dynamic-performer.cc index f5d24e01be..7c2375d90b 100644 --- a/lily/span-dynamic-performer.cc +++ b/lily/span-dynamic-performer.cc @@ -11,6 +11,11 @@ #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 span_req_l_drul_; + Music* span_start_event_; + Drul_array span_events_; Array dynamic_tuples_; Array 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; diff --git a/lily/tie.cc b/lily/tie.cc index debdfc8e2d..177094443e 100644 --- a/lily/tie.cc +++ b/lily/tie.cc @@ -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; diff --git a/lily/translator-group.cc b/lily/translator-group.cc index ced3458717..357e34372f 100644 --- a/lily/translator-group.cc +++ b/lily/translator-group.cc @@ -89,7 +89,9 @@ void Translator_group::add_fresh_group_translator (Translator*t) { Translator_group*tg = dynamic_cast (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 diff --git a/ly/init.ly b/ly/init.ly index d640456328..7cfe5f3ab7 100644 --- a/ly/init.ly +++ b/ly/init.ly @@ -19,3 +19,11 @@ (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))) + diff --git a/scm/lily.scm b/scm/lily.scm index 5a73f51553..a322713cf1 100644 --- a/scm/lily.scm +++ b/scm/lily.scm @@ -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"))) + diff --git a/scripts/lilypond-book.py b/scripts/lilypond-book.py index 31f81f9b30..66db3075b6 100644 --- a/scripts/lilypond-book.py +++ b/scripts/lilypond-book.py @@ -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') -- 2.39.5