Someone should double check this patch (and my other email).<div><br></div><div>I tested them by creating this package:</div><div><a href="http://hackage.haskell.org/package/missing-foreign">http://hackage.haskell.org/package/missing-foreign</a></div>
<div><br></div><div>I put that on hackage in case a) these are not accepted to base, or b) someone is using a version of base that doesn&#39;t have them yet.</div><div><br></div><div>Thanks,</div><div>Jason<br><br><div class="gmail_quote">
On Sun, Apr 3, 2011 at 1:28 PM, Jason Dagit <span dir="ltr">&lt;<a href="mailto:dagitj@gmail.com">dagitj@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
---<br>
 Foreign/Marshal/Alloc.hs |   29 +++++++++++++++++++++++++++++<br>
 1 files changed, 29 insertions(+), 0 deletions(-)<br>
<br>
diff --git a/Foreign/Marshal/Alloc.hs b/Foreign/Marshal/Alloc.hs<br>
index 612d2c7..148190b 100644<br>
--- a/Foreign/Marshal/Alloc.hs<br>
+++ b/Foreign/Marshal/Alloc.hs<br>
@@ -53,6 +53,9 @@ module Foreign.Marshal.Alloc (<br>
   malloc,       -- :: Storable a =&gt;        IO (Ptr a)<br>
   mallocBytes,  -- ::               Int -&gt; IO (Ptr a)<br>
<br>
+  calloc,       -- :: Storable a =&gt;        IO (Ptr a)<br>
+  callocBytes,  -- ::               Int -&gt; IO (Ptr a)<br>
+<br>
   realloc,      -- :: Storable b =&gt; Ptr a        -&gt; IO (Ptr b)<br>
   reallocBytes, -- ::               Ptr a -&gt; Int -&gt; IO (Ptr a)<br>
<br>
@@ -168,6 +171,32 @@ allocaBytesAligned :: Int -&gt; Int -&gt; (Ptr a -&gt; IO b) -&gt; IO b<br>
 allocaBytesAligned size align = allocaBytes size -- wrong<br>
 #endif<br>
<br>
+-- | Allocate a block of memory that is sufficient to hold values of type<br>
+-- @a@.  The size of the area allocated is determined by the &#39;sizeOf&#39;<br>
+-- method from the instance of &#39;Storable&#39; for the appropriate type.<br>
+-- The memory is initalized to 0.<br>
+--<br>
+-- The memory may be deallocated using &#39;free&#39; or &#39;finalizerFree&#39; when<br>
+-- no longer required.<br>
+--<br>
+{-# INLINE calloc #-}<br>
+calloc :: Storable a =&gt; IO (Ptr a)<br>
+calloc = doCalloc undefined<br>
+  where<br>
+  doCalloc       :: Storable b =&gt; b -&gt; IO (Ptr b)<br>
+  doCalloc dummy = callocBytes (sizeOf dummy)<br>
+<br>
+-- | Allocate a block of memory of the given number of bytes.<br>
+-- The block of memory is sufficiently aligned for any of the basic<br>
+-- foreign tyes that fit into a memory block of the allocated size.<br>
+-- The memory is initialized to 0.<br>
+--<br>
+-- The memory may be deallocated using &#39;free&#39; or &#39;finalizerFree&#39; when<br>
+-- no longer required.<br>
+--<br>
+callocBytes :: Int -&gt; IO (Ptr a)<br>
+callocBytes size = failWhenNULL &quot;calloc&quot; (_calloc (fromIntegral size) 1)<br>
+<br>
 -- |Resize a memory area that was allocated with &#39;malloc&#39; or &#39;mallocBytes&#39;<br>
 -- to the size needed to store values of type @b@.  The returned pointer<br>
 -- may refer to an entirely different memory area, but will be suitably<br>
<font color="#888888">--<br>
1.7.4.1<br>
<br>
</font></blockquote></div><br></div>