]> git.donarmstrong.com Git - lilypond.git/blob - lily/smobs.cc
(parse_symbol_list): Bugfix.
[lilypond.git] / lily / smobs.cc
1 /*
2   smobs.cc -- implement Smob protection
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 2005 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
8
9 #include "smobs.hh"
10
11 static SCM smob_protection_list;
12
13 void
14 init_smob_protection ()
15 {
16   smob_protection_list = scm_cons (SCM_UNDEFINED, SCM_EOL);
17   scm_permanent_object (smob_protection_list);
18 }
19 ADD_SCM_INIT_FUNC (init_smob_protection, init_smob_protection);
20
21 void
22 protect_smob (SCM smob, SCM *prot_cons)
23 {
24   SCM s = scm_cdr (smob_protection_list);
25   while (scm_is_pair (s) && scm_car (s) == SCM_UNDEFINED)
26     {
27       s = scm_cdr (s);
28     }
29
30   SCM prot = scm_cons (smob, s);
31   scm_set_cdr_x (smob_protection_list,
32                  prot);
33   *prot_cons = prot;
34 }
35
36 void
37 unprotect_smob (SCM *prot_cons)
38 {
39   SCM next = scm_cdr (*prot_cons);
40
41   if (next == SCM_EOL)
42     {
43       scm_set_car_x (*prot_cons, SCM_UNDEFINED);
44     }
45   else
46     {
47       scm_set_car_x (*prot_cons, SCM_UNDEFINED);
48       while (scm_is_pair (next)
49              && scm_car (next) == SCM_UNDEFINED)
50
51         next = scm_cdr (next);
52
53       scm_set_cdr_x (*prot_cons, next);
54     }
55
56   *prot_cons = SCM_EOL;
57 }