2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 1999--2010 Han-Wen Nienhuys <hanwen@xs4all.nl>
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.
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.
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/>.
25 #define IMPLEMENT_TYPE_P(CL, FUNCNAME) \
26 SCM CL ## _type_p_proc; \
27 void init_type_ ## CL () \
29 SCM subr = scm_c_define_gsubr (FUNCNAME, 1, 0, 0, \
30 (Scheme_function_unknown) CL::smob_p); \
31 CL ## _type_p_proc = subr; \
32 ly_add_function_documentation (subr, FUNCNAME, "(SCM x)", \
33 "Is @var{x} a @code{" #CL "} object?"); \
34 scm_c_export (FUNCNAME, NULL); \
36 ADD_SCM_INIT_FUNC (init_type_ ## CL, init_type_ ## CL)
38 #define IMPLEMENT_BASE_SMOBS(CL) \
40 CL ## _type_adder () \
42 ly_add_type_predicate ((void*) &CL::unsmob, #CL); \
44 ADD_SCM_INIT_FUNC(CL ## _type_adder_ctor, \
46 const char *CL::smob_name_ = #CL; \
47 scm_t_bits CL::smob_tag_; \
51 if (SCM_NIMP (s) && SCM_CELL_TYPE (s) == smob_tag_) \
61 smob_tag_ = scm_make_smob_type (#CL, 0); \
62 scm_set_smob_mark (smob_tag_, CL::mark_smob); \
63 scm_set_smob_free (smob_tag_, CL::free_smob); \
64 scm_set_smob_print (smob_tag_, CL::print_smob); \
65 scm_set_smob_equalp (smob_tag_, CL::equal_p); \
69 CL::free_smob (SCM ses) \
71 CL *s = (CL *) SCM_CELL_WORD_1 (ses); \
73 /* scm_gc_unregister_collectable_memory (s, sizeof (CL), #CL " smob"); */ \
74 return SMOB_FREE_RETURN_VAL (CL); \
77 ADD_SCM_INIT_FUNC (CL, CL::init_smobs)
79 #define IMPLEMENT_SIMPLE_SMOBS(CL) \
80 IMPLEMENT_BASE_SMOBS (CL); \
81 SCM CL::smobbed_copy () const \
83 CL *ptr = new CL (*this); \
85 s = scm_cons (SCM_PACK (CL::smob_tag_), SCM_PACK (ptr)); \
86 scm_gc_register_collectable_memory ((CL *)this, sizeof (CL), #CL " smob"); \
91 #define IMPLEMENT_SMOBS(CL) \
92 IMPLEMENT_BASE_SMOBS (CL) \
96 protection_cons_ = SCM_EOL; \
97 self_scm_ = unprotected_smobify_self (); \
103 protect_smob (self_scm_, &protection_cons_); \
108 unprotect_smob (self_scm_, &protection_cons_); \
112 CL::unprotected_smobify_self () \
115 This is local. We don't assign to self_scm_ directly, to assure \
116 that S isn't GC-ed from under us. \
118 We don't use smobbed_self () to ensure that mark_smob () doesn't \
119 have to deal half-initialized objects: scm_done_malloc ( ) might \
120 trigger GC.the warning in smobs.hh is just to be doubleplus \
124 SCM_NEWSMOB (s, CL::smob_tag_, this); \
126 scm_gc_register_collectable_memory (this, sizeof (CL), #CL " smob"); \
130 #define IMPLEMENT_DEFAULT_EQUAL_P(CL) \
132 CL::equal_p (SCM a, SCM b) \
134 return a == b ? SCM_BOOL_T : SCM_BOOL_F; \
137 #endif /* LY_SMOBS_ICC */