windows: use built-in _WIN32 macro to detect Windows#12376
Conversation
- Warn via checksrc if symbol WIN32 is used in preprocessor lines.
|
My initial reaction to this was it's unnecessary, even though it is "more correct". We already use WIN32 and it works fine. However it is, yes, more correct. My biggest concern I think is that we will occasionally forget WIN32 is now _WIN32 and make the mistake of using the former. To that end I've added a checksrc warning category BANNEDPREPROC that checks for banned symbols (eg WIN32) on preprocessor lines. |
- Suppress checksrc warning WIN32 macro eval for CURL_WIN32
|
Good idea to make I'm thinking to sync
This would be a reboot of 1adebe7 What do you think? |
|
I struggle to think of when _WIN32 isn't available. Let's see if anyone else has anything to say on it... Ref: #4855 |
|
Some references:
One list mentions Borland C++, so I made a test with Can't think of more niche compilers that are still around. But if there are, they can almost certainly set |
| #if (defined(_WIN32) || \ | ||
| defined(WIN32) /* !checksrc! disable BANNEDPREPROC 1 */ || \ | ||
| defined(__WIN32__)) && \ | ||
| !defined(__SYMBIAN32__) |
There was a problem hiding this comment.
It's curious that
_WIN32or__WIN32__could end up together with__SYMBIAN32__, so that it had to be guarded-out.
It's been too long for me to recall for certain, but it may have been for x86 builds targeting the Symbian emulator running on Win32.
bagder
left a comment
There was a problem hiding this comment.
I'm fine with also removing CURL_WIN32 from the public header. We never documented it for any purpose. It is mentioned in symbols-in-version simply because it is present in curl.h but I don't think we break any promises (API/ABI) by taking it away again.
This is a reboot of 1adebe7 and 8bd863f + curl#4854 + curl#4855, but instead of keeping around CURL_WIN32 as a replacement for our local WIN32 we just rely on _WIN32, which works universally out of the box. Ref: curl#12376 (comment)
``` Missing symbols mentioned in symbols-in-versions Add them to a header, or mark them as removed. CURL_WIN32 ``` Ref: https://github.com/curl/curl/actions/runs/6956411932/job/18927212026#step:11:1957
This fix was supposed to be committed earlier, but ended up missing from the final commit. Follow-up to e9a7d4a curl#12376 Closes #xxxxx
Follow-up to e9a7d4a curl#12376
Follow-up to e9a7d4a curl#12376 Closes curl#14963
Windows compilers define
_WIN32automatically. Windows SDK headersor build env defines
WIN32, or we have to take care of it. Theagreement seems to be that
_WIN32is the preferred practice here.Make the source code rely on that to detect we're building for Windows.
Public
curl.hwas usingWIN32,__WIN32__andCURL_WIN32forWindows detection, next to the official
_WIN32. After this patch itonly uses
_WIN32for this. Also, make it stop definingCURL_WIN32.There is a slight chance these break compatibility with Windows
compilers that fail to define
_WIN32. I'm not aware of any obsoleteor modern compiler affected, but in case there is one, one possible
solution is to define this macro manually.
grepping for
WIN32remains useful to discover Windows-specific code.Also:
extend
checksrcto ensure we're not usingWIN32anymore.apply minor formatting here and there.
delete unnecessary checks for
!MSDOSwhen_WIN32is present.Closes #12376