Feature request: MLton.Pointer

View: New views
4 Messages — Rating Filter:   Alert me  

Feature request: MLton.Pointer

by John Reppy :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

The MLton.Pointer structure should have

        val sizeofPtr : word

so that one can allocate arrays of pointers in the C heap.

        - John


_______________________________________________
MLton-user mailing list
MLton-user@...
http://mlton.org/mailman/listinfo/mlton-user

Re: Feature request: MLton.Pointer

by Matthew Fluet-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Mon, 2 Jun 2008, John Reppy wrote:
> The MLton.Pointer structure should have
>
> val sizeofPtr : word
>
> so that one can allocate arrays of pointers in the C heap.

Sounds reasonable.

BTW, for importing "malloc", you should use
   _import "malloc": C_Size.word -> MLton.Pointer.t;
rather than
   _import "malloc": Word32.word -> MLton.Pointer.t;
to pass the appropriately sized 'size_t' object on 32-bit and 64-bit
platforms.

The "structure C_Size : WORD" is available from
"$(SML_LIB)/basis/c-types.mlb".

You could also use C_Size.wordSize to compute the sizeof a pointer (MLton
asserts that sizeof(void*) == sizeof(size_t) and CHAR_BIT == 8).

_______________________________________________
MLton-user mailing list
MLton-user@...
http://mlton.org/mailman/listinfo/mlton-user

Re: Feature request: MLton.Pointer

by John Reppy :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Is the C_Size structure documented?  A search on mlton.org did not turn
up any information.

        - John

On Jun 5, 2008, at 12:29 PM, Matthew Fluet wrote:

> On Mon, 2 Jun 2008, John Reppy wrote:
>> The MLton.Pointer structure should have
>>
>> val sizeofPtr : word
>>
>> so that one can allocate arrays of pointers in the C heap.
>
> Sounds reasonable.
>
> BTW, for importing "malloc", you should use
>  _import "malloc": C_Size.word -> MLton.Pointer.t;
> rather than
>  _import "malloc": Word32.word -> MLton.Pointer.t;
> to pass the appropriately sized 'size_t' object on 32-bit and 64-bit  
> platforms.
>
> The "structure C_Size : WORD" is available from "$(SML_LIB)/basis/c-
> types.mlb".
>
> You could also use C_Size.wordSize to compute the sizeof a pointer  
> (MLton asserts that sizeof(void*) == sizeof(size_t) and CHAR_BIT ==  
> 8).
>


_______________________________________________
MLton-user mailing list
MLton-user@...
http://mlton.org/mailman/listinfo/mlton-user

Re: Feature request: MLton.Pointer

by Matthew Fluet-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Thu, 5 Jun 2008, John Reppy wrote:
> Is the C_Size structure documented?  A search on mlton.org did not turn
> up any information.

Not at the present time.  But, it is in the 20070826 release, and I expect
it to remain.

The .mlb file should be pretty self-explanatory:
http://mlton.org/cgi-bin/viewsvn.cgi/mlton/trunk/basis-library/c-types.mlb?view=auto

structure C_Size is bound to some structure Word<N> such that
sizeof(size_t) * 8 = N.


> On Jun 5, 2008, at 12:29 PM, Matthew Fluet wrote:
>
>> On Mon, 2 Jun 2008, John Reppy wrote:
>> > The MLton.Pointer structure should have
>> >
>> >  val sizeofPtr : word
>> >
>> > so that one can allocate arrays of pointers in the C heap.
>>
>> Sounds reasonable.
>>
>> BTW, for importing "malloc", you should use
>> _import "malloc": C_Size.word -> MLton.Pointer.t;
>> rather than
>> _import "malloc": Word32.word -> MLton.Pointer.t;
>> to pass the appropriately sized 'size_t' object on 32-bit and 64-bit
>> platforms.
>>
>> The "structure C_Size : WORD" is available from
>> "$(SML_LIB)/basis/c-types.mlb".
>>
>> You could also use C_Size.wordSize to compute the sizeof a pointer (MLton
>> asserts that sizeof(void*) == sizeof(size_t) and CHAR_BIT == 8).
>>
>
>
> _______________________________________________
> MLton-user mailing list
> MLton-user@...
> http://mlton.org/mailman/listinfo/mlton-user
>

_______________________________________________
MLton-user mailing list
MLton-user@...
http://mlton.org/mailman/listinfo/mlton-user
LightInTheBox - Buy quality products at wholesale price