Skip to content

Commit 4550fd7

Browse files
committed
Add TruffleBoundary to generic specializations.
1 parent f778235 commit 4550fd7

File tree

1 file changed

+16
-6
lines changed
  • graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/common

1 file changed

+16
-6
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/common/CExtCommonNodes.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -535,39 +535,41 @@ static long doPInt(Frame frame, @SuppressWarnings("unused") long obj, @SuppressW
535535
}
536536

537537
@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,
539540
@Shared("raiseNativeNode") @Cached PRaiseNativeNode raiseNativeNode) {
540541
try {
541542
if (signed != 0) {
542543
return obj.intValueExact();
543544
} else if (obj.bitCount() <= 32) {
544545
if (obj.isNegative()) {
545-
return raiseNegativeValue(frame, raiseNativeNode);
546+
return raiseNegativeValue(raiseNativeNode);
546547
}
547548
return obj.intValue();
548549
}
549550
} catch (ArithmeticException e) {
550551
// fall through
551552
}
552-
return raiseTooLarge(frame, raiseNativeNode, targetTypeSize);
553+
return raiseTooLarge(raiseNativeNode, targetTypeSize);
553554
}
554555

555556
@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,
557559
@Shared("raiseNativeNode") @Cached PRaiseNativeNode raiseNativeNode) {
558560
try {
559561
if (signed != 0) {
560562
return obj.longValueExact();
561563
} else if (obj.bitCount() <= 64) {
562564
if (obj.isNegative()) {
563-
return raiseNegativeValue(frame, raiseNativeNode);
565+
return raiseNegativeValue(raiseNativeNode);
564566
}
565567
return obj.longValue();
566568
}
567569
} catch (ArithmeticException e) {
568570
// fall through
569571
}
570-
return raiseTooLarge(frame, raiseNativeNode, targetTypeSize);
572+
return raiseTooLarge(raiseNativeNode, targetTypeSize);
571573
}
572574

573575
@Specialization(guards = {"targetTypeSize != 4", "targetTypeSize != 8"})
@@ -582,6 +584,10 @@ static Object doGeneric(Object obj, int signed, long targetTypeSize,
582584
return asNativePrimitiveNode.execute(obj, signed, (int) targetTypeSize, true);
583585
}
584586

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+
585591
private static int raiseTooLarge(Frame frame, PRaiseNativeNode raiseNativeNode, long targetTypeSize) {
586592
return raiseNativeNode.raiseInt(frame, -1, OverflowError, ErrorMessages.PYTHON_INT_TOO_LARGE_TO_CONV_TO_C_TYPE, targetTypeSize);
587593
}
@@ -590,6 +596,10 @@ private static Integer raiseUnsupportedSize(Frame frame, PRaiseNativeNode raiseN
590596
return raiseNativeNode.raiseInt(frame, -1, SystemError, ErrorMessages.UNSUPPORTED_TARGET_SIZE, targetTypeSize);
591597
}
592598

599+
private static int raiseNegativeValue(PRaiseNativeNode raiseNativeNode) {
600+
return raiseNativeNode.raiseIntWithoutFrame(-1, OverflowError, ErrorMessages.CANNOT_CONVERT_NEGATIVE_VALUE_TO_UNSIGNED_INT);
601+
}
602+
593603
private static int raiseNegativeValue(Frame frame, PRaiseNativeNode raiseNativeNode) {
594604
return raiseNativeNode.raiseInt(frame, -1, OverflowError, ErrorMessages.CANNOT_CONVERT_NEGATIVE_VALUE_TO_UNSIGNED_INT);
595605
}

0 commit comments

Comments
 (0)