]> git.donarmstrong.com Git - lilypond.git/commitdiff
Let ASSERT_LIVE_IS_ALLOWED take an argument to print the last unallowed live object
authorDavid Kastrup <dak@gnu.org>
Wed, 28 Mar 2012 23:37:33 +0000 (01:37 +0200)
committerDavid Kastrup <dak@gnu.org>
Fri, 30 Mar 2012 09:05:25 +0000 (11:05 +0200)
lily/context-def.cc
lily/context-mod.cc
lily/grob-smob.cc
lily/include/smobs.hh
lily/lily-lexer.cc
lily/music-function.cc
lily/prob.cc
lily/skyline.cc
lily/undead.cc
scm/lily.scm

index f2d7e2e1373a67feddef988f1f3aebeaae5b8d30..b4e1e2567cc19397940b58e41a4852a1b9bb9ca2 100644 (file)
@@ -100,7 +100,7 @@ Context_def::print_smob (SCM smob, SCM port, scm_print_state *)
 SCM
 Context_def::mark_smob (SCM smob)
 {
-  ASSERT_LIVE_IS_ALLOWED ();
+  ASSERT_LIVE_IS_ALLOWED (smob);
 
   Context_def *me = (Context_def *) SCM_CELL_WORD_1 (smob);
 
index 460d18bcfd79222ae0c138f798899a3746e3dfdb..cb6cf83562fcd64fe5d8303f3ab4ceb2cd56627b 100644 (file)
@@ -53,7 +53,7 @@ Context_mod::print_smob (SCM smob, SCM port, scm_print_state *)
 SCM
 Context_mod::mark_smob (SCM smob)
 {
-  ASSERT_LIVE_IS_ALLOWED ();
+  ASSERT_LIVE_IS_ALLOWED (smob);
 
   Context_mod *me = (Context_mod *) SCM_CELL_WORD_1 (smob);
 
index e695cdda0cfc12f1cba5f729f095292bd029a848..853546a8868d547d5836e76514a40908abf43bbe 100644 (file)
@@ -31,7 +31,7 @@ IMPLEMENT_TYPE_P (Grob, "ly:grob?");
 SCM
 Grob::mark_smob (SCM ses)
 {
-  ASSERT_LIVE_IS_ALLOWED ();
+  ASSERT_LIVE_IS_ALLOWED (ses);
 
   Grob *s = (Grob *) SCM_CELL_WORD_1 (ses);
   scm_gc_mark (s->immutable_property_alist_);
index c550754910fe9e97dc410fd88e7398cee81afb4e..22a4d183099bf069d70fe9cc423c851d180bd2cc 100644 (file)
@@ -153,19 +153,32 @@ void protect_smob (SCM smob, SCM *prot_cons);
 void unprotect_smob (SCM smob, SCM *prot_cons);
 
 extern bool parsed_objects_should_be_dead;
+class parsed_dead {
+  static vector<parsed_dead *> elements;
+  SCM data;
+  SCM readout_one () {
+    SCM res = data;
+    data = SCM_UNDEFINED;
+    return res;
+  }
+public:
+  parsed_dead () : data (SCM_UNDEFINED)
+  {
+    elements.push_back (this);
+  }
+  void checkin (SCM arg) { data = arg; }
+  static SCM readout ();
+};
 
 #ifndef NDEBUG
-#define ASSERT_LIVE_IS_ALLOWED()     \
-  do { \
-    static bool passed_here_once;\
-    if (parsed_objects_should_be_dead && !passed_here_once) { \
-      ::programming_error (string ("Parsed object should be dead: ")  + __PRETTY_FUNCTION__ ); \
-      passed_here_once = true;\
-    } \
-  } \
-  while (0)
+#define ASSERT_LIVE_IS_ALLOWED(arg)                                    \
+  do {                                                                 \
+    static parsed_dead pass_here;                                      \
+    if (parsed_objects_should_be_dead)                                 \
+      pass_here.checkin (arg);                                         \
+  } while (0)
 #else
-#define ASSERT_LIVE_IS_ALLOWED() do { } \
+#define ASSERT_LIVE_IS_ALLOWED(arg) do { } \
   while (0)
 #endif
 
index 7f017a437bb8874b15b77b73e3741e07e090db2c..1bbc5b81674187e813d3613cb8bb205a0465db46 100644 (file)
@@ -372,7 +372,7 @@ IMPLEMENT_DEFAULT_EQUAL_P (Lily_lexer);
 SCM
 Lily_lexer::mark_smob (SCM s)
 {
-  ASSERT_LIVE_IS_ALLOWED ();
+  ASSERT_LIVE_IS_ALLOWED (s);
 
   Lily_lexer *lexer = (Lily_lexer *) SCM_CELL_WORD_1 (s);
 
index 85b21575761961e209a76811fae4506297940463..b9159fe3a74b7e08f5a72e243adbee87f6b93c5e 100644 (file)
@@ -83,6 +83,6 @@ Musicfunction::mark_smob (SCM s)
 {
   Musicfunction *p = Musicfunction::unsmob (s);
   scm_gc_mark (p->signature_);
-  ASSERT_LIVE_IS_ALLOWED ();
+  ASSERT_LIVE_IS_ALLOWED (s);
   return p->function_;
 }
index 53b562c2701cb9e161dfb0dbcee6efa119b1b5f9..367d1616a7b4aae73b48eb674876b9de4b24f61d 100644 (file)
@@ -119,7 +119,7 @@ Prob::derived_mark () const
 SCM
 Prob::mark_smob (SCM smob)
 {
-  ASSERT_LIVE_IS_ALLOWED ();
+  ASSERT_LIVE_IS_ALLOWED (smob);
 
   Prob *system = (Prob *) SCM_CELL_WORD_1 (smob);
   scm_gc_mark (system->mutable_property_alist_);
index 2a1e54f5f53cd75282afa55b0fe548646ab805a1..0250fc07f4743ba44e7bc1ac8af23ed6057aa435 100644 (file)
@@ -661,9 +661,9 @@ IMPLEMENT_TYPE_P (Skyline, "ly:skyline?");
 IMPLEMENT_DEFAULT_EQUAL_P (Skyline);
 
 SCM
-Skyline::mark_smob (SCM)
+Skyline::mark_smob (SCM s)
 {
-  ASSERT_LIVE_IS_ALLOWED ();
+  ASSERT_LIVE_IS_ALLOWED (s);
   return SCM_EOL;
 }
 
index 9ba0878e3cf55f3a459e3f69f216f096a7fdb11c..a3387ea9e9ff756e7068b271e93ab77faf0352b1 100644 (file)
@@ -69,3 +69,34 @@ LY_DEFINE (ly_get_undead, "ly:get-undead",
   LY_ASSERT_SMOB (Undead, undead, 1);
   return Undead::unsmob (undead)->object ();
 }
+
+// '
+// These are not protected since the means of protecting them would be
+// problematic to trigger during the mark pass where the array element
+// references get set.  However, they get set only when in the mark
+// pass when checking for parsed elements that should be dead, and we
+// query and clear them immediately afterwards.  So there should be no
+// way in which the references would have become unprotected in the
+// mean time.
+
+vector<parsed_dead *> parsed_dead::elements;
+
+SCM
+parsed_dead::readout ()
+{
+  SCM result = SCM_EOL;
+  for (vsize i = 0; i < elements.size (); i++) {
+    SCM elt = elements[i]->readout_one ();
+    if (!SCM_UNBNDP (elt))
+      result = scm_cons (elt, result);
+  }
+  return result;
+}
+
+LY_DEFINE (ly_parsed_undead_list_x, "ly:parsed-undead-list!",
+          0, 0, 0, (),
+          "Return the list of objects that have been found live"
+          " that should have been dead, and clear that list.")
+{
+  return parsed_dead::readout ();
+}
index 64c403b0749432e55df286cae181876a3a1cebde..190670045cd912be3972785fd3d16bdf31370c7b 100644 (file)
@@ -642,6 +642,10 @@ messages into errors.")
           (ly:set-option 'debug-gc-assert-parsed-dead #t)
           (gc)
           (ly:set-option 'debug-gc-assert-parsed-dead #f)
+         (for-each
+          (lambda (x)
+            (ly:programming-error "Parsed object should be dead: ~a" x))
+          (ly:parsed-undead-list!))
           (set! stats (gc-live-object-stats))
           (ly:progress "Dumping live object statistics.\n")
           (dump-live-object-stats outfile)))
@@ -832,6 +836,10 @@ PIDs or the number of the process."
          (ly:set-option 'debug-gc-assert-parsed-dead #t)
          (gc)
          (ly:set-option 'debug-gc-assert-parsed-dead #f)
+        (for-each
+         (lambda (x)
+           (ly:programming-error "Parsed object should be dead: ~a" x))
+         (ly:parsed-undead-list!))
          (if (ly:get-option 'debug-gc)
              (dump-gc-protects)
              (ly:reset-all-fonts))