63
63
import com .oracle .graal .python .nodes .PNodeWithContext ;
64
64
import com .oracle .graal .python .nodes .PRaiseNode ;
65
65
import com .oracle .graal .python .nodes .truffle .PythonArithmeticTypes ;
66
+ import com .oracle .graal .python .nodes .util .CastToJavaLongNode ;
67
+ import com .oracle .graal .python .nodes .util .CastToJavaLongNode .CannotCastException ;
66
68
import com .oracle .graal .python .nodes .util .CastToJavaStringNode ;
67
69
import com .oracle .graal .python .runtime .PythonOptions ;
68
70
import com .oracle .graal .python .runtime .object .PythonObjectFactory ;
@@ -254,24 +256,25 @@ public static String getUTF32Name(int byteorder) {
254
256
@ ImportStatic (PythonOptions .class )
255
257
public abstract static class UnicodeFromWcharNode extends PNodeWithContext {
256
258
257
- public abstract String execute (Object arr , Object length , Object elementSize );
259
+ public abstract String execute (Object arr , Object elementSize );
258
260
259
261
@ Specialization (guards = "elementSize == cachedElementSize" , limit = "getVariableArgumentInlineCacheLimit()" )
260
- static String doBytes (Object arr , long n , long elementSize ,
261
- @ Cached ("elementSize" ) long cachedElementSize ,
262
+ static String doBytes (Object arr , @ SuppressWarnings ( "unused" ) long elementSize ,
263
+ @ Cached (value = "elementSize" , allowUncached = true ) long cachedElementSize ,
262
264
@ CachedLibrary ("arr" ) InteropLibrary lib ,
263
265
@ CachedLibrary (limit = "1" ) InteropLibrary elemLib ,
264
266
@ Exclusive @ Cached PRaiseNode raiseNode ) {
265
267
try {
266
268
ByteBuffer bytes ;
267
269
if (cachedElementSize == 1L || cachedElementSize == 2L || cachedElementSize == 4L ) {
268
270
if (!lib .hasArrayElements (arr )) {
269
- throw raiseNode .raise (SystemError , "provided object is not an array" , elementSize );
271
+ throw raiseNode .raise (SystemError , "provided object is not an array" , cachedElementSize );
270
272
}
271
- bytes = readWithSize (lib , elemLib , arr , PInt .intValueExact (n ), (int ) cachedElementSize );
273
+ long arraySize = lib .getArraySize (arr );
274
+ bytes = readWithSize (lib , elemLib , arr , PInt .intValueExact (arraySize ), (int ) cachedElementSize );
272
275
bytes .flip ();
273
276
} else {
274
- throw raiseNode .raise (ValueError , "unsupported 'wchar_t' size; was: %d" , elementSize );
277
+ throw raiseNode .raise (ValueError , "unsupported 'wchar_t' size; was: %d" , cachedElementSize );
275
278
}
276
279
return decode (bytes );
277
280
} catch (ArithmeticException e ) {
@@ -288,14 +291,15 @@ static String doBytes(Object arr, long n, long elementSize,
288
291
}
289
292
290
293
@ Specialization (limit = "getVariableArgumentInlineCacheLimit()" )
291
- static String doBytes (Object arr , PInt n , PInt elementSize ,
294
+ static String doBytes (Object arr , Object elementSizeObj ,
295
+ @ Cached CastToJavaLongNode castToJavaLongNode ,
292
296
@ CachedLibrary ("arr" ) InteropLibrary lib ,
293
297
@ CachedLibrary (limit = "1" ) InteropLibrary elemLib ,
294
298
@ Exclusive @ Cached PRaiseNode raiseNode ) {
295
299
try {
296
- long es = elementSize . longValueExact ( );
297
- return doBytes (arr , n . longValueExact (), es , es , lib , elemLib , raiseNode );
298
- } catch (ArithmeticException e ) {
300
+ long es = castToJavaLongNode . execute ( elementSizeObj );
301
+ return doBytes (arr , es , es , lib , elemLib , raiseNode );
302
+ } catch (CannotCastException e ) {
299
303
throw raiseNode .raise (ValueError , "invalid parameters" );
300
304
}
301
305
}
0 commit comments