|
86 | 86 | import com.oracle.graal.python.nodes.control.GetNextNode;
|
87 | 87 | import com.oracle.graal.python.nodes.function.builtins.clinic.ArgumentCastNode;
|
88 | 88 | import com.oracle.graal.python.nodes.object.IsBuiltinClassProfile;
|
89 |
| -import com.oracle.graal.python.nodes.truffle.PythonArithmeticTypes; |
90 | 89 | import com.oracle.graal.python.nodes.util.CastToByteNode;
|
91 | 90 | import com.oracle.graal.python.nodes.util.CastToJavaByteNode;
|
92 | 91 | import com.oracle.graal.python.nodes.util.CastToJavaStringNode;
|
|
106 | 105 | import com.oracle.truffle.api.dsl.GenerateUncached;
|
107 | 106 | import com.oracle.truffle.api.dsl.ImportStatic;
|
108 | 107 | import com.oracle.truffle.api.dsl.Specialization;
|
109 |
| -import com.oracle.truffle.api.dsl.TypeSystemReference; |
110 | 108 | import com.oracle.truffle.api.frame.VirtualFrame;
|
111 | 109 | import com.oracle.truffle.api.interop.UnsupportedMessageException;
|
112 | 110 | import com.oracle.truffle.api.library.CachedLibrary;
|
@@ -588,7 +586,6 @@ public static ExpectStringNode create(@ArgumentIndex int argNum, String classNam
|
588 | 586 | }
|
589 | 587 | }
|
590 | 588 |
|
591 |
| - @TypeSystemReference(PythonArithmeticTypes.class) |
592 | 589 | @ImportStatic(PGuards.class)
|
593 | 590 | public abstract static class BytesInitNode extends PNodeWithRaise {
|
594 | 591 |
|
@@ -629,15 +626,16 @@ static byte[] fromIterable(VirtualFrame frame, Object source, @SuppressWarnings(
|
629 | 626 | return toByteNode.execute(frame, source, lenNode.execute(frame, source));
|
630 | 627 | }
|
631 | 628 |
|
632 |
| - @Specialization |
633 |
| - byte[] fromString(String source, String encoding, @SuppressWarnings("unused") Object errors) { |
| 629 | + @Specialization(guards = {"isString(source)", "isString(encoding)"}) |
| 630 | + byte[] fromString(Object source, Object encoding, Object errors, |
| 631 | + @Cached CastToJavaStringNode castStr) { |
634 | 632 | String e = errors instanceof String ? (String) errors : "strict";
|
635 |
| - return BytesBuiltins.stringToByte(source, encoding, e, getRaiseNode()); |
| 633 | + return BytesBuiltins.stringToByte(castStr.execute(source), castStr.execute(encoding), e, getRaiseNode()); |
636 | 634 | }
|
637 | 635 |
|
638 |
| - @Specialization |
| 636 | + @Specialization(guards = "isString(source)") |
639 | 637 | @SuppressWarnings("unused")
|
640 |
| - byte[] fromString(String source, PNone encoding, Object errors) { |
| 638 | + byte[] fromString(Object source, PNone encoding, Object errors) { |
641 | 639 | throw raise(TypeError, ErrorMessages.STRING_ARG_WO_ENCODING);
|
642 | 640 | }
|
643 | 641 |
|
@@ -838,7 +836,7 @@ static String doit(VirtualFrame frame, Object value,
|
838 | 836 | }
|
839 | 837 |
|
840 | 838 | /*-
|
841 |
| - * This should be equivalent to PyUnicode_EncodeFSDefault |
| 839 | + * This should be equivalent to PyUnicode_EncodeFSDefault |
842 | 840 | * TODO: encoding perference is set per context but will force
|
843 | 841 | * it to UTF-8 for the time being.
|
844 | 842 | */
|
|
0 commit comments