]> git.donarmstrong.com Git - lilypond.git/commitdiff
(protect_smob): experiment: O(1) GC (un)protection.
authorHan-Wen Nienhuys <hanwen@xs4all.nl>
Sun, 24 Jul 2005 15:39:03 +0000 (15:39 +0000)
committerHan-Wen Nienhuys <hanwen@xs4all.nl>
Sun, 24 Jul 2005 15:39:03 +0000 (15:39 +0000)
lily/include/box.hh
lily/include/ly-smobs.icc
lily/smobs.cc [new file with mode: 0644]

index fc8eda7bec01e5b3dd8bd98f2d71ade0397443c6..55da1fb78ded0bdf58d3bef8467b120eaba21a36 100644 (file)
@@ -8,10 +8,10 @@
 #include "interval.hh"
 #include "offset.hh"
 
-struct Box
+class Box
 {
   Interval interval_a_[NO_AXES];
-
+public:
   Interval &x () {return interval_a_[X_AXIS]; }
   Interval &y (){ return interval_a_[Y_AXIS]; }
   Interval x () const{ return interval_a_[X_AXIS]; }
index 3a02164952960d7ef7f2e6e1eb0479fa8dd3fcd4..7497b66d367417ba1144a936211163245f053469 100644 (file)
@@ -64,7 +64,7 @@
     CL *ptr = new CL (*this);                                          \
     SCM s;                                                             \
     s = scm_cons (SCM_PACK (CL::smob_tag_), SCM_PACK (ptr));           \
-    /*    scm_gc_register_collectable_memory ((CL *)this, sizeof (CL), #CL " smob");*/ \
+    scm_gc_register_collectable_memory ((CL *)this, sizeof (CL), #CL " smob"); \
                                                                        \
     return s;                                                          \
   }
     SCM s;                                                             \
     SCM_NEWSMOB (s, CL::smob_tag_, this);                              \
     self_scm_ = s;                                                     \
-    /* scm_gc_register_collectable_memory (this, sizeof (CL), #CL " smob");*/ \
+    scm_gc_register_collectable_memory (this, sizeof (CL), #CL " smob"); \
     return s;                                                          \
   }
 
diff --git a/lily/smobs.cc b/lily/smobs.cc
new file mode 100644 (file)
index 0000000..63d36f2
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+  smobs.cc -- implement Smob protection
+
+  source file of the GNU LilyPond music typesetter
+
+  (c) 2005 Han-Wen Nienhuys <hanwen@xs4all.nl>
+
+*/
+
+#include "smobs.hh"
+
+static SCM smob_protection_list;
+
+void
+init_smob_protection()
+{
+  smob_protection_list = scm_cons (SCM_UNDEFINED, SCM_EOL);
+  scm_permanent_object (smob_protection_list);
+}
+ADD_SCM_INIT_FUNC(init_smob_protection, init_smob_protection);
+
+void
+protect_smob (SCM smob, SCM *prot_cons)
+{
+  SCM s = scm_cdr (smob_protection_list);
+  while (scm_is_pair (s) && scm_car (s) == SCM_UNDEFINED)
+    {
+      s = scm_cdr (s);
+    }
+
+  SCM prot = scm_cons (smob, s);
+  scm_set_cdr_x (smob_protection_list,
+                prot);
+  *prot_cons = prot;
+}
+
+void
+unprotect_smob (SCM *prot_cons)
+{
+  SCM next = scm_cdr (*prot_cons);
+
+  if (next == SCM_EOL)
+    {
+      scm_set_car_x (*prot_cons, SCM_UNDEFINED);
+    }
+  else
+    {
+      scm_set_car_x (*prot_cons, SCM_UNDEFINED);
+      while (scm_is_pair (next)
+            && scm_car (next) == SCM_UNDEFINED)
+
+       {
+         next = scm_cdr (next);
+       }
+
+      scm_set_cdr_x (*prot_cons, next);
+    }
+
+  *prot_cons = SCM_EOL;
+}