Skip to content

Commit 534f48a

Browse files
committed
make debugger work better with native object wrappers
1 parent a8484af commit 534f48a

File tree

4 files changed

+36
-5
lines changed

4 files changed

+36
-5
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,11 +340,11 @@ protected Iterable<Scope> findLocalScopes(PythonContext context, Node node, Fram
340340
scopes.add(s);
341341
}
342342
if (frame != null) {
343-
PythonObject globals = PArguments.getGlobals(frame);
343+
PythonObject globals = PArguments.getGlobalsSafe(frame);
344344
if (globals != null) {
345345
scopes.add(Scope.newBuilder("globals()", globals).build());
346346
}
347-
Frame generatorFrame = PArguments.getGeneratorFrame(frame);
347+
Frame generatorFrame = PArguments.getGeneratorFrameSafe(frame);
348348
if (generatorFrame != null) {
349349
for (Scope s : super.findLocalScopes(context, node, generatorFrame)) {
350350
scopes.add(s);

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,10 @@ public enum PythonBuiltinClassType {
9191
PTuple(com.oracle.graal.python.builtins.objects.tuple.PTuple.class, "tuple"),
9292
PythonBuiltinClass(com.oracle.graal.python.builtins.objects.type.PythonBuiltinClass.class, "type"),
9393
PythonClass(com.oracle.graal.python.builtins.objects.type.PythonClass.class, "type"),
94+
PythonNativeClass(com.oracle.graal.python.builtins.objects.cext.PythonNativeClass.class, "type"),
9495
PythonModule(com.oracle.graal.python.builtins.objects.module.PythonModule.class, "module"),
9596
PythonObject(com.oracle.graal.python.builtins.objects.object.PythonObject.class, "object"),
97+
PythonNativeObject(com.oracle.graal.python.builtins.objects.cext.PythonNativeObject.class, "object"),
9698
PythonParseResult(com.oracle.graal.python.runtime.PythonParseResult.class, "code"),
9799
PZip(com.oracle.graal.python.builtins.objects.iterator.PZip.class, "zip"),
98100
PBuffer(com.oracle.graal.python.builtins.objects.memoryview.PBuffer.class, "buffer");

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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import static com.oracle.graal.python.nodes.SpecialMethodNames.__GETATTRIBUTE__;
4242
import static com.oracle.graal.python.nodes.SpecialMethodNames.__SETATTR__;
4343

44+
import com.oracle.graal.python.PythonLanguage;
4445
import com.oracle.graal.python.builtins.objects.PNone;
4546
import com.oracle.graal.python.builtins.objects.PythonAbstractObject;
4647
import com.oracle.graal.python.builtins.objects.bytes.PByteArray;
@@ -90,12 +91,16 @@
9091

9192
@MessageResolution(receiverType = PythonObjectNativeWrapper.class)
9293
public class PythonObjectNativeWrapperMR {
94+
protected static String GP_OBJECT = "gp_object";
9395

9496
@Resolve(message = "READ")
9597
abstract static class ReadNode extends Node {
9698
@Child private ReadNativeMemberNode readNativeMemberNode;
9799

98100
public Object access(Object object, Object key) {
101+
if (key.equals(GP_OBJECT)) {
102+
return ((PythonObjectNativeWrapper) object).getPythonObject();
103+
}
99104
if (readNativeMemberNode == null) {
100105
CompilerDirectives.transferToInterpreterAndInvalidate();
101106
readNativeMemberNode = insert(ReadNativeMemberNode.create());
@@ -438,7 +443,9 @@ abstract static class KeyInfoNode extends Node {
438443
public int access(Object object, Object fieldName) {
439444
assert object instanceof PythonObjectNativeWrapper;
440445
int info = KeyInfo.NONE;
441-
if (fieldName instanceof String && NativeMemberNames.isValid((String) fieldName)) {
446+
if (fieldName.equals(GP_OBJECT)) {
447+
info |= KeyInfo.READABLE;
448+
} else if (fieldName instanceof String && NativeMemberNames.isValid((String) fieldName)) {
442449
info |= KeyInfo.READABLE;
443450

444451
// TODO be more specific
@@ -457,8 +464,14 @@ public Object access(Object obj) {
457464

458465
@Resolve(message = "KEYS")
459466
abstract static class PForeignKeysNode extends Node {
460-
public Object access(@SuppressWarnings("unused") Object object) {
461-
return null;
467+
@Child Node objKeys = Message.KEYS.createNode();
468+
469+
public Object access(Object object) {
470+
if (object instanceof PythonObjectNativeWrapper) {
471+
return PythonLanguage.getContext().getEnv().asGuestValue(new String[]{GP_OBJECT});
472+
} else {
473+
throw UnsupportedMessageException.raise(Message.KEYS);
474+
}
462475
}
463476
}
464477

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/PArguments.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,14 @@ public static PythonObject getGlobals(Frame frame) {
139139
return (PythonObject) frame.getArguments()[INDEX_GLOBALS_ARGUMENT];
140140
}
141141

142+
public static PythonObject getGlobalsSafe(Frame frame) {
143+
if (frame.getArguments()[INDEX_GLOBALS_ARGUMENT] instanceof PythonObject) {
144+
return getGlobals(frame);
145+
} else {
146+
return null;
147+
}
148+
}
149+
142150
public static void setPFrame(Frame frame, PFrame pFrame) {
143151
((PFrame[]) frame.getArguments()[INDEX_PFRAME_ARGUMENT])[0] = pFrame;
144152
}
@@ -184,6 +192,14 @@ public static Frame getGeneratorFrame(Frame frame) {
184192
return (Frame) frame.getArguments()[INDEX_GENERATOR_FRAME];
185193
}
186194

195+
public static Frame getGeneratorFrameSafe(Frame frame) {
196+
if (frame.getArguments()[INDEX_GENERATOR_FRAME] instanceof Frame) {
197+
return getGeneratorFrame(frame);
198+
} else {
199+
return null;
200+
}
201+
}
202+
187203
public static void setGeneratorFrame(Object[] arguments, Frame generatorFrame) {
188204
arguments[INDEX_GENERATOR_FRAME] = generatorFrame;
189205
}

0 commit comments

Comments
 (0)