]> git.donarmstrong.com Git - lilypond.git/blob - lily/smobs.cc
Web-ja: update introduction
[lilypond.git] / lily / smobs.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2005--2015 Han-Wen Nienhuys <hanwen@xs4all.nl>
5
6   LilyPond is free software: you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation, either version 3 of the License, or
9   (at your option) any later version.
10
11   LilyPond is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   GNU General Public License for more details.
15
16   You should have received a copy of the GNU General Public License
17   along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include "smobs.hh"
21 #include "listener.hh"
22
23 Listener
24 Smob_core::get_listener (SCM callback)
25 {
26   return Listener (callback, self_scm ());
27 }
28
29 /*
30   The CDR contains the actual protected list.
31  */
32 static SCM smob_protection_list = SCM_EOL;
33
34 void
35 init_smob_protection ()
36 {
37   smob_protection_list = scm_cons (SCM_BOOL_F, SCM_EOL);
38   scm_gc_protect_object (smob_protection_list);
39 }
40 ADD_SCM_INIT_FUNC (init_smob_protection, init_smob_protection);
41
42 LY_DEFINE (ly_smob_protects, "ly:smob-protects",
43            0, 0, 0, (),
44            "Return LilyPond's internal smob protection list.")
45 {
46   return scm_is_pair (smob_protection_list)
47          ? scm_cdr (smob_protection_list)
48          : SCM_EOL;
49 }
50
51 void
52 protect_smob (SCM smob, SCM *prot_cons)
53 {
54 #if 0
55   SCM s = scm_cdr (smob_protection_list);
56   while (scm_is_pair (s) && scm_is_false (scm_car (s))
57     {
58       s = scm_cdr (s);
59     }
60   SCM prot = scm_cons (smob, s);
61   scm_set_cdr_x (smob_protection_list,
62                  prot);
63   *prot_cons = prot;
64 #else
65   (void) prot_cons;
66   scm_gc_protect_object (smob);
67 #endif
68 }
69
70 void
71 unprotect_smob (SCM smob, SCM *prot_cons)
72 {
73 #if 1
74   (void) prot_cons;
75   scm_gc_unprotect_object (smob);
76 #else
77   SCM next = scm_cdr (*prot_cons);
78
79   if (scm_is_null (next)))
80     scm_set_car_x (*prot_cons, SCM_BOOL_F);
81   else
82     {
83       scm_set_car_x (*prot_cons, SCM_BOOL_F);
84       while (scm_is_pair (next)
85              && scm_is_false (scm_car (next)))
86
87         next = scm_cdr (next);
88
89       scm_set_cdr_x (*prot_cons, next);
90     }
91
92   *prot_cons = SCM_EOL;
93 #endif
94 }
95
96
97 Scm_init const *Scm_init::list_ = 0;
98
99 void
100 Scm_init::init ()
101 {
102   for (Scm_init const *p = list_; p; p = p->next_)
103     p->fun_ ();
104 }