================
@@ -0,0 +1,46 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLDB_HOST_WINDOWS_LAZYIMPORT_H
+#define LLDB_HOST_WINDOWS_LAZYIMPORT_H
+
+#include "lldb/Host/windows/windows.h"
+
+namespace lldb_private {
+
+template <typename FnPtr> class LazyImport {
+public:
+  constexpr LazyImport(const wchar_t *dll, const char *symbol)
+      : m_dll(dll), m_symbol(symbol) {}
+
+  /// Returns the resolved function pointer, or nullptr if the DLL or symbol
+  /// is unavailable on this system. Resolution happens once.
+  FnPtr get() const {
+    static FnPtr resolved = Resolve(m_dll, m_symbol);
----------------
Nerixyz wrote:

This static is unique per function signature, not per function (name/dll). So 
if you have `void doFoo()` and `void doBar()` that you import, you'd create two 
`LazyImport<void(*)()>`, but they would return the function that was first 
resolved with `get()`.

I think you could fix this if you resolve the function in the constructor and 
only save the pointer to it (most importantly it would remove this `static`).

https://github.com/llvm/llvm-project/pull/199983
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to