Skip to content

Commit 38a94bc

Browse files
committed
Move ReleaseNode.check* mehtods to PMemoryView
1 parent 45ca379 commit 38a94bc

File tree

2 files changed

+18
-19
lines changed

2 files changed

+18
-19
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/memoryview/MemoryViewNodes.java

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

43-
import static com.oracle.graal.python.builtins.PythonBuiltinClassType.BufferError;
4443
import static com.oracle.graal.python.builtins.PythonBuiltinClassType.IndexError;
4544
import static com.oracle.graal.python.builtins.PythonBuiltinClassType.NotImplementedError;
4645
import static com.oracle.graal.python.builtins.PythonBuiltinClassType.OverflowError;
@@ -727,34 +726,20 @@ public abstract static class ReleaseNode extends PNodeWithContext {
727726
@Specialization(guards = "self.getReference() == null")
728727
static void releaseSimple(PMemoryView self,
729728
@Shared("raise") @Cached PRaiseNode raiseNode) {
730-
checkExports(raiseNode, self);
729+
self.checkExports(raiseNode);
731730
self.setReleased();
732731
}
733732

734733
@Specialization(guards = {"self.getReference() != null"})
735734
static void releaseNative(PMemoryView self,
736735
@Cached ReleaseBufferNode releaseNode,
737736
@Shared("raise") @Cached PRaiseNode raiseNode) {
738-
checkExports(raiseNode, self);
739-
if (checkShouldReleaseBuffer(self)) {
737+
self.checkExports(raiseNode);
738+
if (self.checkShouldReleaseBuffer()) {
740739
releaseNode.execute(self.getLifecycleManager());
741740
}
742741
self.setReleased();
743742
}
744-
745-
private static boolean checkShouldReleaseBuffer(PMemoryView self) {
746-
if (self.getReference() != null) {
747-
return self.getReference().getLifecycleManager().decrementExports() == 0;
748-
}
749-
return false;
750-
}
751-
752-
private static void checkExports(PRaiseNode node, PMemoryView self) {
753-
long exports = self.getExports().get();
754-
if (exports > 0) {
755-
throw node.raise(BufferError, ErrorMessages.MEMORYVIEW_HAS_D_EXPORTED_BUFFERS, exports);
756-
}
757-
}
758743
}
759744

760745
@GenerateUncached

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/memoryview/PMemoryView.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,12 +240,26 @@ public void setShouldReleaseImmediately(boolean shouldReleaseImmediately) {
240240
this.shouldReleaseImmediately = shouldReleaseImmediately;
241241
}
242242

243-
public void checkReleased(PRaiseNode raiseNode) {
243+
void checkReleased(PRaiseNode raiseNode) {
244244
if (isReleased()) {
245245
throw raiseNode.raise(ValueError, ErrorMessages.MEMORYVIEW_FORBIDDEN_RELEASED);
246246
}
247247
}
248248

249+
boolean checkShouldReleaseBuffer() {
250+
if (getReference() != null) {
251+
return getReference().getLifecycleManager().decrementExports() == 0;
252+
}
253+
return false;
254+
}
255+
256+
void checkExports(PRaiseNode node) {
257+
long exports = getExports().get();
258+
if (exports > 0) {
259+
throw node.raise(BufferError, ErrorMessages.MEMORYVIEW_HAS_D_EXPORTED_BUFFERS, exports);
260+
}
261+
}
262+
249263
public void checkReleased(PNodeWithRaise node) {
250264
if (isReleased()) {
251265
throw node.raise(ValueError, ErrorMessages.MEMORYVIEW_FORBIDDEN_RELEASED);

0 commit comments

Comments
 (0)