2 smobs.cc -- implement Smob protection
4 source file of the GNU LilyPond music typesetter
6 (c) 2005--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
12 The CDR contains the actual protected list.
14 static SCM smob_protection_list;
17 init_smob_protection ()
19 smob_protection_list = scm_cons (SCM_UNDEFINED, SCM_EOL);
20 scm_permanent_object (smob_protection_list);
22 ADD_SCM_INIT_FUNC (init_smob_protection, init_smob_protection);
24 LY_DEFINE(ly_smob_protects, "ly:smob-protects",
26 "Return lily's internal smob protection list")
28 return scm_cdr (smob_protection_list);
35 protect_smob (SCM smob, SCM *prot_cons)
37 SCM s = scm_cdr (smob_protection_list);
38 while (scm_is_pair (s) && scm_car (s) == SCM_UNDEFINED)
41 SCM prot = scm_cons (smob, s);
42 scm_set_cdr_x (smob_protection_list,
48 unprotect_smob (SCM *prot_cons)
50 SCM next = scm_cdr (*prot_cons);
53 scm_set_car_x (*prot_cons, SCM_UNDEFINED);
56 scm_set_car_x (*prot_cons, SCM_UNDEFINED);
57 while (scm_is_pair (next)
58 && scm_car (next) == SCM_UNDEFINED)
60 next = scm_cdr (next);
62 scm_set_cdr_x (*prot_cons, next);