71
71
import com .oracle .graal .python .nodes .function .builtins .clinic .ArgumentCastNode .ArgumentCastNodeWithRaiseAndIndirectCall ;
72
72
import com .oracle .graal .python .nodes .function .builtins .clinic .ArgumentClinicProvider ;
73
73
import com .oracle .graal .python .nodes .util .CastToJavaStringNode ;
74
+ import com .oracle .graal .python .runtime .sequence .storage .ByteSequenceStorage ;
74
75
import com .oracle .truffle .api .CompilerDirectives .CompilationFinal ;
75
76
import com .oracle .truffle .api .CompilerDirectives .TruffleBoundary ;
76
77
import com .oracle .truffle .api .dsl .Cached ;
@@ -160,21 +161,22 @@ abstract static class A2bBase64Node extends PythonUnaryClinicBuiltinNode {
160
161
PBytes doConvert (VirtualFrame frame , Object buffer ,
161
162
@ CachedLibrary ("buffer" ) PythonBufferAccessLibrary bufferLib ) {
162
163
try {
163
- return b64decode (bufferLib .getInternalOrCopiedByteArray (buffer ), bufferLib .getBufferLength (buffer ));
164
+ ByteSequenceStorage storage = b64decode (bufferLib .getInternalOrCopiedByteArray (buffer ), bufferLib .getBufferLength (buffer ));
165
+ return factory ().createBytes (storage );
164
166
} finally {
165
167
bufferLib .release (buffer , frame , this );
166
168
}
167
169
}
168
170
169
171
@ TruffleBoundary
170
- private PBytes b64decode (byte [] data , int dataLen ) {
172
+ private ByteSequenceStorage b64decode (byte [] data , int dataLen ) {
171
173
try {
172
174
// Using MIME decoder because that one skips over anything that is not the alphabet,
173
175
// just like CPython does
174
176
ByteBuffer result = Base64 .getMimeDecoder ().decode (ByteBuffer .wrap (data , 0 , dataLen ));
175
- return factory (). createBytes (result .array (), result .limit ());
177
+ return new ByteSequenceStorage (result .array (), result .limit ());
176
178
} catch (IllegalArgumentException e ) {
177
- throw raise ( BinasciiError , e );
179
+ throw PRaiseNode . raiseUncached ( this , BinasciiError , e );
178
180
}
179
181
}
180
182
@@ -192,22 +194,23 @@ abstract static class A2bHexNode extends PythonUnaryClinicBuiltinNode {
192
194
PBytes a2b (VirtualFrame frame , Object buffer ,
193
195
@ CachedLibrary ("buffer" ) PythonBufferAccessLibrary bufferLib ) {
194
196
try {
195
- return a2b (bufferLib .getInternalOrCopiedByteArray (buffer ), bufferLib .getBufferLength (buffer ));
197
+ byte [] bytes = a2b (bufferLib .getInternalOrCopiedByteArray (buffer ), bufferLib .getBufferLength (buffer ));
198
+ return factory ().createBytes (bytes );
196
199
} finally {
197
200
bufferLib .release (buffer , frame , this );
198
201
}
199
202
}
200
203
201
204
@ TruffleBoundary
202
- private PBytes a2b (byte [] bytes , int length ) {
205
+ private byte [] a2b (byte [] bytes , int length ) {
203
206
if (length % 2 != 0 ) {
204
- throw raise ( BinasciiError , ErrorMessages .ODD_LENGTH_STRING );
207
+ throw PRaiseNode . raiseUncached ( this , BinasciiError , ErrorMessages .ODD_LENGTH_STRING );
205
208
}
206
209
byte [] output = new byte [length / 2 ];
207
210
for (int i = 0 ; i < length / 2 ; i ++) {
208
211
output [i ] = (byte ) (digitValue ((char ) bytes [i * 2 ]) * 16 + digitValue ((char ) bytes [i * 2 + 1 ]));
209
212
}
210
- return factory (). createBytes ( output ) ;
213
+ return output ;
211
214
}
212
215
213
216
private int digitValue (char b ) {
@@ -218,7 +221,7 @@ private int digitValue(char b) {
218
221
} else if (b >= 'A' && b <= 'F' ) {
219
222
return b - 'A' + 10 ;
220
223
} else {
221
- throw raise ( BinasciiError , ErrorMessages .NON_HEX_DIGIT_FOUND );
224
+ throw PRaiseNode . raiseUncached ( this , BinasciiError , ErrorMessages .NON_HEX_DIGIT_FOUND );
222
225
}
223
226
}
224
227
0 commit comments