Picon

Suggested patch for Open Dylan's C runtime

Hello,

the current 1.0beta4 version of Open Dylan doesn't support finalizers
for objects in programs built with the C runtime that uses the
Boehm-Demers-Weiser garbage collector.

However, I think it is pretty easy to add that feature. I have tested
the attached patch for opendylan/sources/dfmc/c-run-time/run-time.{h,c}
on my PowerPC MacOS X installation of Open Dylan and it seems to work
just fine.

cu,
Thomas

--- _run-time.h	2007-07-26 20:34:57.000000000 +0200
+++ run-time.h	2007-07-26 20:44:01.000000000 +0200
@@ -1044,8 +1044,8 @@
 #define primitive_gc_state() (I(0)) /* !@#$ DUMMY DEFN */
 #define primitive_pin_object(x) (x)
 extern void primitive_unpin_object(D);
-#define primitive_mps_finalize(x) { }
-#define primitive_mps_finalization_queue_first() ((D)0)
+extern void primitive_mps_finalize(D);
+extern void* primitive_mps_finalization_queue_first();
 #define primitive_mps_park()
 #define primitive_mps_clamp()
 #define primitive_mps_release()
--- _run-time.c	2007-07-26 20:34:46.000000000 +0200
+++ run-time.c	2007-07-26 22:38:49.000000000 +0200
@@ -95,6 +95,37 @@
   return(header); 
 }

+static struct _mps_finalization_queue {
+  D first;
+  struct _mps_finalization_queue *rest;
+} * mps_finalization_queue = NULL;
+
+static void mps_finalization_proc(D obj, void *data) {
+  struct _mps_finalization_queue *new_finalization_queue =
+    GC_NEW(struct _mps_finalization_queue);
+  
+  new_finalization_queue->first = obj;
+  do {
+    new_finalization_queue->rest = mps_finalization_queue;
+  } while (!CONDITIONAL_UPDATE(mps_finalization_queue,
+                               new_finalization_queue,
+                               new_finalization_queue->rest));
+}
+
+void primitive_mps_finalize(void *obj) {
+  GC_register_finalizer(obj, mps_finalization_proc, NULL, NULL, NULL);
+}
+  
+void* primitive_mps_finalization_queue_first() {
+  if (mps_finalization_queue) {
+    D obj = mps_finalization_queue->first;
+    mps_finalization_queue = mps_finalization_queue->rest;
+    return(obj);
+  }
+  else
+    return(NULL);
+}
+
 void  primitive_mps_collect (DBOOL ignored) {
   ignore(ignored);
   GC_gcollect();
--

-- 
Gd-hackers mailing list
Gd-hackers <at> gwydiondylan.org
https://www.opendylan.org/mailman/listinfo/gd-hackers

Gmane