+void
+runCFinalizer(StgVoid *fn, StgVoid *ptr, StgVoid *env, StgWord flag)
+{
+ if (flag)
+ ((void (*)(void *, void *))fn)(env, ptr);
+ else
+ ((void (*)(void *))fn)(ptr);
+}
+
+void
+runAllCFinalizers(StgWeak *list)
+{
+ StgWeak *w;
+
+ for (w = list; w; w = w->link) {
+ StgArrWords *farr;
+
+ farr = (StgArrWords *)UNTAG_CLOSURE(w->cfinalizer);
+
+ if ((StgClosure *)farr != &stg_NO_FINALIZER_closure)
+ runCFinalizer((StgVoid *)farr->payload[0],
+ (StgVoid *)farr->payload[1],
+ (StgVoid *)farr->payload[2],
+ farr->payload[3]);
+ }
+}
+