OpenVINO™ is an open source toolkit for optimizing and deploying AI inference
C++ aicomputer-visiondeep-learningdeploy-aidiffusion-modelsgenerative-aigood-first-issueinferencellm-inferencenatural-language-processingnlpopenvinooptimize-aiperformance-boostrecommendation-systemspeech-recognitionstable-diffusiontransformersyolo
[FE] Use ov::util::path_to_string for frontend plugin filename conversion (#35974)
Jaskaran Singh Nagi828eb533e6a1
diff --git a/src/common/util/include/openvino/util/wstring_convert_util.hpp b/src/common/util/include/openvino/util/wstring_convert_util.hppindex 165a0b1fee6..731a36c0919 100644--- a/src/common/util/include/openvino/util/wstring_convert_util.hpp+++ b/src/common/util/include/openvino/util/wstring_convert_util.hpp@@ -9,6 +9,16 @@#include "openvino/util/util.hpp"+/// @brief Widens a narrow string literal to a native path literal.+/// On Windows (where std::filesystem::path::value_type is wchar_t) this prepends L.+/// On other platforms it is a no-op.+#ifdef _WIN32+# define OV_WSTR_IMPL(s) L##s+# define OV_WSTR(s) OV_WSTR_IMPL(s)+#else+# define OV_WSTR(s) s+#endif+namespace ov::util {#ifdef OPENVINO_ENABLE_UNICODE_PATH_SUPPORTdiff --git a/src/core/tests/frontend/frontend_manager.cpp b/src/core/tests/frontend/frontend_manager.cppindex 2feef4a283a..64906193ef3 100644--- a/src/core/tests/frontend/frontend_manager.cpp+++ b/src/core/tests/frontend/frontend_manager.cpp@@ -5,8 +5,10 @@#include <gmock/gmock.h>#include <gtest/gtest.h>+#include <fstream>#include <memory>+#include "common_test_utils/common_utils.hpp"#include "common_test_utils/file_utils.hpp"#include "common_test_utils/test_assertions.hpp"#include "openvino/frontend/exception.hpp"@@ -503,3 +505,13 @@ TEST(FrontEndManagerTest, Exception_Safety_FrontEnd_Supported_By_Path) {fe->supported(std::filesystem::path("throw_now"));});}++TEST(FrontEndManagerTest, testFindPluginsDoesNotCrashOnUnicodeFilename) {+ const auto fe_dir = ov::test::utils::to_fs_path(ov::test::utils::getExecutableDirectory());+ auto unicode_file = fe_dir / std::filesystem::u8path("\xE8\xBF\x99\xE6\x98\xAF_");+ unicode_file += ov::test::utils::generateTestFilePrefix();+ { std::ofstream{unicode_file}; }++ OV_ASSERT_NO_THROW(FrontEndManager{});+ std::filesystem::remove(unicode_file);+}diff --git a/src/frontends/common/src/plugin_loader.cpp b/src/frontends/common/src/plugin_loader.cppindex 2ee431d5028..a820d14af50 100644--- a/src/frontends/common/src/plugin_loader.cpp+++ b/src/frontends/common/src/plugin_loader.cpp@@ -77,12 +77,12 @@ void load_static_plugins(std::vector<PluginInfo>& res) {#endif // OPENVINO_STATIC_LIBRARY-static bool is_fe_lib_name(const std::string_view& file_name) {- static constexpr auto prefix = std::string_view(FRONTEND_LIB_PREFIX);- static constexpr auto suffix = std::string_view(FRONTEND_LIB_SUFFIX);- auto prefix_pos = file_name.find(prefix);- auto suffix_pos = file_name.rfind(suffix);- return (prefix_pos == 0 && suffix_pos != std::string::npos && (suffix_pos == file_name.length() - suffix.length()));+static bool is_fe_lib_name(std::basic_string_view<std::filesystem::path::value_type> file_name) {+ using sv = std::basic_string_view<std::filesystem::path::value_type>;+ static constexpr sv prefix{OV_WSTR(FRONTEND_LIB_PREFIX)};+ static constexpr sv suffix{OV_WSTR(FRONTEND_LIB_SUFFIX)};+ return file_name.size() > prefix.size() + suffix.size() && file_name.substr(0, prefix.size()) == prefix &&+ ov::util::ends_with(file_name, suffix);}static std::vector<std::filesystem::path> list_files(const std::filesystem::path& path) {@@ -91,8 +91,7 @@ static std::vector<std::filesystem::path> list_files(const std::filesystem::pathif (const auto dir_iter = std::filesystem::directory_iterator(path, ec); !ec) {for (const auto& dir_entry : dir_iter) {if (!std::filesystem::is_directory(dir_entry.status())) {- const auto file_name = dir_entry.path().filename().string();- if (is_fe_lib_name(file_name)) {+ if (is_fe_lib_name(dir_entry.path().filename().native())) {res.push_back(dir_entry.path());}}