Skip to content

Commit 7f3aaf0

Browse files
committed
Fix: add forgotten WeakReference.get()
1 parent ba66049 commit 7f3aaf0

File tree

7 files changed

+42
-19
lines changed

7 files changed

+42
-19
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/PythonDispatchers.java

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
import com.oracle.truffle.api.dsl.Specialization;
6363
import com.oracle.truffle.api.frame.VirtualFrame;
6464
import com.oracle.truffle.api.nodes.Node;
65+
import com.oracle.truffle.api.utilities.TruffleWeakReference;
6566

6667
abstract class PythonDispatchers {
6768
private PythonDispatchers() {
@@ -87,7 +88,13 @@ static FunctionInvokeNode createInvokeNode(PFunction callee) {
8788
@GenerateCached(false)
8889
@ImportStatic(PGuards.class)
8990
abstract static class UnaryPythonSlotDispatcherNode extends PythonSlotDispatcherNodeBase {
90-
abstract Object execute(VirtualFrame frame, Node inliningTarget, Object callable, Object type, Object self);
91+
final Object execute(VirtualFrame frame, Node inliningTarget, Object callable, Object type, Object self) {
92+
assert !(callable instanceof TruffleWeakReference<?>);
93+
assert !(type instanceof TruffleWeakReference<?>);
94+
return executeImpl(frame, inliningTarget, callable, type, self);
95+
}
96+
97+
abstract Object executeImpl(VirtualFrame frame, Node inliningTarget, Object callable, Object type, Object self);
9198

9299
@Specialization(guards = {"isSingleContext()", "callee == cachedCallee", "isSimpleSignature(cachedCallee, 1)"}, limit = "getCallSiteInlineCacheMaxDepth()")
93100
protected static Object doCachedPFunction(VirtualFrame frame, @SuppressWarnings("unused") PFunction callee, @SuppressWarnings("unused") Object type, Object self,
@@ -121,7 +128,13 @@ static Object doGeneric(VirtualFrame frame, Node inliningTarget, Object callable
121128
@GenerateInline
122129
@GenerateCached(false)
123130
abstract static class BinaryPythonSlotDispatcherNode extends PythonSlotDispatcherNodeBase {
124-
abstract Object execute(VirtualFrame frame, Node inliningTarget, Object callable, Object type, Object self, Object arg1);
131+
final Object execute(VirtualFrame frame, Node inliningTarget, Object callable, Object type, Object self, Object arg1) {
132+
assert !(callable instanceof TruffleWeakReference<?>);
133+
assert !(type instanceof TruffleWeakReference<?>);
134+
return executeImpl(frame, inliningTarget, callable, type, self, arg1);
135+
}
136+
137+
abstract Object executeImpl(VirtualFrame frame, Node inliningTarget, Object callable, Object type, Object self, Object arg1);
125138

126139
@Specialization(guards = {"isSingleContext()", "callee == cachedCallee", "isSimpleSignature(cachedCallee, 2)"}, limit = "getCallSiteInlineCacheMaxDepth()")
127140
protected static Object doCachedPFunction(VirtualFrame frame, @SuppressWarnings("unused") PFunction callee, @SuppressWarnings("unused") Object type, Object self, Object arg1,
@@ -156,7 +169,13 @@ static Object doGeneric(VirtualFrame frame, Node inliningTarget, Object callable
156169
@GenerateInline
157170
@GenerateCached(false)
158171
abstract static class TernaryOrBinaryPythonSlotDispatcherNode extends PythonSlotDispatcherNodeBase {
159-
abstract Object execute(VirtualFrame frame, Node inliningTarget, boolean callTernary, Object callable, Object type, Object self, Object arg1, Object arg2);
172+
final Object execute(VirtualFrame frame, Node inliningTarget, boolean callTernary, Object callable, Object type, Object self, Object arg1, Object arg2) {
173+
assert !(callable instanceof TruffleWeakReference<?>);
174+
assert !(type instanceof TruffleWeakReference<?>);
175+
return executeImpl(frame, inliningTarget, callTernary, callable, type, self, arg1, arg2);
176+
}
177+
178+
abstract Object executeImpl(VirtualFrame frame, Node inliningTarget, boolean callTernary, Object callable, Object type, Object self, Object arg1, Object arg2);
160179

161180
@Idempotent
162181
static int getArgsCount(boolean callTernary) {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlot.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,8 +298,8 @@ public static boolean isSlotFactory(NodeFactory<?> factory) {
298298
* Convenience base class for Python slots that has only one callable.
299299
*/
300300
public static final class TpSlotPythonSingle extends TpSlotPython {
301-
final TruffleWeakReference<Object> callable;
302-
final TruffleWeakReference<Object> type;
301+
private final TruffleWeakReference<Object> callable;
302+
private final TruffleWeakReference<Object> type;
303303
private final TruffleString name;
304304

305305
public TpSlotPythonSingle(Object callable, Object type, TruffleString name) {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotDescrSet.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,9 @@ public PBuiltinFunction createBuiltin(Python3Core core, Object type, TruffleStri
127127
}
128128

129129
public static final class TpSlotDescrSetPython extends TpSlotPython {
130-
final TruffleWeakReference<Object> setCallable;
131-
final TruffleWeakReference<Object> delCallable;
132-
final TruffleWeakReference<Object> type;
130+
private final TruffleWeakReference<Object> setCallable;
131+
private final TruffleWeakReference<Object> delCallable;
132+
private final TruffleWeakReference<Object> type;
133133

134134
public TpSlotDescrSetPython(Object setCallable, Object delCallable, Object type) {
135135
this.setCallable = asWeakRef(setCallable);

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotGetAttr.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,9 @@ public abstract static class GetAttrBuiltinNode extends PythonBinaryBuiltinNode
126126
}
127127

128128
public static final class TpSlotGetAttrPython extends TpSlotPython {
129-
final TruffleWeakReference<Object> getattr;
130-
final TruffleWeakReference<Object> getattribute;
131-
final TruffleWeakReference<Object> type;
129+
private final TruffleWeakReference<Object> getattr;
130+
private final TruffleWeakReference<Object> getattribute;
131+
private final TruffleWeakReference<Object> type;
132132

133133
public TpSlotGetAttrPython(Object getattribute, Object getattr, Object type) {
134134
this.getattr = asWeakRef(getattr);
@@ -156,6 +156,10 @@ public Object getGetattr() {
156156
return safeGet(getattr);
157157
}
158158

159+
public boolean hasGetattr() {
160+
return getattr != null;
161+
}
162+
159163
public Object getGetattribute() {
160164
return safeGet(getattribute);
161165
}
@@ -283,15 +287,15 @@ static Object callCachedBuiltin(VirtualFrame frame, @SuppressWarnings("unused")
283287
return slotNode.executeGetAttr(frame, self, name);
284288
}
285289

286-
@Specialization(guards = "isNoValue(slot.getattr)")
290+
@Specialization(guards = "!slot.hasGetattr()")
287291
static Object callPythonSimple(VirtualFrame frame, Node inliningTarget, TpSlotGetAttrPython slot, Object self, Object name,
288292
@Exclusive @Cached BinaryPythonSlotDispatcherNode callPythonFun) {
289293
// equivalent of typeobject.c:slot_tp_getattro, which is used if there is no __getattr__
290294
// hook
291-
return callPythonFun.execute(frame, inliningTarget, slot.getattribute, slot.type, self, name);
295+
return callPythonFun.execute(frame, inliningTarget, slot.getGetattribute(), slot.getType(), self, name);
292296
}
293297

294-
@Specialization(guards = "!isNoValue(slot.getattr)")
298+
@Specialization(guards = "slot.hasGetattr()")
295299
static Object callPythonSimple(VirtualFrame frame, Node inliningTarget, TpSlotGetAttrPython slot, Object self, Object name,
296300
@Exclusive @Cached BinaryPythonSlotDispatcherNode callPythonFun,
297301
@Cached IsBuiltinObjectProfile errorProfile) {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotInquiry.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ static boolean doIt(VirtualFrame frame, TpSlotPythonSingle slot, Object self,
158158
// TODO: it is not clear to me why CPython lookups __len__ in the slot wrapper although
159159
// the slow wrapper is assigned only in the presence of __bool__ magic method and not
160160
// __len__. We ignore the __len__ lookup for now.
161-
Object result = dispatcherNode.execute(frame, inliningTarget, slot.getCallable(), slot.type, self);
161+
Object result = dispatcherNode.execute(frame, inliningTarget, slot.getCallable(), slot.getType(), self);
162162
if (!pyBoolCheckNode.execute(inliningTarget, result)) {
163163
throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.BOOL_SHOULD_RETURN_BOOL, result);
164164
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotLen.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ static int doIt(VirtualFrame frame, TpSlotPythonSingle slot, Object self,
241241
@Cached CastToJavaIntLossyNode castLossy,
242242
@Cached PyNumberAsSizeNode asSizeNode) {
243243
// See CPython: slot_sq_length
244-
Object result = dispatcherNode.execute(frame, inliningTarget, slot.getCallable(), slot.type, self);
244+
Object result = dispatcherNode.execute(frame, inliningTarget, slot.getCallable(), slot.getType(), self);
245245
if (!genericCheck.wasEntered(inliningTarget)) {
246246
try {
247247
return checkLen(inliningTarget, raiseNode, PGuards.expectInteger(result));

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/slots/TpSlotSetAttr.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,9 @@ public final Object execute(VirtualFrame frame, Object obj, Object nameObj, Obje
145145
}
146146

147147
public static final class TpSlotSetAttrPython extends TpSlotPython {
148-
final TruffleWeakReference<Object> setattr;
149-
final TruffleWeakReference<Object> delattr;
150-
final TruffleWeakReference<Object> type;
148+
private final TruffleWeakReference<Object> setattr;
149+
private final TruffleWeakReference<Object> delattr;
150+
private final TruffleWeakReference<Object> type;
151151

152152
public TpSlotSetAttrPython(Object setattr, Object delattr, Object type) {
153153
this.setattr = asWeakRef(setattr);

0 commit comments

Comments
 (0)