2 smobs.hh -- declare smob related stuff.
4 source file of the GNU LilyPond music typesetter
6 (c) 1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
13 #include "lily-guile.hh"
16 A smob is a C++ class with static member functions to glue it with
17 Scheme. Every instance carries SELF_SCM_, a pointer to the Scheme
18 smob of itself. Upon destruction, SELF_SCM_ is set to SCM_EOL.
20 smob_free() checks if SELF_SCM_ equals its argument, so we can also
21 use a smobbified object on the stack: the destruction will happen
22 before GC hits the object.
24 This is discouraged, though, because it causes memory leaks, and has
30 #define DECLARE_SMOBS \
31 SCM smobify_self (); \
32 static SCM mark_smob (SCM); \
33 static scm_sizet free_smob (SCM s); \
34 static int print_smob (SCM s, SCM p, scm_print_state*); \
35 static long smob_tag_; \
36 static void init_smobs(); \
37 void unsmobify_self ();\
38 void do_smobify_self();\
43 Check if S is of the specified C++ class.
45 #define SMOB_IS_TYPE_B(TYPE, S) (SCM_NIMP((S)) && SCM_CAR((S)) == TYPE::smob_tag_)
47 /// Cast S. No checks are done.
48 #define SMOB_TO_TYPE(TYPE, S) ((TYPE*) SCM_CDR((S)))