Skip to content

Commit

Permalink
flambda-backend: Fix ocaml/otherlibs/unix/ (ocaml-flambda#2963)
Browse files Browse the repository at this point in the history
  • Loading branch information
mshinwell authored Aug 22, 2024
1 parent c071af7 commit 592e8c5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
5 changes: 1 addition & 4 deletions otherlibs/unix/dune
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion otherlibs/unix/getnameinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
11 changes: 7 additions & 4 deletions otherlibs/unix/unix_unix.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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
)

Expand Down

0 comments on commit 592e8c5

Please sign in to comment.