Hi Duncan,<br><br>Yes, I forgot to leave out that I&#39;d like to see &#39;size_t&#39; mapped to CSize.<br><br>As a (dirty) workaround, one can use &#39;castPtr&#39; as the marshaler when dealing with pointers to &#39;size_t&#39;. I&#39;m a little more concerned about FunPtr&#39;s (though &#39;castPtr&#39; still makes the issue go away).<br>
<br>Here&#39;s my specific case dealing with function pointers:<br><br>In 64bit world, it looks like this:<br><div style="margin-left: 40px;"><span style="font-family: courier new,monospace;">type ReadableCallback = Ptr () -&gt; Ptr CUChar -&gt; <b>Ptr CULong</b> -&gt; IO CUInt</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">{#fun gcry_ac_io_init_readable_callback {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">        id `ACIO&#39;,</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">        id `FunPtr ReadableCallback&#39;,</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">        id `Ptr ()&#39;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">    } -&gt; `()&#39;#}</span><br></div><br>In 32bit world, it looks like this:<br><div style="margin-left: 40px;"><span style="font-family: courier new,monospace;">
type ReadableCallback = Ptr () -&gt; Ptr CUChar -&gt; <b>Ptr CUInt</b> -&gt; IO CUInt</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
{#fun gcry_ac_io_init_readable_callback {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
        id `ACIO&#39;,</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
        id `FunPtr ReadableCallback&#39;,</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
        id `Ptr ()&#39;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
    } -&gt; `()&#39;#}</span><br></div><br>I&#39;d really like it if I could use &#39;Ptr CSize&#39; (which corresponds to the &#39;size_t * ptr&#39; in the C code).<br><br>My current workaround (which doesn&#39;t use a cast in Haskell) is to redefine the function pointer type in a C
header file to use &#39;unsigned long&#39; instead of &#39;size_t&#39;, but this gets
cludgy in a hurry. If c2hs could translate to CSize directly, I could pass a pointer to CSize.<br><br>Is it really such a problem to make the conversion? My assumption is that CSize would match &#39;size_t&#39; for the specific architecture.<br>
<br>Thanks for your comment.<br><br>/jve<br><br><br><div class="gmail_quote">On Thu, Oct 1, 2009 at 12:37 PM, Duncan Coutts <span dir="ltr">&lt;<a href="mailto:duncan.coutts@googlemail.com">duncan.coutts@googlemail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div class="im">On Thu, 2009-10-01 at 10:20 -0400, John Van Enk wrote:<br>
&gt; Hello List,<br>
&gt;<br>
&gt; I&#39;m running into a problem with c2hs and how it parses the C typedef<br>
&gt; &#39;size_t&#39;. On 32bit systems, this ends up being parsed as a CUInt. On<br>
&gt; 64bit systems, this ends up as a CULong. This gets especially sticky<br>
&gt; with function pointers.<br>
<br>
</div>Right. Of course that&#39;s because on those different platforms size_t<br>
really is a typedef for unsigned int or unsigned long.<br>
<div class="im"><br>
&gt; I see there is a ticket open for this:<br>
&gt; <a href="http://hackage.haskell.org/trac/c2hs/ticket/20" target="_blank">http://hackage.haskell.org/trac/c2hs/ticket/20</a><br>
&gt;<br>
&gt; Has any one else run into this issue? Is there a good workaround that<br>
&gt; doesn&#39;t involve writing a C function/typedef for each collision?<br>
<br>
</div>So what you would want, presumably, is to map the &quot;size_t&quot; typedef to<br>
the Haskell type Foreign.C.Types.CSize, rather than what c2hs discovers<br>
as the actual raw type of &quot;size_t&quot;. Then you&#39;re making the promise that<br>
unsigned long, or unsigned int really really does match<br>
Foreign.C.Types.CSize.<br>
<br>
Currently c2hs has no support for remapping basic types like that.<br>
<br>
As for a workaround, just use fromIntegral to convert to CSize. You know<br>
this is always possible because you know CSize matches CUInt or CULong<br>
on the appropriate platforms.<br>
<br>
$ cat foo.h<br>
#include &lt;stddef.h&gt;<br>
size_t foo(void);<br>
<br>
$ cat foo.c<br>
#include &quot;foo.h&quot;<br>
size_t foo(void) { return 42; }<br>
<br>
$ cat foo.chs<br>
<br>
import Foreign.C.Types<br>
foo :: IO CSize<br>
foo = fmap fromIntegral {# call foo as bar #}<br>
<br>
$ gcc -c foo.c<br>
$ c2hs foo.h foo.chs<br>
$ ghci foo.hs -fffi foo.o<br>
Main&gt; foo<br>
42<br>
<font color="#888888"><br>
<br>
Duncan<br>
<br>
</font></blockquote></div><br>