|
45 | 45 | import static com.oracle.graal.python.nodes.ErrorMessages.BAD_ARG_TYPE_FOR_BUILTIN_OP; |
46 | 46 | import static com.oracle.graal.python.nodes.SpecialMethodNames.__GETITEM__; |
47 | 47 |
|
| 48 | +import java.nio.ByteBuffer; |
| 49 | +import java.nio.CharBuffer; |
| 50 | +import java.nio.charset.CharsetDecoder; |
| 51 | +import java.nio.charset.CodingErrorAction; |
| 52 | +import java.nio.charset.StandardCharsets; |
48 | 53 | import java.util.List; |
| 54 | + |
49 | 55 | import com.oracle.graal.python.builtins.Builtin; |
50 | 56 | import com.oracle.graal.python.builtins.CoreFunctions; |
51 | 57 | import com.oracle.graal.python.builtins.Python3Core; |
|
66 | 72 | import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes; |
67 | 73 | import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes.GetNativeNullNode; |
68 | 74 | import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes.PRaiseNativeNode; |
| 75 | +import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes.ToNewRefNode; |
69 | 76 | import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes.TransformExceptionToNativeNode; |
70 | 77 | import com.oracle.graal.python.builtins.objects.cext.common.CExtCommonNodes.GetByteArrayNode; |
71 | 78 | import com.oracle.graal.python.builtins.objects.ints.PInt; |
|
110 | 117 | import com.oracle.truffle.api.frame.VirtualFrame; |
111 | 118 | import com.oracle.truffle.api.interop.InteropException; |
112 | 119 | import com.oracle.truffle.api.profiles.ConditionProfile; |
113 | | -import java.nio.ByteBuffer; |
114 | | -import java.nio.CharBuffer; |
115 | | -import java.nio.charset.CharsetDecoder; |
116 | | -import java.nio.charset.CodingErrorAction; |
117 | | -import java.nio.charset.StandardCharsets; |
118 | 120 |
|
119 | 121 | @CoreFunctions(extendsModule = PythonCextBuiltins.PYTHON_CEXT) |
120 | 122 | @GenerateNodeFactory |
@@ -731,7 +733,7 @@ int doGeneric(Object type, long lindex, |
731 | 733 | abstract static class PyUnicodeNewNode extends PythonBuiltinNode { |
732 | 734 | @Specialization |
733 | 735 | Object doGeneric(Object ptr, int elementSize, int isAscii, |
734 | | - @Cached CExtNodes.ToNewRefNode toNewRefNode) { |
| 736 | + @Cached ToNewRefNode toNewRefNode) { |
735 | 737 | return toNewRefNode.execute(factory().createString(new NativeCharSequence(ptr, elementSize, isAscii != 0))); |
736 | 738 | } |
737 | 739 | } |
@@ -766,6 +768,24 @@ int contains(VirtualFrame frame, Object haystack, Object needle, |
766 | 768 | } |
767 | 769 | } |
768 | 770 |
|
| 771 | + @Builtin(name = "PyUnicode_Split", minNumOfPositionalArgs = 4, declaresExplicitSelf = true) |
| 772 | + @GenerateNodeFactory |
| 773 | + abstract static class PyUnicodeSplit extends PythonQuaternaryBuiltinNode { |
| 774 | + @Specialization |
| 775 | + Object split(VirtualFrame frame, Object module, Object string, Object sep, Object maxsplit, |
| 776 | + @Cached StringBuiltins.SplitNode splitNode, |
| 777 | + @Cached ToNewRefNode toSulongNode, |
| 778 | + @Cached TransformExceptionToNativeNode transformExceptionToNativeNode, |
| 779 | + @Cached GetNativeNullNode getNativeNullNode) { |
| 780 | + try { |
| 781 | + return toSulongNode.execute(splitNode.execute(frame, string, sep, maxsplit)); |
| 782 | + } catch (PException e) { |
| 783 | + transformExceptionToNativeNode.execute(frame, e); |
| 784 | + return getNativeNullNode.execute(module); |
| 785 | + } |
| 786 | + } |
| 787 | + } |
| 788 | + |
769 | 789 | @Builtin(name = "_PyUnicode_AsUTF8String", minNumOfPositionalArgs = 3) |
770 | 790 | @GenerateNodeFactory |
771 | 791 | abstract static class _PyUnicode_AsUTF8String extends NativeEncoderNode { |
@@ -813,7 +833,7 @@ abstract static class PyUnicode_Decode extends NativeBuiltin { |
813 | 833 | @Specialization |
814 | 834 | Object doDecode(VirtualFrame frame, Object module, PMemoryView mv, String encoding, String errors, |
815 | 835 | @Cached CodecsModuleBuiltins.DecodeNode decodeNode, |
816 | | - @Cached CExtNodes.ToNewRefNode toSulongNode, |
| 836 | + @Cached ToNewRefNode toSulongNode, |
817 | 837 | @Cached TransformExceptionToNativeNode transformExceptionToNativeNode, |
818 | 838 | @Cached GetNativeNullNode getNativeNullNode) { |
819 | 839 | try { |
|
0 commit comments