@@ -1698,57 +1698,63 @@ static Object doNativeWrapper(PythonContext context, String name, DynamicObjectN
1698
1698
static Object doPrimitiveWrapper (PythonContext context , String name , @ SuppressWarnings ("unused" ) PythonNativeWrapper result ,
1699
1699
@ Shared ("language" ) @ CachedLanguage PythonLanguage language ,
1700
1700
@ Shared ("fact" ) @ Cached PythonObjectFactory factory ,
1701
- @ Shared ("raise" ) @ Cached PRaiseNode raise ) {
1702
- checkFunctionResult (name , false , false , language , context , raise , factory );
1701
+ @ Shared ("raise" ) @ Cached PRaiseNode raise ,
1702
+ @ Shared ("errOccurredProfile" ) @ Cached ConditionProfile errOccurredProfile ) {
1703
+ checkFunctionResult (name , false , false , language , context , raise , factory , errOccurredProfile );
1703
1704
return result ;
1704
1705
}
1705
1706
1706
1707
@ Specialization (guards = "isNoValue(result)" )
1707
1708
static Object doNoValue (PythonContext context , String name , @ SuppressWarnings ("unused" ) PNone result ,
1708
1709
@ Shared ("language" ) @ CachedLanguage PythonLanguage language ,
1709
1710
@ Shared ("fact" ) @ Cached PythonObjectFactory factory ,
1710
- @ Shared ("raise" ) @ Cached PRaiseNode raise ) {
1711
- checkFunctionResult (name , true , false , language , context , raise , factory );
1711
+ @ Shared ("raise" ) @ Cached PRaiseNode raise ,
1712
+ @ Shared ("errOccurredProfile" ) @ Cached ConditionProfile errOccurredProfile ) {
1713
+ checkFunctionResult (name , true , false , language , context , raise , factory , errOccurredProfile );
1712
1714
return PNone .NO_VALUE ;
1713
1715
}
1714
1716
1715
1717
@ Specialization (guards = "!isNoValue(result)" )
1716
1718
static Object doPythonObject (PythonContext context , String name , @ SuppressWarnings ("unused" ) PythonAbstractObject result ,
1717
1719
@ Shared ("language" ) @ CachedLanguage PythonLanguage language ,
1718
1720
@ Shared ("fact" ) @ Cached PythonObjectFactory factory ,
1719
- @ Shared ("raise" ) @ Cached PRaiseNode raise ) {
1720
- checkFunctionResult (name , false , false , language , context , raise , factory );
1721
+ @ Shared ("raise" ) @ Cached PRaiseNode raise ,
1722
+ @ Shared ("errOccurredProfile" ) @ Cached ConditionProfile errOccurredProfile ) {
1723
+ checkFunctionResult (name , false , false , language , context , raise , factory , errOccurredProfile );
1721
1724
return result ;
1722
1725
}
1723
1726
1724
1727
@ Specialization
1725
1728
static Object doPythonNativeNull (PythonContext context , String name , @ SuppressWarnings ("unused" ) PythonNativeNull result ,
1726
1729
@ Shared ("language" ) @ CachedLanguage PythonLanguage language ,
1727
1730
@ Shared ("fact" ) @ Cached PythonObjectFactory factory ,
1728
- @ Shared ("raise" ) @ Cached PRaiseNode raise ) {
1729
- checkFunctionResult (name , true , false , language , context , raise , factory );
1731
+ @ Shared ("raise" ) @ Cached PRaiseNode raise ,
1732
+ @ Shared ("errOccurredProfile" ) @ Cached ConditionProfile errOccurredProfile ) {
1733
+ checkFunctionResult (name , true , false , language , context , raise , factory , errOccurredProfile );
1730
1734
return result ;
1731
1735
}
1732
1736
1733
1737
@ Specialization
1734
1738
static int doInteger (PythonContext context , String name , int result ,
1735
1739
@ Shared ("language" ) @ CachedLanguage PythonLanguage language ,
1736
1740
@ Shared ("fact" ) @ Cached PythonObjectFactory factory ,
1737
- @ Shared ("raise" ) @ Cached PRaiseNode raise ) {
1741
+ @ Shared ("raise" ) @ Cached PRaiseNode raise ,
1742
+ @ Shared ("errOccurredProfile" ) @ Cached ConditionProfile errOccurredProfile ) {
1738
1743
// If the native functions returns a primitive int, only a value '-1' indicates an
1739
1744
// error.
1740
- checkFunctionResult (name , result == -1 , true , language , context , raise , factory );
1745
+ checkFunctionResult (name , result == -1 , true , language , context , raise , factory , errOccurredProfile );
1741
1746
return result ;
1742
1747
}
1743
1748
1744
1749
@ Specialization
1745
1750
static long doLong (PythonContext context , String name , long result ,
1746
1751
@ Shared ("language" ) @ CachedLanguage PythonLanguage language ,
1747
1752
@ Shared ("fact" ) @ Cached PythonObjectFactory factory ,
1748
- @ Shared ("raise" ) @ Cached PRaiseNode raise ) {
1753
+ @ Shared ("raise" ) @ Cached PRaiseNode raise ,
1754
+ @ Shared ("errOccurredProfile" ) @ Cached ConditionProfile errOccurredProfile ) {
1749
1755
// If the native functions returns a primitive int, only a value '-1' indicates an
1750
1756
// error.
1751
- checkFunctionResult (name , result == -1 , true , language , context , raise , factory );
1757
+ checkFunctionResult (name , result == -1 , true , language , context , raise , factory , errOccurredProfile );
1752
1758
return result ;
1753
1759
}
1754
1760
@@ -1764,15 +1770,16 @@ static Object doForeign(PythonContext context, String name, Object result,
1764
1770
@ Exclusive @ CachedLibrary (limit = "3" ) InteropLibrary lib ,
1765
1771
@ Shared ("language" ) @ CachedLanguage PythonLanguage language ,
1766
1772
@ Shared ("fact" ) @ Cached PythonObjectFactory factory ,
1767
- @ Shared ("raise" ) @ Cached PRaiseNode raise ) {
1768
- checkFunctionResult (name , isNullProfile .profile (lib .isNull (result )), false , language , context , raise , factory );
1773
+ @ Shared ("raise" ) @ Cached PRaiseNode raise ,
1774
+ @ Shared ("errOccurredProfile" ) @ Cached ConditionProfile errOccurredProfile ) {
1775
+ checkFunctionResult (name , isNullProfile .profile (lib .isNull (result )), false , language , context , raise , factory , errOccurredProfile );
1769
1776
return result ;
1770
1777
}
1771
1778
1772
1779
private static void checkFunctionResult (String name , boolean indicatesError , boolean isPrimitiveResult , PythonLanguage language , PythonContext context , PRaiseNode raise ,
1773
- PythonObjectFactory factory ) {
1774
- checkFunctionResult (name , indicatesError , isPrimitiveResult , language , context , raise , factory , ErrorMessages . RETURNED_NULL_WO_SETTING_ERROR ,
1775
- ErrorMessages .RETURNED_RESULT_WITH_ERROR_SET );
1780
+ PythonObjectFactory factory , ConditionProfile errOccurredProfile ) {
1781
+ checkFunctionResult (name , indicatesError , isPrimitiveResult , language , context , raise , factory , errOccurredProfile ,
1782
+ ErrorMessages .RETURNED_NULL_WO_SETTING_ERROR , ErrorMessages . RETURNED_RESULT_WITH_ERROR_SET );
1776
1783
}
1777
1784
1778
1785
/**
@@ -1791,16 +1798,18 @@ private static void checkFunctionResult(String name, boolean indicatesError, boo
1791
1798
* @param context The Python context.
1792
1799
* @param raise A raise node to raise {@code SystemError}s.
1793
1800
* @param factory A factory to create a base exception object.
1801
+ * @param errOccurredProfile Profiles if a Python exception occurred and is set in the
1802
+ * context.
1794
1803
* @param nullButNoErrorMessage Error message used if the value indicates an error and is
1795
1804
* not primitive but no error was set.
1796
1805
* @param resultWithErrorMessage Error message used if an error was set but the value does
1797
1806
* not indicate and error.
1798
1807
*/
1799
1808
static void checkFunctionResult (String name , boolean indicatesError , boolean isPrimitiveResult , PythonLanguage language , PythonContext context , PRaiseNode raise ,
1800
- PythonObjectFactory factory , String nullButNoErrorMessage , String resultWithErrorMessage ) {
1809
+ PythonObjectFactory factory , ConditionProfile errOccurredProfile , String nullButNoErrorMessage , String resultWithErrorMessage ) {
1801
1810
PythonThreadState threadState = context .getThreadState (language );
1802
1811
PException currentException = threadState .getCurrentException ();
1803
- boolean errOccurred = currentException != null ;
1812
+ boolean errOccurred = errOccurredProfile . profile ( currentException != null ) ;
1804
1813
if (indicatesError ) {
1805
1814
// consume exception
1806
1815
threadState .setCurrentException (null );
0 commit comments