]> git.donarmstrong.com Git - lilypond.git/blob - lily/smobs.cc
* lily/smobs.cc (protect_smob): switch off fancy smob protection
[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--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
8
9 #include "smobs.hh"
10
11 /*
12   The CDR contains the actual protected list.
13  */
14 static SCM smob_protection_list = SCM_EOL;
15
16 void
17 init_smob_protection ()
18 {
19   smob_protection_list = scm_cons (SCM_BOOL_F, SCM_EOL);
20   scm_gc_protect_object (smob_protection_list);
21 }
22 ADD_SCM_INIT_FUNC (init_smob_protection, init_smob_protection);
23
24 LY_DEFINE(ly_smob_protects, "ly:smob-protects",
25           0, 0, 0, (),
26           "Return lily's internal smob protection list")
27 {
28   return scm_is_pair (smob_protection_list)
29     ? scm_cdr (smob_protection_list)
30     : SCM_EOL;
31 }
32
33 void
34 protect_smob (SCM smob, SCM *prot_cons)
35 {
36 #if 0
37   SCM s = scm_cdr (smob_protection_list);
38   while (scm_is_pair (s) && scm_car (s) == SCM_BOOL_F)
39     {
40       s = scm_cdr (s);
41     }
42   SCM prot = scm_cons (smob, s);
43   scm_set_cdr_x (smob_protection_list,
44                  prot);
45   *prot_cons = prot;
46 #else
47   scm_gc_protect_object (smob);
48 #endif
49 }
50
51 void
52 unprotect_smob (SCM smob, SCM *prot_cons)
53 {
54 #if 1
55   scm_gc_unprotect_object (smob);
56 #else
57   SCM next = scm_cdr (*prot_cons);
58
59   if (next == SCM_EOL)
60     scm_set_car_x (*prot_cons, SCM_BOOL_F);
61   else
62     {
63       scm_set_car_x (*prot_cons, SCM_BOOL_F);
64       while (scm_is_pair (next)
65              && scm_car (next) == SCM_BOOL_F)
66
67         next = scm_cdr (next);
68
69       scm_set_cdr_x (*prot_cons, next);
70     }
71
72   *prot_cons = SCM_EOL;
73 #endif
74 }