2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 1998--2015 Han-Wen Nienhuys <hanwen@xs4all.nl>
6 LilyPond is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 LilyPond is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
20 #include "protected-scm.hh"
22 // We store the data in the car of a cons cell: it is faster to keep
23 // only one object protected during the life time of Protected_scm
26 Protected_scm::Protected_scm ()
27 : object_ (SCM_UNDEFINED)
31 Protected_scm::Protected_scm (SCM s)
34 // Only allow immediate objects at construction time. Protected_scm
35 // is intended for variables of static duration, and creating
36 // non-immediate objects when GUILE is not yet up is a bad idea.
40 // For static objects, this will be called at program exit. With the
41 // state of the memory system unknown, we refrain from any cleanup
42 // actions outside of the object memory itself.
44 Protected_scm::~Protected_scm ()
46 object_ = SCM_UNDEFINED;
49 SCM Protected_scm::list_ = SCM_EOL;
50 SCM Protected_scm::last_ = SCM_EOL;
53 Protected_scm::operator = (SCM s)
55 if (SCM_CONSP (object_))
56 SCM_SETCAR (object_, s);
62 if (SCM_CONSP (last_))
63 SCM_SETCDR (last_, s);
65 list_ = scm_permanent_object (s);
73 Protected_scm::operator = (Protected_scm const &s)
75 return *this = (SCM) s;
78 Protected_scm::operator SCM () const
80 return SCM_CONSP (object_) ? SCM_CAR (object_) : object_;