summaryrefslogtreecommitdiff
path: root/0020-ocaml-Fix-guestfs_065_implicit_close.ml-for-OCaml-5.patch
blob: 2bd88571f39b9cef87a9697b84ed8287e913afba (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
From 7ceafac98d3eb28d25195622cb6dc1158e9c1c2f Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Tue, 27 Jun 2023 16:20:49 +0100
Subject: [PATCH] ocaml: Fix guestfs_065_implicit_close.ml for OCaml 5

Link: https://discuss.ocaml.org/t/ocaml-5-forcing-objects-to-be-collected-and-finalized/12492/3
Thanks: Josh Berdine
Thanks: Vincent Laviron
(cherry picked from commit 7d4e9c927e8478662ece204b98ee3b5b147ab4b9)
---
 ocaml/t/guestfs_065_implicit_close.ml | 33 +++++++++++++++------------
 1 file changed, 19 insertions(+), 14 deletions(-)

diff --git a/ocaml/t/guestfs_065_implicit_close.ml b/ocaml/t/guestfs_065_implicit_close.ml
index f2dfecbd..9e68bc4c 100644
--- a/ocaml/t/guestfs_065_implicit_close.ml
+++ b/ocaml/t/guestfs_065_implicit_close.ml
@@ -16,22 +16,27 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *)
 
-let close_invoked = ref 0
+let [@inline never][@local never] run () =
+  let close_invoked = ref 0 in
 
-let close _ _ _ _ =
-  incr close_invoked
+  let close _ _ _ _ =
+    incr close_invoked
+  in
 
-let () =
-  let g = new Guestfs.guestfs () in
-  ignore (g#set_event_callback close [Guestfs.EVENT_CLOSE]);
-  assert (!close_invoked = 0)
-(* Allow the 'g' handle to go out of scope here, to ensure there is no
- * reference held on the stack.
- *)
+  let () =
+    let g = new Guestfs.guestfs () in
+    ignore (g#set_event_callback close [Guestfs.EVENT_CLOSE]);
+    assert (!close_invoked = 0)
+  (* Allow the 'g' handle to go out of scope here, to ensure there is no
+   * reference held on the stack.
+   *)
+  in
 
-(* This should cause the GC to close the handle. *)
-let () = Gc.full_major ()
+  (* This should cause the GC to close the handle. *)
+  Gc.full_major ();
 
-let () = assert  (!close_invoked = 1)
+  assert  (!close_invoked = 1);
 
-let () = Gc.compact ()
+  Gc.compact ()
+
+let () = run ()