From 5a8b30aa6fb8ba65283777fa30c45fa47f40ba48 Mon Sep 17 00:00:00 2001 From: David Kastrup Date: Thu, 14 May 2015 20:50:57 +0200 Subject: [PATCH] Issue 4398/1: Move the protection of default_global_scale to Protected_scm Previously, this abused the protect/unprotect mechanism only intended for temporary protection. --- lily/scale.cc | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/lily/scale.cc b/lily/scale.cc index a5afd41dae..1249bb104b 100644 --- a/lily/scale.cc +++ b/lily/scale.cc @@ -20,6 +20,7 @@ */ #include "scale.hh" +#include "protected-scm.hh" /* @@ -53,25 +54,25 @@ LY_DEFINE (ly_make_scale, "ly:make-scale", SCM_ASSERT_TYPE (type_ok, steps, SCM_ARG1, __FUNCTION__, "vector of rational"); - Scale *s = new Scale (tones); + return (new Scale (tones))->unprotect (); +} - SCM retval = s->self_scm (); - s->unprotect (); +Scale *default_global_scale = 0; +Protected_scm default_global_scale_scm (SCM_BOOL_F); - return retval; -} +// TODO: This is somewhat fishy: pitches protect their scale via a +// mark_smob hook. But since pitches are of Simple_smob variety, they +// are unknown to GUILE unless a smobbed_copy has been created. So +// changing the default scale might cause some existing pitches to +// lose their scale's protection. LY_DEFINE (ly_default_scale, "ly:default-scale", 0, 0, 0, (), "Get the global default scale.") { - return default_global_scale - ? default_global_scale->self_scm () - : SCM_BOOL_F; + return default_global_scale_scm; } -Scale *default_global_scale = 0; - LY_DEFINE (ly_set_default_scale, "ly:set-default-scale", 1, 0, 0, (SCM scale), "Set the global default scale. This determines the tuning of" @@ -83,11 +84,8 @@ LY_DEFINE (ly_set_default_scale, "ly:set-default-scale", { LY_ASSERT_SMOB (Scale, scale, 1); - Scale *s = Scale::unsmob (scale); - if (default_global_scale) - default_global_scale->unprotect (); - default_global_scale = s; - s->protect (); + default_global_scale_scm = scale; + default_global_scale = Scale::unsmob (scale); return SCM_UNSPECIFIED; } -- 2.39.5