Skip to content

Commit 9c3dfc7

Browse files
author
Adam Hrbac
committed
Use a better name for context in PythonThreadState
1 parent 753edbc commit 9c3dfc7

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/contextvars/PContextVarsContext.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,13 @@ public void enter(PythonContext.PythonThreadState threadState) {
5757
}
5858
previousContext = threadState.getContextVarsContext();
5959
assert previousContext != null : "ThreadState had null Context. This should not happen";
60-
threadState.setContext(this);
60+
threadState.setContextVarsContext(this);
6161
}
6262

6363
public void leave(PythonContext.PythonThreadState threadState) {
6464
assert threadState.getContextVarsContext() == this : "leaving a context which is not currently entered";
6565
assert previousContext != null : "entered context has no previous context";
66-
threadState.setContext(previousContext);
66+
threadState.setContextVarsContext(previousContext);
6767
previousContext = null;
6868
}
6969

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

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@
8787
import java.util.concurrent.locks.ReentrantLock;
8888
import java.util.logging.Level;
8989

90-
import com.oracle.graal.python.builtins.objects.contextvars.PContextVarsContext;
9190
import org.graalvm.nativeimage.ImageInfo;
9291
import org.graalvm.options.OptionKey;
9392

@@ -109,6 +108,7 @@
109108
import com.oracle.graal.python.builtins.objects.common.HashingStorage;
110109
import com.oracle.graal.python.builtins.objects.common.HashingStorageLibrary;
111110
import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodes;
111+
import com.oracle.graal.python.builtins.objects.contextvars.PContextVarsContext;
112112
import com.oracle.graal.python.builtins.objects.dict.PDict;
113113
import com.oracle.graal.python.builtins.objects.frame.PFrame;
114114
import com.oracle.graal.python.builtins.objects.frame.PFrame.Reference;
@@ -247,9 +247,13 @@ public static final class PythonThreadState {
247247
/* The event currently being traced, only useful if tracing is true. */
248248
TraceEvent tracingWhat;
249249

250-
boolean contextInitialized = false;
250+
/*
251+
* tracks whether a contextVarsContext was ever set. This is useful to make bugs where
252+
* contextVarsContext gets set to null noticable.
253+
*/
254+
boolean contextVarsContextInitialized = false;
251255

252-
PContextVarsContext context;
256+
PContextVarsContext contextVarsContext;
253257

254258
/*
255259
* The constructor needs to have this particular signature such that we can use it for
@@ -335,15 +339,16 @@ public void setNativeWrapper(PThreadState nativeWrapper) {
335339
}
336340

337341
public PContextVarsContext getContextVarsContext() {
338-
if (!contextInitialized) {
339-
context = PythonObjectFactory.getUncached().createContextVarsContext();
340-
contextInitialized = true;
342+
if (!contextVarsContextInitialized) {
343+
contextVarsContext = PythonObjectFactory.getUncached().createContextVarsContext();
344+
contextVarsContextInitialized = true;
341345
}
342-
return context;
346+
return contextVarsContext;
343347
}
344348

345-
public void setContext(PContextVarsContext context) {
346-
this.context = context;
349+
public void setContextVarsContext(PContextVarsContext contextVarsContext) {
350+
this.contextVarsContext = contextVarsContext;
351+
this.contextVarsContextInitialized = true;
347352
}
348353

349354
public void dispose() {

0 commit comments

Comments
 (0)