caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* OCaml Int64 <-> C int64_t
@ 2010-08-18 17:28 Jianzhou Zhao
  2010-08-18 17:36 ` [Caml-list] " Mathias Kende
  0 siblings, 1 reply; 4+ messages in thread
From: Jianzhou Zhao @ 2010-08-18 17:28 UTC (permalink / raw)
  To: caml-list

Hi,

To convert between OCaml Int64 and C Integer, I think uint64_t or
int64_t can be the target C type. Int64_val is the macro converting
OCaml value to int64, I failed to find the macro for the other
direction under ./byterun. ./byterun/ints.c defines operations on
int64, caml_copy_int64(I64_of_intnat(..)) seems to be working for such
conversion? But mlvalues.h does not declare them to use. How can I
convert int64 to value?

Thanks
-- 
Jianzhou


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] OCaml Int64 <-> C int64_t
  2010-08-18 17:28 OCaml Int64 <-> C int64_t Jianzhou Zhao
@ 2010-08-18 17:36 ` Mathias Kende
  2010-08-18 18:16   ` Jianzhou Zhao
  0 siblings, 1 reply; 4+ messages in thread
From: Mathias Kende @ 2010-08-18 17:36 UTC (permalink / raw)
  To: Jianzhou Zhao; +Cc: caml-list

Le mercredi 18 août 2010 à 13:28 -0400, Jianzhou Zhao a écrit :
> But mlvalues.h does not declare them to use. How can I
> convert int64 to value?

caml_copy_int64 is declared in <caml/alloc.h>. There is no Val_int64
macro because int64 values are heap objects which must be allocated (the
Val_... macros are mostly just static_cast).

Mathias


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] OCaml Int64 <-> C int64_t
  2010-08-18 17:36 ` [Caml-list] " Mathias Kende
@ 2010-08-18 18:16   ` Jianzhou Zhao
  2010-08-18 18:47     ` Mathias Kende
  0 siblings, 1 reply; 4+ messages in thread
From: Jianzhou Zhao @ 2010-08-18 18:16 UTC (permalink / raw)
  To: Mathias Kende; +Cc: caml-list

On Wed, Aug 18, 2010 at 1:36 PM, Mathias Kende <mathias@kende.fr> wrote:
> Le mercredi 18 août 2010 à 13:28 -0400, Jianzhou Zhao a écrit :
>> But mlvalues.h does not declare them to use. How can I
>> convert int64 to value?
>
> caml_copy_int64 is declared in <caml/alloc.h>. There is no Val_int64
> macro because int64 values are heap objects which must be allocated (the
> Val_... macros are mostly just static_cast).

Does caml_copy_int64 do all I want?

int64_t C_fun();

CAMLprim value stub()
{
  return (caml_copy_int64 (C_fun()));
}

Do we still need I64_of_intnat? It is not included in <caml/alloc.h>
or other headers.

>
> Mathias
>
>



-- 
Jianzhou


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] OCaml Int64 <-> C int64_t
  2010-08-18 18:16   ` Jianzhou Zhao
@ 2010-08-18 18:47     ` Mathias Kende
  0 siblings, 0 replies; 4+ messages in thread
From: Mathias Kende @ 2010-08-18 18:47 UTC (permalink / raw)
  To: Jianzhou Zhao; +Cc: caml-list

Le mercredi 18 août 2010 à 14:16 -0400, Jianzhou Zhao a écrit :
> Does caml_copy_int64 do all I want?

I believe so, but then I don't know what you want...

> 
> int64_t C_fun();
> 
> CAMLprim value stub()
> {
>   return (caml_copy_int64 (C_fun()));
> }
> 
> Do we still need I64_of_intnat? It is not included in <caml/alloc.h>
> or other headers.

INT64_of_intnat is an internal macro. There is no reason to use it. Your
snippet of code seems correct, but remember that caml_copy_int64 will
allocate values in the heap so you need to use the CAMLparam/CAMLreturn
macro if your function receives arguments from the caml world.


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2010-08-18 18:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-08-18 17:28 OCaml Int64 <-> C int64_t Jianzhou Zhao
2010-08-18 17:36 ` [Caml-list] " Mathias Kende
2010-08-18 18:16   ` Jianzhou Zhao
2010-08-18 18:47     ` Mathias Kende

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).