diff --git a/src/extension/extension.cpp b/src/extension/extension.cpp index f8ed2d6f283..ea57b31f28b 100644 --- a/src/extension/extension.cpp +++ b/src/extension/extension.cpp @@ -11,16 +11,6 @@ #include "main/database.h" #include "transaction/transaction.h" -#ifdef _WIN32 - -#include "windows.h" -#define RTLD_NOW 0 -#define RTLD_LOCAL 0 - -#else -#include -#endif - namespace kuzu { namespace extension { diff --git a/src/include/extension/extension.h b/src/include/extension/extension.h index d11fcd741d6..0729a532887 100644 --- a/src/include/extension/extension.h +++ b/src/include/extension/extension.h @@ -6,6 +6,17 @@ #include "common/api.h" #include "function/function.h" #include "main/db_config.h" +#include "common/exception/io.h" + +#ifdef _WIN32 + +#include "windows.h" +#define RTLD_NOW 0 +#define RTLD_LOCAL 0 + +#else +#include +#endif #define ADD_FUNC(FUNC_STRUCT) \ kuzu::extension::ExtensionUtils::registerFunctionSet(db, std::string(FUNC_STRUCT::name), \ @@ -125,5 +136,33 @@ struct ExtensionOptions { main::ExtensionOption* getExtensionOption(std::string name); }; +#ifdef _WIN32 +std::wstring utf8ToUnicode(const char* input) { + uint32_t result; + + result = MultiByteToWideChar(CP_UTF8, 0, input, -1, nullptr, 0); + if (result == 0) { + throw common::IOException("Failure in MultiByteToWideChar"); + } + auto buffer = std::make_unique(result); + result = MultiByteToWideChar(CP_UTF8, 0, input, -1, buffer.get(), result); + if (result == 0) { + throw common::IOException("Failure in MultiByteToWideChar"); + } + return std::wstring(buffer.get(), result); +} + +void* dlopen(const char* file, int /*mode*/) { + KU_ASSERT(file); + auto fpath = utf8ToUnicode(file); + return (void*)LoadLibraryW(fpath.c_str()); +} + +void* dlsym(void* handle, const char* name) { + KU_ASSERT(handle); + return (void*)GetProcAddress((HINSTANCE)handle, name); +} +#endif + } // namespace extension } // namespace kuzu diff --git a/src/processor/operator/simple/load_extension.cpp b/src/processor/operator/simple/load_extension.cpp index b5e66a3dccd..420069996c2 100644 --- a/src/processor/operator/simple/load_extension.cpp +++ b/src/processor/operator/simple/load_extension.cpp @@ -15,34 +15,6 @@ std::string LoadExtensionPrintInfo::toString() const { return "Load " + extensionName; } -#ifdef _WIN32 -std::wstring utf8ToUnicode(const char* input) { - uint32_t result; - - result = MultiByteToWideChar(CP_UTF8, 0, input, -1, nullptr, 0); - if (result == 0) { - throw IOException("Failure in MultiByteToWideChar"); - } - auto buffer = std::make_unique(result); - result = MultiByteToWideChar(CP_UTF8, 0, input, -1, buffer.get(), result); - if (result == 0) { - throw IOException("Failure in MultiByteToWideChar"); - } - return std::wstring(buffer.get(), result); -} - -void* dlopen(const char* file, int /*mode*/) { - KU_ASSERT(file); - auto fpath = utf8ToUnicode(file); - return (void*)LoadLibraryW(fpath.c_str()); -} - -void* dlsym(void* handle, const char* name) { - KU_ASSERT(handle); - return (void*)GetProcAddress((HINSTANCE)handle, name); -} -#endif - static void executeExtensionLoader(main::ClientContext* context, const std::string& extensionName) { auto loaderPath = ExtensionUtils::getLocalPathForExtensionLoader(context, extensionName); if (context->getVFSUnsafe()->fileOrPathExists(loaderPath)) {