2 smobs.cc -- implement Smob protection
4 source file of the GNU LilyPond music typesetter
6 (c) 2005 Han-Wen Nienhuys <hanwen@xs4all.nl>
11 static SCM smob_protection_list;
14 init_smob_protection ()
16 smob_protection_list = scm_cons (SCM_UNDEFINED, SCM_EOL);
17 scm_permanent_object (smob_protection_list);
19 ADD_SCM_INIT_FUNC (init_smob_protection, init_smob_protection);
22 protect_smob (SCM smob, SCM *prot_cons)
24 SCM s = scm_cdr (smob_protection_list);
25 while (scm_is_pair (s) && scm_car (s) == SCM_UNDEFINED)
30 SCM prot = scm_cons (smob, s);
31 scm_set_cdr_x (smob_protection_list,
37 unprotect_smob (SCM *prot_cons)
39 SCM next = scm_cdr (*prot_cons);
43 scm_set_car_x (*prot_cons, SCM_UNDEFINED);
47 scm_set_car_x (*prot_cons, SCM_UNDEFINED);
48 while (scm_is_pair (next)
49 && scm_car (next) == SCM_UNDEFINED)
51 next = scm_cdr (next);
53 scm_set_cdr_x (*prot_cons, next);