Windows: stop including <windows.h> from public OIIO headers #3597
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Including windows.h leads to a lot of possibly common names being "taken", mostly by preprocessor defines. Some of these are possible to turn off (like "max" and "min" by defining "NOMINMAX" before including <windows.h>). But many others are not possible to turn off, e.g. "near" and "far" just get defined to nothing, preventing from using variables named like that.
Additionally, includes have a cost, and while <windows.h>, being a C header does not have expensive language constructs that would slow down compilation a lot, it's still something close to 100k lines of preprocessed code to wade through.
Now, only the OIIO implementation .cpp files that actually need <windows.h> include it (all of them under "libutil").
There were two exceptions:
pause()
implementation usesYieldProcessor()
macro when ona Windows system. Replaced it with manually "re-implemented"
things that YieldProcessor expands to. Right now made the
implementation for all 4 platforms that Windows normally supports
(x64, x86, arm, arm64); the latter two OIIO does not support though
when on Windows so it's untested.
Timer::now()
inline function usedQueryPerformanceCounter
and
LARGE_INTEGER
. These are quite hard to somehow "forward-declare"or similar, without resulting in duplicate type definitions. So on
Windows I moved the now() function to be non-inline. A though for another
day: maybe all of that could be replaced by C++
<chrono>
instead.Tests
Existing CI tests.
Checklist:
have previously submitted a Contributor License Agreement
(individual, and if there is any way my
employers might think my programming belongs to them, then also
corporate).
(adding new test cases if necessary).