@@ -535,39 +535,41 @@ static long doPInt(Frame frame, @SuppressWarnings("unused") long obj, @SuppressW
535
535
}
536
536
537
537
@ Specialization (guards = "targetTypeSize == 4" )
538
- static int doPIntTo32Bit (Frame frame , PInt obj , int signed , @ SuppressWarnings ("unused" ) long targetTypeSize ,
538
+ @ TruffleBoundary
539
+ static int doPIntTo32Bit (PInt obj , int signed , @ SuppressWarnings ("unused" ) long targetTypeSize ,
539
540
@ Shared ("raiseNativeNode" ) @ Cached PRaiseNativeNode raiseNativeNode ) {
540
541
try {
541
542
if (signed != 0 ) {
542
543
return obj .intValueExact ();
543
544
} else if (obj .bitCount () <= 32 ) {
544
545
if (obj .isNegative ()) {
545
- return raiseNegativeValue (frame , raiseNativeNode );
546
+ return raiseNegativeValue (raiseNativeNode );
546
547
}
547
548
return obj .intValue ();
548
549
}
549
550
} catch (ArithmeticException e ) {
550
551
// fall through
551
552
}
552
- return raiseTooLarge (frame , raiseNativeNode , targetTypeSize );
553
+ return raiseTooLarge (raiseNativeNode , targetTypeSize );
553
554
}
554
555
555
556
@ Specialization (guards = "targetTypeSize == 8" )
556
- static long doPIntTo64Bit (Frame frame , PInt obj , int signed , @ SuppressWarnings ("unused" ) long targetTypeSize ,
557
+ @ TruffleBoundary
558
+ static long doPIntTo64Bit (PInt obj , int signed , @ SuppressWarnings ("unused" ) long targetTypeSize ,
557
559
@ Shared ("raiseNativeNode" ) @ Cached PRaiseNativeNode raiseNativeNode ) {
558
560
try {
559
561
if (signed != 0 ) {
560
562
return obj .longValueExact ();
561
563
} else if (obj .bitCount () <= 64 ) {
562
564
if (obj .isNegative ()) {
563
- return raiseNegativeValue (frame , raiseNativeNode );
565
+ return raiseNegativeValue (raiseNativeNode );
564
566
}
565
567
return obj .longValue ();
566
568
}
567
569
} catch (ArithmeticException e ) {
568
570
// fall through
569
571
}
570
- return raiseTooLarge (frame , raiseNativeNode , targetTypeSize );
572
+ return raiseTooLarge (raiseNativeNode , targetTypeSize );
571
573
}
572
574
573
575
@ Specialization (guards = {"targetTypeSize != 4" , "targetTypeSize != 8" })
@@ -582,6 +584,10 @@ static Object doGeneric(Object obj, int signed, long targetTypeSize,
582
584
return asNativePrimitiveNode .execute (obj , signed , (int ) targetTypeSize , true );
583
585
}
584
586
587
+ private static int raiseTooLarge (PRaiseNativeNode raiseNativeNode , long targetTypeSize ) {
588
+ return raiseNativeNode .raiseIntWithoutFrame (-1 , OverflowError , ErrorMessages .PYTHON_INT_TOO_LARGE_TO_CONV_TO_C_TYPE , targetTypeSize );
589
+ }
590
+
585
591
private static int raiseTooLarge (Frame frame , PRaiseNativeNode raiseNativeNode , long targetTypeSize ) {
586
592
return raiseNativeNode .raiseInt (frame , -1 , OverflowError , ErrorMessages .PYTHON_INT_TOO_LARGE_TO_CONV_TO_C_TYPE , targetTypeSize );
587
593
}
@@ -590,6 +596,10 @@ private static Integer raiseUnsupportedSize(Frame frame, PRaiseNativeNode raiseN
590
596
return raiseNativeNode .raiseInt (frame , -1 , SystemError , ErrorMessages .UNSUPPORTED_TARGET_SIZE , targetTypeSize );
591
597
}
592
598
599
+ private static int raiseNegativeValue (PRaiseNativeNode raiseNativeNode ) {
600
+ return raiseNativeNode .raiseIntWithoutFrame (-1 , OverflowError , ErrorMessages .CANNOT_CONVERT_NEGATIVE_VALUE_TO_UNSIGNED_INT );
601
+ }
602
+
593
603
private static int raiseNegativeValue (Frame frame , PRaiseNativeNode raiseNativeNode ) {
594
604
return raiseNativeNode .raiseInt (frame , -1 , OverflowError , ErrorMessages .CANNOT_CONVERT_NEGATIVE_VALUE_TO_UNSIGNED_INT );
595
605
}
0 commit comments