]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
test3026: reduce runtime in legacy mingw builds
authorJay Satiro <raysatiro@yahoo.com>
Mon, 14 Nov 2022 09:07:30 +0000 (04:07 -0500)
committerJay Satiro <raysatiro@yahoo.com>
Fri, 18 Nov 2022 07:54:57 +0000 (02:54 -0500)
- Load Windows system libraries secur32 and iphlpapi beforehand, so
  that libcurl's repeated global init/cleanup only increases/decreases
  the library's refcount rather than causing it to load/unload.

Assisted-by: Marc Hoersken
Closes https://github.com/curl/curl/pull/9412

tests/libtest/lib3026.c
tests/libtest/testutil.c
tests/libtest/testutil.h

index 8ad7e949024359ad905de07747655b5af67a8cbf..41389eb7a6d9a9f2a55f14591fcdedc068183ca2 100644 (file)
@@ -69,6 +69,14 @@ int test(char *URL)
     return -1;
   }
 
+  /* On Windows libcurl global init/cleanup calls LoadLibrary/FreeLibrary for
+     secur32.dll and iphlpapi.dll. Here we load them beforehand so that when
+     libcurl calls LoadLibrary/FreeLibrary it only increases/decreases the
+     library's refcount rather than actually loading/unloading the library,
+     which would affect the test runtime. */
+  (void)win32_load_system_library(TEXT("secur32.dll"));
+  (void)win32_load_system_library(TEXT("iphlpapi.dll"));
+
   for(i = 0; i < tid_count; i++) {
     curl_win_thread_handle_t th;
     results[i] = CURL_LAST; /* initialize with invalid value */
index a46e0f9fc1340081b47cf7958094c0d4935ec526..0d77aa227abf0878c0cf7946716fa59b1cb90713 100644 (file)
@@ -117,7 +117,6 @@ long tutil_tvdiff(struct timeval newer, struct timeval older)
     (long)(newer.tv_usec-older.tv_usec)/1000;
 }
 
-
 /*
  * Same as tutil_tvdiff but with full usec resolution.
  *
@@ -130,3 +129,34 @@ double tutil_tvdiff_secs(struct timeval newer, struct timeval older)
       (double)(newer.tv_usec-older.tv_usec)/1000000.0;
   return (double)(newer.tv_usec-older.tv_usec)/1000000.0;
 }
+
+#ifdef WIN32
+HMODULE win32_load_system_library(const TCHAR *filename)
+{
+  size_t filenamelen = _tcslen(filename);
+  size_t systemdirlen = GetSystemDirectory(NULL, 0);
+  size_t written;
+  TCHAR *path;
+
+  if(!filenamelen || filenamelen > 32768 ||
+     !systemdirlen || systemdirlen > 32768)
+    return NULL;
+
+  /* systemdirlen includes null character */
+  path = malloc(sizeof(TCHAR) * (systemdirlen + 1 + filenamelen));
+  if(!path)
+    return NULL;
+
+  /* if written >= systemdirlen then nothing was written */
+  written = GetSystemDirectory(path, (unsigned int)systemdirlen);
+  if(!written || written >= systemdirlen)
+    return NULL;
+
+  if(path[written - 1] != _T('\\'))
+    path[written++] = _T('\\');
+
+  _tcscpy(path + written, filename);
+
+  return LoadLibrary(path);
+}
+#endif
index 94550fc01499ca4ef3b3dd40b74c7ecd48d1df23..106cd86759f47a480d515b2304fb0e7315bff6ca 100644 (file)
@@ -42,5 +42,8 @@ long tutil_tvdiff(struct timeval t1, struct timeval t2);
  */
 double tutil_tvdiff_secs(struct timeval t1, struct timeval t2);
 
+#ifdef WIN32
+HMODULE win32_load_system_library(const TCHAR *filename);
+#endif
 
 #endif  /* HEADER_CURL_LIBTEST_TESTUTIL_H */