Skip to content
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

Various cleanups: Store properly-typed function pointers in winapisupp.cpp #4123

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions stl/src/tzdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,14 +378,14 @@ _EXTERN_C

_Info->_Num_time_zones = static_cast<size_t>(_Num_time_zones);
// value-init to ensure __std_tzdb_delete_time_zones() cleanup is valid
if (const auto _Names = new (_STD nothrow) const char* [_Info->_Num_time_zones] {}; _Names) {
if (const auto _Names = new (_STD nothrow) const char* [_Info->_Num_time_zones] {}) {
_Info->_Names = _Names;
} else {
return nullptr;
}

// value-init to ensure __std_tzdb_delete_time_zones() cleanup is valid
if (const auto _Links = new (_STD nothrow) const char* [_Info->_Num_time_zones] {}; _Links) {
if (const auto _Links = new (_STD nothrow) const char* [_Info->_Num_time_zones] {}) {
_Info->_Links = _Links;
} else {
return nullptr;
Expand Down
22 changes: 9 additions & 13 deletions stl/src/winapisupp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,25 @@
#if !defined(_ONECORE)
namespace {

enum wrapKERNEL32Functions {
// Use this macro for defining the following function pointers
#define DEFINEFUNCTIONPOINTER(fn_name) decltype(&fn_name) __KERNEL32Function_##fn_name = nullptr

#if !defined(_CRT_WINDOWS) && !defined(UNDOCKED_WINDOWS_UCRT)
eGetCurrentPackageId,
DEFINEFUNCTIONPOINTER(GetCurrentPackageId);
#endif // !defined(_CRT_WINDOWS) && !defined(UNDOCKED_WINDOWS_UCRT)

#if _STL_WIN32_WINNT < _WIN32_WINNT_WIN8
eGetSystemTimePreciseAsFileTime,
DEFINEFUNCTIONPOINTER(GetSystemTimePreciseAsFileTime);
#endif // _STL_WIN32_WINNT < _WIN32_WINNT_WIN8

eGetTempPath2W,

eMaxKernel32Function
};

PVOID __KERNEL32Functions[eMaxKernel32Function]{};
DEFINEFUNCTIONPOINTER(GetTempPath2W);

// Use this macro for caching a function pointer from a DLL
#define STOREFUNCTIONPOINTER(instance, function_name) \
__KERNEL32Functions[e##function_name] = reinterpret_cast<PVOID>(GetProcAddress(instance, #function_name))
#define STOREFUNCTIONPOINTER(instance, fn_name) \
__KERNEL32Function_##fn_name = reinterpret_cast<decltype(&fn_name)>(GetProcAddress(instance, #fn_name))

// Use this macro for retrieving a cached function pointer from a DLL
#define IFDYNAMICGETCACHEDFUNCTION(name) \
if (const auto pf##name = reinterpret_cast<decltype(&name)>(__KERNEL32Functions[e##name]); pf##name)
#define IFDYNAMICGETCACHEDFUNCTION(fn_name) if (const auto pf##fn_name = __KERNEL32Function_##fn_name)

} // unnamed namespace
#endif // ^^^ !defined(_ONECORE) ^^^
Expand Down