From 5c3227333599dd4edb0e54ba985fb94beff272c2 Mon Sep 17 00:00:00 2001 From: Han-Wen Nienhuys Date: Wed, 19 Jun 2002 14:33:53 +0000 Subject: [PATCH] * lily/music.cc (Music): fix very subtle and nasty memory corruption bug. * mutopia/claop.py: new file: CLA(O)P II by Peter Wallin. --- ChangeLog | 3 +++ lily/accidental-engraver.cc | 2 -- lily/grob.cc | 11 +++++++++++ lily/include/lily-guile.hh | 4 ++++ lily/include/musical-request.hh | 2 +- lily/lily-guile.cc | 8 ++++++++ lily/music.cc | 27 +++++++++++++++++++-------- lily/translator.cc | 1 - mutopia/claop.py | 1 + 9 files changed, 47 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index c651140062..2fa4e6226c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2002-06-19 Han-Wen Nienhuys + * lily/music.cc (Music): fix very subtle and nasty memory + corruption bug. + * mutopia/claop.py: new file: CLA(O)P II by Peter Wallin. 2002-06-19 Han-Wen diff --git a/lily/accidental-engraver.cc b/lily/accidental-engraver.cc index 7497bacb57..1670ba2fa9 100644 --- a/lily/accidental-engraver.cc +++ b/lily/accidental-engraver.cc @@ -64,8 +64,6 @@ public: This is not a property, and it is not protected. This poses a very small risk of the value being GC'd from under us. - - Oh well. */ SCM last_keysig_; diff --git a/lily/grob.cc b/lily/grob.cc index 8e64b58098..b61e151e34 100644 --- a/lily/grob.cc +++ b/lily/grob.cc @@ -54,6 +54,11 @@ Grob::Grob (SCM basicprops) immutable_property_alist_ = basicprops; mutable_property_alist_ = SCM_EOL; + /* + We do smobify_self() as the first step. Since the object lives on + the heap, none of its SCM variables are protected from GC. After + smobify_self(), they are. + */ smobify_self (); @@ -116,11 +121,17 @@ Grob::Grob (Grob const&s) original_l_ = (Grob*) &s; immutable_property_alist_ = s.immutable_property_alist_; mutable_property_alist_ = SCM_EOL; + + /* + No properties are copied. That is the job of handle_broken_dependencies. + */ status_c_ = s.status_c_; pscore_l_ = s.pscore_l_; smobify_self (); + + } Grob::~Grob () diff --git a/lily/include/lily-guile.hh b/lily/include/lily-guile.hh index 6b13fc9eb8..deda57935f 100644 --- a/lily/include/lily-guile.hh +++ b/lily/include/lily-guile.hh @@ -144,6 +144,8 @@ SCM ly_assoc_cdr (SCM key, SCM alist); Interval ly_scm2interval (SCM); SCM ly_interval2scm (Drul_array); +void taint (SCM *); + SCM ly_parse_scm (char const* s, int* n); SCM ly_quote_scm (SCM s); @@ -279,4 +281,6 @@ FNAME ARGLIST\ + + #endif // LILY_GUILE_HH diff --git a/lily/include/musical-request.hh b/lily/include/musical-request.hh index 4511e660a0..e383dcaa3c 100644 --- a/lily/include/musical-request.hh +++ b/lily/include/musical-request.hh @@ -133,7 +133,7 @@ public: /** - instruct lyric context to alter typesetting (unimplemented). */ + instruct lyric context to alter typesetting. */ class Melisma_req : public Span_req { public: diff --git a/lily/lily-guile.cc b/lily/lily-guile.cc index dbd2a90a56..4170055924 100644 --- a/lily/lily-guile.cc +++ b/lily/lily-guile.cc @@ -760,3 +760,11 @@ ly_split_list (SCM s, SCM list) } + +void +taint (SCM * foo) +{ + /* + nop. + */ +} diff --git a/lily/music.cc b/lily/music.cc index 69364a2a3f..ef5615524c 100644 --- a/lily/music.cc +++ b/lily/music.cc @@ -42,11 +42,15 @@ Music::Music () Music::Music (Music const &m) { immutable_property_alist_ = m.immutable_property_alist_; - SCM c =ly_deep_mus_copy (m.mutable_property_alist_); - mutable_property_alist_ = c; + mutable_property_alist_ = SCM_EOL; + /* + First we smobify_self, then we copy over the stuff. If we don't, + stack vars that hold the copy might be optimized away, meaning + that they won't be protected from GC. + */ smobify_self (); - + mutable_property_alist_ = ly_deep_mus_copy (m.mutable_property_alist_); set_spot (*m.origin ()); } @@ -107,7 +111,10 @@ Music::start_mom () const void print_alist (SCM a, SCM port) { - for (SCM s = a; gh_pair_p (s); s = ly_cdr (s)) + /* + SCM_EOL -> catch malformed lists. + */ + for (SCM s = a; s != SCM_EOL; s = ly_cdr (s)) { scm_display (ly_caar (s), port); scm_puts (" = ", port); @@ -174,6 +181,8 @@ Music::internal_get_mus_property (SCM sym) const return (s == SCM_BOOL_F) ? SCM_EOL : ly_cdr (s); } +void paranoia_check (Music*); + void Music::internal_set_mus_property (SCM s, SCM v) { @@ -181,10 +190,12 @@ Music::internal_set_mus_property (SCM s, SCM v) if (internal_type_checking_global_b) assert (type_check_assignment (s, v, ly_symbol2scm ("music-type?"))); #endif - - mutable_property_alist_ = scm_assq_set_x (mutable_property_alist_, s, v); + + mutable_property_alist_ = scm_assq_set_x (mutable_property_alist_, s, v); } + + #include "main.hh" void @@ -214,8 +225,7 @@ LY_DEFINE(ly_get_mus_property, SCM_ASSERT_TYPE(sc, mus, SCM_ARG1, __FUNCTION__, "grob"); SCM_ASSERT_TYPE(gh_symbol_p(sym), sym, SCM_ARG2, __FUNCTION__, "symbol"); - return sc->internal_get_mus_property (sym); - + return sc->internal_get_mus_property (sym); } LY_DEFINE(ly_set_mus_property, @@ -285,3 +295,4 @@ LY_DEFINE(ly_music_list_p,"music-list?", 1, 0, 0, return SCM_BOOL_T; } ADD_MUSIC(Music); + diff --git a/lily/translator.cc b/lily/translator.cc index bdd21e5863..66dde042a5 100644 --- a/lily/translator.cc +++ b/lily/translator.cc @@ -35,7 +35,6 @@ Translator::Translator () init (); output_def_l_ = 0; smobify_self (); - } Translator::Translator (Translator const &s) diff --git a/mutopia/claop.py b/mutopia/claop.py index 3147aeb217..cae831896d 100644 --- a/mutopia/claop.py +++ b/mutopia/claop.py @@ -301,5 +301,6 @@ sys.stdout.write (r"""> minimumVerticalExtent = #'(-3 . 3) } } + } """) -- 2.39.5