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

caml_ba_get_N treats char elements as signed #6523

Closed
vicuna opened this issue Aug 28, 2014 · 3 comments
Closed

caml_ba_get_N treats char elements as signed #6523

vicuna opened this issue Aug 28, 2014 · 3 comments

Comments

@vicuna
Copy link

vicuna commented Aug 28, 2014

Original bug ID: 6523
Reporter: @yallop
Assigned to: @mshinwell
Status: resolved (set by @mshinwell on 2014-08-29T10:52:14Z)
Resolution: open
Priority: urgent
Severity: block
Fixed in version: 4.02.0+dev
Category: otherlibs
Related to: #6064

Bug description

$ cat ba_char.ml
let b = Bigarray.(Array1.create char c_layout 1) in
let c = '\128' in
begin
b.{0} <- c;
assert (b.{0} = c)
end;;
print_endline "ok";
$ ocamlc unix.cma bigarray.cma ba_char.ml -o ba_char && ./ba_char
Fatal error: exception File "ba_char.ml", line 5, characters 2-8: Assertion failed

Native code is fine, since it uses bigarray intrinsics:

$ ocamlopt unix.cmxa bigarray.cmxa ba_char.ml -o ba_char && ./ba_char
ok

The top-level crashes, since it assumes char can't hold negative values:

$ ocaml
OCaml version 4.02.0+dev16-2014-08-21

#load "unix.cma";;

#load "bigarray.cma";;

let b = Bigarray.(Array1.create char c_layout 1);;

val b :
(char, Bigarray.int8_unsigned_elt, Bigarray.c_layout) Bigarray.Array1.t =

b.{0} <- '\128';;

  • : unit = ()

b.{0};;

Segmentation fault

File attachments

@vicuna
Copy link
Author

vicuna commented Aug 28, 2014

Comment author: @yallop

Similarly the (unspecified) comparison order has changed, since it reads the elements through a char*. Patch attached.

@vicuna
Copy link
Author

vicuna commented Aug 29, 2014

Comment author: @mshinwell

Fixed in 4.02 (rev 15148).

@vicuna vicuna closed this as completed Aug 29, 2014
@vicuna
Copy link
Author

vicuna commented Aug 29, 2014

Comment author: @xavierleroy

Nitpick: owing to the use of the C 'char' type (instead of 'unsigned char'), char bigarray elements were treated EITHER as signed OR as unsigned depending on the platform. End of nitpick.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants