68
68
import com .oracle .graal .python .nodes .function .builtins .PythonClinicBuiltinNode ;
69
69
import com .oracle .graal .python .nodes .function .builtins .PythonTernaryClinicBuiltinNode ;
70
70
import com .oracle .graal .python .nodes .function .builtins .PythonUnaryClinicBuiltinNode ;
71
- import com .oracle .graal .python .nodes .function .builtins .clinic .ArgumentCastNode ;
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 ;
77
78
import com .oracle .truffle .api .dsl .Fallback ;
78
79
import com .oracle .truffle .api .dsl .GenerateNodeFactory ;
79
80
import com .oracle .truffle .api .dsl .NodeFactory ;
80
81
import com .oracle .truffle .api .dsl .Specialization ;
82
+ import com .oracle .truffle .api .frame .VirtualFrame ;
81
83
import com .oracle .truffle .api .library .CachedLibrary ;
82
84
import com .oracle .truffle .api .library .ExportLibrary ;
83
85
import com .oracle .truffle .api .library .ExportMessage ;
@@ -90,11 +92,11 @@ protected List<? extends NodeFactory<? extends PythonBuiltinBaseNode>> getNodeFa
90
92
return BinasciiModuleBuiltinsFactory .getFactories ();
91
93
}
92
94
93
- abstract static class AsciiBufferConverter extends ArgumentCastNode . ArgumentCastNodeWithRaise {
95
+ abstract static class AsciiBufferConverter extends ArgumentCastNodeWithRaiseAndIndirectCall {
94
96
@ Specialization (guards = "acquireLib.hasBuffer(value)" , limit = "getCallSiteInlineCacheMaxDepth()" )
95
- Object doObject (Object value ,
97
+ Object doObject (VirtualFrame frame , Object value ,
96
98
@ CachedLibrary ("value" ) PythonBufferAcquireLibrary acquireLib ) {
97
- return acquireLib .acquireReadonly (value );
99
+ return acquireLib .acquireReadonly (value , frame , getContext (), getLanguage (), this );
98
100
}
99
101
100
102
@ ExportLibrary (PythonBufferAccessLibrary .class )
@@ -156,24 +158,25 @@ public static AsciiBufferConverter create() {
156
158
@ GenerateNodeFactory
157
159
abstract static class A2bBase64Node extends PythonUnaryClinicBuiltinNode {
158
160
@ Specialization (limit = "3" )
159
- PBytes doConvert (Object buffer ,
161
+ PBytes doConvert (VirtualFrame frame , Object buffer ,
160
162
@ CachedLibrary ("buffer" ) PythonBufferAccessLibrary bufferLib ) {
161
163
try {
162
- return b64decode (bufferLib .getInternalOrCopiedByteArray (buffer ), bufferLib .getBufferLength (buffer ));
164
+ ByteSequenceStorage storage = b64decode (bufferLib .getInternalOrCopiedByteArray (buffer ), bufferLib .getBufferLength (buffer ));
165
+ return factory ().createBytes (storage );
163
166
} finally {
164
- bufferLib .release (buffer );
167
+ bufferLib .release (buffer , frame , this );
165
168
}
166
169
}
167
170
168
171
@ TruffleBoundary
169
- private PBytes b64decode (byte [] data , int dataLen ) {
172
+ private ByteSequenceStorage b64decode (byte [] data , int dataLen ) {
170
173
try {
171
174
// Using MIME decoder because that one skips over anything that is not the alphabet,
172
175
// just like CPython does
173
176
ByteBuffer result = Base64 .getMimeDecoder ().decode (ByteBuffer .wrap (data , 0 , dataLen ));
174
- return factory (). createBytes (result .array (), result .limit ());
177
+ return new ByteSequenceStorage (result .array (), result .limit ());
175
178
} catch (IllegalArgumentException e ) {
176
- throw raise ( BinasciiError , e );
179
+ throw PRaiseNode . raiseUncached ( this , BinasciiError , e );
177
180
}
178
181
}
179
182
@@ -188,25 +191,26 @@ protected ArgumentClinicProvider getArgumentClinic() {
188
191
@ GenerateNodeFactory
189
192
abstract static class A2bHexNode extends PythonUnaryClinicBuiltinNode {
190
193
@ Specialization (limit = "3" )
191
- PBytes a2b (Object buffer ,
194
+ PBytes a2b (VirtualFrame frame , Object buffer ,
192
195
@ CachedLibrary ("buffer" ) PythonBufferAccessLibrary bufferLib ) {
193
196
try {
194
- return a2b (bufferLib .getInternalOrCopiedByteArray (buffer ), bufferLib .getBufferLength (buffer ));
197
+ byte [] bytes = a2b (bufferLib .getInternalOrCopiedByteArray (buffer ), bufferLib .getBufferLength (buffer ));
198
+ return factory ().createBytes (bytes );
195
199
} finally {
196
- bufferLib .release (buffer );
200
+ bufferLib .release (buffer , frame , this );
197
201
}
198
202
}
199
203
200
204
@ TruffleBoundary
201
- private PBytes a2b (byte [] bytes , int length ) {
205
+ private byte [] a2b (byte [] bytes , int length ) {
202
206
if (length % 2 != 0 ) {
203
- throw raise ( BinasciiError , ErrorMessages .ODD_LENGTH_STRING );
207
+ throw PRaiseNode . raiseUncached ( this , BinasciiError , ErrorMessages .ODD_LENGTH_STRING );
204
208
}
205
209
byte [] output = new byte [length / 2 ];
206
210
for (int i = 0 ; i < length / 2 ; i ++) {
207
211
output [i ] = (byte ) (digitValue ((char ) bytes [i * 2 ]) * 16 + digitValue ((char ) bytes [i * 2 + 1 ]));
208
212
}
209
- return factory (). createBytes ( output ) ;
213
+ return output ;
210
214
}
211
215
212
216
private int digitValue (char b ) {
@@ -217,7 +221,7 @@ private int digitValue(char b) {
217
221
} else if (b >= 'A' && b <= 'F' ) {
218
222
return b - 'A' + 10 ;
219
223
} else {
220
- throw raise ( BinasciiError , ErrorMessages .NON_HEX_DIGIT_FOUND );
224
+ throw PRaiseNode . raiseUncached ( this , BinasciiError , ErrorMessages .NON_HEX_DIGIT_FOUND );
221
225
}
222
226
}
223
227
@@ -249,12 +253,12 @@ private PBytes b2a(byte[] data, int lenght, int newline) {
249
253
}
250
254
251
255
@ Specialization (limit = "3" )
252
- PBytes b2aBuffer (Object buffer , int newline ,
256
+ PBytes b2aBuffer (VirtualFrame frame , Object buffer , int newline ,
253
257
@ CachedLibrary ("buffer" ) PythonBufferAccessLibrary bufferLib ) {
254
258
try {
255
259
return b2a (bufferLib .getInternalOrCopiedByteArray (buffer ), bufferLib .getBufferLength (buffer ), newline );
256
260
} finally {
257
- bufferLib .release (buffer );
261
+ bufferLib .release (buffer , frame , this );
258
262
}
259
263
}
260
264
@@ -273,7 +277,7 @@ abstract static class B2aHexNode extends PythonTernaryClinicBuiltinNode {
273
277
@ CompilationFinal (dimensions = 1 ) private static final byte [] HEX_DIGITS = {'0' , '1' , '2' , '3' , '4' , '5' , '6' , '7' , '8' , '9' , 'a' , 'b' , 'c' , 'd' , 'e' , 'f' };
274
278
275
279
@ Specialization (limit = "3" )
276
- PBytes b2a (Object buffer , Object sep , int bytesPerSep ,
280
+ PBytes b2a (VirtualFrame frame , Object buffer , Object sep , int bytesPerSep ,
277
281
@ CachedLibrary ("buffer" ) PythonBufferAccessLibrary bufferLib ) {
278
282
if (sep != PNone .NO_VALUE || bytesPerSep != 1 ) {
279
283
// TODO implement sep and bytes_per_sep
@@ -282,7 +286,7 @@ PBytes b2a(Object buffer, Object sep, int bytesPerSep,
282
286
try {
283
287
return b2a (bufferLib .getInternalOrCopiedByteArray (buffer ), bufferLib .getBufferLength (buffer ));
284
288
} finally {
285
- bufferLib .release (buffer );
289
+ bufferLib .release (buffer , frame , this );
286
290
}
287
291
}
288
292
@@ -310,12 +314,12 @@ protected ArgumentClinicProvider getArgumentClinic() {
310
314
abstract static class Crc32Node extends PythonBinaryClinicBuiltinNode {
311
315
// TODO crc != NO_VALUE
312
316
@ Specialization (guards = "isNoValue(crc)" , limit = "3" )
313
- static long b2a (Object buffer , @ SuppressWarnings ("unused" ) PNone crc ,
317
+ long b2a (VirtualFrame frame , Object buffer , @ SuppressWarnings ("unused" ) PNone crc ,
314
318
@ CachedLibrary ("buffer" ) PythonBufferAccessLibrary bufferLib ) {
315
319
try {
316
320
return getCrcValue (bufferLib .getInternalOrCopiedByteArray (buffer ), bufferLib .getBufferLength (buffer ));
317
321
} finally {
318
- bufferLib .release (buffer );
322
+ bufferLib .release (buffer , frame , this );
319
323
}
320
324
}
321
325
0 commit comments