]> git.donarmstrong.com Git - lilypond.git/blob - lily/undead.cc
Avoid "Parsed object should be dead" warning for saved init data
[lilypond.git] / lily / undead.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2012 Han-Wen Nienhuys <hanwen@xs4all.nl>
5
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.
10
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.
15
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/>.
18 */
19
20 #include "smobs.hh"
21 #include "ly-smobs.icc"
22
23 class Undead {
24   DECLARE_SIMPLE_SMOBS (Undead);
25   SCM object_;
26 public:
27   SCM object () { return object_; }
28   Undead (SCM object = SCM_UNDEFINED) : object_(object) { };
29 };
30
31 SCM
32 Undead::mark_smob (SCM s)
33 {
34   bool saved = parsed_objects_should_be_dead;
35   parsed_objects_should_be_dead = false;
36   scm_gc_mark (Undead::unsmob (s)->object ());
37   parsed_objects_should_be_dead = saved;
38   return SCM_UNDEFINED;
39 }
40
41 int
42 Undead::print_smob (SCM undead,
43                     SCM port,
44                     scm_print_state *)
45 {
46   scm_puts ("#<Undead ", port);
47   scm_display (Undead::unsmob (undead)->object (), port);
48   scm_puts (" >", port);
49   return 1;
50 }
51
52 IMPLEMENT_SIMPLE_SMOBS (Undead);
53 IMPLEMENT_DEFAULT_EQUAL_P (Undead);
54 IMPLEMENT_TYPE_P (Undead, "ly:undead?")
55
56 LY_DEFINE (ly_make_undead, "ly:make-undead",
57            1, 0, 0, (SCM object),
58            "This packages @var{object} in a manner that keeps it from"
59            " triggering \"Parsed object should be dead\" messages.")
60 {
61   Undead undead (object);
62   return undead.smobbed_copy ();
63 }
64
65 LY_DEFINE (ly_get_undead, "ly:get-undead",
66            1, 0, 0, (SCM undead),
67            "Get back object from @var{undead}.")
68 {
69   LY_ASSERT_SMOB (Undead, undead, 1);
70   return Undead::unsmob (undead)->object ();
71 }