2 ly-smobs.icc -- implement smob glue.
4 source file of the GNU LilyPond music typesetter
6 (c) 1999--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
14 #define IMPLEMENT_TYPE_P(CL, FUNCNAME) \
15 SCM CL ## _type_p_proc; \
16 void init_type_ ## CL () \
18 SCM subr = scm_c_define_gsubr (FUNCNAME, 1, 0, 0, \
19 (Scheme_function_unknown) CL::smob_p); \
20 CL ## _type_p_proc = subr; \
21 ly_add_function_documentation (subr, FUNCNAME, "(SCM x)", \
22 "Is @var{x} a @code{" #CL "} object?"); \
23 scm_c_export (FUNCNAME, NULL); \
25 ADD_SCM_INIT_FUNC (init_type_ ## CL, init_type_ ## CL)
28 #define SCM_CELL_TYPE(X) SCM_CAR (X)
31 #ifndef SCM_CELL_WORD_1
32 #define SCM_CELL_WORD_1(X) SCM_CDR (X)
35 #define IMPLEMENT_BASE_SMOBS(CL) \
36 scm_t_bits CL::smob_tag_; \
40 if (SCM_NIMP (s) && SCM_CELL_TYPE (s) == smob_tag_) \
50 smob_tag_ = scm_make_smob_type (#CL, 0); \
51 scm_set_smob_mark (smob_tag_, CL::mark_smob); \
52 scm_set_smob_free (smob_tag_, CL::free_smob); \
53 scm_set_smob_print (smob_tag_, CL::print_smob); \
54 scm_set_smob_equalp (smob_tag_, CL::equal_p); \
58 CL::free_smob (SCM ses) \
60 CL *s = (CL*) SCM_CDR (ses); \
62 scm_gc_unregister_collectable_memory (s, sizeof (CL), #CL " smob"); \
63 return SMOB_FREE_RETURN_VAL(CL); \
66 ADD_SCM_INIT_FUNC (CL, CL::init_smobs)
68 #define IMPLEMENT_SIMPLE_SMOBS(CL) \
69 IMPLEMENT_BASE_SMOBS(CL); \
70 SCM CL::smobbed_copy () const \
72 CL *ptr = new CL (*this); \
74 s = scm_cons (SCM_PACK (CL::smob_tag_), SCM_PACK (ptr)); \
75 scm_gc_register_collectable_memory ((CL*)this, sizeof (CL), #CL " smob"); \
81 #define IMPLEMENT_SMOBS(CL) \
82 IMPLEMENT_BASE_SMOBS (CL) \
86 SCM s = unprotected_smobify_self (); \
87 scm_gc_protect_object (s); \
91 CL::unprotected_smobify_self () \
94 This is local. We don't assign to self_scm_ directly, to assure \
95 that S isn't GC-ed from under us. \
97 We don't use smobbed_self () to ensure that mark_smob () doesn't have to \
98 deal half-initialized objects: scm_done_malloc ( ) might trigger GC. \
99 the warning in smobs.hh is just to be doubleplus goodly sure \
102 SCM_NEWSMOB (s, CL::smob_tag_, this); \
104 scm_gc_register_collectable_memory (this, sizeof (CL), #CL " smob"); \
108 #define IMPLEMENT_DEFAULT_EQUAL_P(CL) \
110 CL::equal_p (SCM a , SCM b) \
112 return a == b ? SCM_BOOL_T : SCM_BOOL_F; \
116 #endif /* LY_SMOBS_ICC */