[add alloca__ primitive, make it work with -fvia-ghc
John Meacham <john@repetae.net>**20061115031709] hunk ./E/ToHs.hs 263
+    ("alloca__",args)   -> mparen $ mapM transE args >>= \args' -> return $ hsep (text "alloca__":args')
hunk ./data/ViaGhc.hs 16
+type JIO a = World__ -> (# World__, a #)
+
hunk ./data/ViaGhc.hs 40
+
+alloca__ :: Int# -> (Addr# -> JIO a) -> JIO a
+alloca__ size action s =
+     case newPinnedByteArray# size s      of { (# s, mbarr# #) ->
+     case unsafeFreezeByteArray# mbarr# s of { (# s, barr#  #) ->
+     case action (byteArrayContents# barr#) s of { (# s, r #) ->
+     case touch# barr# s of { s -> (# s, r #) }
+     }}}
+
hunk ./lib/base/Foreign/Marshal/Alloc.hs 24
+import Jhc.Prim
+import Jhc.Int(unboxInt)
+import Jhc.Addr
+import qualified Jhc.Options as JO
hunk ./lib/base/Foreign/Marshal/Alloc.hs 32
+allocaBytes' :: Int -> (Ptr a -> IO b) -> IO b
+allocaBytes' b f = do
+    p <- mallocBytes b
+    r <- f p
+    free p
+    return r
+
hunk ./lib/base/Foreign/Marshal/Alloc.hs 40
-allocaBytes b f = do
-    p <- mallocBytes b
-    r <- f p
-    free p
-    return r
+allocaBytes num fn = case JO.target of
+    JO.GhcHs -> case unboxInt num of n -> alloca__ n (\addr -> fn (boxAddr addr))
+    _ -> allocaBytes' num fn
hunk ./lib/base/Foreign/Marshal/Alloc.hs 44
+foreign import primitive alloca__ :: Int__ -> (Addr__ -> IO b) -> IO b
+foreign import primitive "box" boxAddr :: Addr__ -> Ptr a