Skip to content

Conversation

@sethk
Copy link
Contributor

@sethk sethk commented Apr 1, 2025

  • Copy __builtin_clz wrapper into another source file.
  • mode_t is not defined on _WIN32
  • Avoid arithmetic on void *
  • Try to thin out of use of <windows.h>

- Copy __builtin_clz wrapper into another source file.
- mode_t is not defined on _WIN32
- Avoid arithmetic on void *
- Try to thin out of use of <windows.h>
@sethk sethk force-pushed the sethk_msvc_misc branch from 4f7f5f5 to d995910 Compare April 1, 2025 07:11
sethk added 2 commits April 1, 2025 00:22
This avoids bringing in all of windows.h, but should work with both MSVC
and MINGW64.
@sethk sethk force-pushed the sethk_msvc_misc branch from 61e82be to 8d65d10 Compare April 1, 2025 07:56
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
Copy link
Collaborator

Choose a reason for hiding this comment

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

You are guarding all of these headers, but if you don't have any of these the code will fail to compile. Is that right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry about the massive delay getting back to this, had to ship a demo.

Different combinations of headers are required for different runtimes. Most systems put many things into unistd.h, and then there's MSVC/UCRT, which doesn't have unistd.h, but instead isatty() and mkdir() are provided by corecrt_io.h and direct.h, respectively. MINGW64 defines _WIN32 but has unistd.h and lacks corecrt_io.h, meaning that we can't just use #ifdef _WIN32 to guard that. These header tests seem like the simplest way to address the full build matrix.

I have another change that checks for malloc.h/alloca.h so it can use alloca() in place of variable-length arrays. I separated it from this one because I think it could be more controversial.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Forgot to mention: I revised this patch with some comments to clarify why each header is used. It's true that I could have done:

#ifdef HAVE_OTHER_HEADER_H
#include <other_header.h> // foo()
#elif defined(HAVE_UNISTD_H)
#include <unistd.h>
#else
#error "Don't know which header defines foo() on this system"
#endif

But unistd.h also has a ton of other stuff, and the pattern I used is one I've seen in many autoconf-based projects.

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