Skip to content

Commit fbd4fc5

Browse files
Merge pull request #953 from dra27/check-symbols-caml_unix
Support OCaml 5 new Unix API names
2 parents b3e7dd0 + e27707d commit fbd4fc5

File tree

8 files changed

+36
-10
lines changed

8 files changed

+36
-10
lines changed

CHANGES

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

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

89
====== Additions ======
910

src/unix/dune

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ let preprocess =
88

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

11+
(rule
12+
(targets lwt_process.ml)
13+
(deps (:ml lwt_process.cppo.ml))
14+
(action
15+
(chdir %{project_root}
16+
(run %{bin:cppo} -V OCAML:%{ocaml_version} %{ml} -o %{targets}))))
17+
1118
(rule
1219
(targets lwt_unix.ml)
1320
(deps (:ml lwt_unix.cppo.ml))

src/unix/lwt_process.ml renamed to src/unix/lwt_process.cppo.ml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,11 @@ let unix_redirect fd redirection = match redirection with
136136
Unix.dup2 fd' fd;
137137
Unix.close fd'
138138

139+
#if OCAML_VERSION >= (5, 0, 0)
140+
external unix_exit : int -> 'a = "caml_unix_exit"
141+
#else
139142
external unix_exit : int -> 'a = "unix_exit"
143+
#endif
140144

141145
let unix_spawn
142146
?cwd

src/unix/lwt_unix.cppo.ml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2434,7 +2434,11 @@ let wait () = waitpid [] (-1)
24342434

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

2437+
#if OCAML_VERSION >= (5, 0, 0)
2438+
external unix_exit : int -> 'a = "caml_unix_exit"
2439+
#else
24372440
external unix_exit : int -> 'a = "unix_exit"
2441+
#endif
24382442

24392443
let system cmd =
24402444
if Sys.win32 then

src/unix/unix_c/unix_get_network_information_utils.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,6 @@ char *s_strdup(const char *s)
102102
}
103103
#endif
104104

105-
CAMLexport value alloc_inet_addr(struct in_addr *inaddr);
106-
CAMLexport value alloc_inet6_addr(struct in6_addr *inaddr);
107-
108105
static value alloc_one_addr(char const *a)
109106
{
110107
struct in_addr addr;

src/unix/unix_c/unix_getaddrinfo_job.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,10 @@ static value convert_addrinfo(struct addrinfo *a)
5151
vcanonname =
5252
caml_copy_string(a->ai_canonname == NULL ? "" : a->ai_canonname);
5353
vres = caml_alloc_small(5, 0);
54-
Field(vres, 0) = cst_to_constr(a->ai_family, socket_domain_table, 3, 0);
55-
Field(vres, 1) = cst_to_constr(a->ai_socktype, socket_type_table, 4, 0);
54+
Field(vres, 0) =
55+
cst_to_constr(a->ai_family, caml_unix_socket_domain_table, 3, 0);
56+
Field(vres, 1) =
57+
cst_to_constr(a->ai_socktype, caml_unix_socket_type_table, 4, 0);
5658
Field(vres, 2) = Val_int(a->ai_protocol);
5759
Field(vres, 3) = vaddr;
5860
Field(vres, 4) = vcanonname;
@@ -97,11 +99,11 @@ CAMLprim value lwt_unix_getaddrinfo_job(value node, value service, value hints)
9799
if (Is_block(v)) switch (Tag_val(v)) {
98100
case 0: /* AI_FAMILY of socket_domain */
99101
job->hints.ai_family =
100-
socket_domain_table[Int_val(Field(v, 0))];
102+
caml_unix_socket_domain_table[Int_val(Field(v, 0))];
101103
break;
102104
case 1: /* AI_SOCKTYPE of socket_type */
103105
job->hints.ai_socktype =
104-
socket_type_table[Int_val(Field(v, 0))];
106+
caml_unix_socket_type_table[Int_val(Field(v, 0))];
105107
break;
106108
case 2: /* AI_PROTOCOL of int */
107109
job->hints.ai_protocol = Int_val(Field(v, 0));

src/unix/unix_c/unix_open_job.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <caml/alloc.h>
1111
#include <caml/mlvalues.h>
1212
#include <caml/unixsupport.h>
13+
#include <caml/version.h>
1314
#include <sys/types.h>
1415
#include <sys/stat.h>
1516
#include <errno.h>
@@ -30,6 +31,10 @@
3031
#define O_RSYNC 0
3132
#endif
3233

34+
#if OCAML_VERSION_MAJOR < 5
35+
#define caml_unix_cloexec_default unix_cloexec_default
36+
#endif
37+
3338
static int open_flag_table[] = {
3439
O_RDONLY, O_WRONLY, O_RDWR, O_NONBLOCK, O_APPEND, O_CREAT, O_TRUNC,
3540
O_EXCL, O_NOCTTY, O_DSYNC, O_SYNC, O_RSYNC, 0, /* O_SHARE_DELETE,
@@ -64,7 +69,7 @@ static void worker_open(struct job_open *job)
6469
else if (job->fd & KEEPEXEC)
6570
cloexec = 0;
6671
else
67-
cloexec = unix_cloexec_default;
72+
cloexec = caml_unix_cloexec_default;
6873

6974
#if defined(O_CLOEXEC)
7075
if (cloexec) job->flags |= O_CLOEXEC;

src/unix/unix_c/unix_recv_send_utils.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,18 @@
2727

2828
#include <caml/mlvalues.h>
2929
#include <caml/socketaddr.h>
30+
#include <caml/version.h>
3031
#include <sys/socket.h>
3132
#include <sys/uio.h>
3233

34+
#if OCAML_VERSION_MAJOR < 5
35+
#define caml_unix_socket_domain_table socket_domain_table
36+
#define caml_unix_socket_type_table socket_type_table
37+
#endif
38+
3339
extern int msg_flag_table[];
34-
extern int socket_domain_table[];
35-
extern int socket_type_table[];
40+
extern int caml_unix_socket_domain_table[];
41+
extern int caml_unix_socket_type_table[];
3642
extern void get_sockaddr(value mladdr, union sock_addr_union *addr /*out*/,
3743
socklen_t *addr_len /*out*/);
3844
value wrapper_recv_msg(int fd, int n_iovs, struct iovec *iovs);

0 commit comments

Comments
 (0)