|
51 | 51 |
|
52 | 52 | import org.graalvm.collections.EconomicMap;
|
53 | 53 |
|
54 |
| -import com.oracle.graal.python.PythonLanguage; |
55 | 54 | import com.oracle.graal.python.builtins.Builtin;
|
56 | 55 | import com.oracle.graal.python.builtins.CoreFunctions;
|
57 | 56 | import com.oracle.graal.python.builtins.Python3Core;
|
58 |
| -import com.oracle.graal.python.builtins.PythonBuiltinClassType; |
59 | 57 | import com.oracle.graal.python.builtins.PythonBuiltins;
|
60 | 58 | import com.oracle.graal.python.builtins.objects.PNone;
|
| 59 | +import com.oracle.graal.python.builtins.objects.array.PArray; |
61 | 60 | import com.oracle.graal.python.builtins.objects.buffer.PythonBufferAccessLibrary;
|
62 | 61 | import com.oracle.graal.python.builtins.objects.buffer.PythonBufferAcquireLibrary;
|
| 62 | +import com.oracle.graal.python.builtins.objects.bytes.BytesNodes; |
63 | 63 | import com.oracle.graal.python.builtins.objects.cext.common.NativePointer;
|
64 | 64 | import com.oracle.graal.python.builtins.objects.exception.PBaseException;
|
| 65 | +import com.oracle.graal.python.builtins.objects.memoryview.PMemoryView; |
| 66 | +import com.oracle.graal.python.builtins.objects.mmap.PMMap; |
65 | 67 | import com.oracle.graal.python.builtins.objects.module.PythonModule;
|
66 | 68 | import com.oracle.graal.python.builtins.objects.object.PythonObject;
|
67 | 69 | import com.oracle.graal.python.builtins.objects.slice.SliceNodes;
|
68 |
| -import com.oracle.graal.python.builtins.objects.tuple.PTuple; |
69 | 70 | import com.oracle.graal.python.lib.PyLongAsIntNode;
|
70 | 71 | import com.oracle.graal.python.lib.PyNumberAsSizeNode;
|
71 | 72 | import com.oracle.graal.python.lib.PyNumberIndexNode;
|
72 | 73 | import com.oracle.graal.python.lib.PyObjectGetItem;
|
73 | 74 | import com.oracle.graal.python.lib.PyObjectLookupAttr;
|
74 | 75 | import com.oracle.graal.python.lib.PyObjectSizeNode;
|
| 76 | +import com.oracle.graal.python.lib.PyUnicodeCheckNode; |
75 | 77 | import com.oracle.graal.python.nodes.BuiltinNames;
|
76 | 78 | import com.oracle.graal.python.nodes.ErrorMessages;
|
77 | 79 | import com.oracle.graal.python.nodes.HiddenAttr;
|
|
89 | 91 | import com.oracle.graal.python.runtime.PythonContext;
|
90 | 92 | import com.oracle.graal.python.runtime.PythonOptions;
|
91 | 93 | import com.oracle.graal.python.runtime.exception.PException;
|
92 |
| -import com.oracle.graal.python.runtime.object.PFactory; |
93 | 94 | import com.oracle.truffle.api.CompilerDirectives;
|
94 | 95 | import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
|
95 | 96 | import com.oracle.truffle.api.dsl.Bind;
|
@@ -556,32 +557,26 @@ abstract static class RECheckInputTypeNode extends Node {
|
556 | 557 | public abstract void execute(VirtualFrame frame, Object input, boolean expectBytes);
|
557 | 558 |
|
558 | 559 | @Specialization
|
559 |
| - static void check(VirtualFrame frame, Object input, boolean expectBytes, |
| 560 | + static void check(Object input, boolean expectBytes, |
560 | 561 | @Bind("this") Node inliningTarget,
|
561 |
| - @Cached("getSupportedBinaryInputTypes()") PTuple supportedBinaryInputTypes, |
562 |
| - @Cached BuiltinFunctions.IsInstanceNode isStringNode, |
563 |
| - @Cached BuiltinFunctions.IsInstanceNode isBytesNode, |
564 |
| - @Cached InlinedConditionProfile unsupportedInputTypeProfile, |
565 |
| - @Cached InlinedConditionProfile unexpectedInputTypeProfile, |
566 |
| - @Cached PRaiseNode raiseNode) { |
567 |
| - boolean isString = (boolean) isStringNode.execute(frame, input, PythonBuiltinClassType.PString); |
568 |
| - boolean isBytes = !isString && (boolean) isBytesNode.execute(frame, input, supportedBinaryInputTypes); |
569 |
| - if (unsupportedInputTypeProfile.profile(inliningTarget, !isString && !isBytes)) { |
570 |
| - throw raiseNode.raise(inliningTarget, TypeError, T_UNSUPPORTED_INPUT_TYPE); |
571 |
| - } |
572 |
| - if (unexpectedInputTypeProfile.profile(inliningTarget, expectBytes != isBytes)) { |
| 562 | + @Cached PyUnicodeCheckNode unicodeCheckNode, |
| 563 | + @Cached BytesNodes.BytesLikeCheck bytesLikeCheck, |
| 564 | + @Cached PRaiseNode unexpectedStrRaise, |
| 565 | + @Cached PRaiseNode unexpectedBytesRaise, |
| 566 | + @Cached PRaiseNode unexpectedTypeRaise) { |
| 567 | + if (unicodeCheckNode.execute(inliningTarget, input)) { |
573 | 568 | if (expectBytes) {
|
574 |
| - throw raiseNode.raise(inliningTarget, TypeError, T_UNEXPECTED_STR); |
575 |
| - } else { |
576 |
| - throw raiseNode.raise(inliningTarget, TypeError, T_UNEXPECTED_BYTES); |
| 569 | + throw unexpectedStrRaise.raise(inliningTarget, TypeError, T_UNEXPECTED_STR); |
577 | 570 | }
|
| 571 | + return; |
578 | 572 | }
|
579 |
| - } |
580 |
| - |
581 |
| - @NeverDefault |
582 |
| - protected PTuple getSupportedBinaryInputTypes() { |
583 |
| - return PFactory.createTuple(PythonLanguage.get(null), new Object[]{PythonBuiltinClassType.PBytes, PythonBuiltinClassType.PByteArray, PythonBuiltinClassType.PMMap, |
584 |
| - PythonBuiltinClassType.PMemoryView, PythonBuiltinClassType.PArray}); |
| 573 | + if (bytesLikeCheck.execute(inliningTarget, input) || input instanceof PMMap || input instanceof PMemoryView || input instanceof PArray) { |
| 574 | + if (!expectBytes) { |
| 575 | + throw unexpectedBytesRaise.raise(inliningTarget, TypeError, T_UNEXPECTED_BYTES); |
| 576 | + } |
| 577 | + return; |
| 578 | + } |
| 579 | + throw unexpectedTypeRaise.raise(inliningTarget, TypeError, T_UNSUPPORTED_INPUT_TYPE); |
585 | 580 | }
|
586 | 581 | }
|
587 | 582 |
|
|
0 commit comments