From d57f289264dfe9fa3eb84c21299c5fe507397a67 Mon Sep 17 00:00:00 2001 From: Alex Forshtat Date: Fri, 16 Jan 2026 00:49:29 +0100 Subject: [PATCH] Try fixing non-ASCII parameters in llama-cli on Windows --- common/common.cpp | 34 ++++++++++++++++++++++++++++++++++ common/common.h | 2 ++ tools/cli/cli.cpp | 2 ++ 3 files changed, 38 insertions(+) diff --git a/common/common.cpp b/common/common.cpp index 26250abb6c..5765285770 100644 --- a/common/common.cpp +++ b/common/common.cpp @@ -45,6 +45,7 @@ #include #include #include +#include #else #include #include @@ -60,6 +61,39 @@ #pragma warning(disable: 4244 4267) // possible loss of data #endif +#ifdef _WIN32 +void common_init_args(int & argc, char ** & argv) { + int wargc; + static std::vector argv_utf8; + static std::vector args_utf8; + LPWSTR * wargv = CommandLineToArgvW(GetCommandLineW(), &wargc); + if (!wargv) return; + + args_utf8.resize(wargc); + argv_utf8.resize(wargc + 1); + + for (int i = 0; i < wargc; ++i) { + int size = WideCharToMultiByte(CP_UTF8, 0, wargv[i], -1, NULL, 0, NULL, NULL); + if (size > 0) { + args_utf8[i].resize(size); + WideCharToMultiByte(CP_UTF8, 0, wargv[i], -1, &args_utf8[i][0], size, NULL, NULL); + args_utf8[i].resize(size - 1); + argv_utf8[i] = &args_utf8[i][0]; + } + } + argv_utf8[wargc] = nullptr; + + argc = wargc; + argv = argv_utf8.data(); + + LocalFree(wargv); +} +#else +void common_init_args(int &, char ** &) { + // no-op on non-Windows +} +#endif + common_time_meas::common_time_meas(int64_t & t_acc, bool disable) : t_start_us(disable ? -1 : ggml_time_us()), t_acc(t_acc) {} common_time_meas::~common_time_meas() { diff --git a/common/common.h b/common/common.h index b9566df62c..8eaccdb029 100644 --- a/common/common.h +++ b/common/common.h @@ -582,6 +582,8 @@ struct common_params { // initializes the logging system and prints info about the build void common_init(); +void common_init_args(int & argc, char **& argv); + std::string common_params_get_system_info(const common_params & params); bool parse_cpu_range(const std::string & range, bool(&boolmask)[GGML_MAX_N_THREADS]); diff --git a/tools/cli/cli.cpp b/tools/cli/cli.cpp index 2f0ffea1c2..a47fa36446 100644 --- a/tools/cli/cli.cpp +++ b/tools/cli/cli.cpp @@ -159,6 +159,8 @@ struct cli_context { }; int main(int argc, char ** argv) { + common_init_args(argc, argv); + common_params params; params.verbosity = LOG_LEVEL_ERROR; // by default, less verbose logs