Skip to content

Commit 9f63b4f

Browse files
committed
Change ModelLoader::load_tensors() method read file by wide character path(wchar_t *) to support all language path.
1 parent 0e64238 commit 9f63b4f

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

model.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,33 @@
1414
#include "ggml/ggml-backend.h"
1515
#include "ggml/ggml.h"
1616

17+
18+
19+
#if defined(_MSC_VER)
20+
#include <Windows.h>
21+
// windows.h, naming conflict with micros: std::min, sdt::max, SDLogLevel::ERROR
22+
23+
#undef ERROR
24+
static wchar_t* str2wstr(const char* str) {
25+
size_t len = strlen(str) + 1;
26+
wchar_t* wstr = (wchar_t*)malloc(len * sizeof(wchar_t));
27+
MultiByteToWideChar(CP_UTF8, 0, str, (int)(len * sizeof(char)), wstr,
28+
(int)len);
29+
return wstr;
30+
};
31+
32+
//#include <stringapiset.h>
33+
// donot only include stringapiset.h, C1189 #error: "No Target Architecture"
34+
35+
#else // defined(_MSC_VER)
36+
37+
#endif // defined(_MSC_VER)
38+
39+
40+
41+
42+
43+
1744
#define ST_HEADER_SIZE_LEN 8
1845

1946
uint64_t read_u64(uint8_t* buffer) {
@@ -1203,7 +1230,17 @@ bool ModelLoader::load_tensors(on_new_tensor_cb_t on_new_tensor_cb) {
12031230
std::string file_path = file_paths_[file_index];
12041231
LOG_DEBUG("loading tensors from %s", file_path.c_str());
12051232

1233+
1234+
#if defined(_MSC_VER)
1235+
const char * c_file_path = file_path.c_str();
1236+
const wchar_t * c_w_file_path = str2wstr(c_file_path);
1237+
std::ifstream file(c_w_file_path, std::ios::binary);
1238+
delete c_w_file_path;
1239+
1240+
#else // defined(_MSC_VER)
12061241
std::ifstream file(file_path, std::ios::binary);
1242+
#endif // defined(_MSC_VER)
1243+
12071244
if (!file.is_open()) {
12081245
LOG_ERROR("failed to open '%s'", file_path.c_str());
12091246
return false;

0 commit comments

Comments
 (0)