Skip to content

Commit 6b13437

Browse files
committed
make PythonBufferAccessLibrary more generic
1 parent 291b48e commit 6b13437

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/buffer/PythonBufferAccessLibrary.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
import com.oracle.graal.python.PythonLanguage;
4646
import com.oracle.graal.python.builtins.objects.bytes.PBytesLike;
4747
import com.oracle.graal.python.nodes.IndirectCallNode;
48-
import com.oracle.graal.python.nodes.PNodeWithRaiseAndIndirectCall;
4948
import com.oracle.graal.python.runtime.ExecutionContext.IndirectCallContext;
5049
import com.oracle.graal.python.runtime.PythonContext;
5150
import com.oracle.graal.python.util.PythonUtils;
@@ -55,6 +54,7 @@
5554
import com.oracle.truffle.api.library.GenerateLibrary.Abstract;
5655
import com.oracle.truffle.api.library.Library;
5756
import com.oracle.truffle.api.library.LibraryFactory;
57+
import com.oracle.truffle.api.nodes.Node;
5858

5959
/**
6060
* A library for accessing buffers obtained using {@link PythonBufferAcquireLibrary}. The buffer
@@ -101,7 +101,7 @@ public static void assertIsBuffer(Object receiver) {
101101
/**
102102
* Release the buffer. Equivalent of CPython's {@code PyBuffer_Release}, but must not be called
103103
* multiple times on the same buffer. If the caller has access to a VirtualFrame
104-
* {@link #release(Object, VirtualFrame, PNodeWithRaiseAndIndirectCall)} or
104+
* {@link #release(Object, VirtualFrame, PNodeWithIndirectCall)} or
105105
* {@link #release(Object, VirtualFrame, PythonContext, PythonLanguage, IndirectCallNode)}
106106
* should be used. If the caller doesn't have access to a VirtualFrame it must be ensured that
107107
* an IndirectCallContext was already created in the call path.
@@ -113,7 +113,7 @@ public void release(@SuppressWarnings("unused") Object receiver) {
113113
* Release the buffer. Equivalent of CPython's {@code PyBuffer_Release}, but must not be called
114114
* multiple times on the same buffer.
115115
*/
116-
public final void release(Object receiver, VirtualFrame frame, PNodeWithRaiseAndIndirectCall callNode) {
116+
public final <T extends Node & IndirectCallNode> void release(Object receiver, VirtualFrame frame, T callNode) {
117117
Object savedState = IndirectCallContext.enter(frame, callNode);
118118
try {
119119
release(receiver);

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
import com.oracle.graal.python.builtins.objects.frame.PFrame.Reference;
4747
import com.oracle.graal.python.builtins.objects.function.PArguments;
4848
import com.oracle.graal.python.nodes.IndirectCallNode;
49-
import com.oracle.graal.python.nodes.PNodeWithRaiseAndIndirectCall;
5049
import com.oracle.graal.python.nodes.PRootNode;
5150
import com.oracle.graal.python.nodes.control.TopLevelExceptionHandler;
5251
import com.oracle.graal.python.nodes.frame.MaterializeFrameNode;
@@ -355,7 +354,7 @@ public static Object enter(VirtualFrame frame, PythonLanguage language, PythonCo
355354
return enter(frame, pythonThreadState, needsCallerFrame, needsExceptionState, callNode);
356355
}
357356

358-
public static Object enter(VirtualFrame frame, PNodeWithRaiseAndIndirectCall indirectCallNode) {
357+
public static <T extends Node & IndirectCallNode> Object enter(VirtualFrame frame, T indirectCallNode) {
359358
if (frame == null || indirectCallNode == null) {
360359
return null;
361360
}
@@ -365,7 +364,7 @@ public static Object enter(VirtualFrame frame, PNodeWithRaiseAndIndirectCall ind
365364
return null;
366365
}
367366

368-
PythonThreadState pythonThreadState = indirectCallNode.getContext().getThreadState(indirectCallNode.getLanguage());
367+
PythonThreadState pythonThreadState = PythonContext.get(indirectCallNode).getThreadState(PythonLanguage.get(indirectCallNode));
369368
return enter(frame, pythonThreadState, needsCallerFrame, needsExceptionState, indirectCallNode);
370369
}
371370

@@ -414,11 +413,11 @@ public static void exit(VirtualFrame frame, PythonLanguage language, PythonConte
414413
assert savedState == null : "tried to exit an indirect call with state, but without frame/context";
415414
}
416415

417-
public static void exit(VirtualFrame frame, PNodeWithRaiseAndIndirectCall indirectCallNode, Object savedState) {
416+
public static <T extends Node & IndirectCallNode> void exit(VirtualFrame frame, T indirectCallNode, Object savedState) {
418417
if (savedState != null && frame != null) {
419-
PythonContext context = indirectCallNode.getContext();
418+
PythonContext context = PythonContext.get(indirectCallNode);
420419
if (context != null) {
421-
PythonLanguage language = indirectCallNode.getLanguage();
420+
PythonLanguage language = PythonLanguage.get(indirectCallNode);
422421
exit(frame, context.getThreadState(language), savedState);
423422
return;
424423
}

0 commit comments

Comments
 (0)