File: alloc_async.ml

package info (click to toggle)
ocaml 5.4.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 44,384 kB
  • sloc: ml: 370,196; ansic: 52,820; sh: 27,419; asm: 5,462; makefile: 3,684; python: 974; awk: 278; javascript: 273; perl: 59; fortran: 21; cs: 9
file content (25 lines) | stat: -rw-r--r-- 803 bytes parent folder | download | duplicates (2)
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
(* TEST
 modules = "alloc_async_stubs.c";
*)

external test : int ref -> unit = "stub"
external print_status : string -> int -> unit = "print_status_caml" [@@noalloc]

(* This tests checks that the finaliser does not run during various
   allocations from C, but runs at the first polling location in OCaml
   code after that. For native backends, something like
   RET_FROM_C_CALL from runtime/amd64.S is necessary, see its
   description there and the documentation of
   [Caml_state->action_pending] in runtime.signals.c. *)

let f () =
  let r = ref 42 in
  Gc.finalise (fun s -> r := !s) (ref 17);
  print_status "OCaml, before" !r;
  test r;
  print_status "OCaml, after" !r;
  ignore (Sys.opaque_identity (ref 100));
  print_status "OCaml, after alloc" !r;
  ()

let () = (f [@inlined never]) ()