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
Ensure C global symbols are consistently prefixed #10926
Conversation
Thank you for the clean-up work, it's definitely useful! You wrote that In perfect hindsight, for the Unix library, it would make sense to use |
This PR needs to be rebased and adapted to the recent removal of otherlibs/win32unix. I'm still mildly in favor of this PR, but the 5.0 window is closing, and we need to focus our changes. |
Rebased - updates to follow. |
I've added some commits which eliminate the use of Separately, I'll kick off a health-check run to how widespread |
Seems reasonable to me. I also support the change from |
David Allsopp (2022/05/25 03:53 -0700):
I've added some commits which eliminate the use of `win_` as a prefix completely ***@***.***, @nojb - thoughts + opinions?). In a few cases, we have identically-behaving primitives between what was win32unix and unix but with different names.
Separately, I'll kick off a health-check run to how widespread
`uerror` really is and also just how bad renaming all the C symbols to
be `caml_unix_` actually would be.
This all sounds really cool! Thanks!
|
Even if |
And perhaps (I don't think we're doing it already) explain in the manual that the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had a quick look at the changes, nothing amiss except yacc.
My vote also goes to caml_unix
although this means the PR will touch 150 files instead of 83.
Damien Doligez (2022/05/25 05:59 -0700):
@damiendoligez approved this pull request.
Had a quick look at the changes, nothing amiss except yacc.
My vote also goes to `caml_unix` although this means the PR will touch 150 files instead of 83.
> +int caml_win32_wide_char_to_multi_byte(const wchar_t *s, int slen,
+ char *out, int outlen)
Do we really want to touch `ocamlyacc`? This is a standalone program
that doesn't export any libraries.
It seems to me it's nice to keep it in sync with the rest of the files,
although there is no risk of interferring.
|
So, just before I pause for a week:
However, I'm not sure this means adding one or both of those additional commits is a bad idea (especially as the fixes where needed in libraries is really quite easy), but a different strategy for bulk testing might be in order. It would be relatively simple to hack Asmlibrarian and Bytelibrarian temporarily to check for the old primitive names, but I won't get to that before 6 June. Either way, there's still a little bit of time to decide whether this wants to be in alpha1 or not. |
Work towards eliminating win_ symbols.
I agree. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good except for one misplaced macro.
otherlibs/unix/socketaddr.h
Outdated
#define get_sockaddr caml_unix_get_sockaddr | ||
#define alloc_sockaddr caml_unix_alloc_sockaddr | ||
#define alloc_inet_addr caml_unix_alloc_inet_addr | ||
#define alloc_inet6_addr caml_unix_alloc_inet6_addr |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd move this one inside the #ifdef HAS_IPV6
on line 84.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea, yes!
diff --git a/otherlibs/unix/socketaddr.h b/otherlibs/unix/socketaddr.h
index 66e7b02aac..768669d0cc 100644
--- a/otherlibs/unix/socketaddr.h
+++ b/otherlibs/unix/socketaddr.h
@@ -69,7 +69,6 @@ extern "C" {
#define get_sockaddr caml_unix_get_sockaddr
#define alloc_sockaddr caml_unix_alloc_sockaddr
#define alloc_inet_addr caml_unix_alloc_inet_addr
-#define alloc_inet6_addr caml_unix_alloc_inet6_addr
#endif /* CAML_BUILDING_UNIX */
extern void caml_unix_get_sockaddr (value mladdr,
@@ -84,7 +83,12 @@ extern value caml_unix_alloc_inet_addr (struct in_addr * inaddr);
#ifdef HAS_IPV6
extern value caml_unix_alloc_inet6_addr (struct in6_addr * inaddr);
#define GET_INET6_ADDR(v) (*((struct in6_addr *) (v)))
-#endif
+
+/* Compatibility definition for the pre-5.0 name of this function */
+#ifndef CAML_BUILDING_UNIX
+#define alloc_inet6_addr caml_unix_alloc_inet6_addr
+#endif /* CAML_BUILDING_UNIX */
+#endif /* HAS_IPV6 */
#ifdef __cplusplus
}
Thanks, @damiendoligez - I also added you to the |
Before merging, wait for @Octachron to finish his own review. |
ACK |
This is a great line of work, thanks for working on it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can confirm that the changes look good even with a third pair of eyes.
@@ -34,7 +34,7 @@ | |||
UDP (datagram) sockets. | |||
Returns 0 if OK, a nonzero error code if error. */ | |||
|
|||
static int unix_check_stream_semantics(int fd) | |||
static int caml_unix_check_stream_semantics(int fd) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one doesn't need the caml_unix_
prefix, it's static, and the Windows file doesn't have it.
(oops, too late).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fortunately, since the function is static, renaming it is not a breaking change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There're a few static symbols which could get simplified names in future, yes! (there's caml_unix_error_exn
as well). Wood for the trees, 'n all that 🙂
Ensure C global symbols are consistently prefixed (cherry picked from commit 000d15d)
(cherry picked from commit 0dc4924)
Would it be sensible to have a CI job that ensures all global symbols in (e.g.) libasmrun.a contain a |
Thanks, @hannesm! Thank you also to everyone for the reviewing time on this - these changes in 5.0 are obviously insignificant next to the headline features, but it's very pleasing to have been able to use the major version bump to correct them.
There already is 🙂 It was updated as part of this PR. It's done |
CHANGES: * Ensure compatibility with OCaml 5.0, after `uerror` change (ocaml/ocaml#10926) (mirage/mirage-block-unix#115, @dra27)
This PR starts out from upstreaming a change which has been carried for some time in opam-repository-mingw. The compilers there add a prefix to the
list_
functions inwinlist.c
.win_multi_byte_to_wide_char
andwin_wide_char_to_multi_byte
have the prefixwin_
changed tocaml_
. They're internal - the actual conversions should be done using macros.unix_
with the exception ofuerror
.win_
have stayed that way (for now).tools/check-symbol-names
has been updated with these changes.We could change the last remaining functions in win32unix if we wanted. They are:
win_CRT_fd_of_filedescr
,win_filedescr_of_channel
,win_handle_fd
,win_inchannel_of_filedescr
,win_outchannel_of_filedescr
,win_clear_close_on_exec
,win_set_close_on_exec
,win_create_process
,win_create_process_native
,win_terminate_process
,win_cleanup
,win_startup
,win_system
,win_alloc_handle
,win_alloc_socket
,win_set_inherit
,win_findclose
,win_findfirst
,win_findnext
,win_waitpid
. At present, win32unix specifically is allowed to havewin_
as a prefix.Thoughts on this so far welcomed. I'm very happy to split off bits which are acceptable (e.g. the two
win_
functions in the runtime) as approved. It won't be a zero-impact change as there are libraries which hack into the internals of the Unix library, but it's a very detectable change - if we're happy to go ahead, we can do some pre-emptive checking in opam-repository for affected packages.