+
+-- run a batch of finalizers from the garbage collector. We're given
+-- an array of finalizers and the length of the array, and we just
+-- call each one in turn.
+--
+-- the IO primitives are inlined by hand here to get the optimal
+-- code (sigh) --SDM.
+
+runFinalizerBatch :: Int -> Array# (IO ()) -> IO ()
+runFinalizerBatch (I# n) arr =
+ let go m = IO $ \s ->
+ case m of
+ 0# -> (# s, () #)
+ _ -> let m' = m -# 1# in
+ case indexArray# arr m' of { (# io #) ->
+ case unIO io s of { (# s, _ #) ->
+ unIO (go m') s
+ }}
+ in
+ go n
+