]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/include/ly-smobs.icc
* lily/midi-item.cc lily/include/midi-item.hh (get_fine_tuning):
[lilypond.git] / lily / include / ly-smobs.icc
index 69c7d2ecfe633c5da76a089fe6cff73b838d1594..3aa1af60d877f5271ab9da5a5dcc1dd44dbd2fc6 100644 (file)
@@ -3,8 +3,7 @@
   
   source file of the GNU LilyPond music typesetter
   
-  (c) 1999--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
-  
+  (c)  1999--2003 Han-Wen Nienhuys <hanwen@cs.uu.nl>
  */
 
 #ifndef LY_SMOBS_ICC
 #include "smobs.hh"
 
 
-#define IMPLEMENT_UNSMOB(CL, name)             \
-CL *                                           \
-unsmob_ ## name ( SCM s)                       \
-{                                              \
-return  CL::unsmob (s);                                \
-}
-
 #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)", "Check if @var{x} is a " #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)
@@ -36,6 +30,7 @@ ADD_SCM_INIT_FUNC (init_type_p_ ## CL, init_type_p_ ## CL)
 #endif
 
 
+
 #define IMPLEMENT_SIMPLE_SMOBS(CL)                             \
 scm_t_bits CL::smob_tag_;                                       \
 SCM                                                            \
@@ -60,25 +55,18 @@ SCM CL::smobbed_self () const                                       \
 {                                                              \
   SCM s;                                                       \
   s = gh_cons (SCM_PACK (CL::smob_tag_), SCM_PACK (this));     \
-  scm_done_malloc (sizeof (CL));                               \
+  scm_gc_register_collectable_memory ((CL*)this, sizeof (CL), #CL " smob");                            \
                                                                \
   return s;                                                    \
 }                                                              \
-CL *                                                           \
-CL::unsmob (SCM s)                                             \
-{                                                              \
-  if (SCM_NIMP (s) && SCM_CELL_TYPE (s) == smob_tag_)          \
-    return (CL*) SCM_CELL_WORD_1 (s);                          \
-  else                                                         \
-    return 0;                                                  \
-}                                                              \
 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_SMOBS(CL)                                                    \
@@ -101,12 +89,10 @@ CL::unprotected_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;                                                                    \
 }