lilypond-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Context: prevent dangling references in child contexts when the daddy is


From: nine . fierce . ballads
Subject: Context: prevent dangling references in child contexts when the daddy is destroyed (issue 182400043 by address@hidden)
Date: Wed, 03 Dec 2014 04:08:12 +0000

Reviewers: ,

Description:
I have some books which use an on-the-fly markup procedure that refers
to a context in a closure.  I now question the wisdom of this, but
that's what I have.  In certain circumstances (when processing a certain
book with hundreds of scores, but not other books with tens of scores),
one or more of the ancestors of the important context are destroyed.
When the time finally comes to evaluate the markup, the first thing the
on-the-fly procedure does is get a context property, which walks up the
now-invalid hierarchy until a segfault occurs.

Nullifying the child's pointer in the parent's destructor was the
obvious way to fix this.  Is there a better way?

Please review this at https://codereview.appspot.com/182400043/

Affected files (+8, -1 lines):
  M lily/context.cc


Index: lily/context.cc
diff --git a/lily/context.cc b/lily/context.cc
index 4a1381ae1bb8830970be3a927eaf73f7ed2b2f8c..d74e9204a752bf5cea6afaaa9a5b24ab01ee910d 100644
--- a/lily/context.cc
+++ b/lily/context.cc
@@ -248,7 +248,7 @@ Context::set_property_from_event (SCM sev)
         unset_property (sym);
         return;
       }
-
+
       bool ok = true;
ok = type_check_assignment (sym, val, ly_symbol2scm ("translation-type?"));

@@ -645,6 +645,13 @@ Context::get_output_def () const

 Context::~Context ()
 {
+  // prevent dangling references in child contexts
+  for (SCM p = context_list_; scm_is_pair (p); p = scm_cdr (p))
+    {
+      Context *ctx = Context::unsmob (scm_car (p));
+      if (ctx)
+        ctx->daddy_context_ = 0;
+    }
 }

 Moment





reply via email to

[Prev in Thread] Current Thread [Next in Thread]