Skip to content

Commit 572cb12

Browse files
fangerercosminbasca
authored andcommitted
Retry PyInit_<modulename> on arity exception
1 parent 072165a commit 572cb12

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import java.io.IOException;
4848
import java.io.PrintWriter;
4949
import java.io.StringWriter;
50+
import java.util.Arrays;
5051
import java.util.List;
5152
import java.util.concurrent.locks.ReentrantLock;
5253

@@ -354,7 +355,17 @@ private Object initCApiModule(TruffleObject sulongLibrary, String initFuncName,
354355
} catch (UnknownIdentifierException | UnsupportedMessageException e1) {
355356
throw new ImportException(null, name, path, ErrorMessages.NO_FUNCTION_FOUND, "", initFuncName, path);
356357
}
357-
Object nativeResult = interop.execute(pyinitFunc);
358+
Object nativeResult;
359+
try {
360+
nativeResult = interop.execute(pyinitFunc);
361+
} catch (ArityException e) {
362+
// In case of multi-phase init, the init function may take more than one arguments.
363+
// However, CPython gracefully ignores that. So, we pass just NULL pointers.
364+
Object[] arguments = new Object[e.getExpectedArity()];
365+
Arrays.fill(arguments, PNone.NO_VALUE);
366+
nativeResult = interop.execute(pyinitFunc, arguments);
367+
}
368+
358369
getCheckResultNode().execute(initFuncName, nativeResult);
359370

360371
Object result = AsPythonObjectNodeGen.getUncached().execute(nativeResult);

0 commit comments

Comments
 (0)