Skip to content

Use caml_unix_get_sockaddr instead of its legacy name get_sockaddr#1100

Merged
raphael-proust merged 2 commits intoocsigen:masterfrom
kit-ty-kate:ocaml-5.5
Feb 23, 2026
Merged

Use caml_unix_get_sockaddr instead of its legacy name get_sockaddr#1100
raphael-proust merged 2 commits intoocsigen:masterfrom
kit-ty-kate:ocaml-5.5

Conversation

@kit-ty-kate
Copy link
Contributor

This adds support for OCaml 5.5 to lwt due to the change of definition of caml_unix_get_sockaddr in ocaml/ocaml#14310 which triggers the following failure:

File "src/unix/dune", line 92, characters 3-18:    
92 |    unix_bytes_recv
        ^^^^^^^^^^^^^^^
In file included from lwt_unix.h:14,
                 from unix_bytes_recv.c:17:
/home/kit_ty_kate/.opam/5.5/lib/ocaml/caml/socketaddr.h:117:5: error: expected declaration specifiers or ‘...’ before ‘(’ token
  117 |     (vaddr),                                                  \
      |     ^
/home/kit_ty_kate/.opam/5.5/lib/ocaml/caml/socketaddr.h:69:22: note: in expansion of macro ‘caml_unix_get_sockaddr’
   69 | #define get_sockaddr caml_unix_get_sockaddr
      |                      ^~~~~~~~~~~~~~~~~~~~~~
unix_recv_send_utils.h:48:13: note: in expansion of macro ‘get_sockaddr’
   48 | extern void get_sockaddr(value mladdr, union sock_addr_union *addr /*out*/,
      |             ^~~~~~~~~~~~

@kit-ty-kate
Copy link
Contributor Author

Some extra reasoning for the way i've done things in this PR: ocaml/ocaml#14516 (comment)

@raphael-proust
Copy link
Collaborator

There's

File "test/react/dune", line 2, characters 7-11:
2 |  (name main)
           ^^^^
(cd _build/default && /home/runner/work/lwt/lwt/_opam/bin/ocamlopt.opt -w @1..3@5..28@31..39@43@46..47@49..57@61..62@67@69-40 -strict-sequence -strict-formats -short-paths -keep-locs -g -o test/react/main.exe src/core/lwt.cmxa /home/runner/work/lwt/lwt/_opam/lib/react/react.cmxa src/react/lwt_react.cmxa /home/runner/work/lwt/lwt/_opam/lib/ocaml/unix.cmxa -I /home/runner/work/lwt/lwt/_opam/lib/ocaml /home/runner/work/lwt/lwt/_opam/lib/ocaml/bigarray.cmxa -I /home/runner/work/lwt/lwt/_opam/lib/ocaml /home/runner/work/lwt/lwt/_opam/lib/ocplib-endian/ocplib_endian.cmxa /home/runner/work/lwt/lwt/_opam/lib/ocplib-endian/bigstring/ocplib_endian_bigstring.cmxa /home/runner/work/lwt/lwt/_opam/lib/ocaml/threads/threads.cmxa -I /home/runner/work/lwt/lwt/_opam/lib/ocaml src/unix/lwt_unix.cmxa -I src/unix test/lwttester.cmxa test/react/.main.eobjs/native/dune__exe.cmx test/react/.main.eobjs/native/dune__exe__Test_lwt_event.cmx test/react/.main.eobjs/native/dune__exe__Test_lwt_signal.cmx test/react/.main.eobjs/native/dune__exe__Main.cmx)
/usr/bin/ld: src/unix/liblwt_unix_stubs.a(unix_getnameinfo_job.o): in function `lwt_unix_getnameinfo_job':
/home/runner/work/lwt/lwt/_build/default/src/unix/unix_getnameinfo_job.c:62:(.text+0x1cc): undefined reference to `caml_unix_get_sockaddr'
/usr/bin/ld: src/unix/liblwt_unix_stubs.a(unix_bind_job.o): in function `lwt_unix_bind_job':
/home/runner/work/lwt/lwt/_build/default/src/unix/unix_bind_job.c:45:(.text+0xc2): undefined reference to `caml_unix_get_sockaddr'
collect2: error: ld returned 1 exit status
File "caml_startup", line 1:
Error: Error during linking (exit code 1)

on 4.14

investigating

@raphael-proust
Copy link
Collaborator

fix

commit 56c1d293b7ce86e271c686a2a8908f81c4861155
Author: Raphaël Proust <code@bnwr.net>
Date:   Mon Feb 23 09:53:06 2026 +0100

    add missing macro def to some .c files

diff --git a/src/unix/unix_c/unix_bind_job.c b/src/unix/unix_c/unix_bind_job.c
index c34c24fcb..6edfcf277 100644
--- a/src/unix/unix_c/unix_bind_job.c
+++ b/src/unix/unix_c/unix_bind_job.c
@@ -14,6 +14,10 @@
 #include <sys/types.h>
 #include <sys/socket.h>
 
+#if OCAML_VERSION_MAJOR < 5
+#define caml_unix_get_sockaddr get_sockaddr
+#endif
+
 #include "lwt_unix.h"
 
 struct job_bind {
diff --git a/src/unix/unix_c/unix_getnameinfo_job.c b/src/unix/unix_c/unix_getnameinfo_job.c
index ccc37322a..68f9eb52d 100644
--- a/src/unix/unix_c/unix_getnameinfo_job.c
+++ b/src/unix/unix_c/unix_getnameinfo_job.c
@@ -16,6 +16,10 @@
 #include <netdb.h>
 #include <sys/socket.h>
 
+#if OCAML_VERSION_MAJOR < 5
+#define caml_unix_get_sockaddr get_sockaddr
+#endif
+
 #include "lwt_unix.h"
 
 struct job_getnameinfo {

I think at some point I need to revisit all the defs and such, there might be some common patterns that would be better pulled together in a single file.

@raphael-proust raphael-proust merged commit 12b20c1 into ocsigen:master Feb 23, 2026
40 of 56 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants