|
64 | 64 | import java.nio.channels.ReadableByteChannel;
|
65 | 65 | import java.nio.channels.SeekableByteChannel;
|
66 | 66 | import java.nio.channels.WritableByteChannel;
|
67 |
| -import java.nio.charset.StandardCharsets; |
68 | 67 | import java.nio.file.AccessDeniedException;
|
69 | 68 | import java.nio.file.FileAlreadyExistsException;
|
70 | 69 | import java.nio.file.FileSystemException;
|
|
99 | 98 | import com.oracle.graal.python.builtins.modules.PosixModuleBuiltinsFactory.StatNodeFactory;
|
100 | 99 | import com.oracle.graal.python.builtins.objects.PNone;
|
101 | 100 | import com.oracle.graal.python.builtins.objects.bytes.BytesNodes;
|
102 |
| -import com.oracle.graal.python.builtins.objects.bytes.BytesNodes.ToBytesNode; |
103 | 101 | import com.oracle.graal.python.builtins.objects.bytes.PByteArray;
|
104 | 102 | import com.oracle.graal.python.builtins.objects.bytes.PBytes;
|
105 | 103 | import com.oracle.graal.python.builtins.objects.bytes.PIBytesLike;
|
@@ -527,8 +525,6 @@ Object setInheritable(int fd, @SuppressWarnings("unused") Object inheritable) {
|
527 | 525 | @ImportStatic(SpecialMethodNames.class)
|
528 | 526 | @TypeSystemReference(PythonArithmeticTypes.class)
|
529 | 527 | public abstract static class StatNode extends PythonBinaryBuiltinNode {
|
530 |
| - @Child private ToBytesNode toBytesNode; |
531 |
| - |
532 | 528 | private final BranchProfile fileNotFound = BranchProfile.create();
|
533 | 529 |
|
534 | 530 | private static final int S_IFIFO = 0010000;
|
@@ -786,19 +782,6 @@ private static int posixPermissionsToMode(int inputMode, final Set<PosixFilePerm
|
786 | 782 | return mode;
|
787 | 783 | }
|
788 | 784 |
|
789 |
| - private String toJavaString(VirtualFrame frame, PIBytesLike bytesLike) { |
790 |
| - if (toBytesNode == null) { |
791 |
| - CompilerDirectives.transferToInterpreterAndInvalidate(); |
792 |
| - toBytesNode = insert(ToBytesNode.create()); |
793 |
| - } |
794 |
| - return newString(toBytesNode.execute(frame, bytesLike)); |
795 |
| - } |
796 |
| - |
797 |
| - @TruffleBoundary |
798 |
| - private static String newString(byte[] bytes) { |
799 |
| - return new String(bytes, StandardCharsets.UTF_8); |
800 |
| - } |
801 |
| - |
802 | 785 | public static StatNode create() {
|
803 | 786 | return StatNodeFactory.create();
|
804 | 787 | }
|
@@ -910,12 +893,20 @@ int dupOvf(PInt fd) {
|
910 | 893 | abstract static class Dup2Node extends PythonFileNode {
|
911 | 894 | @Specialization
|
912 | 895 | int dup(int fd, int fd2) {
|
913 |
| - return getResources().dup2(fd, fd2); |
| 896 | + try { |
| 897 | + return getResources().dup2(fd, fd2); |
| 898 | + } catch (IOException e) { |
| 899 | + throw raise(OSError, "invalid fd %r", fd2); |
| 900 | + } |
914 | 901 | }
|
915 | 902 |
|
916 | 903 | @Specialization(rewriteOn = ArithmeticException.class)
|
917 | 904 | int dupPInt(PInt fd, PInt fd2) {
|
918 |
| - return getResources().dup2(fd.intValueExact(), fd2.intValueExact()); |
| 905 | + try { |
| 906 | + return getResources().dup2(fd.intValueExact(), fd2.intValueExact()); |
| 907 | + } catch (IOException e) { |
| 908 | + throw raise(OSError, "invalid fd %r", fd2); |
| 909 | + } |
919 | 910 | }
|
920 | 911 |
|
921 | 912 | @Specialization(replaces = "dupPInt")
|
@@ -1072,7 +1063,6 @@ private static Object setPosition(long pos, int how, SeekableByteChannel fc) thr
|
1072 | 1063 | @Builtin(name = "close", minNumOfPositionalArgs = 1)
|
1073 | 1064 | @GenerateNodeFactory
|
1074 | 1065 | public abstract static class CloseNode extends PythonFileNode {
|
1075 |
| - private final BranchProfile gotException = BranchProfile.create(); |
1076 | 1066 | private final ConditionProfile noFile = ConditionProfile.createBinaryProfile();
|
1077 | 1067 |
|
1078 | 1068 | @Specialization
|
@@ -1993,9 +1983,7 @@ PNone killFallback(VirtualFrame frame, Object pid, Object signal,
|
1993 | 1983 | abstract static class FSyncNode extends PythonUnaryBuiltinNode {
|
1994 | 1984 | @Specialization
|
1995 | 1985 | PNone fsync(VirtualFrame frame, int fd) {
|
1996 |
| - try { |
1997 |
| - getContext().getResources().fsync(fd); |
1998 |
| - } catch (ArrayIndexOutOfBoundsException e) { |
| 1986 | + if (!getContext().getResources().fsync(fd)) { |
1999 | 1987 | throw raiseOSError(frame, OSErrorEnum.ENOENT.getNumber());
|
2000 | 1988 | }
|
2001 | 1989 | return PNone.NONE;
|
|
0 commit comments