Skip to content

Commit 54cd0af

Browse files
committed
Fix: initialize HPy API before running ctors of extension
1 parent 10cc987 commit 54cd0af

File tree

1 file changed

+5
-3
lines changed
  • graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy

1 file changed

+5
-3
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/GraalHPyContext.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -320,15 +320,17 @@ public static GraalHPyContext ensureHPyWasLoaded(Node node, PythonContext contex
320320
public static Object loadHPyModule(Node location, PythonContext context, String name, String path, boolean debug,
321321
HPyCheckFunctionResultNode checkResultNode) throws IOException, ApiInitException, ImportException {
322322

323-
// Now, try to detect the C extension's API by looking for the appropriate init
324-
// functions.
323+
/*
324+
* Unfortunately, we need eagerly initialize the HPy context because the ctors of the
325+
* extension may already require some of the symbols defined in the HPy API or C API.
326+
*/
327+
GraalHPyContext hpyContext = GraalHPyContext.ensureHPyWasLoaded(location, context, name, path);
325328
Object llvmLibrary = loadLLVMLibrary(location, context, name, path);
326329
InteropLibrary llvmInteropLib = InteropLibrary.getUncached(llvmLibrary);
327330
String basename = name.substring(name.lastIndexOf('.') + 1);
328331
String hpyInitFuncName = "HPyInit_" + basename;
329332
try {
330333
if (llvmInteropLib.isMemberExisting(llvmLibrary, hpyInitFuncName)) {
331-
GraalHPyContext hpyContext = GraalHPyContext.ensureHPyWasLoaded(location, context, name, path);
332334
return hpyContext.initHPyModule(context, llvmLibrary, hpyInitFuncName, name, path, debug, llvmInteropLib, checkResultNode);
333335
}
334336
throw new ImportException(null, name, path, ErrorMessages.CANNOT_INITIALIZE_WITH, path, basename, "");

0 commit comments

Comments
 (0)