2 ly-smobs.icc -- implement smob glue.
4 source file of the GNU LilyPond music typesetter
6 (c) 1999--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
16 #define IMPLEMENT_UNSMOB(CL, name) \
18 unsmob_ ## name ( SCM s) \
20 return CL::unsmob (s); \
23 #define IMPLEMENT_TYPE_P(CL, FUNCNAME)\
24 void init_type_p_ ## CL ()\
26 scm_make_gsubr (FUNCNAME, 1, 0, 0, (Scheme_function_unknown) CL::smob_p);\
28 ADD_SCM_INIT_FUNC(init_type_p_ ## CL, init_type_p_ ## CL)
31 #define SCM_CELL_TYPE(X) SCM_CAR(X)
34 #ifndef SCM_CELL_WORD_1
35 #define SCM_CELL_WORD_1(X) SCM_CDR(X)
39 #define IMPLEMENT_SIMPLE_SMOBS(CL) \
44 if (SCM_NIMP(s) && SCM_CELL_TYPE(s) == smob_tag_) \
53 smob_tag_ = scm_make_smob_type_mfpe ( \
54 #CL, 0, CL::mark_smob, CL::free_smob, CL::print_smob, 0); \
56 SCM CL::smobbed_self () const \
59 s = gh_cons (SCM_PACK(CL::smob_tag_), SCM_PACK(this)); \
60 scm_done_malloc(sizeof(CL)); \
67 if (SCM_NIMP(s) && SCM_CELL_TYPE(s) == smob_tag_) \
68 return (CL*) SCM_CELL_WORD_1(s); \
73 CL::free_smob (SCM ses) \
75 CL * s = (CL*) SCM_CDR(ses); \
79 ADD_SCM_INIT_FUNC(CL, CL::init_smobs)
81 #define IMPLEMENT_SMOBS(CL) \
82 IMPLEMENT_SIMPLE_SMOBS(CL) \
86 SCM s = unprotected_smobify_self ();\
87 scm_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 \
103 SCM_SETCAR(s,CL::smob_tag_); \
104 SCM_SETCDR (s, SCM_PACK(this)); \
106 scm_done_malloc(sizeof(CL)); \
110 #define IMPLEMENT_DEFAULT_EQUAL_P(CL) \
112 CL::equal_p (SCM a , SCM b) \
114 return a == b ? SCM_BOOL_T : SCM_BOOL_F; \
118 #endif /* LY_SMOBS_ICC */