10000 BUG: Fix order of Windows OS detection macros. by mahge · Pull Request #24762 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

BUG: Fix order of Windows OS detection macros. #24762

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

Merged
merged 3 commits into from
Sep 23, 2023
Merged

Conversation

mahge
Copy link
Contributor
@mahge mahge commented Sep 20, 2023
  • The order should be __MINGW32__/__MINGW64__, then _WIN64, and then _WIN32.

    • 64 bit MinGW compilers define _MINGW32__, __MINGW64__, _WIN32, and _WIN64.
    • 32 bit MinGW compilers define __MINGW32__, and _WIN32.
    • 64 bit MSVC compilation defines _WIN32 and _WIN64.
    • 32 bit MSVC compilation defines _WIN32.
  • Closes BUG: Order of OS detection macros (for Windows) seems faulty #24761. See the linked issue for more details.

This is a preliminary PR to accompany issue #24761. Please feel free to close it if there is a more appropriate way to handle it.

  - The order should be `__MINGW32__/__MINGW64__`, then `_WIN64`,
    and then `_WIN32`.

    64 bit MinGW compilers define `_MINGW32__`, `__MINGW64__`, `_WIN32`, and `_WIN64`.
    32 bit MinGW compilers define `__MINGW32__`, and `_WIN32`.
    64 bit MSVC compilation defines `_WIN32` and  `_WIN64`.
    32 bit MSVC compilation defines `_WIN32`.

  - Fixes numpy#24761.
Copy link
Member
@HaoZeke HaoZeke left a comment

Choose a reason for hiding this comment

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

LGTM, thanks @mahge

  - This is better than just relying on the order of evaluation in the whole
    chain. Once Windows is detected (`_WIN32`), handle the possible known
    Windows environments separately.
@mahge mahge requested a review from HaoZeke September 21, 2023 14:43
@@ -19,12 +19,18 @@
#define NPY_OS_SOLARIS
#elif defined(__CYGWIN__)
#define NPY_OS_CYGWIN
/* We are on Windows.*/
#elif defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
Copy link
Contributor
@DimitriPapadopoulos DimitriPapadopoulos Sep 22, 2023

Choose a reason for hiding this comment

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

Perhaps it's time to retire WIN32 and WIN64.

As far as I can understand and according to QM Bites: Understand Windows OS Identification Preprocessor Macros:

  • _WIN32 and _WIN64 are defined by the compiler,
  • WIN32 and WIN64 are defined by the user, to indicate whatever the user chooses them to indicate. They mean 32-bit and 64-bit Windows compilation by convention only.

MSVC has been defining _WIN32 and _WIN64 for a long time, provably at least since Visual Studio 2015, and in practice as early as in the days of 16-bit Windows:

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 agree. I kept them there because they were already there. @HaoZeke should we remove them?

Copy link
Member

Choose a reason for hiding this comment

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

I agree. I kept them there because they were already there. @HaoZeke should we remove them?

Yup, that would be for the best I believe, please go ahead with that, also, thanks for the review and fix @mahge and @DimitriPapadopoulos

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup, that would be for the best I believe, please go ahead with that, also, thanks for the review and fix @mahge and @DimitriPapadopoulos

No problem at all. Fixed in 356325c.

@charris charris added the 09 - Backport-Candidate PRs tagged should be backported label Sep 22, 2023
  - `WIN32`, `__WIN32__`, `WIN64`, `__WIN64__` are not standard macros defined
    by Window compilers.

    It should be enough to check for `_WIN32` and `_WIN64` alone.
Copy link
Member
@HaoZeke HaoZeke left a comment

Choose a reason for hiding this comment

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

LGTM, thanks

@charris charris merged commit 03d3eb1 into numpy:main Sep 23, 2023
@charris
Copy link
Member
charris commented Sep 23, 2023

Thanks @mahge .

@mahge mahge deleted the fix_os_check branch September 24, 2023 10:30
charris pushed a commit to charris/numpy that referenced this pull request Sep 26, 2023
* BUG: Fix order of Windows OS detection macros.

  - The order should be `__MINGW32__/__MINGW64__`, then `_WIN64`,
    and then `_WIN32`.

    64 bit MinGW compilers define `_MINGW32__`, `__MINGW64__`, `_WIN32`, and `_WIN64`.
    32 bit MinGW compilers define `__MINGW32__`, and `_WIN32`.
    64 bit MSVC compilation defines `_WIN32` and  `_WIN64`.
    32 bit MSVC compilation defines `_WIN32`.

  - Fixes numpy#24761.

* Adjust the structure slightly and add comments.

  - This is better than just relying on the order of evaluation in the whole
    chain. Once Windows is detected (`_WIN32`), handle the possible known
    Windows environments separately.

* Remove check for non-standard macros.

  - `WIN32`, `__WIN32__`, `WIN64`, `__WIN64__` are not standard macros defined
    by Window compilers.

    It should be enough to check for `_WIN32` and `_WIN64` alone.
@charris charris removed the 09 - Backport-Candidate PRs tagged should be backported label Sep 26, 2023
charris pushed a commit to charris/numpy that referenced this pull request Nov 11, 2023
* BUG: Fix order of Windows OS detection macros.

  - The order should be `__MINGW32__/__MINGW64__`, then `_WIN64`,
    and then `_WIN32`.

    64 bit MinGW compilers define `_MINGW32__`, `__MINGW64__`, `_WIN32`, and `_WIN64`.
    32 bit MinGW compilers define `__MINGW32__`, and `_WIN32`.
    64 bit MSVC compilation defines `_WIN32` and  `_WIN64`.
    32 bit MSVC compilation defines `_WIN32`.

  - Fixes numpy#24761.

* Adjust the structure slightly and add comments.

  - This is better than just relying on the order of evaluation in the whole
    chain. Once Windows is detected (`_WIN32`), handle the possible known
    Windows environments separately.

* Remove check for non-standard macros.

  - `WIN32`, `__WIN32__`, `WIN64`, `__WIN64__` are not standard macros defined
    by Window compilers.

    It should be enough to check for `_WIN32` and `_WIN64` alone.
@TimotheusBachinger TimotheusBachinger mentioned this pull request Nov 25, 2024
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.

BUG: Order of OS detection macros (for Windows) seems faulty
4 participants
0