Skip to content

Commit 08a5541

Browse files
committed
Raise SystemError if HPyInit_* does not return a module object
1 parent 6c9df07 commit 08a5541

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/GraalHPyUniversalModuleBuiltins.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,12 @@ private PythonModule loadHPyModule(PythonContext context, String name, String pa
120120
HPyCheckHandleResultNode checkHandleResultNode) throws IOException, ApiInitException, ImportException {
121121
Object result = GraalHPyContext.loadHPyModule(this, context, name, path, debug, checkHandleResultNode);
122122
if (!(result instanceof PythonModule)) {
123-
// TODO: PyModule_FromDefAndSpec((PyModuleDef*)m, spec);
124-
throw PRaiseNode.raiseUncached(this, PythonErrorType.NotImplementedError, ErrorMessages.MULTI_PHASE_INIT_OF_EXTENSION_MODULE_S, name);
123+
/*
124+
* HPy does currently not support multi-phase extension module initialization. This
125+
* means there is no structure defined in HPy that we could parse. Hence, whenever
126+
* we reach this point, it's an error.
127+
*/
128+
throw PRaiseNode.raiseUncached(this, PythonErrorType.SystemError, ErrorMessages.INIT_S_RETURNED_AN_UNEXPECTED_VALUE, name);
125129
}
126130
PythonModule module = (PythonModule) result;
127131
module.setAttribute(__FILE__, path);

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/ErrorMessages.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -812,6 +812,7 @@ public abstract class ErrorMessages {
812812
public static final String DEQUE_INDEX_OUT_OF_RANGE = "deque index out of range";
813813
public static final String CAN_ONLY_CONCATENATE_DEQUE_NOT_P_TO_DEQUE = "can only concatenate deque (not \"%p\") to deque";
814814
public static final String MULTI_PHASE_INIT_OF_EXTENSION_MODULE_S = "multi-phase init of extension module %s";
815+
public static final String INIT_S_RETURNED_AN_UNEXPECTED_VALUE = "HPyInit_%s returned an unexpected value (expected a Python module).";
815816

816817
// pickle errors
817818
public static final String CANNOT_PICKLE_OBJECT_TYPE = "cannot pickle '%p' object";

0 commit comments

Comments
 (0)