test-drop-caches: simplify delay loading of NtSetSystemInformation

Take advantage of the recent addition of support for lazy loading functions[1] on Windows to simplify the loading of NtSetSystemInformation. [1] db2f7c48cb (Win32: simplify loading of DLL functions, 2017-09-25) Signed-off-by: Ben Peart <benpeart@microsoft.com> Reviewed-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ben Peart committed May 1, 2018 at 12:46 UTC 447ed832e5ce50e4dc98dd53e0bbcf3e1a338f35
1 file changed +4 -12
t/helper/test-drop-caches.c
+4 -12
@@ -2,6 +2,7 @@
2 #include "git-compat-util.h"
3
4 #if defined(GIT_WINDOWS_NATIVE)
5 +#include "lazyload.h"
6
7 static int cmd_sync(void)
8 {
@@ -82,8 +83,7 @@ static int cmd_dropcaches(void)
83 {
84 HANDLE hProcess = GetCurrentProcess();
85 HANDLE hToken;
85 - HMODULE ntdll;
86 - DWORD(WINAPI *NtSetSystemInformation)(INT, PVOID, ULONG);
86 + DECLARE_PROC_ADDR(ntdll.dll, DWORD, NtSetSystemInformation, INT, PVOID, ULONG);
87 SYSTEM_MEMORY_LIST_COMMAND command;
88 int status;
89
@@ -95,14 +95,8 @@ static int cmd_dropcaches(void)
95
96 CloseHandle(hToken);
97
98 - ntdll = LoadLibrary("ntdll.dll");
99 - if (!ntdll)
100 - return error("Can't load ntdll.dll, wrong Windows version?");
101 -
102 - NtSetSystemInformation =
103 - (DWORD(WINAPI *)(INT, PVOID, ULONG))GetProcAddress(ntdll, "NtSetSystemInformation");
104 - if (!NtSetSystemInformation)
105 - return error("Can't get function addresses, wrong Windows version?");
98 + if (!INIT_PROC_ADDR(NtSetSystemInformation))
99 + return error("Could not find NtSetSystemInformation() function");
100
101 command = MemoryPurgeStandbyList;
102 status = NtSetSystemInformation(
@@ -115,8 +109,6 @@ static int cmd_dropcaches(void)
109 else if (status != STATUS_SUCCESS)
110 error("Unable to execute the memory list command %d", status);
111
118 - FreeLibrary(ntdll);
119 -
112 return status;
113 }
114