Various cleanups: Store properly-typed function pointers in winapisupp.cpp
#4123
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.
winapisupp.cpp
: Use separate function pointers with proper types, instead of enumerators into an array ofPVOID
.This is within an unnamed namespace (after #2841 dramatically simplified the code), so we can freely modify this machinery.
Originally, the function pointer table's ordering seemed really important to us, and we were scared about adding/removing/reordering entries. #2841 showed that those fears were unfounded, but it was changing a ton of code so I didn't eliminate the table entirely at that time.
The table wasn't buying us anything - we were able to properly size it via
eMaxKernel32Function
, but we still had to mention every function to manually form theeMeow
enumerators. By introducingDEFINEFUNCTIONPOINTER
, we can spend the same number of lines to form separate global variables, which will still consume the same amount of memory as the array (they're just pointers, they pack perfectly either way).I'm naming these function pointers
__KERNEL32Function_##fn_name
with an underscore in the middle for clarity, e.g.__KERNEL32Function_GetTempPath2W
. I thought about omittingFunction
but it seems reasonable here. The advantage of this technique is that every function pointer can be given the correct typedecltype(&fn_name)
. We need to adjust how we cast the return value ofGetProcAddress()
, but then we don't need to cast when reading the variable later.Note that
IFDYNAMICGETCACHEDFUNCTION
still formsconst auto pf##fn_name
to defend against modifying the cache unintentionally, and to provide a nice namepfMeow
for the code that follows its usage.Finally, I'm changing all of the macro parameter names to
fn_name
for consistency.@frederick-vs-ja noticed an opportunity to simplify
if (T meow = init; meow)
toif (T meow = init)
; I also found a couple of lines instl/src/tzdb.cpp
that could benefit.