forked from JuliaLang/julia
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ensure libc is using a UTF8-compatible encoding
Some basic functionality in libc (such as printf) might be broken if the string encoding is not matching our Cstring expectations.
- Loading branch information
Showing
6 changed files
with
108 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# This file is a part of Julia. License is MIT: https://julialang.org/license | ||
|
||
function withlocales(f, newlocales) | ||
# save current locales | ||
locales = Dict{Int,String}() | ||
for cat in 0:9999 | ||
cstr = ccall(:setlocale, Cstring, (Cint, Cstring), cat, C_NULL) | ||
if cstr != C_NULL | ||
locales[cat] = unsafe_string(cstr) | ||
end | ||
end | ||
timestrs = String[] | ||
try | ||
# change to each of given locales | ||
for lc in newlocales | ||
set = true | ||
for (cat, _) in locales | ||
set &= ccall(:setlocale, Cstring, (Cint, Cstring), cat, lc) != C_NULL | ||
end | ||
set && f() | ||
end | ||
finally | ||
# recover locales | ||
for (cat, lc) in locales | ||
cstr = ccall(:setlocale, Cstring, (Cint, Cstring), cat, lc) | ||
end | ||
end | ||
end |