Skip to content

Commit da729ad

Browse files
committed
Refactor and fix CheckFunctionResultNodes
1 parent a6890cc commit da729ad

File tree

3 files changed

+180
-104
lines changed

3 files changed

+180
-104
lines changed

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

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3673,30 +3673,29 @@ static Object doGeneric(CApiContext capiContext, ModuleSpec moduleSpec, PythonAb
36733673
Object[] cArguments = new Object[]{moduleSpecToNativeNode.execute(capiContext, moduleSpec.originalModuleSpec), moduleDef};
36743674
try {
36753675
Object result = interopLib.execute(createFunction, cArguments);
3676-
DefaultCheckFunctionResultNode.checkFunctionResult(mName, interopLib.isNull(result), false, PythonLanguage.get(callGetterNode), capiContext.getContext(), raiseNode, factory,
3677-
errOccurredProfile,
3678-
CREATION_FAILD_WITHOUT_EXCEPTION, CREATION_RAISED_EXCEPTION);
3676+
DefaultCheckFunctionResultNode.checkFunctionResult(raiseNode, mName, interopLib.isNull(result), true, PythonLanguage.get(callGetterNode), capiContext.getContext(),
3677+
errOccurredProfile, CREATION_FAILD_WITHOUT_EXCEPTION, CREATION_RAISED_EXCEPTION);
36793678
module = toJavaNode.execute(capiContext, result);
36803679
} catch (UnsupportedTypeException | ArityException | UnsupportedMessageException e) {
36813680
throw CompilerDirectives.shouldNotReachHere();
36823681
}
36833682

3684-
/*
3685-
* We are more strict than CPython and require this to be a PythonModule object.
3686-
* This means, if the custom 'create' function uses a native subtype of the
3687-
* module type, then we require it to call our new function.
3688-
*/
3689-
if (!(module instanceof PythonModule)) {
3690-
if (mSize > 0) {
3691-
throw raiseNode.raise(SystemError, NOT_A_MODULE_OBJECT_BUT_REQUESTS_MODULE_STATE, mName);
3692-
}
3693-
if (hasExecutionSlots) {
3694-
throw raiseNode.raise(SystemError, "module %s specifies execution slots, but did not create a ModuleType instance", mName);
3695-
}
3696-
// otherwise CPython is just fine
3697-
} else {
3698-
((PythonModule) module).setNativeModuleDef(moduleDef);
3683+
/*
3684+
* We are more strict than CPython and require this to be a PythonModule object.
3685+
* This means, if the custom 'create' function uses a native subtype of the module
3686+
* type, then we require it to call our new function.
3687+
*/
3688+
if (!(module instanceof PythonModule)) {
3689+
if (mSize > 0) {
3690+
throw raiseNode.raise(SystemError, NOT_A_MODULE_OBJECT_BUT_REQUESTS_MODULE_STATE, mName);
3691+
}
3692+
if (hasExecutionSlots) {
3693+
throw raiseNode.raise(SystemError, "module %s specifies execution slots, but did not create a ModuleType instance", mName);
36993694
}
3695+
// otherwise CPython is just fine
3696+
} else {
3697+
((PythonModule) module).setNativeModuleDef(moduleDef);
3698+
}
37003699
} else {
37013700
PythonModule pythonModule = factory.createPythonModule(mName);
37023701
pythonModule.setNativeModuleDef(moduleDef);
@@ -3811,8 +3810,7 @@ static int doGeneric(CApiContext capiContext, PythonModule module, Object module
38113810
* and won't ignore this if no error is set. This is then the same
38123811
* behaviour if we would have a pointer return type and got 'NULL'.
38133812
*/
3814-
DefaultCheckFunctionResultNode.checkFunctionResult(mName, iResult != 0, false, PythonLanguage.get(callGetterNode), capiContext.getContext(), raiseNode, factory,
3815-
errOccurredProfile,
3813+
DefaultCheckFunctionResultNode.checkFunctionResult(raiseNode, mName, iResult != 0, true, PythonLanguage.get(callGetterNode), capiContext.getContext(), errOccurredProfile,
38163814
EXECUTION_FAILED_WITHOUT_EXCEPTION, EXECUTION_RAISED_EXCEPTION);
38173815
break;
38183816
default:

0 commit comments

Comments
 (0)