46
46
import static com .oracle .graal .python .builtins .objects .exception .UnicodeErrorBuiltins .IDX_REASON ;
47
47
import static com .oracle .graal .python .builtins .objects .exception .UnicodeErrorBuiltins .IDX_START ;
48
48
import static com .oracle .graal .python .builtins .objects .exception .UnicodeErrorBuiltins .UNICODE_ERROR_ATTR_FACTORY ;
49
+ import static com .oracle .graal .python .builtins .objects .exception .UnicodeErrorBuiltins .getArgAsBytes ;
49
50
import static com .oracle .graal .python .builtins .objects .exception .UnicodeErrorBuiltins .getArgAsInt ;
50
- import static com .oracle .graal .python .builtins .objects .exception .UnicodeErrorBuiltins .getArgAsObject ;
51
51
import static com .oracle .graal .python .builtins .objects .exception .UnicodeErrorBuiltins .getArgAsString ;
52
52
import static com .oracle .graal .python .nodes .SpecialMethodNames .__INIT__ ;
53
53
import static com .oracle .graal .python .nodes .SpecialMethodNames .__STR__ ;
59
59
import com .oracle .graal .python .builtins .PythonBuiltinClassType ;
60
60
import com .oracle .graal .python .builtins .PythonBuiltins ;
61
61
import com .oracle .graal .python .builtins .objects .PNone ;
62
- import com .oracle .graal .python .lib . PyObjectGetItem ;
63
- import com .oracle .graal .python .lib . PyObjectSizeNode ;
62
+ import com .oracle .graal .python .builtins . objects . bytes . PBytesLike ;
63
+ import com .oracle .graal .python .builtins . objects . common . SequenceStorageNodes ;
64
64
import com .oracle .graal .python .lib .PyObjectStrAsJavaStringNode ;
65
65
import com .oracle .graal .python .nodes .function .PythonBuiltinBaseNode ;
66
66
import com .oracle .graal .python .nodes .function .PythonBuiltinNode ;
@@ -88,15 +88,16 @@ public abstract static class UnicodeDecodeErrorInitNode extends PythonBuiltinNod
88
88
public abstract Object execute (VirtualFrame frame , PBaseException self , Object [] args );
89
89
90
90
@ Specialization
91
- Object initNoArgs (PBaseException self , Object [] args ,
91
+ Object initNoArgs (VirtualFrame frame , PBaseException self , Object [] args ,
92
+ @ Cached UnicodeErrorBuiltins .GetArgAsBytesNode getArgAsBytesNode ,
92
93
@ Cached CastToJavaStringNode toJavaStringNode ,
93
94
@ Cached CastToJavaIntExactNode toJavaIntExactNode ,
94
95
@ Cached BaseExceptionBuiltins .BaseExceptionInitNode baseInitNode ) {
95
96
baseInitNode .execute (self , args );
96
97
// PyArg_ParseTuple(args, "UOnnU"), TODO: add proper error messages
97
98
self .setExceptionAttributes (new Object []{
98
99
getArgAsString (args , 0 , this , toJavaStringNode ),
99
- getArgAsObject ( args , 1 , this ),
100
+ getArgAsBytes ( frame , args , 1 , this , getArgAsBytesNode ),
100
101
getArgAsInt (args , 2 , this , toJavaIntExactNode ),
101
102
getArgAsInt (args , 3 , this , toJavaIntExactNode ),
102
103
getArgAsString (args , 4 , this , toJavaStringNode )
@@ -111,8 +112,8 @@ public abstract static class UnicodeEncodeErrorStrNode extends PythonUnaryBuilti
111
112
@ Specialization
112
113
Object str (VirtualFrame frame , PBaseException self ,
113
114
@ Cached BaseExceptionAttrNode attrNode ,
114
- @ Cached PyObjectGetItem getItem ,
115
- @ Cached PyObjectSizeNode sizeNode ,
115
+ @ Cached SequenceStorageNodes . GetItemNode getitemNode ,
116
+ @ Cached SequenceStorageNodes . LenNode lenNode ,
116
117
@ Cached PyObjectStrAsJavaStringNode strNode ) {
117
118
if (self .getExceptionAttributes () == null ) {
118
119
// Not properly initialized.
@@ -121,13 +122,13 @@ Object str(VirtualFrame frame, PBaseException self,
121
122
122
123
// Get reason and encoding as strings, which they might not be if they've been
123
124
// modified after we were constructed.
124
- Object object = attrNode .get (self , IDX_OBJECT , UNICODE_ERROR_ATTR_FACTORY );
125
+ PBytesLike object = ( PBytesLike ) attrNode .get (self , IDX_OBJECT , UNICODE_ERROR_ATTR_FACTORY );
125
126
final int start = attrNode .getInt (self , IDX_START , UNICODE_ERROR_ATTR_FACTORY );
126
127
final int end = attrNode .getInt (self , IDX_END , UNICODE_ERROR_ATTR_FACTORY );
127
128
final String encoding = strNode .execute (frame , attrNode .get (self , IDX_ENCODING , UNICODE_ERROR_ATTR_FACTORY ));
128
129
final String reason = strNode .execute (frame , attrNode .get (self , IDX_REASON , UNICODE_ERROR_ATTR_FACTORY ));
129
- if (start < sizeNode .execute (frame , object ) && end == start + 1 ) {
130
- final int b = (int ) getItem .execute (frame , object , 0 );
130
+ if (start < lenNode .execute (object . getSequenceStorage () ) && end == start + 1 ) {
131
+ final int b = (int ) getitemNode .execute (frame , object . getSequenceStorage () , 0 );
131
132
return PythonUtils .format ("'%s' codec can't decode byte 0x%02x in position %d: %s" , encoding , b , start , reason );
132
133
} else {
133
134
return PythonUtils .format ("'%s' codec can't decode bytes in position %d-%d: %s" , encoding , start , end - 1 , reason );
0 commit comments