]> git.donarmstrong.com Git - lilypond.git/commitdiff
* lily/music.cc (Music): fix very subtle and nasty memory
authorHan-Wen Nienhuys <hanwen@xs4all.nl>
Wed, 19 Jun 2002 14:33:53 +0000 (14:33 +0000)
committerHan-Wen Nienhuys <hanwen@xs4all.nl>
Wed, 19 Jun 2002 14:33:53 +0000 (14:33 +0000)
corruption bug.

* mutopia/claop.py: new file: CLA(O)P II by Peter Wallin.

ChangeLog
lily/accidental-engraver.cc
lily/grob.cc
lily/include/lily-guile.hh
lily/include/musical-request.hh
lily/lily-guile.cc
lily/music.cc
lily/translator.cc
mutopia/claop.py

index c651140062b5f16a7911d7ef93bffeac0e03f447..2fa4e6226c8170cd988748df96f9c0678b55e8c0 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2002-06-19  Han-Wen Nienhuys  <hanwen@cs.uu.nl>
 
+       * 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  <hanwen@cs.uu.nl>
index 7497bacb5757f2801b98d91ee9cdac8cd22ec5b4..1670ba2fa9d96133b3add89101a7e106bc110fd4 100644 (file)
@@ -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_;
 
index 8e64b58098e3a353a6be9d88cce91c47f1360647..b61e151e34ddd6927d767260e9e09ab589b4fe8b 100644 (file)
@@ -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 ()
index 6b13fc9eb8f491fafae72875a6c3621485d17a19..deda57935f9e17a46981a3b7a1c9a0aafe9ffaee 100644 (file)
@@ -144,6 +144,8 @@ SCM ly_assoc_cdr (SCM key, SCM alist);
 Interval ly_scm2interval (SCM);
 SCM ly_interval2scm (Drul_array<Real>);
 
+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
index 4511e660a0ef5ecdf619997dfabe657796e73050..e383dcaa3caeb84735d0503c114add84fc98c980 100644 (file)
@@ -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:
index dbd2a90a5688f0944637af12875f2e1f1d35be4e..41700559247079820e498a62f8a8c4c4379b101b 100644 (file)
@@ -760,3 +760,11 @@ ly_split_list (SCM s, SCM list)
   
 }
 
+
+void
+taint (SCM * foo)
+{
+  /*
+    nop.
+   */
+}
index 69364a2a3ff21cef2a419b14eed69b78c183281e..ef5615524cb69ef631aaca77402ce8f4b406cbff 100644 (file)
@@ -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);
+
index bdd21e58636e0b9b5167cc19cd0ad3654faf3cc4..66dde042a5ded3cec025ecdf18b33770be79a2bf 100644 (file)
@@ -35,7 +35,6 @@ Translator::Translator ()
   init ();
   output_def_l_ = 0;
   smobify_self ();
-
 }
 
 Translator::Translator (Translator const &s)
index 3147aeb217a6a5aa65c8009100c48f9d8a718ee8..cae831896db02cb3f67e501fc38b99abc94f2b38 100644 (file)
@@ -301,5 +301,6 @@ sys.stdout.write (r""">
             minimumVerticalExtent = #'(-3 . 3)
        }
     }
+    
 }
 """)