You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Original bug ID: 3801 Reporter: administrator Status: closed Resolution: not a bug Priority: normal Severity: minor Category: ~DO NOT USE (was: OCaml general)
I'm new to Bigarray and the C language, so I don't know where to find the
solution. But this code misbehaves on amd64 (and not on x86) : the "get" gives
me 4 on the Caml side ; 0 on the C side, and it seems to be specific to the last
row.
let m =
Bigarray.Array2.create
Bigarray.int
Bigarray.c_layout
10
10 in
Bigarray.Array2.fill m 4;
print_int (Bigarray.Array2.get m 9 9) ; print_newline();
print_9_9 m;
;;
I'm new to Bigarray and the C language, so I don't know where to
find the solution. But this code misbehaves on amd64 (and not on
x86) : the "get" gives me 4 on the Caml side ; 0 on the C side, and
it seems to be specific to the last row.
I think this is due to a wrong type on the C side: a bigarray
with Bigarray.int elements contains platform-native integers,
i.e. 32-bit ints on x86 and 64-bit ints on AMD64. The correct type to
use on the C side is therefore "long" and not "int":
value print_9_9_native (value mv) {
struct caml_bigarray * mt;
int (*m) [10][10];
^^^ should be "long"
mt = Bigarray_val(mv);
m = mt->data;
printf("%d\n", (*m)[9][9]);
}
Alternatively, if you want an array of 32-bit integers on both
platforms, keep "int" in the C code and use Bigarray.int32 on the Caml
side.
Original bug ID: 3801
Reporter: administrator
Status: closed
Resolution: not a bug
Priority: normal
Severity: minor
Category: ~DO NOT USE (was: OCaml general)
Bug description
Full_Name: Tiphaine Turpin
Version: 3.08.4
OS: gentoo linux amd64
Submission from: babar.irisa.fr (131.254.50.11)
I'm new to Bigarray and the C language, so I don't know where to find the
solution. But this code misbehaves on amd64 (and not on x86) : the "get" gives
me 4 on the Caml side ; 0 on the C side, and it seems to be specific to the last
row.
Tiphaine Turpin
Ocaml:
external print_9_9 :
(int, Bigarray.int_elt, Bigarray.c_layout) Bigarray.Array2.t
-> unit =
"print_9_9_bytecode" "print_9_9_native"
;;
let m =
Bigarray.Array2.create
Bigarray.int
Bigarray.c_layout
10
10 in
Bigarray.Array2.fill m 4;
print_int (Bigarray.Array2.get m 9 9) ; print_newline();
print_9_9 m;
;;
C:
#include <caml/mlvalues.h>
#include <caml/bigarray.h>
#include <stdio.h>
value print_9_9_native (value mv) {
struct caml_bigarray * mt;
int (*m) [10][10];
mt = Bigarray_val(mv);
m = mt->data;
printf("%d\n", (*m)[9][9]);
}
value print_9_9_bytecode (value* args, int un) {
return print_9_9_native(args[0]);
}
Output :
4
0
The text was updated successfully, but these errors were encountered: