Skip to content

Commit 6871c15

Browse files
committed
deffer running post init patches on parse request and not immediately after initialization
1 parent 31ff629 commit 6871c15

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/PythonLanguage.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,9 +237,11 @@ protected void initializeContext(PythonContext context) throws Exception {
237237
@Override
238238
protected CallTarget parse(ParsingRequest request) throws Exception {
239239
PythonContext context = this.getContextReference().get();
240-
if (!context.getCore().isInitialized()) {
241-
context.getCore().initialize();
240+
PythonCore pythonCore = context.getCore();
241+
if (!pythonCore.isInitialized()) {
242+
pythonCore.initialize();
242243
}
244+
pythonCore.runPostInit();
243245
context.getOrCreateMainModule(request.getSource().getPath());
244246

245247
// if we are running the interpreter, module 'site' is automatically imported
@@ -248,7 +250,7 @@ protected CallTarget parse(ParsingRequest request) throws Exception {
248250
// no frame required
249251
new ImportNode("site").execute(null);
250252
}
251-
PythonParseResult parseResult = context.getCore().getParser().parse(context.getCore(), request.getSource());
253+
PythonParseResult parseResult = pythonCore.getParser().parse(pythonCore, request.getSource());
252254
RootNode root = parseResult.getRootNode();
253255
root = new TopLevelExceptionHandler(this, root);
254256
return Truffle.getRuntime().createCallTarget(root);

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/Python3Core.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -357,10 +357,14 @@ public void initialize() {
357357
exportCInterface(getContext());
358358
currentException = null;
359359
initialized = true;
360+
}
360361

361-
// apply the patches after initialization is done (we need to lookup modules that are mostly
362-
// in stdlib)
363-
loadFile(POST_INIT_MODULE_NAME, coreHome);
362+
@Override
363+
public void runPostInit() {
364+
if (initialized) {
365+
String coreHome = PythonCore.getCoreHomeOrFail();
366+
loadFile(POST_INIT_MODULE_NAME, coreHome);
367+
}
364368
}
365369

366370
public Object duplicate(Map<Object, Object> replacements, Object value) {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/PythonCore.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@ public interface PythonCore {
123123

124124
public PythonContext getContext();
125125

126+
default void runPostInit() {
127+
128+
}
129+
126130
static void writeWarning(TruffleLanguage.Env env, String warning) {
127131
if (!LIBPOLYGLOT || env.getOptions().get(PythonOptions.VerboseFlag)) {
128132
write(env, "WARNING: " + warning);

0 commit comments

Comments
 (0)