blob: 3afcc6c5522b324658c64e478c241d2a96ff5295 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
external caml_string_get_16 : string -> int -> int = "%caml_string_get16"
external caml_string_get_32 : string -> int -> int32 = "%caml_string_get32"
external caml_string_get_64 : string -> int -> int64 = "%caml_string_get64"
external caml_string_set_16 : string -> int -> int -> unit =
"%caml_string_set16"
external caml_string_set_32 : string -> int -> int32 -> unit =
"%caml_string_set32"
external caml_string_set_64 : string -> int -> int64 -> unit =
"%caml_string_set64"
let s = String.make 10 '\x00'
let empty_s = ""
let assert_bound_check2 f v1 v2 =
try
ignore(f v1 v2);
assert false
with
| Invalid_argument("index out of bounds") -> ()
let assert_bound_check3 f v1 v2 v3 =
try
ignore(f v1 v2 v3);
assert false
with
| Invalid_argument("index out of bounds") -> ()
let () =
assert_bound_check2 caml_string_get_16 s (-1);
assert_bound_check2 caml_string_get_16 s 9;
assert_bound_check2 caml_string_get_32 s (-1);
assert_bound_check2 caml_string_get_32 s 7;
assert_bound_check2 caml_string_get_64 s (-1);
assert_bound_check2 caml_string_get_64 s 3;
assert_bound_check3 caml_string_set_16 s (-1) 0;
assert_bound_check3 caml_string_set_16 s 9 0;
assert_bound_check3 caml_string_set_32 s (-1) 0l;
assert_bound_check3 caml_string_set_32 s 7 0l;
assert_bound_check3 caml_string_set_64 s (-1) 0L;
assert_bound_check3 caml_string_set_64 s 3 0L;
assert_bound_check2 caml_string_get_16 empty_s 0;
assert_bound_check2 caml_string_get_32 empty_s 0;
assert_bound_check2 caml_string_get_64 empty_s 0;
assert_bound_check3 caml_string_set_16 empty_s 0 0;
assert_bound_check3 caml_string_set_32 empty_s 0 0l;
assert_bound_check3 caml_string_set_64 empty_s 0 0L
let () =
caml_string_set_16 s 0 0x1234;
Printf.printf "%x %x %x\n%!"
(caml_string_get_16 s 0)
(caml_string_get_16 s 1)
(caml_string_get_16 s 2);
caml_string_set_16 s 0 0xFEDC;
Printf.printf "%x %x %x\n%!"
(caml_string_get_16 s 0)
(caml_string_get_16 s 1)
(caml_string_get_16 s 2)
let () =
caml_string_set_32 s 0 0x12345678l;
Printf.printf "%lx %lx %lx\n%!"
(caml_string_get_32 s 0)
(caml_string_get_32 s 1)
(caml_string_get_32 s 2);
caml_string_set_32 s 0 0xFEDCBA09l;
Printf.printf "%lx %lx %lx\n%!"
(caml_string_get_32 s 0)
(caml_string_get_32 s 1)
(caml_string_get_32 s 2)
let () =
caml_string_set_64 s 0 0x1234567890ABCDEFL;
Printf.printf "%Lx %Lx %Lx\n%!"
(caml_string_get_64 s 0)
(caml_string_get_64 s 1)
(caml_string_get_64 s 2);
caml_string_set_64 s 0 0xFEDCBA0987654321L;
Printf.printf "%Lx %Lx %Lx\n%!"
(caml_string_get_64 s 0)
(caml_string_get_64 s 1)
(caml_string_get_64 s 2)
|