]> git.donarmstrong.com Git - lilypond.git/commitdiff
implement and use ASSERT_LIVE_IS_ALLOWED()
authorHan-Wen Nienhuys <hanwen@xs4all.nl>
Thu, 2 Nov 2006 15:04:05 +0000 (16:04 +0100)
committerHan-Wen Nienhuys <hanwen@xs4all.nl>
Thu, 2 Nov 2006 15:04:05 +0000 (16:04 +0100)
lily/context-def.cc
lily/include/parse-scm.hh
lily/include/smobs.hh
lily/parse-scm.cc
lily/prob.cc
lily/program-option.cc
scm/lily.scm

index 0af5fabf4fdef003342bc705ffe19797b642be15..c3a2a6c293b88594989b633393bb7f340103f629 100644 (file)
@@ -87,6 +87,8 @@ Context_def::print_smob (SCM smob, SCM port, scm_print_state*)
 SCM
 Context_def::mark_smob (SCM smob)
 {
+  ASSERT_LIVE_IS_ALLOWED();
+  
   Context_def *me = (Context_def *) SCM_CELL_WORD_1 (smob);
 
   scm_gc_mark (me->description_);
index 28223cac7ecd66413304b74b7af8a5f2b1005c37..0f48de2c533b6a384a04d359caca3b131d8b03f1 100644 (file)
@@ -13,6 +13,7 @@
 #include "lily-guile.hh"
 
 extern bool parse_protect_global;
+extern bool parsed_objects_should_be_dead;
 
 struct Parse_start
 {
index cfd49db34f7260e9053aeafee57fc83740c9c869..a2dcdb613d31dd442cb3ce15464aeb4b91c688a0 100644 (file)
@@ -11,6 +11,7 @@
 
 #include "lily-guile.hh"
 #include "virtual-methods.hh"
+#include "warn.hh"
 
 /*
   Smobs are GUILEs mechanism of exporting C(++) objects to the Scheme
 void protect_smob (SCM smob, SCM *prot_cons);
 void unprotect_smob (SCM smob, SCM *prot_cons);
 
+extern bool parsed_objects_should_be_dead;
+
+#define ASSERT_LIVE_IS_ALLOWED()     \
+  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;\
+  }    
+
 #endif /* SMOBS_HH */
 
index 75f161540dfd0e705520c4fabf3f80b82d7c7b26..0769083cfa6c4f1371659a4612f3bd9fee4c0d52 100644 (file)
@@ -115,6 +115,7 @@ protected_ly_parse_scm (Parse_start *ps)
 }
 
 bool parse_protect_global = true;
+bool parsed_objects_should_be_dead = false;
 
 /* Try parsing.  Upon failure return SCM_UNDEFINED.
    FIXME: shouldn't we return SCM_UNSCPECIFIED -- jcn  */
index e28c24411a309a53bd0eead98b759e9c55d45c7e..b6df86590fe157f4746b391a3dabe349579c78af 100644 (file)
@@ -101,6 +101,8 @@ Prob::derived_mark () const
 SCM
 Prob::mark_smob (SCM smob)
 {
+  ASSERT_LIVE_IS_ALLOWED();
+  
   Prob *system = (Prob *) SCM_CELL_WORD_1 (smob);
   scm_gc_mark (system->mutable_property_alist_);
   system->derived_mark ();
index 9ec4901c857bbadcfd8d7673d8ed944232dd0ada..b12a246f311f8ae023d0a4b8aa31f0a82afe3877 100644 (file)
@@ -68,6 +68,11 @@ void internal_set_option (SCM var, SCM val)
       do_internal_type_checking_global = to_boolean (val);
       val = scm_from_bool (to_boolean (val));
     }
+  else if (var == ly_symbol2scm ("debug-gc-assert-parsed-dead"))
+    {
+      parsed_objects_should_be_dead = to_boolean (val);
+      val = scm_from_bool (parsed_objects_should_be_dead);
+    }
   else if (var == ly_symbol2scm ("old-relative"))
     {
       lily_1_8_relative = to_boolean (val);
index 807adcb4850c35a7c60c0ec47354189d02754b12..282fdb758e21bd45587adcde57948eaee82790ba 100644 (file)
@@ -22,6 +22,9 @@
              (clip-systems #f "Generate cut-out snippets of a score")
              (debug-gc #f
                        "dump memory debugging statistics")
+             (debug-gc-assert-parsed-dead #f
+                       "for memory debugging: ensure that all refs to parsed objects are dead.")
+             
              (debug-midi #f "generate human readable MIDI")
              (delete-intermediate-files #f
                                         "delete unusable PostScript files")
@@ -383,6 +386,8 @@ The syntax is the same as `define*-public'."
          (display "Live object statistics: GC'ing\n")
          (gc)
          (gc)
+         (ly:set-option 'debug-gc-assert-parsed-dead #t)
+         (gc)
          
          (set! stats (gc-live-object-stats))
          (display "Dumping live object statistics.\n")
@@ -442,6 +447,7 @@ The syntax is the same as `define*-public'."
 
     (for-each
      (lambda (x)
+       (ly:set-option 'debug-gc-assert-parsed-dead #f)
        (lilypond-file handler x)
        (ly:clear-anonymous-modules)
        (if (ly:get-option 'debug-gc)
@@ -455,8 +461,7 @@ The syntax is the same as `define*-public'."
         (lambda () (ly:parse-file file-name))
         (lambda (x . args) (handler x file-name))))
 
-(use-modules (scm editor)
-            )
+(use-modules (scm editor))
 
 (define-public (gui-main files)
   (if (null? files)