Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dimensions of Array2 on amd64 #3801

Closed
vicuna opened this issue Oct 3, 2005 · 2 comments
Closed

dimensions of Array2 on amd64 #3801

vicuna opened this issue Oct 3, 2005 · 2 comments
Labels

Comments

@vicuna
Copy link

vicuna commented Oct 3, 2005

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

@vicuna
Copy link
Author

vicuna commented Oct 13, 2005

Comment author: administrator

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.

  • Xavier Leroy

@vicuna
Copy link
Author

vicuna commented Oct 13, 2005

Comment author: administrator

Probably a type mismatch on the C side.

@vicuna vicuna closed this as completed Oct 13, 2005
@vicuna vicuna added the bug label Mar 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant