|
22 | 22 | import com.oracle.truffle.api.CompilerDirectives;
|
23 | 23 | import com.oracle.truffle.api.interop.InteropException;
|
24 | 24 | import com.oracle.truffle.api.interop.InteropLibrary;
|
25 |
| -import org.graalvm.nativeimage.ImageInfo; |
26 |
| -import org.graalvm.nativeimage.ProcessProperties; |
27 | 25 | import org.graalvm.shadowed.org.jcodings.Encoding;
|
28 | 26 | import org.graalvm.shadowed.org.jcodings.EncodingDB;
|
29 | 27 | import org.truffleruby.RubyContext;
|
|
39 | 37 |
|
40 | 38 | import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
|
41 | 39 | import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
|
| 40 | +import org.truffleruby.shared.Platform; |
| 41 | +import org.truffleruby.signal.LibRubySignal; |
42 | 42 |
|
43 | 43 | import static org.truffleruby.core.encoding.Encodings.INITIAL_NUMBER_OF_ENCODINGS;
|
44 | 44 |
|
@@ -129,11 +129,16 @@ public void initializeDefaultEncodings(TruffleNFIPlatform nfi, NativeConfigurati
|
129 | 129 | }
|
130 | 130 |
|
131 | 131 | private void initializeLocaleEncoding(TruffleNFIPlatform nfi, NativeConfiguration nativeConfiguration) {
|
132 |
| - if (ImageInfo.inImageRuntimeCode()) { |
133 |
| - // Call setlocale(LC_ALL, "") to ensure the locale is set to the environment's locale |
134 |
| - // rather than the default "C" locale. |
135 |
| - ProcessProperties.setLocale("LC_ALL", ""); |
136 |
| - } |
| 132 | + // CRuby does setlocale(LC_CTYPE, "") because this is needed to get the locale encoding with nl_langinfo(CODESET). |
| 133 | + // This means every locale category except LC_CTYPE remains the initial "C". |
| 134 | + // LC_CTYPE is set according to environment variables (LC_ALL, LC_CTYPE, LANG). |
| 135 | + // HotSpot does setlocale(LC_ALL, "") and Native Image does nothing. |
| 136 | + // We match CRuby by doing setlocale(LC_ALL, "C") and setlocale(LC_CTYPE, ""). |
| 137 | + // This is notably important for Prism to be able to parse floating-point numbers: |
| 138 | + // https://github.com/ruby/prism/issues/2638 |
| 139 | + // It also affects C functions that depend on the locale in C extensions, so best to follow CRuby here. |
| 140 | + LibRubySignal.loadLibrary(language.getRubyHome(), Platform.LIB_SUFFIX); |
| 141 | + LibRubySignal.setupLocale(); |
137 | 142 |
|
138 | 143 | final String localeEncodingName;
|
139 | 144 | final String detector;
|
|
0 commit comments