From: Richard W.M. Jones <"Richard W.M. Jones "> Date: Sun, 16 Nov 2008 14:08:24 +0000 (+0000) Subject: More test programs to track down Format / overflow bug. X-Git-Url: http://git.annexia.org/?p=fedora-mingw.git;a=commitdiff_plain;h=ca6e467060deb728164f28de6f636ca1e29ac9ba More test programs to track down Format / overflow bug. --- diff --git a/.hgignore b/.hgignore index 194037a..02c7963 100644 --- a/.hgignore +++ b/.hgignore @@ -77,6 +77,8 @@ ocaml/test3 ocaml/test4 ocaml/test_format ocaml/sudoku +ocaml/test_buffer +ocaml/test_overflow ocaml/*.exe ocaml/*.cmi ocaml/*.cmx diff --git a/ocaml/Makefile b/ocaml/Makefile index 723a526..3a2972d 100644 --- a/ocaml/Makefile +++ b/ocaml/Makefile @@ -2,7 +2,8 @@ # Test programs for testing out the cross-compiler. all: test1 test1.exe test2 test2.exe test3 test3.exe test4 test4.exe \ - test_format test_format.exe sudoku sudoku.exe + test_format test_format.exe sudoku sudoku.exe \ + test_buffer test_buffer.exe test_overflow test_overflow.exe test1: test1.ml ocamlopt $< -o $@ @@ -40,5 +41,18 @@ sudoku: sudoku.ml sudoku.exe: sudoku.ml i686-pc-mingw32-ocamlopt $< -o $@ +test_buffer: test_buffer.ml + ocamlopt $< -o $@ + +test_buffer.exe: test_buffer.ml + i686-pc-mingw32-ocamlopt $< -o $@ + +test_overflow: test_overflow.ml + ocamlopt $< -o $@ + +test_overflow.exe: test_overflow.ml + i686-pc-mingw32-ocamlopt $< -o $@ + clean: - rm -f test[1-4] test_format sudoku *.exe *.cmi *.cmx *.o + rm -f test[1-4] test_format sudoku test_buffer test_overflow \ + *.exe *.cmi *.cmx *.o diff --git a/ocaml/test_buffer.ml b/ocaml/test_buffer.ml new file mode 100644 index 0000000..88ea48c --- /dev/null +++ b/ocaml/test_buffer.ml @@ -0,0 +1,11 @@ +(* Test the Buffer module. *) + +let () = + let buf = Buffer.create 100 in + for i = 0 to 10 do + Buffer.add_char buf 'a'; + Buffer.add_string buf "b"; + Buffer.add_char buf 'c' + done; + let str = Buffer.contents buf in + Printf.printf "contents of buffer = %S\n%!" str diff --git a/ocaml/test_format.ml b/ocaml/test_format.ml index 3f2f128..d6a74ef 100644 --- a/ocaml/test_format.ml +++ b/ocaml/test_format.ml @@ -2,21 +2,24 @@ open Format -let debug = false +let debug = true let () = - if debug then Printf.printf "creating buffer ...\n%!"; let buf = Buffer.create 100 in - if debug then Printf.printf "creating formatter ...\n%!"; let fmt = formatter_of_buffer buf in - if debug then Printf.printf "open box ...\n%!"; + + if debug then + Printf.printf "pp_max_boxes before open_box = %d\n" + (pp_get_max_boxes fmt ()); + pp_open_box fmt 0; - if debug then Printf.printf "print string ...\n%!"; + + if debug then + Printf.printf "pp_max_boxes before open_box = %d\n" + (pp_get_max_boxes fmt ()); + pp_print_string fmt "This is a string"; - if debug then Printf.printf "close box ...\n%!"; pp_close_box fmt (); - if debug then Printf.printf "flush ...\n%!"; pp_print_flush fmt (); - if debug then Printf.printf "get buffer contents ...\n%!"; let str = Buffer.contents buf in Printf.printf "contents of buffer = %S\n%!" str diff --git a/ocaml/test_overflow.ml b/ocaml/test_overflow.ml new file mode 100644 index 0000000..e9a8cf1 --- /dev/null +++ b/ocaml/test_overflow.ml @@ -0,0 +1,23 @@ +(* Look for assembler errors like this: + * 'Warning: 9223372036854775807 shortened to 4294967295' + * Try to reproduce and fix. + *) + +open Printf + +let () = + let i = max_int in (* Different on 32 & 64 bit platforms.*) + printf "max_int = %d\n" i; + let i = min_int in + printf "min_int = %d\n" i; + let i64 = Int64.max_int in (* Same on all platforms. *) + printf "Int64.max_int = %Ld\n" i64; + let i32 = Int32.max_int in + printf "Int32.max_int = %ld\n" i32; + + (* This is how the stdlib computes min_int: + * min_int = 1 lsl (if 1 lsl 31 = 0 (* ie. 32 bit *) then 30 else 62) + *) + printf "1 lsl 31 = %d\n" (1 lsl 31); + printf "1 lsl 30 = %d\n" (1 lsl 30); + printf "1 lsl 62 = %d\n" (1 lsl 62)