summaryrefslogtreecommitdiff
path: root/testsuite/tests/tool-ocaml/t340-weak.ml
blob: 6c3d26e2f30cbbd05c51c032d3a30bd13c393a1b (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
(* TEST
include tool-ocaml-lib
flags = "-w -a"
ocaml_script_as_argument = "true"
* setup-ocaml-build-env
** ocaml
*)

open Lib;;
let x = Array.make 20 "" in
let w = weak_create 20 in
for i = 0 to 19 do
  x.(i) <- String.make 20 's';
  weak_set w i (Some x.(i));
done;
Gc.full_major ();
for i = 0 to 19 do
  match weak_get w i with
  | None -> raise Not_found
  | _ -> ()
done;
for i = 0 to 19 do
  if i mod 2 = 0 then x.(i) <- ""
done;
Gc.full_major ();
for i = 0 to 19 do
  match weak_get w i with
  | None when i mod 2 = 0 -> ()
  | Some s when i mod 2 = 1 -> if s.[5] <> 's' then raise Not_found
  | _ -> raise Not_found
done
;;