From 1cd3b2484a4095d4e3fb6422dbc695a1a1219eea Mon Sep 17 00:00:00 2001 From: Han-Wen Nienhuys Date: Tue, 31 May 2005 15:25:26 +0000 Subject: [PATCH] * lily/score.cc (Score): unprotect copy of Output_def. Plugs memory leak. * lily/parser.yy (score_body): don't clone Score, that's done in Lily_lexer::try_special_identifiers(). This fixes a memory leak. * lily/score-engraver.cc (derived_mark): new function. (initialize): unprotect Paper_score. This fixes a memory leak. * lily/score-performer.cc (derived_mark): new function. * lily/score-translator.cc (get_output): use SCM for get_output() call. --- ChangeLog | 13 +++++++++++++ lily/global-context-scheme.cc | 6 +++--- lily/global-context.cc | 2 +- lily/grob.cc | 4 ++-- lily/include/global-context.hh | 2 +- lily/include/score-context.hh | 2 +- lily/include/score-engraver.hh | 7 ++++++- lily/include/score-performer.hh | 3 ++- lily/include/score-translator.hh | 2 +- lily/music-output.cc | 9 +++++++-- lily/paper-score.cc | 2 ++ lily/parser.yy | 2 +- lily/score-context.cc | 2 +- lily/score-engraver.cc | 15 ++++++++++++--- lily/score-performer.cc | 15 +++++++++++++-- lily/score-translator.cc | 4 ++-- lily/score.cc | 7 +++++-- scm/lily.scm | 6 +++--- 18 files changed, 76 insertions(+), 27 deletions(-) diff --git a/ChangeLog b/ChangeLog index 26bfe8eb43..e77c4a37a1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,18 @@ 2005-05-31 Han-Wen Nienhuys + * lily/score.cc (Score): unprotect copy of Output_def. Plugs + memory leak. + + * lily/parser.yy (score_body): don't clone Score, that's done in + Lily_lexer::try_special_identifiers(). This fixes a memory leak. + + * lily/score-engraver.cc (derived_mark): new function. + (initialize): unprotect Paper_score. This fixes a memory leak. + + * lily/score-performer.cc (derived_mark): new function. + + * lily/score-translator.cc (get_output): use SCM for get_output() call. + * stepmake/aclocal.m4: put FlexLexer.h test in conftest.cc. Fixes spurious warning. diff --git a/lily/global-context-scheme.cc b/lily/global-context-scheme.cc index c98a6fd8e4..8b77fab5c6 100644 --- a/lily/global-context-scheme.cc +++ b/lily/global-context-scheme.cc @@ -24,10 +24,10 @@ LY_DEFINE (ly_format_output, "ly:format-output", Global_context *g = dynamic_cast (unsmob_context (context)); SCM_ASSERT_TYPE (g, context, SCM_ARG1, __FUNCTION__, "Global context"); - Music_output *output = g->get_output (); + SCM output = g->get_output (); progress_indication ("\n"); - output->process (); - return output->self_scm (); + unsmob_music_output (output)->process (); + return output; } LY_DEFINE (ly_run_translator, "ly:run-translator", diff --git a/lily/global-context.cc b/lily/global-context.cc index df9187d1e5..7f342a182f 100644 --- a/lily/global-context.cc +++ b/lily/global-context.cc @@ -97,7 +97,7 @@ Global_context::get_score_context () const : 0; } -Music_output * +SCM Global_context::get_output () { return get_score_context ()->get_output (); diff --git a/lily/grob.cc b/lily/grob.cc index fca538fb7e..548c82f2c8 100644 --- a/lily/grob.cc +++ b/lily/grob.cc @@ -663,8 +663,8 @@ Grob::mark_smob (SCM ses) if (s->original_) scm_gc_mark (s->original_->self_scm ()); - if (s->pscore_ && s->pscore_->layout ()) - scm_gc_mark (s->pscore_->layout ()->self_scm ()); + if (s->pscore_) + scm_gc_mark (s->pscore_->self_scm ()); s->do_derived_mark (); return s->mutable_property_alist_; diff --git a/lily/include/global-context.hh b/lily/include/global-context.hh index adc0b07932..720147e03d 100644 --- a/lily/include/global-context.hh +++ b/lily/include/global-context.hh @@ -29,7 +29,7 @@ public: void apply_finalizations (); void add_finalization (SCM); - virtual Music_output *get_output (); + virtual SCM get_output (); virtual void prepare (Moment); virtual void one_time_step (); virtual void finish (); diff --git a/lily/include/score-context.hh b/lily/include/score-context.hh index f22038a841..44028900d7 100644 --- a/lily/include/score-context.hh +++ b/lily/include/score-context.hh @@ -15,7 +15,7 @@ class Score_context : public Context public: Score_context (Object_key const *); - virtual Music_output *get_output (); + virtual SCM get_output (); virtual void prepare (Moment); virtual void finish (); virtual void one_time_step (); diff --git a/lily/include/score-engraver.hh b/lily/include/score-engraver.hh index a790b5f967..6286759fee 100644 --- a/lily/include/score-engraver.hh +++ b/lily/include/score-engraver.hh @@ -32,6 +32,7 @@ protected: virtual void prepare (Moment); virtual void one_time_step (); + /* Engraver_group_engraver interface */ virtual void acknowledge_grob (Grob_info); virtual bool try_music (Music *); @@ -40,10 +41,14 @@ protected: virtual void announce_grob (Grob_info); virtual void stop_translation_timestep (); + /* + Translator interface + */ + virtual void derived_mark () const; public: TRANSLATOR_DECLARATIONS (Score_engraver); void forbid_breaks (); - virtual Music_output *get_output (); + virtual SCM get_output (); }; #endif /* SCORE_ENGRAVER_HH */ diff --git a/lily/include/score-performer.hh b/lily/include/score-performer.hh index 9c36525db8..cd3ebefa69 100644 --- a/lily/include/score-performer.hh +++ b/lily/include/score-performer.hh @@ -29,7 +29,8 @@ protected: virtual void announce_element (Audio_element_info); virtual int get_tempo () const; virtual void play_element (Audio_element *p); - virtual Music_output *get_output (); + virtual SCM get_output (); + virtual void derived_mark () const; private: void header (Midi_stream &); diff --git a/lily/include/score-translator.hh b/lily/include/score-translator.hh index 532ef94348..7c3e503324 100644 --- a/lily/include/score-translator.hh +++ b/lily/include/score-translator.hh @@ -15,7 +15,7 @@ class Score_translator : public virtual Translator_group { friend class Score_context; protected: - virtual Music_output *get_output (); + virtual SCM get_output (); virtual void prepare (Moment); virtual void finish (); virtual void one_time_step (); diff --git a/lily/music-output.cc b/lily/music-output.cc index 5330e864eb..c41d59e3a9 100644 --- a/lily/music-output.cc +++ b/lily/music-output.cc @@ -8,7 +8,9 @@ */ #include "music-output.hh" + #include "ly-smobs.icc" +#include "virtual-methods.hh" Music_output::Music_output () { @@ -44,9 +46,12 @@ Music_output::mark_smob (SCM s) } int -Music_output::print_smob (SCM, SCM p, scm_print_state*) +Music_output::print_smob (SCM s, SCM p, scm_print_state*) { - scm_puts ("#", p); + Music_output *sc = (Music_output *) SCM_CELL_WORD_1 (s); + scm_puts ("#<", p); + scm_puts (classname (sc), p); + scm_puts (">", p); return 1; } diff --git a/lily/paper-score.cc b/lily/paper-score.cc index b756841679..98b734a653 100644 --- a/lily/paper-score.cc +++ b/lily/paper-score.cc @@ -39,6 +39,8 @@ Paper_score::Paper_score (Paper_score const &s) void Paper_score::derived_mark () const { + if (layout_) + scm_gc_mark (layout_->self_scm ()); scm_gc_mark (systems_); scm_gc_mark (paper_systems_); } diff --git a/lily/parser.yy b/lily/parser.yy index 8d1cbb643b..9982ba6690 100644 --- a/lily/parser.yy +++ b/lily/parser.yy @@ -792,7 +792,7 @@ score_body: $$->set_spot (@$); } | SCORE_IDENTIFIER { - $$ = new Score ( *unsmob_score ($1)); + $$ = unsmob_score ($1); $$->set_spot (@$); } | score_body object_id_setting { diff --git a/lily/score-context.cc b/lily/score-context.cc index c89469d8f9..15e2e5e9fa 100644 --- a/lily/score-context.cc +++ b/lily/score-context.cc @@ -36,7 +36,7 @@ Score_context::one_time_step () s->one_time_step (); } -Music_output * +SCM Score_context::get_output () { Translator *t = implementation (); diff --git a/lily/score-engraver.cc b/lily/score-engraver.cc index 08be7890d5..46d2078a42 100644 --- a/lily/score-engraver.cc +++ b/lily/score-engraver.cc @@ -34,6 +34,15 @@ Score_engraver::Score_engraver () pscore_ = 0; } +void +Score_engraver::derived_mark () const +{ + if (pscore_) + scm_gc_mark (pscore_->self_scm ()); + Score_translator::derived_mark (); + Engraver_group_engraver::derived_mark (); +} + void Score_engraver::make_columns () { @@ -106,6 +115,7 @@ Score_engraver::initialize () } pscore_ = new Paper_score (dynamic_cast (get_output_def ())); + scm_gc_unprotect_object (pscore_->self_scm ()); SCM props = updated_grob_properties (context (), ly_symbol2scm ("System")); @@ -217,12 +227,11 @@ Score_engraver::set_columns (Paper_column *new_command, system_->add_column (musical_column_); } -Music_output * +SCM Score_engraver::get_output () { Music_output *o = pscore_; - ///FIXME WTF ? pscore_ = 0; - return o; + return o->self_scm (); } bool diff --git a/lily/score-performer.cc b/lily/score-performer.cc index 31f9ecdade..0c341dd98c 100644 --- a/lily/score-performer.cc +++ b/lily/score-performer.cc @@ -78,18 +78,29 @@ Score_performer::get_tempo () const return ::get_tempo (performance_->midi_, Moment (Rational (1, 4))); } -Music_output * +SCM Score_performer::get_output () { Music_output *o = performance_; performance_ = 0; - return o; + return o->self_scm (); +} + +void +Score_performer::derived_mark () const +{ + if (performance_) + scm_gc_mark (performance_->self_scm ()); + + Score_translator::derived_mark (); + Performer_group_performer::derived_mark (); } void Score_performer::initialize () { performance_ = new Performance; + scm_gc_unprotect_object (performance_->self_scm ()); performance_->midi_ = get_output_def (); Translator_group::initialize (); diff --git a/lily/score-translator.cc b/lily/score-translator.cc index ceb980d3fb..f8fa4d9317 100644 --- a/lily/score-translator.cc +++ b/lily/score-translator.cc @@ -14,10 +14,10 @@ Score_translator::prepare (Moment) { } -Music_output * +SCM Score_translator::get_output () { - return 0; + return SCM_EOL; } void diff --git a/lily/score.cc b/lily/score.cc index ee628b9b25..cec3cef117 100644 --- a/lily/score.cc +++ b/lily/score.cc @@ -78,8 +78,11 @@ Score::Score (Score const &s) scm_gc_unprotect_object (music_); for (int i = 0, n = s.defs_.size (); i < n; i++) - defs_.push (s.defs_[i]->clone ()); - + { + Output_def * copy = s.defs_[i]->clone (); + defs_.push (copy); + scm_gc_unprotect_object (copy->self_scm ()); + } header_ = ly_make_anonymous_module (false); if (ly_c_module_p (s.header_)) ly_module_copy (header_, s.header_); diff --git a/scm/lily.scm b/scm/lily.scm index 9bc8504810..903df5b2f8 100644 --- a/scm/lily.scm +++ b/scm/lily.scm @@ -274,7 +274,7 @@ The syntax is the same as `define*-public'." ".scm")) (outfile (open-file out-file-name "w"))) - (display "Dumping gc protected objs to ...\n") + (display (format "Dumping gc protected objs to ~a...\n" out-file-name)) (display (filter (lambda (x) (not (symbol? x))) @@ -326,8 +326,8 @@ The syntax is the same as `define*-public'." (catch 'ly-file-failed (lambda () (ly:parse-file file-name)) (lambda (x . args) (handler x file-name))) - ;;(lambda (x) (handler x f))) - (if #f + + (if #t (dump-gc-protects))) (use-modules (scm editor)) -- 2.39.2