Skip to content

Commit 1a8b353

Browse files
committed
Add missing TruffleBoundary.
1 parent 0ef8a06 commit 1a8b353

File tree

1 file changed

+19
-8
lines changed
  • graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/mmap

1 file changed

+19
-8
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/mmap/MMapBuiltins.java

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,11 @@ default long position(SeekableByteChannel ch) throws IOException {
123123
default void position(SeekableByteChannel ch, long offset) throws IOException {
124124
ch.position(offset);
125125
}
126+
127+
@TruffleBoundary
128+
default long size(SeekableByteChannel ch) throws IOException {
129+
return ch.size();
130+
}
126131
}
127132

128133
protected interface ByteReadingNode extends MMapBaseNode {
@@ -407,21 +412,27 @@ Object size(PMMap self, @SuppressWarnings("unused") Object typ, @SuppressWarning
407412
abstract static class CloseNode extends PythonUnaryBuiltinNode {
408413

409414
@Specialization
410-
PNone close(PMMap self) {
415+
PNone doClose(PMMap self) {
411416
try {
412-
self.getChannel().close();
417+
close(self);
413418
} catch (IOException e) {
414419
// TODO(fa): ignore ?
415420
}
416421
return PNone.NONE;
417422
}
423+
424+
@TruffleBoundary
425+
private static void close(PMMap self) throws IOException {
426+
self.getChannel().close();
427+
}
418428
}
419429

420430
@Builtin(name = "closed", fixedNumOfPositionalArgs = 1, isGetter = true)
421431
@GenerateNodeFactory
422432
abstract static class ClosedNode extends PythonUnaryBuiltinNode {
423433

424434
@Specialization
435+
@TruffleBoundary
425436
boolean close(PMMap self) {
426437
return !self.getChannel().isOpen();
427438
}
@@ -578,7 +589,7 @@ Object seek(VirtualFrame frame, PMMap self, long dist, Object how) {
578589
SeekableByteChannel channel = self.getChannel();
579590
long size;
580591
if (self.getLength() == 0) {
581-
size = channel.size() - self.getOffset();
592+
size = size(channel) - self.getOffset();
582593
} else {
583594
size = self.getLength();
584595
}
@@ -635,7 +646,7 @@ long find(PMMap primary, PIBytesLike sub, Object starting, Object ending,
635646
@Cached("createValueError()") ReadByteFromChannelNode readByteNode) {
636647
try {
637648
SeekableByteChannel channel = primary.getChannel();
638-
long len1 = channel.size();
649+
long len1 = size(channel);
639650

640651
SequenceStorage needle = sub.getSequenceStorage();
641652
int len2 = needle.length();
@@ -676,7 +687,7 @@ long find(PMMap primary, int sub, Object starting, @SuppressWarnings("unused") O
676687
@Cached("createValueError()") ReadByteFromChannelNode readByteNode) {
677688
try {
678689
SeekableByteChannel channel = primary.getChannel();
679-
long len1 = channel.size();
690+
long len1 = size(channel);
680691

681692
long s = castToLong(starting, 0);
682693
long e = castToLong(ending, len1);
@@ -721,15 +732,15 @@ private SequenceStorageNodes.GetItemNode getGetRightItemNode() {
721732
}
722733
}
723734

724-
abstract static class InternalLenNode extends PNodeWithContext {
735+
abstract static class InternalLenNode extends PNodeWithContext implements MMapBaseNode {
725736

726737
public abstract long execute(VirtualFrame frame, PMMap self);
727738

728739
@Specialization(guards = "self.getLength() == 0")
729740
long doFull(VirtualFrame frame, PMMap self,
730741
@Cached("create()") BranchProfile profile) {
731742
try {
732-
return self.getChannel().size() - self.getOffset();
743+
return size(self.getChannel()) - self.getOffset();
733744
} catch (IOException e) {
734745
profile.enter();
735746
throw raiseOSError(frame, OSErrorEnum.EIO, e.getMessage());
@@ -745,7 +756,7 @@ long doWindow(@SuppressWarnings("unused") VirtualFrame frame, PMMap self) {
745756
long doGeneric(VirtualFrame frame, PMMap self) {
746757
if (self.getLength() == 0) {
747758
try {
748-
return self.getChannel().size() - self.getOffset();
759+
return size(self.getChannel()) - self.getOffset();
749760
} catch (IOException e) {
750761
throw raiseOSError(frame, OSErrorEnum.EIO, e.getMessage());
751762
}

0 commit comments

Comments
 (0)