Skip to content

Commit 4603379

Browse files
committed
ImpModuleBuiltins: GR-26411 while reinitializing builtin modules is not yet supported - set the loader to be the same as the spec loader
1 parent 3b1fcdd commit 4603379

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
import com.oracle.graal.python.nodes.ErrorMessages;
7878
import com.oracle.graal.python.nodes.SpecialMethodNames;
7979
import com.oracle.graal.python.nodes.attributes.ReadAttributeFromObjectNode;
80+
import com.oracle.graal.python.nodes.attributes.SetAttributeNode;
8081
import com.oracle.graal.python.nodes.call.special.CallUnaryMethodNode;
8182
import com.oracle.graal.python.nodes.call.special.LookupAndCallUnaryNode;
8283
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
@@ -507,11 +508,19 @@ public abstract static class CreateBuiltin extends PythonBuiltinNode {
507508
@Specialization(limit = "getCallSiteInlineCacheMaxDepth()")
508509
public Object run(VirtualFrame frame, PythonObject moduleSpec,
509510
@Cached CastToJavaStringNode toJavaStringNode,
511+
@Cached("create(__LOADER__)") SetAttributeNode setAttributeNode,
510512
@CachedLibrary(value = "moduleSpec") PythonObjectLibrary pol) {
511513
Object name = pol.lookupAttribute(moduleSpec, frame, "name");
512514
PythonModule builtinModule = getBuiltinModule(toJavaStringNode.execute(name));
513515
if (builtinModule != null) {
514-
// TODO: builtin modules cannot be re-initialized (see is_builtin)
516+
// TODO: GR-26411 builtin modules cannot be re-initialized (see is_builtin)
517+
// We are setting the loader to the spec loader (since this is the loader that is
518+
// set during bootstrap); this, however, should be handled be the builtin module
519+
// reinitialization (if reinit is possible)
520+
Object loader = pol.lookupAttribute(moduleSpec, frame, "loader");
521+
if (loader != PNone.NO_VALUE) {
522+
setAttributeNode.executeVoid(frame, builtinModule, loader);
523+
}
515524
return builtinModule;
516525
}
517526
throw raise(NotImplementedError, "_imp.create_builtin");

0 commit comments

Comments
 (0)