From 2df973cc940e9bf1862579a80a2f94a009c8f621 Mon Sep 17 00:00:00 2001 From: David Kastrup Date: Sat, 4 Jun 2016 17:41:23 +0200 Subject: [PATCH] Issue 4997/4: Use Preinit in Spanner --- lily/include/spanner.hh | 3 ++- lily/spanner.cc | 23 +++++++++++++++++------ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/lily/include/spanner.hh b/lily/include/spanner.hh index 79032dfb30..bc41ec6e63 100644 --- a/lily/include/spanner.hh +++ b/lily/include/spanner.hh @@ -39,7 +39,7 @@ is absolutely necessary for beams, since they have to adjust the length of stems of notes they encompass. */ -class Spanner : public Grob +class Spanner : public Preinit, public Grob { Drul_array spanned_drul_; vsize break_index_; @@ -66,6 +66,7 @@ public: void set_bound (Direction d, Grob *); Item *get_bound (Direction d) const; + void pre_init (); Spanner (SCM); Spanner (Spanner const &); bool is_broken () const; diff --git a/lily/spanner.cc b/lily/spanner.cc index 3f3d17fb27..1b6798086a 100644 --- a/lily/spanner.cc +++ b/lily/spanner.cc @@ -224,19 +224,27 @@ Spanner::set_bound (Direction d, Grob *s) Pointer_group_interface::add_grob (i, ly_symbol2scm ("bounded-by-me"), this); } +void +Spanner::pre_init () +{ + break_index_ = (vsize)-1; + // This is stupid, but derived_mark may be run before broken_into_ + // has run its constructor and has a recognizable array size. + // So we use break_index_ == -1 as a sentinel. + spanned_drul_.set (0, 0); + pure_property_cache_ = SCM_UNDEFINED; +} + Spanner::Spanner (SCM s) : Grob (s) { break_index_ = 0; - spanned_drul_.set (0, 0); - pure_property_cache_ = SCM_UNDEFINED; } Spanner::Spanner (Spanner const &s) : Grob (s) { - spanned_drul_.set (0, 0); - pure_property_cache_ = SCM_UNDEFINED; + break_index_ = 0; } /* @@ -341,8 +349,11 @@ Spanner::derived_mark () const scm_gc_mark (spanned_drul_[d]->self_scm ()); ; - for (vsize i = broken_intos_.size (); i--;) - scm_gc_mark (broken_intos_[i]->self_scm ()); + // If break_index_ is -1, broken_intos_ might not yet have run its + // constructor and any access might break things. + if (break_index_ != (vsize)-1) + for (vsize i = broken_intos_.size (); i--;) + scm_gc_mark (broken_intos_[i]->self_scm ()); } /* -- 2.39.2