Re: [Caml-list] Val_int vs caml_copy_nativeint

2011-08-09 Thread Gabriel Scherer
Erik de Castro Lopo wrote: > b) caml_copy_nativeint creates a boxed native int (either Int32.t >or Int64.t) not an unboxed Ocaml int. To create an unboxed >Ocaml int, Val_int() is the correct macro. > caml_copy_nativeint returns a element of the OCaml type 'nativeint': http://caml.inri

Re: [Caml-list] Val_int vs caml_copy_nativeint

2011-08-09 Thread Erik de Castro Lopo
Erik de Castro Lopo wrote: > This is strange, it wasn't declared with a CAMLlocal macro and it > was working, but if I do declare it with one the program segfaults > during garbage collection (caml_oldify_local_roots). Ok, with the help of someone off list I've sorted this out to my satisfaction.

RE: [Caml-list] Val_int vs caml_copy_nativeint

2011-08-09 Thread David Allsopp
malc wrote: > On Tue, 9 Aug 2011, David Allsopp wrote: > > > Erik de Castro Lopo wrote: > > > Xavier Leroy wrote: > > > > > > > On 08/08/2011 10:03 AM, Guillaume Yziquel wrote: > > > > > > > > > Then I do not see anything wrong if the code snippet you sent. > > > > > However, when you change Val_i

RE: [Caml-list] Val_int vs caml_copy_nativeint

2011-08-09 Thread malc
On Tue, 9 Aug 2011, David Allsopp wrote: > Erik de Castro Lopo wrote: > > Xavier Leroy wrote: > > > > > On 08/08/2011 10:03 AM, Guillaume Yziquel wrote: > > > > > > > Then I do not see anything wrong if the code snippet you sent. > > > > However, when you change Val_int to caml_copy_nativeint, th

RE: [Caml-list] Val_int vs caml_copy_nativeint

2011-08-09 Thread David Allsopp
Erik de Castro Lopo wrote: > Xavier Leroy wrote: > > > On 08/08/2011 10:03 AM, Guillaume Yziquel wrote: > > > > > Then I do not see anything wrong if the code snippet you sent. > > > However, when you change Val_int to caml_copy_nativeint, the layout > > > of the tuple is different. [...] So if yo

Re: [Caml-list] Val_int vs caml_copy_nativeint

2011-08-08 Thread Romain Beauxis
2011/8/8 Erik de Castro Lopo : > Xavier Leroy wrote: > >> On 08/08/2011 10:03 AM, Guillaume Yziquel wrote: >> >> > Then I do not see anything wrong if the code snippet you sent. However, >> > when you change Val_int to caml_copy_nativeint, the layout of the tuple >> > is different. [...] So if you

Re: [Caml-list] Val_int vs caml_copy_nativeint

2011-08-08 Thread Erik de Castro Lopo
Xavier Leroy wrote: > On 08/08/2011 10:03 AM, Guillaume Yziquel wrote: > > > Then I do not see anything wrong if the code snippet you sent. However, > > when you change Val_int to caml_copy_nativeint, the layout of the tuple > > is different. [...] So if you keep the same OCaml code when reading

Re: [Caml-list] Val_int vs caml_copy_nativeint

2011-08-08 Thread Xavier Leroy
On 08/08/2011 10:03 AM, Guillaume Yziquel wrote: > Then I do not see anything wrong if the code snippet you sent. However, > when you change Val_int to caml_copy_nativeint, the layout of the tuple > is different. [...] So if you keep the same OCaml code when reading > the result value, it's no sur

Re: [Caml-list] Val_int vs caml_copy_nativeint

2011-08-08 Thread Mathias Kende
Le lundi 08 août 2011 à 10:03 +0200, Guillaume Yziquel a écrit : > With Val_int, you have an integral value in the tuple's field. > > With caml_copy_nativeint, you have a pointer in the tuple's field. More explicitly, Val_int creates you a value of type int in the OCaml world, while caml_copy_nat

Re: [Caml-list] Val_int vs caml_copy_nativeint

2011-08-08 Thread Guillaume Yziquel
Le Monday 08 Aug 2011 à 17:46:19 (+1000), Erik de Castro Lopo a écrit : > Guillaume Yziquel wrote: > > > What do you mean by "doesn't work" precisely? > > The integer value I assign in the C file (and print out for a > sanity check) ends up as what looks like an address in the > Ocaml code. > >

Re: [Caml-list] Val_int vs caml_copy_nativeint

2011-08-08 Thread Erik de Castro Lopo
Guillaume Yziquel wrote: > Given that Val_int is Val_long (in mlvalues.h): > > #define Val_int(x) Val_long(x) > > it's not an issue with this piece of code. > > But depending on what "doesn't work" means and on the declarations of > width and height, then sizeof(int) < sizeof(long) may ex

Re: [Caml-list] Val_int vs caml_copy_nativeint

2011-08-08 Thread Erik de Castro Lopo
Guillaume Yziquel wrote: > What do you mean by "doesn't work" precisely? The integer value I assign in the C file (and print out for a sanity check) ends up as what looks like an address in the Ocaml code. Erik -- -- Erik de C

Re: [Caml-list] Val_int vs caml_copy_nativeint

2011-08-07 Thread malc
On Mon, 8 Aug 2011, Guillaume Yziquel wrote: > Le Monday 08 Aug 2011 ? 09:20:17 (+0400), malc a ?crit : > > On Mon, 8 Aug 2011, Erik de Castro Lopo wrote: > > > > > Hi all, > > > > > > I'm writing a C stub function to allow the calling of a C library > > > function from ocaml. The return from th

Re: [Caml-list] Val_int vs caml_copy_nativeint

2011-08-07 Thread Guillaume Yziquel
Le Monday 08 Aug 2011 à 09:20:17 (+0400), malc a écrit : > On Mon, 8 Aug 2011, Erik de Castro Lopo wrote: > > > Hi all, > > > > I'm writing a C stub function to allow the calling of a C library > > function from ocaml. The return from the stub is a tuple and I'm > > doing this: > > > > /* Pa

Re: [Caml-list] Val_int vs caml_copy_nativeint

2011-08-07 Thread malc
On Mon, 8 Aug 2011, Erik de Castro Lopo wrote: > Hi all, > > I'm writing a C stub function to allow the calling of a C library > function from ocaml. The return from the stub is a tuple and I'm > doing this: > > /* Package up the result as a tuple. */ > v_response = caml_alloc_tuple (3)

Re: [Caml-list] Val_int vs caml_copy_nativeint

2011-08-07 Thread Guillaume Yziquel
Le Sunday 07 Aug 2011 à 22:48:08 (-0500), Romain Beauxis a écrit : > 2011/8/7 Erik de Castro Lopo : > > Hi all, > > Hi, > > > I'm writing a C stub function to allow the calling of a C library > > function from ocaml. The return from the stub is a tuple and I'm > > doing this: > > > >    /* Packag

Re: [Caml-list] Val_int vs caml_copy_nativeint

2011-08-07 Thread Guillaume Yziquel
Le Monday 08 Aug 2011 à 13:15:04 (+1000), Erik de Castro Lopo a écrit : > Hi all, > > I'm writing a C stub function to allow the calling of a C library > function from ocaml. The return from the stub is a tuple and I'm > doing this: > > /* Package up the result as a tuple. */ > v_response

Re: [Caml-list] Val_int vs caml_copy_nativeint

2011-08-07 Thread Romain Beauxis
2011/8/7 Erik de Castro Lopo : > Hi all, Hi, > I'm writing a C stub function to allow the calling of a C library > function from ocaml. The return from the stub is a tuple and I'm > doing this: > >    /* Package up the result as a tuple. */ >    v_response = caml_alloc_tuple (3) ; > >    Store_fi