Skip to content

Commit b876637

Browse files
committed
Fix: incorrect repr format for DebugHandle
1 parent 4493414 commit b876637

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

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

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,17 @@
4949
import com.oracle.graal.python.builtins.PythonBuiltins;
5050
import com.oracle.graal.python.builtins.objects.PNotImplemented;
5151
import com.oracle.graal.python.nodes.SpecialMethodNames;
52-
import com.oracle.graal.python.nodes.call.special.LookupAndCallUnaryNode;
52+
import com.oracle.graal.python.nodes.call.special.LookupAndCallUnaryNode.LookupAndCallUnaryDynamicNode;
5353
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
5454
import com.oracle.graal.python.nodes.function.builtins.PythonBinaryBuiltinNode;
5555
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
56+
import com.oracle.graal.python.nodes.util.CastToJavaStringNode;
57+
import com.oracle.graal.python.runtime.ExecutionContext.IndirectCallContext;
5658
import com.oracle.graal.python.runtime.PythonContext;
57-
import com.oracle.graal.python.util.PythonUtils;
59+
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
5860
import com.oracle.truffle.api.dsl.Cached;
5961
import com.oracle.truffle.api.dsl.CachedContext;
62+
import com.oracle.truffle.api.dsl.CachedLanguage;
6063
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
6164
import com.oracle.truffle.api.dsl.NodeFactory;
6265
import com.oracle.truffle.api.dsl.Specialization;
@@ -90,7 +93,7 @@ public abstract static class HPyDebugHandleIdNode extends PythonUnaryBuiltinNode
9093
static Object doGeneric(PDebugHandle self,
9194
@CachedContext(PythonLanguage.class) PythonContext context,
9295
@Cached ConditionProfile profile) {
93-
return self.getHandle().getId(context.getHPyContext(), profile);
96+
return self.getHandle().getId(context.getHPyDebugContext(), profile);
9497
}
9598
}
9699

@@ -119,13 +122,23 @@ static boolean isDebugHandle(Object object) {
119122
public abstract static class HPyDebugHandleReprNode extends PythonUnaryBuiltinNode {
120123

121124
@Specialization
122-
static Object doGeneric(VirtualFrame frame, PDebugHandle self,
123-
@CachedContext(PythonLanguage.class) PythonContext context,
124-
@Cached ConditionProfile profile,
125-
@Cached(parameters = "__REPR__") LookupAndCallUnaryNode callReprNode) {
126-
int id = self.getHandle().getId(context.getHPyContext(), profile);
127-
Object objRepr = callReprNode.executeObject(frame, self.getHandle().getDelegate());
128-
return PythonUtils.format("DebugHandle 0x%s for %s", id, objRepr);
125+
Object doGeneric(VirtualFrame frame, PDebugHandle self,
126+
@CachedLanguage PythonLanguage language,
127+
@CachedContext(PythonLanguage.class) PythonContext context) {
128+
Object state = IndirectCallContext.enter(frame, language, context, this);
129+
try {
130+
return format(context.getHPyDebugContext(), self);
131+
} finally {
132+
IndirectCallContext.exit(frame, language, context, state);
133+
}
134+
}
135+
136+
@TruffleBoundary
137+
private static Object format(GraalHPyDebugContext hpyDebugContext, PDebugHandle self) {
138+
int id = self.getHandle().getId(hpyDebugContext, ConditionProfile.getUncached());
139+
Object objRepr = LookupAndCallUnaryDynamicNode.getUncached().executeObject(self.getHandle().getDelegate(), SpecialMethodNames.__REPR__);
140+
String reprStr = CastToJavaStringNode.getUncached().execute(objRepr);
141+
return String.format("<DebugHandle 0x%s for %s>", Integer.toHexString(id), reprStr);
129142
}
130143
}
131144
}

0 commit comments

Comments
 (0)