]> git.donarmstrong.com Git - lilypond.git/blob - lily/smobs.cc
Nitpick run.
[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     s = scm_cdr (s);
27
28   SCM prot = scm_cons (smob, s);
29   scm_set_cdr_x (smob_protection_list,
30                  prot);
31   *prot_cons = prot;
32 }
33
34 void
35 unprotect_smob (SCM *prot_cons)
36 {
37   SCM next = scm_cdr (*prot_cons);
38
39   if (next == SCM_EOL)
40     scm_set_car_x (*prot_cons, SCM_UNDEFINED);
41   else
42     {
43       scm_set_car_x (*prot_cons, SCM_UNDEFINED);
44       while (scm_is_pair (next)
45              && scm_car (next) == SCM_UNDEFINED)
46
47         next = scm_cdr (next);
48
49       scm_set_cdr_x (*prot_cons, next);
50     }
51
52   *prot_cons = SCM_EOL;
53 }