@@ -1775,6 +1775,27 @@ private static void checkFunctionResult(String name, boolean indicatesError, boo
1775
1775
ErrorMessages .RETURNED_RESULT_WITH_ERROR_SET );
1776
1776
}
1777
1777
1778
+ /**
1779
+ * Check the result of a C extension function.
1780
+ *
1781
+ * @param name The name of the funciton (used for the error message).
1782
+ * @param indicatesError {@code true} if the function results indicates an error (e.g.
1783
+ * {@code NULL} if the return type is a pointer or {@code -1} if the return type
1784
+ * is an int).
1785
+ * @param isPrimitiveResult If {@code true}, the function result is a C primitive value
1786
+ * (e.g. an integer). In this case, the error indication value (e.g. {@code -1}
1787
+ * if the type is an integer) does not necessarily impose an error. So, if the
1788
+ * the value indicates an error and this flag is {@code true}, we will also
1789
+ * accept that no exception is currently set.
1790
+ * @param language The Python language.
1791
+ * @param context The Python context.
1792
+ * @param raise A raise node to raise {@code SystemError}s.
1793
+ * @param factory A factory to create a base exception object.
1794
+ * @param nullButNoErrorMessage Error message used if the value indicates an error and is
1795
+ * not primitive but no error was set.
1796
+ * @param resultWithErrorMessage Error message used if an error was set but the value does
1797
+ * not indicate and error.
1798
+ */
1778
1799
static void checkFunctionResult (String name , boolean indicatesError , boolean isPrimitiveResult , PythonLanguage language , PythonContext context , PRaiseNode raise ,
1779
1800
PythonObjectFactory factory , String nullButNoErrorMessage , String resultWithErrorMessage ) {
1780
1801
PythonThreadState threadState = context .getThreadState (language );
@@ -1783,10 +1804,10 @@ static void checkFunctionResult(String name, boolean indicatesError, boolean isP
1783
1804
if (indicatesError ) {
1784
1805
// consume exception
1785
1806
threadState .setCurrentException (null );
1786
- if (!errOccurred && !isPrimitiveResult ) {
1787
- throw raise .raise (PythonErrorType .SystemError , nullButNoErrorMessage , name );
1788
- } else {
1807
+ if (errOccurred ) {
1789
1808
throw currentException .getExceptionForReraise ();
1809
+ } else if (!isPrimitiveResult ) {
1810
+ throw raise .raise (PythonErrorType .SystemError , nullButNoErrorMessage , name );
1790
1811
}
1791
1812
} else if (errOccurred ) {
1792
1813
// consume exception
0 commit comments