Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0006523OCamlOCaml otherlibspublic2014-08-28 19:102014-08-29 13:41
Reporteryallop 
Assigned Toshinwell 
PriorityurgentSeverityblockReproducibilityalways
StatusresolvedResolutionopen 
PlatformOSOS Version
Product Version 
Target VersionFixed in Version4.02.0+dev 
Summary0006523: caml_ba_get_N treats char elements as signed
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 =
     <abstr>
   # b.{0} <- '\128';;
   - : unit = ()
   # b.{0};;
   Segmentation fault

TagsNo tags attached.
Attached Filesdiff file icon ba_unsigned_char.diff [^] (515 bytes) 2014-08-28 19:10 [Show Content]
diff file icon ba_compare.diff [^] (498 bytes) 2014-08-28 19:20 [Show Content]

- Relationships
related to 0006064resolvedgasche Expose a GADT representation for Bigarray.kind 

-  Notes
(0012056)
yallop (developer)
2014-08-28 19:21

Similarly the (unspecified) comparison order has changed, since it reads the elements through a char*. Patch attached.
(0012058)
shinwell (developer)
2014-08-29 12:52

Fixed in 4.02 (rev 15148).
(0012059)
xleroy (administrator)
2014-08-29 13:41

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.

- Issue History
Date Modified Username Field Change
2014-08-28 19:10 yallop New Issue
2014-08-28 19:10 yallop File Added: ba_unsigned_char.diff
2014-08-28 19:11 yallop Relationship added related to 0006064
2014-08-28 19:20 yallop File Added: ba_compare.diff
2014-08-28 19:21 yallop Note Added: 0012056
2014-08-29 12:29 shinwell Assigned To => shinwell
2014-08-29 12:29 shinwell Status new => assigned
2014-08-29 12:52 shinwell Note Added: 0012058
2014-08-29 12:52 shinwell Status assigned => resolved
2014-08-29 12:52 shinwell Fixed in Version => 4.02.0+dev
2014-08-29 13:41 xleroy Note Added: 0012059


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker