Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support OCaml 5 new Unix API names #953

Merged
merged 4 commits into from
Jun 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

* Lwt is now compatible with OCaml 5.00. Lwt is now incompatible with OCaml 4.02. (#925, #923, Kate Deplaix, Patrick Ferris)
* Lwt is now incompatible with OCaml.4.07 and earlier. (#947, Hannes Mehnert, Tim McGilchrist)
* Lwt-unix is now compatible with OCaml 5.0.0. (#953, David Allsopp)

====== Additions ======

Expand Down
7 changes: 7 additions & 0 deletions src/unix/dune
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ let preprocess =

let () = Jbuild_plugin.V1.send @@ {|

(rule
(targets lwt_process.ml)
(deps (:ml lwt_process.cppo.ml))
(action
(chdir %{project_root}
(run %{bin:cppo} -V OCAML:%{ocaml_version} %{ml} -o %{targets}))))

(rule
(targets lwt_unix.ml)
(deps (:ml lwt_unix.cppo.ml))
Expand Down
4 changes: 4 additions & 0 deletions src/unix/lwt_process.ml → src/unix/lwt_process.cppo.ml
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,11 @@ let unix_redirect fd redirection = match redirection with
Unix.dup2 fd' fd;
Unix.close fd'

#if OCAML_VERSION >= (5, 0, 0)
external unix_exit : int -> 'a = "caml_unix_exit"
#else
external unix_exit : int -> 'a = "unix_exit"
#endif

let unix_spawn
?cwd
Expand Down
4 changes: 4 additions & 0 deletions src/unix/lwt_unix.cppo.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2434,7 +2434,11 @@ let wait () = waitpid [] (-1)

external system_job : string -> int job = "lwt_unix_system_job"

#if OCAML_VERSION >= (5, 0, 0)
external unix_exit : int -> 'a = "caml_unix_exit"
#else
external unix_exit : int -> 'a = "unix_exit"
#endif

let system cmd =
if Sys.win32 then
Expand Down
3 changes: 0 additions & 3 deletions src/unix/unix_c/unix_get_network_information_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,6 @@ char *s_strdup(const char *s)
}
#endif

CAMLexport value alloc_inet_addr(struct in_addr *inaddr);
CAMLexport value alloc_inet6_addr(struct in6_addr *inaddr);

static value alloc_one_addr(char const *a)
{
struct in_addr addr;
Expand Down
10 changes: 6 additions & 4 deletions src/unix/unix_c/unix_getaddrinfo_job.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ static value convert_addrinfo(struct addrinfo *a)
vcanonname =
caml_copy_string(a->ai_canonname == NULL ? "" : a->ai_canonname);
vres = caml_alloc_small(5, 0);
Field(vres, 0) = cst_to_constr(a->ai_family, socket_domain_table, 3, 0);
Field(vres, 1) = cst_to_constr(a->ai_socktype, socket_type_table, 4, 0);
Field(vres, 0) =
cst_to_constr(a->ai_family, caml_unix_socket_domain_table, 3, 0);
Field(vres, 1) =
cst_to_constr(a->ai_socktype, caml_unix_socket_type_table, 4, 0);
Field(vres, 2) = Val_int(a->ai_protocol);
Field(vres, 3) = vaddr;
Field(vres, 4) = vcanonname;
Expand Down Expand Up @@ -97,11 +99,11 @@ CAMLprim value lwt_unix_getaddrinfo_job(value node, value service, value hints)
if (Is_block(v)) switch (Tag_val(v)) {
case 0: /* AI_FAMILY of socket_domain */
job->hints.ai_family =
socket_domain_table[Int_val(Field(v, 0))];
caml_unix_socket_domain_table[Int_val(Field(v, 0))];
break;
case 1: /* AI_SOCKTYPE of socket_type */
job->hints.ai_socktype =
socket_type_table[Int_val(Field(v, 0))];
caml_unix_socket_type_table[Int_val(Field(v, 0))];
break;
case 2: /* AI_PROTOCOL of int */
job->hints.ai_protocol = Int_val(Field(v, 0));
Expand Down
7 changes: 6 additions & 1 deletion src/unix/unix_c/unix_open_job.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <caml/alloc.h>
#include <caml/mlvalues.h>
#include <caml/unixsupport.h>
#include <caml/version.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
Expand All @@ -30,6 +31,10 @@
#define O_RSYNC 0
#endif

#if OCAML_VERSION_MAJOR < 5
#define caml_unix_cloexec_default unix_cloexec_default
#endif

static int open_flag_table[] = {
O_RDONLY, O_WRONLY, O_RDWR, O_NONBLOCK, O_APPEND, O_CREAT, O_TRUNC,
O_EXCL, O_NOCTTY, O_DSYNC, O_SYNC, O_RSYNC, 0, /* O_SHARE_DELETE,
Expand Down Expand Up @@ -64,7 +69,7 @@ static void worker_open(struct job_open *job)
else if (job->fd & KEEPEXEC)
cloexec = 0;
else
cloexec = unix_cloexec_default;
cloexec = caml_unix_cloexec_default;

#if defined(O_CLOEXEC)
if (cloexec) job->flags |= O_CLOEXEC;
Expand Down
10 changes: 8 additions & 2 deletions src/unix/unix_c/unix_recv_send_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,18 @@

#include <caml/mlvalues.h>
#include <caml/socketaddr.h>
#include <caml/version.h>
#include <sys/socket.h>
#include <sys/uio.h>

#if OCAML_VERSION_MAJOR < 5
#define caml_unix_socket_domain_table socket_domain_table
#define caml_unix_socket_type_table socket_type_table
#endif

extern int msg_flag_table[];
extern int socket_domain_table[];
extern int socket_type_table[];
extern int caml_unix_socket_domain_table[];
extern int caml_unix_socket_type_table[];
extern void get_sockaddr(value mladdr, union sock_addr_union *addr /*out*/,
socklen_t *addr_len /*out*/);
value wrapper_recv_msg(int fd, int n_iovs, struct iovec *iovs);
Expand Down