Skip to content

Commit

Permalink
embedding_wrapper.c: Fix Unicode arguments in Windows (#1008)
Browse files Browse the repository at this point in the history
  • Loading branch information
raphasampaio authored Nov 25, 2024
1 parent 6777978 commit 35b3e18
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
17 changes: 16 additions & 1 deletion src/embedding_wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,23 @@ void set_depot_load_path(const char *root_dir) {

// main function (windows UTF16 -> UTF8 argument conversion code copied from
// julia's ui/repl.c)
#ifdef _WIN32
int wmain(int argc, wchar_t *wargv[], wchar_t *envp[]) {
char **argv = (char **)malloc(sizeof(char *) * argc);
if (!argv) return 1;

for (int i = 0; i < argc; i++) { // write the command line to UTF8
wchar_t *warg = wargv[i];
size_t len = WideCharToMultiByte(CP_UTF8, 0, warg, -1, NULL, 0, NULL, NULL);
if (!len) return 1;
char *arg = (char *)malloc(len);
if (!WideCharToMultiByte(CP_UTF8, 0, warg, -1, arg, len, NULL, NULL)) return 1;
argv[i] = arg;
}
#else
int main(int argc, char *argv[]) {
argv = uv_setup_args(argc, argv); // no-op on Windows
argv = uv_setup_args(argc, argv);
#endif
// Find where eventual julia arguments start
int program_argc = argc;
Expand Down
3 changes: 3 additions & 0 deletions src/juliaconfig.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ function cflags()
if Sys.isunix()
print(flags, " -fPIC")
end
if Sys.iswindows()
print(flags, " -municode")
end
return String(take!(flags))
end

Expand Down
4 changes: 2 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ end
rm(joinpath(new_depot, "artifacts"); recursive=true, force=true)
end # try
app_path(app_name) = abspath(app_compiled_dir, "bin", app_name * (Sys.iswindows() ? ".exe" : ""))
app_output = read(`$(app_path("MyApp")) I get --args --julia-args --threads=3 --check-bounds=yes -O1`, String)
app_output = read(`$(app_path("MyApp")) I get --args áéíóú --julia-args --threads=3 --check-bounds=yes -O1`, String)

# Check stdlib filtering
if filter == true
Expand All @@ -130,7 +130,7 @@ end
# Check artifact gets run from the correct place
@test occursin("HelloWorld artifact at $(realpath(app_compiled_dir))", app_output)
# Check ARGS
@test occursin("""ARGS = ["I", "get", "--args"]""", app_output)
@test occursin("""ARGS = ["I", "get", "--args", "áéíóú"]""", app_output)
# Check julia-args
@test occursin("(Base.JLOptions()).opt_level = 1", app_output)
@test occursin("(Base.JLOptions()).nthreads = 3", app_output)
Expand Down

0 comments on commit 35b3e18

Please sign in to comment.