Skip to content

Commit 14230e3

Browse files
committed
[GR-33173] Migrate to new context reference API - removing PythonLanguage.getContext()
1 parent f06e982 commit 14230e3

32 files changed

+103
-101
lines changed

graalpython/com.oracle.graal.python.benchmarks/java/com/oracle/graal/python/benchmarks/parser/ParserBenchRunner.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public ParserBenchRunner() {
106106
context.initialize("python");
107107
context.enter();
108108

109-
this.pyContext = PythonLanguage.getContext();
109+
this.pyContext = PythonContext.get(null);
110110
this.parser = (PythonParserImpl) pyContext.getCore().getParser();
111111
this.core = pyContext.getCore();
112112
}
@@ -179,7 +179,7 @@ private List<Source> createSources() {
179179
}
180180
File file;
181181
PythonFileFilter filter = new PythonFileFilter(recursion, excludedPaths);
182-
PythonContext pyContext = PythonLanguage.getContext();
182+
PythonContext pyContext = PythonContext.get(null);
183183
for (String path : paths) {
184184
file = new File(path);
185185
if (file.isDirectory() || filter.accept(file)) {

graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/WithPythonContextRule.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@
4040
*/
4141
package com.oracle.graal.python;
4242

43-
import static com.oracle.graal.python.PythonLanguage.getContext;
44-
4543
import java.util.HashMap;
4644
import java.util.Map;
4745

@@ -95,7 +93,7 @@ public void evaluate() throws Throwable {
9593
RootCallTarget callTarget = Truffle.getRuntime().createCallTarget(new RootNode(null) {
9694
@Override
9795
public Object execute(VirtualFrame frame) {
98-
pythonContext = getContext();
96+
pythonContext = PythonContext.get(this);
9997
try {
10098
base.evaluate();
10199
} catch (Throwable e) {

graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/builtins/modules/ConversionNodeTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public class ConversionNodeTests {
6767

6868
protected static Object call(Object arg, ArgumentCastNodeWithRaise castNode) {
6969
PythonLanguage language = PythonLanguage.get(castNode);
70-
final PythonContext pythonContext = PythonLanguage.getContext();
70+
final PythonContext pythonContext = PythonContext.get(castNode);
7171

7272
RootCallTarget callTarget = Truffle.getRuntime().createCallTarget(new PRootNode(language) {
7373
@Child private CalleeContext calleeContext = CalleeContext.create();

graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/builtins/modules/DirFdConversionNodeTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
*/
4141
package com.oracle.graal.python.builtins.modules;
4242

43-
import static com.oracle.graal.python.PythonLanguage.getContext;
4443
import static com.oracle.graal.python.runtime.PosixConstants.AT_FDCWD;
4544

4645
import java.math.BigInteger;
@@ -53,6 +52,7 @@
5352
import org.junit.Test;
5453

5554
import com.oracle.graal.python.builtins.objects.PNone;
55+
import com.oracle.graal.python.runtime.PythonContext;
5656
import com.oracle.graal.python.runtime.object.PythonObjectFactory;
5757
import com.oracle.graal.python.test.PythonTests;
5858

@@ -158,6 +158,6 @@ private static PythonObjectFactory factory() {
158158
}
159159

160160
private static Object evalValue(String source) {
161-
return getContext().getEnv().asGuestValue(Context.getCurrent().eval("python", source));
161+
return PythonContext.get(null).getEnv().asGuestValue(Context.getCurrent().eval("python", source));
162162
}
163163
}

graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/builtins/modules/FileDescriptorConversionNodeTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
*/
4141
package com.oracle.graal.python.builtins.modules;
4242

43-
import static com.oracle.graal.python.PythonLanguage.getContext;
4443
import static com.oracle.graal.python.runtime.PosixConstants.AT_FDCWD;
4544

4645
import java.math.BigInteger;
@@ -53,6 +52,7 @@
5352
import org.junit.Test;
5453

5554
import com.oracle.graal.python.builtins.objects.PNone;
55+
import com.oracle.graal.python.runtime.PythonContext;
5656
import com.oracle.graal.python.runtime.object.PythonObjectFactory;
5757
import com.oracle.graal.python.test.PythonTests;
5858

@@ -166,6 +166,6 @@ private static PythonObjectFactory factory() {
166166
}
167167

168168
private static Object evalValue(String source) {
169-
return getContext().getEnv().asGuestValue(Context.getCurrent().eval("python", source));
169+
return PythonContext.get(null).getEnv().asGuestValue(Context.getCurrent().eval("python", source));
170170
}
171171
}

graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/builtins/modules/PathConversionNodeTests.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@
4040
*/
4141
package com.oracle.graal.python.builtins.modules;
4242

43-
import static com.oracle.graal.python.PythonLanguage.getContext;
44-
4543
import java.math.BigInteger;
4644
import java.util.Collections;
4745

@@ -61,6 +59,7 @@
6159
import com.oracle.graal.python.builtins.objects.PNone;
6260
import com.oracle.graal.python.builtins.objects.tuple.PTuple;
6361
import com.oracle.graal.python.runtime.PosixSupportLibrary.Buffer;
62+
import com.oracle.graal.python.runtime.PythonContext;
6463
import com.oracle.graal.python.runtime.object.PythonObjectFactory;
6564
import com.oracle.graal.python.test.PythonTests;
6665
import com.oracle.graal.python.util.Function;
@@ -355,6 +354,6 @@ private static PythonObjectFactory factory() {
355354
}
356355

357356
private static Object evalValue(String source) {
358-
return getContext().getEnv().asGuestValue(Context.getCurrent().eval("python", source));
357+
return PythonContext.get(null).getEnv().asGuestValue(Context.getCurrent().eval("python", source));
359358
}
360359
}

graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/PythonTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ private static String getFileContent(File file) {
294294
public static RootNode getParseResult(com.oracle.truffle.api.source.Source source, PrintStream out, PrintStream err) {
295295
enterContext();
296296
try {
297-
PythonContext ctx = PythonLanguage.getContext();
297+
PythonContext ctx = PythonContext.get(null);
298298
ctx.setOut(out);
299299
ctx.setErr(err);
300300
return (RootNode) ctx.getCore().getParser().parse(ParserMode.File, 0, ctx.getCore(), source, null, null);

graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/parser/ParserTestBase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public ParserTestBase() {
9797
@Before
9898
public void setUp() {
9999
PythonTests.enterContext();
100-
context = PythonLanguage.getContext();
100+
context = PythonContext.get(null);
101101
}
102102

103103
@After

graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/runtime/PythonModuleTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ private Object callBuiltin(Object... args) {
7979
@Before
8080
public void setUp() {
8181
PythonTests.enterContext();
82-
context = PythonLanguage.getContext();
82+
context = PythonContext.get(null);
8383
}
8484

8585
@After

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/PythonLanguage.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ public static String getEvalMimeType(int optimize) {
354354

355355
@Override
356356
protected CallTarget parse(ParsingRequest request) {
357-
PythonContext context = getContext();
357+
PythonContext context = PythonContext.get(null);
358358
Python3Core core = context.getCore();
359359
Source source = request.getSource();
360360
if (source.getMimeType() == null || MIME_TYPE.equals(source.getMimeType())) {
@@ -449,7 +449,7 @@ protected Object[] preparePArguments(VirtualFrame frame) {
449449
@Override
450450
@TruffleBoundary
451451
public Object execute(VirtualFrame frame) {
452-
PythonContext context = getContext();
452+
PythonContext context = PythonContext.get(callNode);
453453
assert context != null;
454454
if (!context.isInitialized()) {
455455
context.initialize();
@@ -493,7 +493,7 @@ protected ExecutableNode parse(InlineParsingRequest request) {
493493

494494
@Override
495495
public Object execute(VirtualFrame frame) {
496-
PythonContext context = getContext();
496+
PythonContext context = PythonContext.get(gilNode);
497497
assert context != null && context.isInitialized();
498498
PythonContext cachedCtx = cachedContext;
499499
if (cachedCtx == null) {
@@ -608,10 +608,6 @@ public String getHome() {
608608
return getLanguageHome();
609609
}
610610

611-
public static PythonContext getContext() {
612-
return PythonContext.get(null);
613-
}
614-
615611
public static Python3Core getCore() {
616612
return PythonContext.get(null).getCore();
617613
}

0 commit comments

Comments
 (0)