Skip to content

Commit 9c01462

Browse files
committed
use LazyString default options when no context is available at the time the class is loaded
1 parent d550d77 commit 9c01462

File tree

1 file changed

+16
-2
lines changed
  • graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/str

1 file changed

+16
-2
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/str/LazyString.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,22 @@
4848

4949
public class LazyString implements CharSequence {
5050

51-
protected static int MinLazyStringLength = PythonOptions.getMinLazyStringLength();
52-
protected static boolean UseLazyStrings = PythonOptions.useLazyString();
51+
protected static final int MinLazyStringLength;
52+
protected static final boolean UseLazyStrings;
53+
static {
54+
boolean useLazyStrings = PythonOptions.LazyStrings.getDefaultValue();
55+
int minLazyStringLength = PythonOptions.MinLazyStringLength.getDefaultValue();
56+
try {
57+
useLazyStrings = PythonOptions.useLazyString();
58+
minLazyStringLength = PythonOptions.getMinLazyStringLength();
59+
} catch (AssertionError e) {
60+
// This can happen e.g. when we build a native image without
61+
// a pre-initialized Python context
62+
assert e.getMessage().equals("No current context available");
63+
}
64+
MinLazyStringLength = minLazyStringLength;
65+
UseLazyStrings = useLazyStrings;
66+
}
5367

5468
public static int length(CharSequence cs, ConditionProfile profile1, ConditionProfile profile2) {
5569
if (profile1.profile(cs instanceof String)) {

0 commit comments

Comments
 (0)