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

Unify MSVC and MinGW-w64 code paths #12769

Merged
merged 2 commits into from
Nov 23, 2023
Merged

Conversation

MisterDA
Copy link
Contributor

MinGW-w64 emulates functions from <unistd.h> using the WinAPI. The MSVC port doesn't provide this header, and we must use the WinAPI directly. In order to have one code path shared by the two ports, we never include <unistd.h> with MinGW-w64 and always use the WinAPI directly in the runtime.

MinGW-w64 emulates usleep (µs-resolution) with Sleep (ms-resolution). We simply call Sleep directly. We have a follow-up plan for higher-resolution sleeps on Windows.

We have checked that in all files used on Windows, unistd.h is guarded by HAS_UNISTD. This can be tested again with grep -R -B1 '<unistd\.h>'.

This goes towards restoring the MSVC port.

Copy link
Contributor

@nojb nojb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't tested it, but the change looks reasonable.

LGTM

Changes Outdated
@@ -178,6 +178,10 @@ Working version
Updates usage of sigprocmask to pthread_sigmask in otherlibs/unix.
(Max Slater, review by Miod Vallat and Xavier Leroy)

- #?????: Unify MSVC and MinGW-w64 code paths, by always using WinAPI
directly.
(David Allsopp, Antonin Décimo, and Samuel Hym, review by ????)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The wording of this changelog entry seems to imply that no other places remain in the code with separate MinGW/MSVC codepaths? Is that the case? If not, I would suggest being more precise (eg mention that this is just about usleep/Sleep or write "Unify some MSVC and MinGW-w64 code paths, ...".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, we were quite surprised that it seems to be the only place in the runtime where there were/could have been different code paths involving <unistd.h>.

@@ -18,8 +18,11 @@

#define CAML_INTERNALS

#include "caml/config.h"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you say a few words about why this included was added?

Copy link
Contributor Author

@MisterDA MisterDA Nov 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's where HAS_UNISTD is defined. If no caml/*.h header is included, as they end up including caml/config.h too, then we don't get this macro. From the Autoconf manual:

The package should ‘#include’ the configuration header file before any other header files, to prevent inconsistencies in declarations (for example, if it redefines const, or if it defines a macro like _FILE_OFFSET_BITS that affects the behavior of system headers).

https://www.gnu.org/software/autoconf/manual/autoconf-2.71/html_node/Configuration-Headers.html

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, thanks.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added a short note about this in the commit message.

@nojb
Copy link
Contributor

nojb commented Nov 22, 2023

(The Changes entry needs to be updated.)

MisterDA and others added 2 commits November 23, 2023 07:53
Co-authored-by: Samuel Hym <samuel.hym@rustyne.lautre.net>
Avoid the MinGW implementation of this library so that the MinGW and
MSVC ports use the same WinAPI code.

Don't define HAS_UNISTD under Windows hosts, always guard its
inclusion with this macro, defined in "caml/config.h".

Co-authored-by: Antonin Décimo <antonin@tarides.com>
Co-authored-by: Samuel Hym <samuel.hym@rustyne.lautre.net>
@MisterDA
Copy link
Contributor Author

Thanks for the review! I've updated the changes entry.

@nojb nojb merged commit 426f1ea into ocaml:trunk Nov 23, 2023
9 checks passed
@MisterDA MisterDA deleted the windows-no-unistd branch November 23, 2023 10:42
@dra27 dra27 mentioned this pull request Feb 1, 2024
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants