Skip to content

Commit efd6a0e

Browse files
committed
fix: open files whose paths contain non-ascii characters
1 parent cf4c11d commit efd6a0e

2 files changed

Lines changed: 72 additions & 4 deletions

File tree

.bazelrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ build:windows --copt=/w
2121
# For using M_* math constants on Windows with MSVC.
2222
build:windows --copt=/D_USE_MATH_DEFINES
2323
build:windows --host_copt=/D_USE_MATH_DEFINES
24+
build:windows --copt=/DUNICODE
25+
build:windows --host_copt=/DUNICODE
2426

2527
# macOS
2628
build:macos --cxxopt=-std=c++17

third_party/mediapipe_workaround.diff

Lines changed: 70 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,35 @@
1+
diff --git a/mediapipe/framework/deps/platform_strings.cc b/mediapipe/framework/deps/platform_strings.cc
2+
index fa8f3c791..e053d549f 100644
3+
--- a/mediapipe/framework/deps/platform_strings.cc
4+
+++ b/mediapipe/framework/deps/platform_strings.cc
5+
@@ -26,21 +26,21 @@ std::string FormatLastError() {
6+
return std::string("(no error reported)");
7+
}
8+
9+
- LPSTR message_buffer = nullptr;
10+
- DWORD size = FormatMessage(
11+
+ LPWSTR message_buffer = nullptr;
12+
+ DWORD size = FormatMessageW(
13+
/*dwFlags=*/(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
14+
FORMAT_MESSAGE_IGNORE_INSERTS),
15+
/*lpSource=*/NULL,
16+
/*dwMessageId=*/message_id,
17+
/*dwLanguageId=*/MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
18+
- /*lpBuffer=*/(LPSTR)&message_buffer,
19+
+ /*lpBuffer=*/reinterpret_cast<LPWSTR>(&message_buffer),
20+
/*nSize=*/0,
21+
/*Arguments=*/NULL);
22+
if (size == 0) {
23+
return "(error while trying to format the error message)";
24+
}
25+
26+
- std::string message(message_buffer, size);
27+
+ std::wstring message(message_buffer, size);
28+
LocalFree(message_buffer);
29+
return NativeToUtf8(message);
30+
}
131
diff --git a/mediapipe/framework/output_stream_handler.cc b/mediapipe/framework/output_stream_handler.cc
2-
index e27d1c68..55f2f3bd 100644
32+
index e27d1c688..55f2f3bd3 100644
333
--- a/mediapipe/framework/output_stream_handler.cc
434
+++ b/mediapipe/framework/output_stream_handler.cc
535
@@ -143,9 +143,7 @@ OutputStreamHandler::GetMonitoringInfo() {
@@ -14,7 +44,7 @@ index e27d1c68..55f2f3bd 100644
1444
return monitoring_info_vector;
1545
}
1646
diff --git a/mediapipe/framework/port/opencv_core_inc.h b/mediapipe/framework/port/opencv_core_inc.h
17-
index 12862472..1a409417 100644
47+
index 128624725..1a4094173 100644
1848
--- a/mediapipe/framework/port/opencv_core_inc.h
1949
+++ b/mediapipe/framework/port/opencv_core_inc.h
2050
@@ -20,7 +20,7 @@
@@ -26,8 +56,44 @@ index 12862472..1a409417 100644
2656
#include <opencv2/cvconfig.h>
2757
#endif
2858

59+
diff --git a/mediapipe/tasks/cc/core/BUILD b/mediapipe/tasks/cc/core/BUILD
60+
index 9c53dcca7..b0d7283c1 100644
61+
--- a/mediapipe/tasks/cc/core/BUILD
62+
+++ b/mediapipe/tasks/cc/core/BUILD
63+
@@ -58,6 +58,7 @@ cc_library(
64+
srcs = ["external_file_handler.cc"],
65+
hdrs = ["external_file_handler.h"],
66+
deps = [
67+
+ "//mediapipe/framework/deps:platform_strings",
68+
"//mediapipe/framework/port:integral_types",
69+
"//mediapipe/framework/port:status",
70+
"//mediapipe/tasks/cc:common",
71+
diff --git a/mediapipe/tasks/cc/core/external_file_handler.cc b/mediapipe/tasks/cc/core/external_file_handler.cc
72+
index 069b904e9..d8b5e0364 100644
73+
--- a/mediapipe/tasks/cc/core/external_file_handler.cc
74+
+++ b/mediapipe/tasks/cc/core/external_file_handler.cc
75+
@@ -40,6 +40,7 @@ limitations under the License.
76+
#include "absl/strings/match.h"
77+
#include "absl/strings/str_format.h"
78+
#include "absl/strings/string_view.h"
79+
+#include "mediapipe/framework/deps/platform_strings.h"
80+
#include "mediapipe/framework/port/status_macros.h"
81+
#include "mediapipe/tasks/cc/common.h"
82+
#include "mediapipe/tasks/cc/core/proto/external_file.pb.h"
83+
@@ -124,7 +125,11 @@ absl::Status ExternalFileHandler::MapExternalFile() {
84+
if (!external_file_.file_name().empty()) {
85+
MP_ASSIGN_OR_RETURN(std::string file_name,
86+
PathToResourceAsFile(external_file_.file_name()));
87+
+#ifdef _WIN32
88+
+ owned_fd_ = _wopen(Utf8ToNative(file_name).c_str(), O_RDONLY | O_BINARY);
89+
+#else
90+
owned_fd_ = open(file_name.c_str(), O_RDONLY | O_BINARY);
91+
+#endif
92+
if (owned_fd_ < 0) {
93+
const std::string error_message = absl::StrFormat(
94+
"Unable to open file at %s", external_file_.file_name());
2995
diff --git a/mediapipe/tasks/cc/core/task_api_factory.h b/mediapipe/tasks/cc/core/task_api_factory.h
30-
index a11a23fc..dbb5fe6c 100644
96+
index a11a23fcf..dbb5fe6ca 100644
3197
--- a/mediapipe/tasks/cc/core/task_api_factory.h
3298
+++ b/mediapipe/tasks/cc/core/task_api_factory.h
3399
@@ -76,15 +76,17 @@ class TaskApiFactory {
@@ -50,7 +116,7 @@ index a11a23fc..dbb5fe6c 100644
50116
std::move(graph_config), std::move(resolver),
51117
std::move(packets_callback), std::move(default_executor),
52118
diff --git a/mediapipe/tasks/cc/vision/holistic_landmarker/holistic_landmarker_graph.cc b/mediapipe/tasks/cc/vision/holistic_landmarker/holistic_landmarker_graph.cc
53-
index 2ff140c0..128a4326 100644
119+
index 2ff140c07..128a43263 100644
54120
--- a/mediapipe/tasks/cc/vision/holistic_landmarker/holistic_landmarker_graph.cc
55121
+++ b/mediapipe/tasks/cc/vision/holistic_landmarker/holistic_landmarker_graph.cc
56122
@@ -387,6 +387,13 @@ class HolisticLandmarkerGraph : public core::ModelTaskGraph {

0 commit comments

Comments
 (0)