Skip to content

Commit a4cb955

Browse files
committed
fix methods' GetModuleNode to work both called with and without a frame
1 parent bc64194 commit a4cb955

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/method/AbstractMethodBuiltins.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
import com.oracle.graal.python.nodes.function.builtins.PythonBinaryBuiltinNode;
5353
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
5454
import com.oracle.graal.python.nodes.function.builtins.PythonVarargsBuiltinNode;
55+
import com.oracle.graal.python.runtime.ExecutionContext.IndirectCallContext;
5556
import com.oracle.graal.python.util.PythonUtils;
5657
import com.oracle.truffle.api.dsl.Cached;
5758
import com.oracle.truffle.api.dsl.Fallback;
@@ -138,14 +139,22 @@ boolean eq(@SuppressWarnings("unused") Object self, @SuppressWarnings("unused")
138139

139140
@Builtin(name = __MODULE__, minNumOfPositionalArgs = 1, maxNumOfPositionalArgs = 2, isGetter = true, isSetter = true)
140141
@GenerateNodeFactory
141-
abstract static class GetModuleNode extends PythonBuiltinNode {
142+
abstract static class GetModuleNode extends PythonBinaryBuiltinNode {
142143
@Specialization(guards = "isNoValue(none)", limit = "2")
143144
Object getModule(VirtualFrame frame, PBuiltinMethod self, @SuppressWarnings("unused") PNone none,
144145
@CachedLibrary(limit = "3") PythonObjectLibrary pylib,
145146
@CachedLibrary("self") DynamicObjectLibrary dylib) {
146147
Object module = dylib.getOrDefault(self, __MODULE__, PNone.NO_VALUE);
147-
if (module == PNone.NO_VALUE) { // specialization of pylib acts as a branch profile
148-
return pylib.lookupAttribute(self.getSelf(), frame, __NAME__);
148+
if (module == PNone.NO_VALUE) {
149+
// getContext() acts as a branch profile. This indirect call is done to easily
150+
// support calls to this builtin with and without virtual frame, and because we
151+
// don't care much about the performance here anyway
152+
Object state = IndirectCallContext.enter(frame, getContext(), this);
153+
try {
154+
return pylib.lookupAttribute(self.getSelf(), null, __NAME__);
155+
} finally {
156+
IndirectCallContext.exit(frame, getContext(), state);
157+
}
149158
} else {
150159
return module;
151160
}

0 commit comments

Comments
 (0)