From: Han-Wen Nienhuys Date: Thu, 2 Nov 2006 15:04:05 +0000 (+0100) Subject: implement and use ASSERT_LIVE_IS_ALLOWED() X-Git-Tag: release/2.10.0-2~34^2~23 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=a946f8f2f14655c4156cd3f13dcdf4867a0a0110;p=lilypond.git implement and use ASSERT_LIVE_IS_ALLOWED() --- diff --git a/lily/context-def.cc b/lily/context-def.cc index 0af5fabf4f..c3a2a6c293 100644 --- a/lily/context-def.cc +++ b/lily/context-def.cc @@ -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_); diff --git a/lily/include/parse-scm.hh b/lily/include/parse-scm.hh index 28223cac7e..0f48de2c53 100644 --- a/lily/include/parse-scm.hh +++ b/lily/include/parse-scm.hh @@ -13,6 +13,7 @@ #include "lily-guile.hh" extern bool parse_protect_global; +extern bool parsed_objects_should_be_dead; struct Parse_start { diff --git a/lily/include/smobs.hh b/lily/include/smobs.hh index cfd49db34f..a2dcdb613d 100644 --- a/lily/include/smobs.hh +++ b/lily/include/smobs.hh @@ -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 @@ -140,5 +141,14 @@ 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 */ diff --git a/lily/parse-scm.cc b/lily/parse-scm.cc index 75f161540d..0769083cfa 100644 --- a/lily/parse-scm.cc +++ b/lily/parse-scm.cc @@ -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 */ diff --git a/lily/prob.cc b/lily/prob.cc index e28c24411a..b6df86590f 100644 --- a/lily/prob.cc +++ b/lily/prob.cc @@ -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 (); diff --git a/lily/program-option.cc b/lily/program-option.cc index 9ec4901c85..b12a246f31 100644 --- a/lily/program-option.cc +++ b/lily/program-option.cc @@ -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); diff --git a/scm/lily.scm b/scm/lily.scm index 807adcb485..282fdb758e 100644 --- a/scm/lily.scm +++ b/scm/lily.scm @@ -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)