X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fsmobs.cc;h=c700ea0d9b0f0a81d7e3f5d40774f5a85236b756;hb=97a0169312a260933246ab224e4f8b0969871dd5;hp=e2ec5d5638124b947cd9cf0c936ebe1e86dff775;hpb=2c22efe5a46a37065b10c3f51c5d7db00d07d318;p=lilypond.git diff --git a/lily/smobs.cc b/lily/smobs.cc index e2ec5d5638..c700ea0d9b 100644 --- a/lily/smobs.cc +++ b/lily/smobs.cc @@ -1,57 +1,104 @@ /* - smobs.cc -- implement Smob protection + This file is part of LilyPond, the GNU music typesetter. - source file of the GNU LilyPond music typesetter + Copyright (C) 2005--2015 Han-Wen Nienhuys - (c) 2005 Han-Wen Nienhuys + LilyPond is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + LilyPond is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with LilyPond. If not, see . */ #include "smobs.hh" +#include "listener.hh" -static SCM smob_protection_list; +Listener +Smob_core::get_listener (SCM callback) +{ + return Listener (callback, self_scm ()); +} + +/* + The CDR contains the actual protected list. + */ +static SCM smob_protection_list = SCM_EOL; void init_smob_protection () { - smob_protection_list = scm_cons (SCM_UNDEFINED, SCM_EOL); - scm_permanent_object (smob_protection_list); + smob_protection_list = scm_cons (SCM_BOOL_F, SCM_EOL); + scm_gc_protect_object (smob_protection_list); } ADD_SCM_INIT_FUNC (init_smob_protection, init_smob_protection); +LY_DEFINE (ly_smob_protects, "ly:smob-protects", + 0, 0, 0, (), + "Return LilyPond's internal smob protection list.") +{ + return scm_is_pair (smob_protection_list) + ? scm_cdr (smob_protection_list) + : SCM_EOL; +} + void protect_smob (SCM smob, SCM *prot_cons) { +#if 0 SCM s = scm_cdr (smob_protection_list); - while (scm_is_pair (s) && scm_car (s) == SCM_UNDEFINED) + while (scm_is_pair (s) && scm_is_false (scm_car (s)) { s = scm_cdr (s); } - SCM prot = scm_cons (smob, s); scm_set_cdr_x (smob_protection_list, - prot); + prot); *prot_cons = prot; +#else + (void) prot_cons; + scm_gc_protect_object (smob); +#endif } void -unprotect_smob (SCM *prot_cons) +unprotect_smob (SCM smob, SCM *prot_cons) { +#if 1 + (void) prot_cons; + scm_gc_unprotect_object (smob); +#else SCM next = scm_cdr (*prot_cons); - if (next == SCM_EOL) - { - scm_set_car_x (*prot_cons, SCM_UNDEFINED); - } + if (scm_is_null (next))) + scm_set_car_x (*prot_cons, SCM_BOOL_F); else { - scm_set_car_x (*prot_cons, SCM_UNDEFINED); + scm_set_car_x (*prot_cons, SCM_BOOL_F); while (scm_is_pair (next) - && scm_car (next) == SCM_UNDEFINED) + && scm_is_false (scm_car (next))) - next = scm_cdr (next); + next = scm_cdr (next); scm_set_cdr_x (*prot_cons, next); } *prot_cons = SCM_EOL; +#endif +} + + +Scm_init const *Scm_init::list_ = 0; + +void +Scm_init::init () +{ + for (Scm_init const *p = list_; p; p = p->next_) + p->fun_ (); }