Skip to content

Commit

Permalink
Fix Base.libllvm_path and jl_get_libllvm don't support non-ASCII char…
Browse files Browse the repository at this point in the history
…acters in path on Windows (#45126) (#45127)

* Fix jl_get_libllvm_impl to support non-ASCII characters

* Fix jl_get_libllvm_impl to support non-ASCII characters, fix whitespace

* Fix jl_get_libllvm_impl to support non-ASCII characters, fix null and buffer

(cherry picked from commit 6976bac)
  • Loading branch information
wesjenkins authored and KristofferC committed Feb 20, 2023
1 parent d43d055 commit b3d42d1
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8927,11 +8927,15 @@ extern "C" JL_DLLEXPORT jl_value_t *jl_get_libllvm_impl(void) JL_NOTSAFEPOINT
HMODULE mod;
if (!GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, (LPCSTR)&llvm::DebugFlag, &mod))
return jl_nothing;

char path[MAX_PATH];
if (!GetModuleFileNameA(mod, path, sizeof(path)))
wchar_t path16[MAX_PATH];
DWORD n16 = GetModuleFileNameW(mod, path16, MAX_PATH);
if (n16 <= 0)
return jl_nothing;
path16[n16++] = 0;
char path8[MAX_PATH * 3];
if (!WideCharToMultiByte(CP_UTF8, 0, path16, n16, path8, MAX_PATH * 3, NULL, NULL))
return jl_nothing;
return (jl_value_t*) jl_symbol(path);
return (jl_value_t*) jl_symbol(path8);
#else
Dl_info dli;
if (!dladdr((void*)LLVMContextCreate, &dli))
Expand Down

0 comments on commit b3d42d1

Please sign in to comment.