Skip to content

Commit 1de2627

Browse files
committed
setlocale() as little as possible if embedded as it is process-wide
* ruby/prism#2638 got fixed so we don't need a C locale for Prism anymore.
1 parent b21df3b commit 1de2627

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/main/java/org/truffleruby/core/encoding/EncodingManager.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@
2020
import java.util.concurrent.ConcurrentHashMap;
2121

2222
import com.oracle.truffle.api.CompilerDirectives;
23+
import com.oracle.truffle.api.TruffleOptions;
2324
import com.oracle.truffle.api.interop.InteropException;
2425
import com.oracle.truffle.api.interop.InteropLibrary;
26+
import org.graalvm.nativeimage.ProcessProperties;
2527
import org.graalvm.shadowed.org.jcodings.Encoding;
2628
import org.graalvm.shadowed.org.jcodings.EncodingDB;
2729
import org.truffleruby.RubyContext;
@@ -134,11 +136,16 @@ private void initializeLocaleEncoding(TruffleNFIPlatform nfi, NativeConfiguratio
134136
// LC_CTYPE is set according to environment variables (LC_ALL, LC_CTYPE, LANG).
135137
// HotSpot does setlocale(LC_ALL, "") and Native Image does nothing.
136138
// 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();
139+
// This also affects C functions that depend on the locale in C extensions, so best to follow CRuby here.
140+
// Change the strict minimum if embedded because setlocale() is process-wide.
141+
if (context.getOptions().EMBEDDED) {
142+
if (TruffleOptions.AOT) {
143+
ProcessProperties.setLocale("LC_CTYPE", "");
144+
}
145+
} else {
146+
LibRubySignal.loadLibrary(language.getRubyHome(), Platform.LIB_SUFFIX);
147+
LibRubySignal.setupLocale();
148+
}
142149

143150
final String localeEncodingName;
144151
final String detector;

0 commit comments

Comments
 (0)