|
129 | 129 | import com.oracle.graal.python.nodes.truffle.PythonArithmeticTypes; |
130 | 130 | import com.oracle.graal.python.nodes.util.CastToIndexNode; |
131 | 131 | import com.oracle.graal.python.nodes.util.CastToIntegerFromIntNode; |
| 132 | +import com.oracle.graal.python.nodes.util.CastToJavaIntNode; |
132 | 133 | import com.oracle.graal.python.nodes.util.CastToJavaLongNode; |
133 | 134 | import com.oracle.graal.python.nodes.util.CastToPathNode; |
134 | 135 | import com.oracle.graal.python.nodes.util.ChannelNodes.ReadFromChannelNode; |
@@ -865,25 +866,16 @@ Object doit(VirtualFrame frame, LazyPythonClass cls, String name, Object pathArg |
865 | 866 |
|
866 | 867 | @Builtin(name = "dup", minNumOfPositionalArgs = 1) |
867 | 868 | @GenerateNodeFactory |
868 | | - @TypeSystemReference(PythonArithmeticTypes.class) |
869 | 869 | abstract static class DupNode extends PythonFileNode { |
870 | 870 | @Specialization |
871 | | - int dup(int fd) { |
| 871 | + int dupInt(int fd) { |
872 | 872 | return getResources().dup(fd); |
873 | 873 | } |
874 | 874 |
|
875 | | - @Specialization(rewriteOn = ArithmeticException.class) |
876 | | - int dupPInt(PInt fd) { |
877 | | - return getResources().dup(fd.intValueExact()); |
878 | | - } |
879 | | - |
880 | | - @Specialization(replaces = "dupPInt") |
881 | | - int dupOvf(PInt fd) { |
882 | | - try { |
883 | | - return dupPInt(fd); |
884 | | - } catch (ArithmeticException e) { |
885 | | - throw raise(OSError, "invalid fd %r", fd); |
886 | | - } |
| 875 | + @Specialization(replaces = "dupInt") |
| 876 | + int dupGeneric(Object fd, |
| 877 | + @Cached CastToJavaIntNode castToJavaIntNode) { |
| 878 | + return getResources().dup(castToJavaIntNode.execute(fd)); |
887 | 879 | } |
888 | 880 | } |
889 | 881 |
|
@@ -1026,22 +1018,31 @@ public abstract static class LseekNode extends PythonFileNode { |
1026 | 1018 |
|
1027 | 1019 | @Specialization |
1028 | 1020 | Object lseek(VirtualFrame frame, long fd, long pos, int how, |
1029 | | - @Cached PRaiseOSErrorNode raise, |
1030 | | - @Cached("createClassProfile()") ValueProfile channelClassProfile) { |
| 1021 | + @Shared("channelClassProfile") @Cached("createClassProfile()") ValueProfile channelClassProfile) { |
1031 | 1022 | Channel channel = getResources().getFileChannel((int) fd, channelClassProfile); |
1032 | | - if (noFile.profile(channel == null || !(channel instanceof SeekableByteChannel))) { |
1033 | | - throw raise.raiseOSError(frame, OSErrorEnum.ESPIPE); |
| 1023 | + if (noFile.profile(!(channel instanceof SeekableByteChannel))) { |
| 1024 | + throw raiseOSError(frame, OSErrorEnum.ESPIPE); |
1034 | 1025 | } |
1035 | 1026 | SeekableByteChannel fc = (SeekableByteChannel) channel; |
1036 | 1027 | try { |
1037 | 1028 | return setPosition(pos, how, fc); |
1038 | 1029 | } catch (IOException e) { |
1039 | 1030 | gotException.enter(); |
1040 | 1031 | // if this happen, we should raise OSError with appropriate errno |
1041 | | - throw raise.raiseOSError(frame, -1); |
| 1032 | + throw raiseOSError(frame, -1); |
1042 | 1033 | } |
1043 | 1034 | } |
1044 | 1035 |
|
| 1036 | + @Specialization |
| 1037 | + Object lseekGeneric(VirtualFrame frame, Object fd, Object pos, Object how, |
| 1038 | + @Shared("channelClassProfile") @Cached("createClassProfile()") ValueProfile channelClassProfile, |
| 1039 | + @Cached CastToJavaLongNode castFdNode, |
| 1040 | + @Cached CastToJavaLongNode castPosNode, |
| 1041 | + @Cached CastToJavaIntNode castHowNode) { |
| 1042 | + |
| 1043 | + return lseek(frame, castFdNode.execute(fd), castPosNode.execute(pos), castHowNode.execute(how), channelClassProfile); |
| 1044 | + } |
| 1045 | + |
1045 | 1046 | @TruffleBoundary(allowInlining = true) |
1046 | 1047 | private static Object setPosition(long pos, int how, SeekableByteChannel fc) throws IOException { |
1047 | 1048 | switch (how) { |
|
0 commit comments