From 592e8c52fe563f8fadf0ccd13779475413fa4e20 Mon Sep 17 00:00:00 2001 From: Mark Shinwell Date: Thu, 22 Aug 2024 16:28:16 +0100 Subject: [PATCH] flambda-backend: Fix ocaml/otherlibs/unix/ (#2963) --- otherlibs/unix/dune | 5 +---- otherlibs/unix/getnameinfo.c | 3 ++- otherlibs/unix/unix_unix.ml | 11 +++++++---- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/otherlibs/unix/dune b/otherlibs/unix/dune index f7a7b2b5612..77d9b2ad045 100644 --- a/otherlibs/unix/dune +++ b/otherlibs/unix/dune @@ -12,10 +12,7 @@ ;* * ;************************************************************************** -(rule - (deps unix_unix.ml) - (targets unix.ml) - (action (copy unix_unix.ml unix.ml))) +(copy_files# caml/*.h) (library (name unix) diff --git a/otherlibs/unix/getnameinfo.c b/otherlibs/unix/getnameinfo.c index 5d486525a50..80594c8987a 100644 --- a/otherlibs/unix/getnameinfo.c +++ b/otherlibs/unix/getnameinfo.c @@ -44,7 +44,8 @@ CAMLprim value caml_unix_getnameinfo(value vaddr, value vopts) int opts, retcode; caml_unix_get_sockaddr(vaddr, &addr, &addr_len); - opts = caml_convert_flag_list(vopts, getnameinfo_flag_table); + // CR ocaml 5 all-runtime5: remove cast + opts = caml_convert_flag_list(vopts, (int*) getnameinfo_flag_table); caml_enter_blocking_section(); retcode = getnameinfo((const struct sockaddr *) &addr.s_gen, addr_len, diff --git a/otherlibs/unix/unix_unix.ml b/otherlibs/unix/unix_unix.ml index c79758d7347..b24875cfcce 100644 --- a/otherlibs/unix/unix_unix.ml +++ b/otherlibs/unix/unix_unix.ml @@ -938,12 +938,15 @@ type popen_process = | Process_full of in_channel * out_channel * in_channel let popen_processes = (Hashtbl.create 7 : (popen_process, int) Hashtbl.t) -let popen_mutex = Mutex.create () + +(* CR ocaml 5 all-runtime5: remove lazy, which is here to stop: + "Must initialize systhreads library before using Mutex" *) +let popen_mutex = lazy (Mutex.create ()) let open_proc prog args envopt proc input output error = let pid = create_process_gen prog args envopt input output error in - Mutex.protect popen_mutex (fun () -> + Mutex.protect (Lazy.force popen_mutex) (fun () -> Hashtbl.add popen_processes proc pid) let open_process_args_in prog args = @@ -1034,14 +1037,14 @@ let open_process_full cmd = let find_proc_id fun_name proc = try - Mutex.protect popen_mutex (fun () -> + Mutex.protect (Lazy.force popen_mutex) (fun () -> Hashtbl.find popen_processes proc ) with Not_found -> raise(Unix_error(EBADF, fun_name, "")) let remove_proc_id proc = - Mutex.protect popen_mutex (fun () -> + Mutex.protect (Lazy.force popen_mutex) (fun () -> Hashtbl.remove popen_processes proc )