Jonas Hahnfeld <hah...@hahnjo.de> writes: > Am Dienstag, dem 06.07.2021 um 17:03 +0200 schrieb David Kastrup: >> Jean Abou Samra <j...@abou-samra.fr> writes: >> >> > For example, if I were the author of the below code, how >> > would I understand that the mmrest_event_ should be >> > unprotected? >> > >> > void >> > Part_combine_iterator::kill_mmrest (Context *c) >> > { >> > if (!mmrest_event_) >> > { >> > mmrest_event_ = new Stream_event >> > (Lily::ly_make_event_class (ly_symbol2scm ("multi-measure-rest-event"))); >> > set_property (mmrest_event_, "duration", SCM_EOL); >> > mmrest_event_->unprotect (); >> > } >> > >> > c->event_source ()->broadcast (mmrest_event_); >> > } >> >> Uh, after the call to mmrest_event_->unprotect () there is nothing that >> would protect the newly created mmrest_event_ . > > Sure there is, the snippet is just too small to show the marking: > > void > Part_combine_iterator::derived_mark () const > { > Simultaneous_music_iterator::derived_mark (); > > if (mmrest_event_) > scm_gc_mark (mmrest_event_->self_scm ()); > } > > The code makes perfect sense: If mmrest_event_ isn't set yet, the block > will allocate and unprotect a new object so that before the broadcast, > there is an event under the control of the iterator object for all > possible flows through the function.
Ah, I overlooked that mmrest_event_ is not a local variable. Sorry for the confusion. -- David Kastrup