@@ -294,18 +294,19 @@ Object fstatStd(@SuppressWarnings("unused") int fd) {
294
294
@ Specialization (guards = "fd > 2" )
295
295
@ TruffleBoundary
296
296
Object fstat (int fd ,
297
- @ Cached ("create()" ) BranchProfile fstatForNonFile ) {
297
+ @ Cached ("create()" ) BranchProfile fstatForNonFile ,
298
+ @ Cached ("createClassProfile()" ) ValueProfile channelClassProfile ) {
298
299
PosixResources resources = getResources ();
299
300
String filePath = resources .getFilePath (fd );
300
301
if (filePath != null ) {
301
302
if (statNode == null ) {
302
303
CompilerDirectives .transferToInterpreterAndInvalidate ();
303
304
statNode = insert (StatNode .create ());
304
305
}
305
- return statNode .executeWith (getResources () .getFilePath (fd ), PNone .NO_VALUE );
306
+ return statNode .executeWith (resources .getFilePath (fd ), PNone .NO_VALUE );
306
307
} else {
307
308
fstatForNonFile .enter ();
308
- Channel fileChannel = resources .getFileChannel (fd );
309
+ Channel fileChannel = resources .getFileChannel (fd , channelClassProfile );
309
310
int mode = 0 ;
310
311
if (fileChannel instanceof ReadableByteChannel ) {
311
312
mode |= 0444 ;
@@ -623,8 +624,9 @@ Object open(String pathname, int flags, int fileMode, @SuppressWarnings("unused"
623
624
public abstract static class LseekNode extends PythonFileNode {
624
625
@ Specialization
625
626
@ TruffleBoundary
626
- Object lseek (int fd , long pos , int how ) {
627
- Channel channel = getResources ().getFileChannel (fd );
627
+ Object lseek (int fd , long pos , int how ,
628
+ @ Cached ("createClassProfile()" ) ValueProfile channelClassProfile ) {
629
+ Channel channel = getResources ().getFileChannel (fd , channelClassProfile );
628
630
if (channel == null || !(channel instanceof SeekableByteChannel )) {
629
631
throw raise (OSError , "Illegal seek" );
630
632
}
@@ -653,12 +655,14 @@ Object lseek(int fd, long pos, int how) {
653
655
public abstract static class CloseNode extends PythonFileNode {
654
656
@ Specialization
655
657
@ TruffleBoundary
656
- Object close (int fd ) {
657
- Channel channel = getResources ().getFileChannel (fd );
658
+ Object close (int fd ,
659
+ @ Cached ("createClassProfile()" ) ValueProfile channelClassProfile ) {
660
+ PosixResources resources = getResources ();
661
+ Channel channel = resources .getFileChannel (fd , channelClassProfile );
658
662
if (channel == null ) {
659
663
throw raise (OSError , "invalid fd" );
660
664
} else {
661
- getResources () .close (fd );
665
+ resources .close (fd );
662
666
try {
663
667
channel .close ();
664
668
} catch (IOException e ) {
@@ -726,8 +730,9 @@ public abstract static class WriteNode extends PythonFileNode {
726
730
727
731
@ Specialization
728
732
@ TruffleBoundary
729
- Object write (int fd , byte [] data ) {
730
- Channel channel = getResources ().getFileChannel (fd );
733
+ Object write (int fd , byte [] data ,
734
+ @ Cached ("createClassProfile()" ) ValueProfile channelClassProfile ) {
735
+ Channel channel = getResources ().getFileChannel (fd , channelClassProfile );
731
736
if (channel instanceof WritableByteChannel ) {
732
737
try {
733
738
return ((WritableByteChannel ) channel ).write (ByteBuffer .wrap (data ));
@@ -741,20 +746,23 @@ Object write(int fd, byte[] data) {
741
746
742
747
@ Specialization
743
748
@ TruffleBoundary
744
- Object write (int fd , String data ) {
745
- return write (fd , data .getBytes ());
749
+ Object write (int fd , String data ,
750
+ @ Cached ("createClassProfile()" ) ValueProfile channelClassProfile ) {
751
+ return write (fd , data .getBytes (), channelClassProfile );
746
752
}
747
753
748
754
@ Specialization
749
755
@ TruffleBoundary
750
- Object write (int fd , PBytes data ) {
751
- return write (fd , getByteArray (data ));
756
+ Object write (int fd , PBytes data ,
757
+ @ Cached ("createClassProfile()" ) ValueProfile channelClassProfile ) {
758
+ return write (fd , getByteArray (data ), channelClassProfile );
752
759
}
753
760
754
761
@ Specialization
755
762
@ TruffleBoundary
756
- Object write (int fd , PByteArray data ) {
757
- return write (fd , getByteArray (data ));
763
+ Object write (int fd , PByteArray data ,
764
+ @ Cached ("createClassProfile()" ) ValueProfile channelClassProfile ) {
765
+ return write (fd , getByteArray (data ), channelClassProfile );
758
766
}
759
767
760
768
@ Specialization
@@ -782,8 +790,9 @@ public static WriteNode create() {
782
790
@ TypeSystemReference (PythonArithmeticTypes .class )
783
791
public abstract static class ReadNode extends PythonFileNode {
784
792
@ Specialization (guards = "readOpaque(frame)" )
785
- Object readOpaque (@ SuppressWarnings ("unused" ) VirtualFrame frame , int fd , @ SuppressWarnings ("unused" ) Object requestedSize ) {
786
- Channel channel = getResources ().getFileChannel (fd );
793
+ Object readOpaque (@ SuppressWarnings ("unused" ) VirtualFrame frame , int fd , @ SuppressWarnings ("unused" ) Object requestedSize ,
794
+ @ Cached ("createClassProfile()" ) ValueProfile channelClassProfile ) {
795
+ Channel channel = getResources ().getFileChannel (fd , channelClassProfile );
787
796
try {
788
797
return new OpaqueBytes (doRead (channel , Integer .MAX_VALUE ));
789
798
} catch (IOException e ) {
@@ -792,8 +801,9 @@ Object readOpaque(@SuppressWarnings("unused") VirtualFrame frame, int fd, @Suppr
792
801
}
793
802
794
803
@ Specialization (guards = "!readOpaque(frame)" )
795
- Object read (@ SuppressWarnings ("unused" ) VirtualFrame frame , int fd , long requestedSize ) {
796
- Channel channel = getResources ().getFileChannel (fd );
804
+ Object read (@ SuppressWarnings ("unused" ) VirtualFrame frame , int fd , long requestedSize ,
805
+ @ Cached ("createClassProfile()" ) ValueProfile channelClassProfile ) {
806
+ Channel channel = getResources ().getFileChannel (fd , channelClassProfile );
797
807
try {
798
808
byte [] array = doRead (channel , (int ) requestedSize );
799
809
return factory ().createBytes (array );
@@ -1171,18 +1181,19 @@ Object rename(Object src, Object dst, @SuppressWarnings("unused") Object[] args,
1171
1181
1172
1182
Object effectiveSrc = src ;
1173
1183
Object effectiveDst = dst ;
1184
+ PosixResources resources = getResources ();
1174
1185
for (int i = 0 ; i < kwargs .length ; i ++) {
1175
1186
Object value = kwargs [i ].getValue ();
1176
1187
if ("src_dir_fd" .equals (kwargs [i ].getName ())) {
1177
1188
if (!(value instanceof Integer )) {
1178
1189
throw raise (OSError , "invalid file descriptor provided" );
1179
1190
}
1180
- effectiveSrc = getResources () .getFilePath ((int ) value );
1191
+ effectiveSrc = resources .getFilePath ((int ) value );
1181
1192
} else if ("dst_dir_fd" .equals (kwargs [i ].getName ())) {
1182
1193
if (!(value instanceof Integer )) {
1183
1194
throw raise (OSError , "invalid file descriptor provided" );
1184
1195
}
1185
- effectiveDst = getResources () .getFilePath ((int ) value );
1196
+ effectiveDst = resources .getFilePath ((int ) value );
1186
1197
}
1187
1198
}
1188
1199
return rename (convertSrcNode .execute (effectiveSrc ), convertDstNode .execute (effectiveDst ));
0 commit comments