]> git.donarmstrong.com Git - lilypond.git/blob - lily/smobs.cc
164ac21b0353d10d85503d7fcf84a78ac7be64f4
[lilypond.git] / lily / smobs.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2005--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
22 /*
23   The CDR contains the actual protected list.
24  */
25 static SCM smob_protection_list = SCM_EOL;
26
27 void
28 init_smob_protection ()
29 {
30   smob_protection_list = scm_cons (SCM_BOOL_F, SCM_EOL);
31   scm_gc_protect_object (smob_protection_list);
32 }
33 ADD_SCM_INIT_FUNC (init_smob_protection, init_smob_protection);
34
35 LY_DEFINE (ly_smob_protects, "ly:smob-protects",
36            0, 0, 0, (),
37            "Return LilyPond's internal smob protection list.")
38 {
39   return scm_is_pair (smob_protection_list)
40          ? scm_cdr (smob_protection_list)
41          : SCM_EOL;
42 }
43
44 void
45 protect_smob (SCM smob, SCM *prot_cons)
46 {
47 #if 0
48   SCM s = scm_cdr (smob_protection_list);
49   while (scm_is_pair (s) && scm_car (s) == SCM_BOOL_F)
50     {
51       s = scm_cdr (s);
52     }
53   SCM prot = scm_cons (smob, s);
54   scm_set_cdr_x (smob_protection_list,
55                  prot);
56   *prot_cons = prot;
57 #else
58   (void) prot_cons;
59   scm_gc_protect_object (smob);
60 #endif
61 }
62
63 void
64 unprotect_smob (SCM smob, SCM *prot_cons)
65 {
66 #if 1
67   (void) prot_cons;
68   scm_gc_unprotect_object (smob);
69 #else
70   SCM next = scm_cdr (*prot_cons);
71
72   if (next == SCM_EOL)
73     scm_set_car_x (*prot_cons, SCM_BOOL_F);
74   else
75     {
76       scm_set_car_x (*prot_cons, SCM_BOOL_F);
77       while (scm_is_pair (next)
78              && scm_car (next) == SCM_BOOL_F)
79
80         next = scm_cdr (next);
81
82       scm_set_cdr_x (*prot_cons, next);
83     }
84
85   *prot_cons = SCM_EOL;
86 #endif
87 }