Skip to content

Commit b6fcf84

Browse files
committed
Fix compilation failure in contextvars builtins
1 parent 3322726 commit b6fcf84

File tree

6 files changed

+21
-20
lines changed

6 files changed

+21
-20
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextContextBuiltins.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ static Object doGeneric(Object var, Object def, Object marker,
113113
return raiseNative.get(inliningTarget).raise(null, marker, PythonBuiltinClassType.TypeError, ErrorMessages.INSTANCE_OF_CONTEXTVAR_EXPECTED);
114114
}
115115
PythonContext.PythonThreadState threadState = context.getThreadState(context.getLanguage(inliningTarget));
116-
Object result = ((PContextVar) var).getValue(threadState);
116+
Object result = ((PContextVar) var).getValue(inliningTarget, threadState);
117117
if (result == null) {
118118
if (def == PNone.NO_VALUE) {
119119
if (((PContextVar) var).getDefault() == PContextVar.NO_DEFAULT) {
@@ -141,8 +141,8 @@ static Object doGeneric(Object var, Object val,
141141
}
142142
PythonLanguage language = pythonContext.getLanguage(inliningTarget);
143143
PythonContext.PythonThreadState threadState = pythonContext.getThreadState(language);
144-
Object oldValue = pvar.getValue(threadState);
145-
pvar.setValue(threadState, val);
144+
Object oldValue = pvar.getValue(inliningTarget, threadState);
145+
pvar.setValue(inliningTarget, threadState, val);
146146
return PFactory.createContextVarsToken(language, pvar, oldValue);
147147
}
148148
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ static Object get(PContextVar self, Object def,
122122
Object defValue = defIsNoValueProfile.profile(inliningTarget, isNoValue(def)) ? PContextVar.NO_DEFAULT : def;
123123
PythonContext context = PythonContext.get(inliningTarget);
124124
PythonContext.PythonThreadState threadState = context.getThreadState(context.getLanguage(inliningTarget));
125-
Object value = self.get(threadState, defValue);
125+
Object value = self.get(inliningTarget, threadState, defValue);
126126
if (value != null) {
127127
return value;
128128
}
@@ -139,8 +139,8 @@ static Object set(PContextVar self, Object value,
139139
@Bind PythonContext context) {
140140
PythonLanguage language = context.getLanguage(inliningTarget);
141141
PythonContext.PythonThreadState threadState = context.getThreadState(language);
142-
Object oldValue = self.getValue(threadState);
143-
self.setValue(threadState, value);
142+
Object oldValue = self.getValue(inliningTarget, threadState);
143+
self.setValue(inliningTarget, threadState, value);
144144
return PFactory.createContextVarsToken(language, self, oldValue);
145145
}
146146
}
@@ -157,10 +157,10 @@ static Object reset(PContextVar self, PContextVarsToken token,
157157
token.use(inliningTarget, raise);
158158
PythonContext.PythonThreadState threadState = pythonContext.getThreadState(pythonContext.getLanguage(inliningTarget));
159159
if (token.getOldValue() == null) {
160-
PContextVarsContext context = threadState.getContextVarsContext();
160+
PContextVarsContext context = threadState.getContextVarsContext(inliningTarget);
161161
context.contextVarValues = context.contextVarValues.without(self, self.getHash());
162162
} else {
163-
self.setValue(threadState, token.getOldValue());
163+
self.setValue(inliningTarget, threadState, token.getOldValue());
164164
}
165165
} else {
166166
throw raise.raise(inliningTarget, ValueError, ErrorMessages.TOKEN_FOR_DIFFERENT_CONTEXTVAR, token);

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -42,6 +42,7 @@
4242

4343
import com.oracle.graal.python.builtins.objects.object.PythonBuiltinObject;
4444
import com.oracle.graal.python.runtime.PythonContext;
45+
import com.oracle.truffle.api.nodes.Node;
4546
import com.oracle.truffle.api.object.Shape;
4647
import com.oracle.truffle.api.strings.TruffleString;
4748

@@ -71,17 +72,17 @@ public Object getDefault() {
7172
return def;
7273
}
7374

74-
public Object getValue(PythonContext.PythonThreadState state) {
75-
return state.getContextVarsContext().contextVarValues.lookup(this, getHash());
75+
public Object getValue(Node node, PythonContext.PythonThreadState state) {
76+
return state.getContextVarsContext(node).contextVarValues.lookup(this, getHash());
7677
}
7778

78-
public void setValue(PythonContext.PythonThreadState state, Object value) {
79-
PContextVarsContext current = state.getContextVarsContext();
79+
public void setValue(Node node, PythonContext.PythonThreadState state, Object value) {
80+
PContextVarsContext current = state.getContextVarsContext(node);
8081
current.contextVarValues = current.contextVarValues.withEntry(new Hamt.Entry(this, getHash(), value));
8182
}
8283

83-
public Object get(PythonContext.PythonThreadState state, Object defaultValue) {
84-
Object result = getValue(state);
84+
public Object get(Node node, PythonContext.PythonThreadState state, Object defaultValue) {
85+
Object result = getValue(node, state);
8586
if (result != null) {
8687
return result;
8788
}

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
@@ -56,13 +56,13 @@ public void enter(Node inliningTarget, PythonContext.PythonThreadState threadSta
5656
if (previousContext != null) {
5757
throw raise.raise(inliningTarget, PythonBuiltinClassType.RuntimeError, ErrorMessages.CANNOT_ENTER_CONTEXT_ALREADY_ENTERED, this);
5858
}
59-
previousContext = threadState.getContextVarsContext();
59+
previousContext = threadState.getContextVarsContext(inliningTarget);
6060
assert previousContext != null : "ThreadState had null Context. This should not happen";
6161
threadState.setContextVarsContext(this);
6262
}
6363

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

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyContextCopyCurrent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,6 @@ static PContextVarsContext doIt(Node inliningTarget) {
6363
PythonContext context = PythonContext.get(inliningTarget);
6464
PythonLanguage language = context.getLanguage(inliningTarget);
6565
PythonContext.PythonThreadState threadState = context.getThreadState(language);
66-
return PFactory.copyContextVarsContext(language, threadState.getContextVarsContext());
66+
return PFactory.copyContextVarsContext(language, threadState.getContextVarsContext(inliningTarget));
6767
}
6868
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -460,9 +460,9 @@ public void setNativeWrapper(PThreadState nativeWrapper) {
460460
this.nativeWrapper = nativeWrapper;
461461
}
462462

463-
public PContextVarsContext getContextVarsContext() {
463+
public PContextVarsContext getContextVarsContext(Node node) {
464464
if (contextVarsContext == null) {
465-
contextVarsContext = PFactory.createContextVarsContext(PythonLanguage.get(null));
465+
contextVarsContext = PFactory.createContextVarsContext(PythonLanguage.get(node));
466466
}
467467
return contextVarsContext;
468468
}

0 commit comments

Comments
 (0)