Skip to content

Commit f98b41d

Browse files
committed
Fix: bug in checkFunctionResult for primitives and add doc
1 parent c4c0357 commit f98b41d

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/ExternalFunctionNodes.java

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1775,6 +1775,27 @@ private static void checkFunctionResult(String name, boolean indicatesError, boo
17751775
ErrorMessages.RETURNED_RESULT_WITH_ERROR_SET);
17761776
}
17771777

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+
*/
17781799
static void checkFunctionResult(String name, boolean indicatesError, boolean isPrimitiveResult, PythonLanguage language, PythonContext context, PRaiseNode raise,
17791800
PythonObjectFactory factory, String nullButNoErrorMessage, String resultWithErrorMessage) {
17801801
PythonThreadState threadState = context.getThreadState(language);
@@ -1783,10 +1804,10 @@ static void checkFunctionResult(String name, boolean indicatesError, boolean isP
17831804
if (indicatesError) {
17841805
// consume exception
17851806
threadState.setCurrentException(null);
1786-
if (!errOccurred && !isPrimitiveResult) {
1787-
throw raise.raise(PythonErrorType.SystemError, nullButNoErrorMessage, name);
1788-
} else {
1807+
if (errOccurred) {
17891808
throw currentException.getExceptionForReraise();
1809+
} else if (!isPrimitiveResult) {
1810+
throw raise.raise(PythonErrorType.SystemError, nullButNoErrorMessage, name);
17901811
}
17911812
} else if (errOccurred) {
17921813
// consume exception

0 commit comments

Comments
 (0)