@@ -2595,35 +2595,21 @@ protected static boolean isReprFormatCode(int formatCode) {
2595
2595
2596
2596
@ Builtin (name = "PyUnicode_Decode" , minNumOfPositionalArgs = 4 , declaresExplicitSelf = true )
2597
2597
@ GenerateNodeFactory
2598
- abstract static class PyUnicode_Decode extends NativeUnicodeBuiltin {
2598
+ abstract static class PyUnicode_Decode extends NativeBuiltin {
2599
2599
2600
2600
@ Specialization
2601
- Object doDecode (VirtualFrame frame , Object module , Object cByteArray , String encoding , String errors ,
2602
- @ Cached CExtNodes .ToSulongNode toSulongNode ,
2603
- @ Cached GetByteArrayNode getByteArrayNode ,
2601
+ Object doDecode (VirtualFrame frame , Object module , PMemoryView mv , String encoding , String errors ,
2602
+ @ Cached CodecsModuleBuiltins .DecodeNode decodeNode ,
2603
+ @ Cached CExtNodes .ToNewRefNode toSulongNode ,
2604
+ @ Cached TransformExceptionToNativeNode transformExceptionToNativeNode ,
2604
2605
@ Cached GetNativeNullNode getNativeNullNode ) {
2605
-
2606
2606
try {
2607
- ByteBuffer inputBuffer = wrap (getByteArrayNode .execute (cByteArray , -1 ));
2608
- int n = remaining (inputBuffer );
2609
- CharBuffer resultBuffer = allocateCharBuffer (n * 4 );
2610
- decode (resultBuffer , inputBuffer , encoding , errors );
2611
- return toSulongNode .execute (factory ().createTuple (new Object []{toString (resultBuffer ), n - remaining (inputBuffer )}));
2612
- } catch (IllegalArgumentException e ) {
2613
- return raiseNative (frame , getNativeNullNode .execute (module ), PythonErrorType .LookupError , ErrorMessages .UNKNOWN_ENCODING , encoding );
2614
- } catch (InteropException e ) {
2615
- return raiseNative (frame , getNativeNullNode .execute (module ), PythonErrorType .TypeError , "%m" , e );
2616
- } catch (OverflowException e ) {
2617
- return raiseNative (frame , getNativeNullNode .execute (module ), PythonErrorType .SystemError , ErrorMessages .INPUT_TOO_LONG );
2607
+ return toSulongNode .execute (decodeNode .executeWithStrings (frame , mv , encoding , errors ));
2608
+ } catch (PException e ) {
2609
+ transformExceptionToNativeNode .execute (frame , e );
2610
+ return toSulongNode .execute (getNativeNullNode .execute (module ));
2618
2611
}
2619
2612
}
2620
-
2621
- @ TruffleBoundary
2622
- private void decode (CharBuffer resultBuffer , ByteBuffer inputBuffer , String encoding , String errors ) {
2623
- CharsetDecoder decoder = Charset .forName (encoding ).newDecoder ();
2624
- CodingErrorAction action = BytesBuiltins .toCodingErrorAction (errors , this );
2625
- decoder .onMalformedInput (CodingErrorAction .REPORT ).onUnmappableCharacter (action ).decode (inputBuffer , resultBuffer , true );
2626
- }
2627
2613
}
2628
2614
2629
2615
@ Builtin (name = "PyObject_Size" , minNumOfPositionalArgs = 1 )
0 commit comments