Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
acquamarin committed Aug 21, 2024
1 parent 79f4456 commit 18ada1c
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 38 deletions.
10 changes: 0 additions & 10 deletions src/extension/extension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <dlfcn.h>
#endif

namespace kuzu {
namespace extension {

Expand Down
39 changes: 39 additions & 0 deletions src/include/extension/extension.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <dlfcn.h>
#endif

#define ADD_FUNC(FUNC_STRUCT) \
kuzu::extension::ExtensionUtils::registerFunctionSet(db, std::string(FUNC_STRUCT::name), \
Expand Down Expand Up @@ -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<wchar_t[]>(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
28 changes: 0 additions & 28 deletions src/processor/operator/simple/load_extension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<wchar_t[]>(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)) {
Expand Down

0 comments on commit 18ada1c

Please sign in to comment.