Skip to content

Commit 37b2e91

Browse files
committed
PySequence_size should throw for non-sequence objects
1 parent 714c748 commit 37b2e91

File tree

2 files changed

+7
-18
lines changed

2 files changed

+7
-18
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1015,7 +1015,6 @@ static Object reversed(VirtualFrame frame, Object cls, Object sequence,
10151015
@Cached("create(Reversed)") LookupSpecialMethodSlotNode lookupReversed,
10161016
@Cached CallUnaryMethodNode callReversed,
10171017
@Cached PySequenceSizeNode pySequenceSizeNode,
1018-
@Cached("create(GetItem)") LookupSpecialMethodSlotNode getItemNode,
10191018
@Cached InlinedConditionProfile noReversedProfile,
10201019
@Cached PySequenceCheckNode pySequenceCheck,
10211020
@Shared @Cached PythonObjectFactory factory,

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PySequenceSizeNode.java

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,8 @@
4444
import static com.oracle.graal.python.util.PythonUtils.TS_ENCODING;
4545

4646
import com.oracle.graal.python.builtins.objects.bytes.PBytesLike;
47-
import com.oracle.graal.python.builtins.objects.common.HashingStorageNodes.HashingStorageLen;
48-
import com.oracle.graal.python.builtins.objects.dict.PDict;
47+
import com.oracle.graal.python.builtins.objects.common.PHashingCollection;
4948
import com.oracle.graal.python.builtins.objects.list.PList;
50-
import com.oracle.graal.python.builtins.objects.set.PSet;
5149
import com.oracle.graal.python.builtins.objects.str.PString;
5250
import com.oracle.graal.python.builtins.objects.str.StringNodes;
5351
import com.oracle.graal.python.builtins.objects.tuple.PTuple;
@@ -62,6 +60,7 @@
6260
import com.oracle.graal.python.runtime.exception.PException;
6361
import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff;
6462
import com.oracle.truffle.api.dsl.Cached;
63+
import com.oracle.truffle.api.dsl.Cached.Exclusive;
6564
import com.oracle.truffle.api.dsl.Cached.Shared;
6665
import com.oracle.truffle.api.dsl.Fallback;
6766
import com.oracle.truffle.api.dsl.GenerateCached;
@@ -72,7 +71,6 @@
7271
import com.oracle.truffle.api.frame.Frame;
7372
import com.oracle.truffle.api.frame.VirtualFrame;
7473
import com.oracle.truffle.api.nodes.Node;
75-
import com.oracle.truffle.api.profiles.InlinedBranchProfile;
7674
import com.oracle.truffle.api.strings.TruffleString;
7775

7876
/**
@@ -106,17 +104,10 @@ static int doTuple(PTuple object) {
106104
return object.getSequenceStorage().length();
107105
}
108106

109-
@Specialization(guards = "cannotBeOverriddenForImmutableType(object)")
110-
static int doDict(Node inliningTarget, PDict object,
111-
@Shared("hashingStorageLen") @Cached HashingStorageLen lenNode) {
112-
return lenNode.execute(inliningTarget, object.getDictStorage());
113-
}
114-
115-
@Specialization(guards = "cannotBeOverridden(object, inliningTarget, getClassNode)")
116-
static int doSet(Node inliningTarget, PSet object,
117-
@Shared("getClass") @SuppressWarnings("unused") @Cached GetPythonObjectClassNode getClassNode,
118-
@Shared("hashingStorageLen") @Cached HashingStorageLen lenNode) {
119-
return lenNode.execute(inliningTarget, object.getDictStorage());
107+
@Specialization
108+
static int doPHashingCollection(Node inliningTarget, PHashingCollection object,
109+
@Exclusive @Cached PRaiseNode.Lazy raise) {
110+
throw raise.get(inliningTarget).raise(TypeError, ErrorMessages.IS_NOT_A_SEQUENCE, object);
120111
}
121112

122113
@Specialization(guards = "cannotBeOverridden(object, inliningTarget, getClassNode)")
@@ -137,8 +128,7 @@ static int doPBytes(Node inliningTarget, PBytesLike object,
137128
static int doOthers(Frame frame, Node inliningTarget, Object object,
138129
@Cached GetObjectSlotsNode getTpSlotsNode,
139130
@Cached TpSlotLen.CallSlotLenNode callSlotLenNode,
140-
@Cached InlinedBranchProfile hasNoSqLenBranch,
141-
@Cached PRaiseNode.Lazy raiseNode) {
131+
@Exclusive @Cached PRaiseNode.Lazy raiseNode) {
142132
TpSlots slots = getTpSlotsNode.execute(inliningTarget, object);
143133
if (slots.sq_length() != null) {
144134
return callSlotLenNode.execute((VirtualFrame) frame, inliningTarget, slots.sq_length(), object);

0 commit comments

Comments
 (0)