source file of the GNU LilyPond music typesetter
- (c) 1999--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
-
+ (c) 1999--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
*/
#ifndef LY_SMOBS_ICC
#define IMPLEMENT_TYPE_P(CL, FUNCNAME)\
-void init_type_p_ ## CL ()\
+void init_type_ ## CL ()\
{\
- scm_c_define_gsubr (FUNCNAME, 1, 0, 0, (Scheme_function_unknown) CL::smob_p);\
+ SCM subr = scm_c_define_gsubr (FUNCNAME, 1, 0, 0, (Scheme_function_unknown) CL::smob_p);\
+ ly_add_function_documentation (subr, FUNCNAME, "(SCM x)", "Is @var{x} a @code{" #CL "} object?");\
+ scm_c_export (FUNCNAME, NULL);\
}\
-ADD_SCM_INIT_FUNC (init_type_p_ ## CL, init_type_p_ ## CL)
+ADD_SCM_INIT_FUNC (init_type_ ## CL, init_type_ ## CL)
#ifndef SCM_CELL_TYPE
#define SCM_CELL_TYPE(X) SCM_CAR (X)
#endif
-#define IMPLEMENT_SIMPLE_SMOBS(CL) \
+
+#define IMPLEMENT_BASE_SMOBS(CL) \
scm_t_bits CL::smob_tag_; \
SCM \
CL::smob_p (SCM s) \
scm_set_smob_print (smob_tag_, CL::print_smob); \
scm_set_smob_equalp (smob_tag_, CL::equal_p); \
} \
-SCM CL::smobbed_self () const \
-{ \
- SCM s; \
- s = gh_cons (SCM_PACK (CL::smob_tag_), SCM_PACK (this)); \
- scm_done_malloc (sizeof (CL)); \
- \
- return s; \
-} \
size_t \
CL::free_smob (SCM ses) \
{ \
CL * s = (CL*) SCM_CDR (ses); \
- delete s; \
- return sizeof (CL); \
-} \
+ delete s; \
+ scm_gc_unregister_collectable_memory (s, sizeof (CL), #CL " smob"); \
+ return SMOB_FREE_RETURN_VAL(CL);\
+}\
ADD_SCM_INIT_FUNC (CL, CL::init_smobs)
+
+#define IMPLEMENT_SIMPLE_SMOBS(CL) \
+IMPLEMENT_BASE_SMOBS(CL);\
+SCM CL::smobbed_copy () const \
+{ \
+ CL * ptr = new CL (*this);\
+ SCM s; \
+ s = gh_cons (SCM_PACK (CL::smob_tag_), SCM_PACK (ptr)); \
+ scm_gc_register_collectable_memory ((CL*)this, sizeof (CL), #CL " smob"); \
+ \
+ return s; \
+} \
+
+
#define IMPLEMENT_SMOBS(CL) \
-IMPLEMENT_SIMPLE_SMOBS (CL) \
+IMPLEMENT_BASE_SMOBS (CL) \
SCM \
CL::smobify_self () \
{ \
deal half-initialized objects: scm_done_malloc ( ) might trigger GC. \
the warning in smobs.hh is just to be doubleplus goodly sure \
*/ \
- SCM s; \
- SCM_NEWCELL (s); \
- SCM_SETCAR (s,CL::smob_tag_); \
- SCM_SETCDR (s, SCM_PACK (this)); \
+ SCM s;\
+ SCM_NEWSMOB (s, CL::smob_tag_, this);\
self_scm_ = s; \
- scm_done_malloc (sizeof (CL)); \
+ scm_gc_register_collectable_memory (this, sizeof (CL), #CL " smob"); \
return s; \
}