Skip to content

Commit

Permalink
Fixed add_extension() for Unicode paths on Windows. (#25797)
Browse files Browse the repository at this point in the history
### Details:
 - Fixed add_extension() for Unicode paths on Windows.
 
### Tickets:
 - 146200
  • Loading branch information
popovaan authored Jul 30, 2024
1 parent a009b19 commit 7d59f52
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/common/util/src/os/win/win_shared_object_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@
namespace ov {
namespace util {
std::shared_ptr<void> load_shared_object(const char* path) {
#if defined(OPENVINO_ENABLE_UNICODE_PATH_SUPPORT) && defined(_WIN32)
return ov::util::load_shared_object(ov::util::string_to_wstring(path).c_str());
#else
void* shared_object = nullptr;
using GetDllDirectoryA_Fnc = DWORD (*)(DWORD, LPSTR);
GetDllDirectoryA_Fnc IEGetDllDirectoryA = nullptr;
Expand Down Expand Up @@ -113,6 +116,7 @@ std::shared_ptr<void> load_shared_object(const char* path) {
return {shared_object, [](void* shared_object) {
FreeLibrary(reinterpret_cast<HMODULE>(shared_object));
}};
#endif
}

#ifdef OPENVINO_ENABLE_UNICODE_PATH_SUPPORT
Expand Down
23 changes: 23 additions & 0 deletions src/core/tests/extension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "openvino/core/extension.hpp"

#include <gtest/gtest.h>
#include <stdio.h>

#include "common_test_utils/file_utils.hpp"
#include "openvino/core/graph_util.hpp"
Expand All @@ -18,10 +19,32 @@ inline std::string get_extension_path() {
std::string("openvino_template_extension") + OV_BUILD_POSTFIX);
}

inline std::wstring get_extension_wdir() {
std::wstring dir = ov::util::string_to_wstring(ov::test::utils::getExecutableDirectory());
dir.push_back(ov::util::FileTraits<wchar_t>::file_separator);
dir += ov::util::string_to_wstring("晚安_путь_к_файлу");
dir.push_back(ov::util::FileTraits<wchar_t>::file_separator);
ov::util::create_directory_recursive(dir);
return dir;
}

TEST(extension, load_extension) {
EXPECT_NO_THROW(ov::detail::load_extensions(get_extension_path()));
}

#if defined(_WIN32)
TEST(extension, load_extension_wstring) {
std::wstring wdir = get_extension_wdir();
std::wstring wdir_ext_path = wdir + ov::util::string_to_wstring(ov::util::make_plugin_library_name<char>(
"",
std::string("openvino_template_extension") + OV_BUILD_POSTFIX));
_wrename(ov::util::string_to_wstring(get_extension_path()).c_str(), wdir_ext_path.c_str());
EXPECT_NO_THROW(ov::detail::load_extensions(wdir_ext_path));
_wrename(wdir_ext_path.c_str(), ov::util::string_to_wstring(get_extension_path()).c_str());
_wrmdir(wdir.c_str());
}
#endif

TEST(extension, load_extension_and_cast) {
std::vector<ov::Extension::Ptr> so_extensions = ov::detail::load_extensions(get_extension_path());
ASSERT_LE(1, so_extensions.size());
Expand Down

0 comments on commit 7d59f52

Please sign in to comment.