From 43b87de7d161ea71daab652d5ba154bb90e19b21 Mon Sep 17 00:00:00 2001 From: Tiago Koji Castro Shibata Date: Thu, 7 May 2020 13:32:19 -0700 Subject: [PATCH] Support wide char paths in CreateModel (#3835) * Support wide char paths in CreateModel * Use UTF-8 in WinML adapter API --- winml/adapter/winml_adapter_model.cpp | 7 +++++-- winml/test/api/LearningModelAPITest.cpp | 8 +++++++- winml/test/api/LearningModelAPITest.h | 2 ++ .../models/UnicodePath/こんにちは maçã/foo.onnx | Bin 0 -> 150 bytes 4 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 winml/test/collateral/models/UnicodePath/こんにちは maçã/foo.onnx diff --git a/winml/adapter/winml_adapter_model.cpp b/winml/adapter/winml_adapter_model.cpp index 8203987215..9b5466c40a 100644 --- a/winml/adapter/winml_adapter_model.cpp +++ b/winml/adapter/winml_adapter_model.cpp @@ -14,8 +14,10 @@ #include #include +#include #include "google/protobuf/io/zero_copy_stream_impl.h" #include "core/framework/onnxruntime_typeinfo.h" +#include "StringHelpers.h" namespace winmla = Windows::AI::MachineLearning::Adapter; @@ -118,10 +120,11 @@ OrtModel::OrtModel(std::unique_ptr model_proto) : model_proto_ // factory methods for creating an ort model from a path static OrtStatus* CreateModelProto(const char* path, std::unique_ptr& out) { int file_descriptor; + auto wide_path = _winml::Strings::HStringFromUTF8(path); _set_errno(0); // clear errno - _sopen_s( + _wsopen_s( &file_descriptor, - path, + wide_path.c_str(), O_RDONLY | _O_SEQUENTIAL | _O_BINARY, _SH_DENYWR, _S_IREAD | _S_IWRITE); diff --git a/winml/test/api/LearningModelAPITest.cpp b/winml/test/api/LearningModelAPITest.cpp index d9a514e4be..04167bd9cb 100644 --- a/winml/test/api/LearningModelAPITest.cpp +++ b/winml/test/api/LearningModelAPITest.cpp @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. #include "testPch.h" @@ -26,6 +26,11 @@ static void CreateModelFromFilePath() { WINML_EXPECT_NO_THROW(APITest::LoadModel(L"squeezenet_modifiedforruntimestests.onnx", learningModel)); } +static void CreateModelFromUnicodeFilePath() { + LearningModel learningModel = nullptr; + WINML_EXPECT_NO_THROW(APITest::LoadModel(L"UnicodePath\\こんにちは maçã\\foo.onnx", learningModel)); +} + static void CreateModelFileNotFound() { LearningModel learningModel = nullptr; @@ -274,6 +279,7 @@ const LearningModelApiTestsApi& getapi() { LearningModelAPITestsClassSetup, LearningModelAPITestsGpuMethodSetup, CreateModelFromFilePath, + CreateModelFromUnicodeFilePath, CreateModelFileNotFound, CreateModelFromIStorage, CreateModelFromIStorageOutsideCwd, diff --git a/winml/test/api/LearningModelAPITest.h b/winml/test/api/LearningModelAPITest.h index cd83624620..7658e5df3d 100644 --- a/winml/test/api/LearningModelAPITest.h +++ b/winml/test/api/LearningModelAPITest.h @@ -7,6 +7,7 @@ struct LearningModelApiTestsApi SetupClass LearningModelAPITestsClassSetup; SetupTest LearningModelAPITestsGpuMethodSetup; VoidTest CreateModelFromFilePath; + VoidTest CreateModelFromUnicodeFilePath; VoidTest CreateModelFileNotFound; VoidTest CreateModelFromIStorage; VoidTest CreateModelFromIStorageOutsideCwd; @@ -29,6 +30,7 @@ WINML_TEST_CLASS_BEGIN(LearningModelAPITests) WINML_TEST_CLASS_SETUP_CLASS(LearningModelAPITestsClassSetup) WINML_TEST_CLASS_BEGIN_TESTS WINML_TEST(LearningModelAPITests, CreateModelFromFilePath) +WINML_TEST(LearningModelAPITests, CreateModelFromUnicodeFilePath) WINML_TEST(LearningModelAPITests, CreateModelFileNotFound) WINML_TEST(LearningModelAPITests, CreateModelFromIStorage) WINML_TEST(LearningModelAPITests, CreateModelFromIStorageOutsideCwd) diff --git a/winml/test/collateral/models/UnicodePath/こんにちは maçã/foo.onnx b/winml/test/collateral/models/UnicodePath/こんにちは maçã/foo.onnx new file mode 100644 index 0000000000000000000000000000000000000000..f786e4ca75444fd309509744e5fde2f31d51c131 GIT binary patch literal 150 zcmd;J7Gg`zNX;urv}$GK66Ioy;9?9HVvLkxP0P=ZH&kMF%g-0$0J0TIQj1HplsT9= zm;@M=Bp4VP>=_ss9DoRj8-REL5Fc=GVhoQG2AU$o$Hl|JD8#|V#K8>2Od!E;M1& literal 0 HcmV?d00001