Skip to content

Commit a237a59

Browse files
committed
don't use a supplier for the jython import thread local
1 parent 8d2eba8 commit a237a59

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/PythonContext.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public final class PythonContext {
144144
private final AsyncHandler handler;
145145

146146
// A thread-local to store the full path to the currently active import statement, for Jython compat
147-
private final ThreadLocal<Stack<String>> currentImport = ThreadLocal.withInitial(() -> new Stack<>());
147+
private final ThreadLocal<Stack<String>> currentImport = new ThreadLocal<>();
148148

149149
public PythonContext(PythonLanguage language, TruffleLanguage.Env env, PythonCore core) {
150150
this.language = language;
@@ -729,7 +729,9 @@ public boolean isPyFileInLanguageHome(TruffleFile path) {
729729
@TruffleBoundary
730730
public String getCurrentImport() {
731731
Stack<String> ci = currentImport.get();
732-
if (ci.isEmpty()) {
732+
if (ci == null) {
733+
return "";
734+
} else if (ci.isEmpty()) {
733735
return "";
734736
} else {
735737
return ci.peek();
@@ -738,11 +740,17 @@ public String getCurrentImport() {
738740

739741
@TruffleBoundary
740742
public void pushCurrentImport(String object) {
741-
currentImport.get().push(object);
743+
Stack<String> ci = currentImport.get();
744+
if (ci == null) {
745+
ci = new Stack<>();
746+
currentImport.set(ci);
747+
}
748+
ci.push(object);
742749
}
743750

744751
@TruffleBoundary
745752
public void popCurrentImport() {
753+
assert currentImport.get() != null && currentImport.get().peek() != null : "invalid popCurrentImport without push";
746754
currentImport.get().pop();
747755
}
748756
}

0 commit comments

Comments
 (0)