|
47 | 47 | import java.nio.channels.SeekableByteChannel;
|
48 | 48 | import java.nio.channels.WritableByteChannel;
|
49 | 49 | import java.nio.charset.StandardCharsets;
|
| 50 | +import java.nio.file.AccessDeniedException; |
| 51 | +import java.nio.file.FileAlreadyExistsException; |
| 52 | +import java.nio.file.FileSystemException; |
50 | 53 | import java.nio.file.InvalidPathException;
|
51 | 54 | import java.nio.file.LinkOption;
|
| 55 | +import java.nio.file.NoSuchFileException; |
52 | 56 | import java.nio.file.StandardCopyOption;
|
53 | 57 | import java.nio.file.StandardOpenOption;
|
54 | 58 | import java.nio.file.attribute.FileAttribute;
|
|
59 | 63 | import java.nio.file.attribute.UserPrincipal;
|
60 | 64 | import java.util.Arrays;
|
61 | 65 | import java.util.Collection;
|
| 66 | +import java.util.HashMap; |
62 | 67 | import java.util.HashSet;
|
63 | 68 | import java.util.List;
|
64 | 69 | import java.util.Random;
|
|
126 | 131 | import com.oracle.truffle.api.profiles.ValueProfile;
|
127 | 132 | import com.sun.security.auth.UnixNumericGroupPrincipal;
|
128 | 133 | import com.sun.security.auth.UnixNumericUserPrincipal;
|
129 |
| -import java.nio.file.AccessDeniedException; |
130 |
| -import java.nio.file.FileAlreadyExistsException; |
131 |
| -import java.nio.file.FileSystemException; |
132 |
| -import java.nio.file.NoSuchFileException; |
133 |
| -import java.util.HashMap; |
134 | 134 |
|
135 | 135 | @CoreFunctions(defineModule = "posix")
|
136 | 136 | public class PosixModuleBuiltins extends PythonBuiltins {
|
@@ -1074,25 +1074,29 @@ public static ReadFromChannelNode create() {
|
1074 | 1074 | public abstract static class ReadNode extends PythonFileNode {
|
1075 | 1075 | private static final int MAX_READ = Integer.MAX_VALUE / 2;
|
1076 | 1076 |
|
| 1077 | + @CompilationFinal private BranchProfile tooLargeProfile = BranchProfile.create(); |
| 1078 | + |
1077 | 1079 | @Specialization(guards = "readOpaque(frame)")
|
1078 |
| - Object readOpaque(@SuppressWarnings("unused") VirtualFrame frame, int fd, @SuppressWarnings("unused") Object requestedSize, |
| 1080 | + Object readOpaque(@SuppressWarnings("unused") VirtualFrame frame, int fd, long requestedSize, |
1079 | 1081 | @Cached("createClassProfile()") ValueProfile channelClassProfile,
|
1080 | 1082 | @Cached("create()") ReadFromChannelNode readNode) {
|
1081 |
| - Channel channel = getResources().getFileChannel(fd, channelClassProfile); |
1082 |
| - ByteSequenceStorage bytes = readNode.execute(channel, MAX_READ); |
1083 |
| - return new OpaqueBytes(Arrays.copyOf(bytes.getInternalByteArray(), bytes.length())); |
| 1083 | + if (OpaqueBytes.isInOpaqueFilesystem(getResources().getFilePath(fd), getContext())) { |
| 1084 | + Channel channel = getResources().getFileChannel(fd, channelClassProfile); |
| 1085 | + ByteSequenceStorage bytes = readNode.execute(channel, MAX_READ); |
| 1086 | + return new OpaqueBytes(Arrays.copyOf(bytes.getInternalByteArray(), bytes.length())); |
| 1087 | + } |
| 1088 | + return read(frame, fd, requestedSize, channelClassProfile, readNode); |
1084 | 1089 | }
|
1085 | 1090 |
|
1086 | 1091 | @Specialization(guards = "!readOpaque(frame)")
|
1087 | 1092 | Object read(@SuppressWarnings("unused") VirtualFrame frame, int fd, long requestedSize,
|
1088 | 1093 | @Cached("createClassProfile()") ValueProfile channelClassProfile,
|
1089 |
| - @Cached("create()") BranchProfile tooLarge, |
1090 | 1094 | @Cached("create()") ReadFromChannelNode readNode) {
|
1091 | 1095 | int size;
|
1092 | 1096 | try {
|
1093 | 1097 | size = Math.toIntExact(requestedSize);
|
1094 | 1098 | } catch (ArithmeticException e) {
|
1095 |
| - tooLarge.enter(); |
| 1099 | + tooLargeProfile.enter(); |
1096 | 1100 | size = MAX_READ;
|
1097 | 1101 | }
|
1098 | 1102 | Channel channel = getResources().getFileChannel(fd, channelClassProfile);
|
|
0 commit comments