Skip to content

Commit 02af354

Browse files
committed
Add missing memoryview released check
1 parent b5cb2ef commit 02af354

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
import com.oracle.graal.python.nodes.ErrorMessages;
6363
import com.oracle.graal.python.nodes.PGuards;
6464
import com.oracle.graal.python.nodes.PNodeWithRaise;
65+
import com.oracle.graal.python.nodes.PRaiseNode;
6566
import com.oracle.graal.python.nodes.attributes.ReadAttributeFromObjectNode;
6667
import com.oracle.graal.python.nodes.object.IsBuiltinClassProfile;
6768
import com.oracle.graal.python.runtime.PythonContext;
@@ -546,7 +547,9 @@ public abstract static class ToJavaBytesNode extends Node {
546547
byte[] tobytesCached(PMemoryView self,
547548
@Cached("self.getDimensions()") int cachedDimensions,
548549
@Cached ReadBytesAtNode readBytesAtNode,
549-
@Cached CExtNodes.PCallCapiFunction callCapiFunction) {
550+
@Cached CExtNodes.PCallCapiFunction callCapiFunction,
551+
@Cached PRaiseNode raiseNode) {
552+
self.checkReleased(raiseNode);
550553
byte[] bytes = new byte[self.getLength()];
551554
if (cachedDimensions == 0) {
552555
readBytesAtNode.execute(bytes, 0, self.getItemSize(), self, self.getBufferPointer(), self.getOffset());
@@ -559,7 +562,9 @@ byte[] tobytesCached(PMemoryView self,
559562
@Specialization(replaces = "tobytesCached")
560563
byte[] tobytesGeneric(PMemoryView self,
561564
@Cached ReadBytesAtNode readBytesAtNode,
562-
@Cached CExtNodes.PCallCapiFunction callCapiFunction) {
565+
@Cached CExtNodes.PCallCapiFunction callCapiFunction,
566+
@Cached PRaiseNode raiseNode) {
567+
self.checkReleased(raiseNode);
563568
byte[] bytes = new byte[self.getLength()];
564569
if (self.getDimensions() == 0) {
565570
readBytesAtNode.execute(bytes, 0, self.getItemSize(), self, self.getBufferPointer(), self.getOffset());

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import com.oracle.graal.python.builtins.objects.object.PythonObjectLibrary;
4949
import com.oracle.graal.python.nodes.ErrorMessages;
5050
import com.oracle.graal.python.nodes.PNodeWithRaise;
51+
import com.oracle.graal.python.nodes.PRaiseNode;
5152
import com.oracle.graal.python.util.BufferFormat;
5253
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
5354
import com.oracle.truffle.api.dsl.Cached;
@@ -221,6 +222,12 @@ public void setReleased() {
221222
owner = null;
222223
}
223224

225+
public void checkReleased(PRaiseNode raiseNode) {
226+
if (isReleased()) {
227+
throw raiseNode.raise(ValueError, ErrorMessages.MEMORYVIEW_FORBIDDEN_RELEASED);
228+
}
229+
}
230+
224231
public void checkReleased(PNodeWithRaise node) {
225232
if (isReleased()) {
226233
throw node.raise(ValueError, ErrorMessages.MEMORYVIEW_FORBIDDEN_RELEASED);

0 commit comments

Comments
 (0)