[MLton] Re: C-types

Matthew Fluet fluet@cs.cornell.edu
Sun, 14 May 2006 09:26:53 -0400 (EDT)


> On May 14, 2006, at 4:56 AM, Matthew Fluet wrote:
>>> On May 13, 2006, at 5:57 PM, Matthew Fluet wrote:
>>>> Suggestions on how to pass rlim_t up to ML user code in a portable 
>>>> manner?
>>> What happens if the FFI lies and uses the wrong signedness?
>> 
>> We can be burned by calling conventions that sign-extend signed values but 
>> zero-extend unsigned values.  This came up with PowerPC in the past.
>
> But you've ensured that the size is correct now, right? So sign-extension 
> will never be needed. I'm not really advocating this, though; I think an 
> explicit sign conversion in SML would be ok..?

No.  The issue is when small sizes are embedded into large sizes; for 
example, if the platform doesn't support 16-bit registers.  When the 
C-calling convention requires arguments to be passed in registers, then 
small sizes need to be extended to large sizes.  Furthermore, the callee 
gets to make assumptions about the high-bits.  See:

   http://mlton.org/pipermail/mlton/2004-September/025918.html

for the example we ran into before.