From 336b513b96c6c092a482a6b4100ad216f0d803e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonin=20D=C3=A9cimo?= Date: Mon, 7 Oct 2024 18:26:15 +0200 Subject: [PATCH 1/2] Wrap caml_convert_flag_list in lwt_convert_flag_list for compat See https://github.com/ocaml/opam-repository/pull/26668 --- src/unix/lwt_unix.h | 4 +++- src/unix/unix_c/unix_bytes_recv.c | 2 +- src/unix/unix_c/unix_bytes_recvfrom.c | 2 +- src/unix/unix_c/unix_bytes_send.c | 2 +- src/unix/unix_c/unix_bytes_sendto.c | 2 +- src/unix/unix_c/unix_getnameinfo_job.c | 2 +- src/unix/unix_c/unix_open_job.c | 4 ++-- src/unix/unix_c/unix_recv.c | 2 +- src/unix/unix_c/unix_recvfrom.c | 2 +- src/unix/unix_c/unix_send.c | 2 +- src/unix/unix_c/unix_sendto.c | 2 +- src/unix/unix_c/unix_wait4.c | 2 +- 12 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/unix/lwt_unix.h b/src/unix/lwt_unix.h index 47f093016..125ca7a12 100644 --- a/src/unix/lwt_unix.h +++ b/src/unix/lwt_unix.h @@ -15,8 +15,10 @@ #include #if OCAML_VERSION < 50000 -#define caml_convert_flag_list(flags, table) \ +#define lwt_convert_flag_list(flags, table) \ caml_convert_flag_list((flags), (int *)(table)) +#else +#define lwt_convert_flag_list caml_convert_flag_list #endif /* The macro to get the file-descriptor from a value. */ diff --git a/src/unix/unix_c/unix_bytes_recv.c b/src/unix/unix_c/unix_bytes_recv.c index fac0ebda8..a535bc07c 100644 --- a/src/unix/unix_c/unix_bytes_recv.c +++ b/src/unix/unix_c/unix_bytes_recv.c @@ -23,7 +23,7 @@ value lwt_unix_bytes_recv(value fd, value buf, value ofs, value len, int ret; ret = recv(Int_val(fd), (char *)Caml_ba_array_val(buf)->data + Long_val(ofs), - Long_val(len), caml_convert_flag_list(flags, msg_flag_table)); + Long_val(len), lwt_convert_flag_list(flags, msg_flag_table)); if (ret == -1) uerror("recv", Nothing); return Val_int(ret); } diff --git a/src/unix/unix_c/unix_bytes_recvfrom.c b/src/unix/unix_c/unix_bytes_recvfrom.c index 1ae1c65a1..b05b221e6 100644 --- a/src/unix/unix_c/unix_bytes_recvfrom.c +++ b/src/unix/unix_c/unix_bytes_recvfrom.c @@ -29,7 +29,7 @@ value lwt_unix_bytes_recvfrom(value fd, value buf, value ofs, value len, socklen_t addr_len; addr_len = sizeof(addr); ret = recvfrom(Int_val(fd), (char *)Caml_ba_data_val(buf) + Long_val(ofs), - Long_val(len), caml_convert_flag_list(flags, msg_flag_table), + Long_val(len), lwt_convert_flag_list(flags, msg_flag_table), &addr.s_gen, &addr_len); if (ret == -1) uerror("recvfrom", Nothing); address = alloc_sockaddr(&addr, addr_len, -1); diff --git a/src/unix/unix_c/unix_bytes_send.c b/src/unix/unix_c/unix_bytes_send.c index 2bdd44a34..558afdd38 100644 --- a/src/unix/unix_c/unix_bytes_send.c +++ b/src/unix/unix_c/unix_bytes_send.c @@ -23,7 +23,7 @@ value lwt_unix_bytes_send(value fd, value buf, value ofs, value len, int ret; ret = send(Int_val(fd), (char *)Caml_ba_array_val(buf)->data + Long_val(ofs), - Long_val(len), caml_convert_flag_list(flags, msg_flag_table)); + Long_val(len), lwt_convert_flag_list(flags, msg_flag_table)); if (ret == -1) uerror("send", Nothing); return Val_int(ret); } diff --git a/src/unix/unix_c/unix_bytes_sendto.c b/src/unix/unix_c/unix_bytes_sendto.c index e9610b895..a555b534f 100644 --- a/src/unix/unix_c/unix_bytes_sendto.c +++ b/src/unix/unix_c/unix_bytes_sendto.c @@ -26,7 +26,7 @@ value lwt_unix_bytes_sendto(value fd, value buf, value ofs, value len, int ret; get_sockaddr(dest, &addr, &addr_len); ret = sendto(Int_val(fd), (char *)Caml_ba_data_val(buf) + Long_val(ofs), - Long_val(len), caml_convert_flag_list(flags, msg_flag_table), + Long_val(len), lwt_convert_flag_list(flags, msg_flag_table), &addr.s_gen, addr_len); if (ret == -1) uerror("send", Nothing); return Val_int(ret); diff --git a/src/unix/unix_c/unix_getnameinfo_job.c b/src/unix/unix_c/unix_getnameinfo_job.c index 8f5e3bbdb..608dcd3bb 100644 --- a/src/unix/unix_c/unix_getnameinfo_job.c +++ b/src/unix/unix_c/unix_getnameinfo_job.c @@ -60,7 +60,7 @@ CAMLprim value lwt_unix_getnameinfo_job(value sockaddr, value opts) { LWT_UNIX_INIT_JOB(job, getnameinfo, 0); get_sockaddr(sockaddr, &job->addr, &job->addr_len); - job->opts = caml_convert_flag_list(opts, getnameinfo_flag_table); + job->opts = lwt_convert_flag_list(opts, getnameinfo_flag_table); return lwt_unix_alloc_job(&job->job); } #endif diff --git a/src/unix/unix_c/unix_open_job.c b/src/unix/unix_c/unix_open_job.c index 0c1be8459..675fc3db6 100644 --- a/src/unix/unix_c/unix_open_job.c +++ b/src/unix/unix_c/unix_open_job.c @@ -113,8 +113,8 @@ static value result_open(struct job_open *job) CAMLprim value lwt_unix_open_job(value name, value flags, value perms) { LWT_UNIX_INIT_JOB_STRING(job, open, 0, name); - job->fd = caml_convert_flag_list(flags, open_cloexec_table); - job->flags = caml_convert_flag_list(flags, open_flag_table); + job->fd = lwt_convert_flag_list(flags, open_cloexec_table); + job->flags = lwt_convert_flag_list(flags, open_flag_table); job->perms = Int_val(perms); return lwt_unix_alloc_job(&(job->job)); } diff --git a/src/unix/unix_c/unix_recv.c b/src/unix/unix_c/unix_recv.c index 4456d7421..d3fec45fb 100644 --- a/src/unix/unix_c/unix_recv.c +++ b/src/unix/unix_c/unix_recv.c @@ -20,7 +20,7 @@ value lwt_unix_recv(value fd, value buf, value ofs, value len, value flags) { int ret; ret = recv(Int_val(fd), &Byte(String_val(buf), Long_val(ofs)), - Long_val(len), caml_convert_flag_list(flags, msg_flag_table)); + Long_val(len), lwt_convert_flag_list(flags, msg_flag_table)); if (ret == -1) uerror("recv", Nothing); return Val_int(ret); } diff --git a/src/unix/unix_c/unix_recvfrom.c b/src/unix/unix_c/unix_recvfrom.c index fd86c247a..2b50a7203 100644 --- a/src/unix/unix_c/unix_recvfrom.c +++ b/src/unix/unix_c/unix_recvfrom.c @@ -27,7 +27,7 @@ value lwt_unix_recvfrom(value fd, value buf, value ofs, value len, value flags) socklen_t addr_len; addr_len = sizeof(addr); ret = recvfrom(Int_val(fd), &Byte(String_val(buf), Long_val(ofs)), - Long_val(len), caml_convert_flag_list(flags, msg_flag_table), + Long_val(len), lwt_convert_flag_list(flags, msg_flag_table), &addr.s_gen, &addr_len); if (ret == -1) uerror("recvfrom", Nothing); address = alloc_sockaddr(&addr, addr_len, -1); diff --git a/src/unix/unix_c/unix_send.c b/src/unix/unix_c/unix_send.c index fc4ba34be..efecc8f41 100644 --- a/src/unix/unix_c/unix_send.c +++ b/src/unix/unix_c/unix_send.c @@ -20,7 +20,7 @@ value lwt_unix_send(value fd, value buf, value ofs, value len, value flags) { int ret; ret = send(Int_val(fd), &Byte(String_val(buf), Long_val(ofs)), - Long_val(len), caml_convert_flag_list(flags, msg_flag_table)); + Long_val(len), lwt_convert_flag_list(flags, msg_flag_table)); if (ret == -1) uerror("send", Nothing); return Val_int(ret); } diff --git a/src/unix/unix_c/unix_sendto.c b/src/unix/unix_c/unix_sendto.c index 8a993e669..845f7edd0 100644 --- a/src/unix/unix_c/unix_sendto.c +++ b/src/unix/unix_c/unix_sendto.c @@ -25,7 +25,7 @@ value lwt_unix_sendto(value fd, value buf, value ofs, value len, value flags, int ret; get_sockaddr(dest, &addr, &addr_len); ret = sendto(Int_val(fd), &Byte(String_val(buf), Long_val(ofs)), - Long_val(len), caml_convert_flag_list(flags, msg_flag_table), + Long_val(len), lwt_convert_flag_list(flags, msg_flag_table), &addr.s_gen, addr_len); if (ret == -1) uerror("send", Nothing); return Val_int(ret); diff --git a/src/unix/unix_c/unix_wait4.c b/src/unix/unix_c/unix_wait4.c index ee0acf5e8..86925c424 100644 --- a/src/unix/unix_c/unix_wait4.c +++ b/src/unix/unix_c/unix_wait4.c @@ -67,7 +67,7 @@ value lwt_unix_wait4(value flags, value pid_req) CAMLlocal2(times, res); int pid, status, cv_flags; - cv_flags = caml_convert_flag_list(flags, wait_flag_table); + cv_flags = lwt_convert_flag_list(flags, wait_flag_table); struct rusage ru; From ac3ba73a9ea7fabcc626c9b4490911af0bcb8886 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Proust?= Date: Thu, 10 Oct 2024 15:32:10 +0200 Subject: [PATCH 2/2] Update src/unix/lwt_unix.h --- src/unix/lwt_unix.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/unix/lwt_unix.h b/src/unix/lwt_unix.h index 125ca7a12..ab4ad64bf 100644 --- a/src/unix/lwt_unix.h +++ b/src/unix/lwt_unix.h @@ -14,6 +14,9 @@ #include #include +// The following macro is for backwards compatibility. +// It is given an `lwt_` prefix to avoid name collisions for code which +// include both this file and alloc.h. #if OCAML_VERSION < 50000 #define lwt_convert_flag_list(flags, table) \ caml_convert_flag_list((flags), (int *)(table))