Skip to content

Commit 08f3f4a

Browse files
authored
ggml : cleanup path_str() (ggml-org#18928)
- Remove pragmas as `std::codecvt_utf8` is not used. - Avoid implicit `strlen()`. Signed-off-by: Adrien Gallouët <angt@huggingface.co>
1 parent 2711919 commit 08f3f4a

1 file changed

Lines changed: 4 additions & 20 deletions

File tree

ggml/src/ggml-backend-reg.cpp

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -77,39 +77,23 @@
7777
#include "ggml-zendnn.h"
7878
#endif
7979

80-
// disable C++17 deprecation warning for std::codecvt_utf8
81-
#if defined(__clang__)
82-
# pragma clang diagnostic push
83-
# pragma clang diagnostic ignored "-Wdeprecated-declarations"
84-
#elif defined(__GNUC__)
85-
# pragma GCC diagnostic push
86-
# pragma GCC diagnostic ignored "-Wdeprecated-declarations"
87-
#endif
88-
8980
namespace fs = std::filesystem;
9081

9182
static std::string path_str(const fs::path & path) {
92-
std::string u8path;
9383
try {
9484
#if defined(__cpp_lib_char8_t)
9585
// C++20 and later: u8string() returns std::u8string
96-
std::u8string u8str = path.u8string();
97-
u8path = std::string(reinterpret_cast<const char*>(u8str.c_str()));
86+
const std::u8string u8str = path.u8string();
87+
return std::string(reinterpret_cast<const char *>(u8str.data()), u8str.size());
9888
#else
9989
// C++17: u8string() returns std::string
100-
u8path = path.u8string();
90+
return path.u8string();
10191
#endif
10292
} catch (...) {
93+
return std::string();
10394
}
104-
return u8path;
10595
}
10696

107-
#if defined(__clang__)
108-
# pragma clang diagnostic pop
109-
#elif defined(__GNUC__)
110-
# pragma GCC diagnostic pop
111-
#endif
112-
11397
#ifdef _WIN32
11498

11599
using dl_handle = std::remove_pointer_t<HMODULE>;

0 commit comments

Comments
 (0)