@@ -123,6 +123,11 @@ default long position(SeekableByteChannel ch) throws IOException {
123
123
default void position (SeekableByteChannel ch , long offset ) throws IOException {
124
124
ch .position (offset );
125
125
}
126
+
127
+ @ TruffleBoundary
128
+ default long size (SeekableByteChannel ch ) throws IOException {
129
+ return ch .size ();
130
+ }
126
131
}
127
132
128
133
protected interface ByteReadingNode extends MMapBaseNode {
@@ -407,21 +412,27 @@ Object size(PMMap self, @SuppressWarnings("unused") Object typ, @SuppressWarning
407
412
abstract static class CloseNode extends PythonUnaryBuiltinNode {
408
413
409
414
@ Specialization
410
- PNone close (PMMap self ) {
415
+ PNone doClose (PMMap self ) {
411
416
try {
412
- self . getChannel (). close ();
417
+ close (self );
413
418
} catch (IOException e ) {
414
419
// TODO(fa): ignore ?
415
420
}
416
421
return PNone .NONE ;
417
422
}
423
+
424
+ @ TruffleBoundary
425
+ private static void close (PMMap self ) throws IOException {
426
+ self .getChannel ().close ();
427
+ }
418
428
}
419
429
420
430
@ Builtin (name = "closed" , fixedNumOfPositionalArgs = 1 , isGetter = true )
421
431
@ GenerateNodeFactory
422
432
abstract static class ClosedNode extends PythonUnaryBuiltinNode {
423
433
424
434
@ Specialization
435
+ @ TruffleBoundary
425
436
boolean close (PMMap self ) {
426
437
return !self .getChannel ().isOpen ();
427
438
}
@@ -578,7 +589,7 @@ Object seek(VirtualFrame frame, PMMap self, long dist, Object how) {
578
589
SeekableByteChannel channel = self .getChannel ();
579
590
long size ;
580
591
if (self .getLength () == 0 ) {
581
- size = channel . size () - self .getOffset ();
592
+ size = size (channel ) - self .getOffset ();
582
593
} else {
583
594
size = self .getLength ();
584
595
}
@@ -635,7 +646,7 @@ long find(PMMap primary, PIBytesLike sub, Object starting, Object ending,
635
646
@ Cached ("createValueError()" ) ReadByteFromChannelNode readByteNode ) {
636
647
try {
637
648
SeekableByteChannel channel = primary .getChannel ();
638
- long len1 = channel . size ();
649
+ long len1 = size (channel );
639
650
640
651
SequenceStorage needle = sub .getSequenceStorage ();
641
652
int len2 = needle .length ();
@@ -676,7 +687,7 @@ long find(PMMap primary, int sub, Object starting, @SuppressWarnings("unused") O
676
687
@ Cached ("createValueError()" ) ReadByteFromChannelNode readByteNode ) {
677
688
try {
678
689
SeekableByteChannel channel = primary .getChannel ();
679
- long len1 = channel . size ();
690
+ long len1 = size (channel );
680
691
681
692
long s = castToLong (starting , 0 );
682
693
long e = castToLong (ending , len1 );
@@ -721,15 +732,15 @@ private SequenceStorageNodes.GetItemNode getGetRightItemNode() {
721
732
}
722
733
}
723
734
724
- abstract static class InternalLenNode extends PNodeWithContext {
735
+ abstract static class InternalLenNode extends PNodeWithContext implements MMapBaseNode {
725
736
726
737
public abstract long execute (VirtualFrame frame , PMMap self );
727
738
728
739
@ Specialization (guards = "self.getLength() == 0" )
729
740
long doFull (VirtualFrame frame , PMMap self ,
730
741
@ Cached ("create()" ) BranchProfile profile ) {
731
742
try {
732
- return self .getChannel (). size ( ) - self .getOffset ();
743
+ return size ( self .getChannel ()) - self .getOffset ();
733
744
} catch (IOException e ) {
734
745
profile .enter ();
735
746
throw raiseOSError (frame , OSErrorEnum .EIO , e .getMessage ());
@@ -745,7 +756,7 @@ long doWindow(@SuppressWarnings("unused") VirtualFrame frame, PMMap self) {
745
756
long doGeneric (VirtualFrame frame , PMMap self ) {
746
757
if (self .getLength () == 0 ) {
747
758
try {
748
- return self .getChannel (). size ( ) - self .getOffset ();
759
+ return size ( self .getChannel ()) - self .getOffset ();
749
760
} catch (IOException e ) {
750
761
throw raiseOSError (frame , OSErrorEnum .EIO , e .getMessage ());
751
762
}
0 commit comments