Skip to content

Commit d9de178

Browse files
committed
[GR-36492] Fix PIntSlice.__eq__ and PySequenceArrayWrapper#GetTypeIDNode.
PullRequest: graalpython/2114
2 parents 46170d8 + a701269 commit d9de178

File tree

4 files changed

+31
-6
lines changed

4 files changed

+31
-6
lines changed

graalpython/com.oracle.graal.python.test/src/tests/test_slice.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2018, 2021, Oracle and/or its affiliates.
1+
# Copyright (c) 2018, 2022, Oracle and/or its affiliates.
22
# Copyright (c) 2013, Regents of the University of California
33
#
44
# All rights reserved.
@@ -194,3 +194,11 @@ def __index__(self):
194194
[1][:"42"]
195195
except TypeError as e:
196196
assert "slice indices must be integers" in str(e)
197+
198+
199+
def test_slice_eq():
200+
# Note: large numbers that do not get interned when boxed...
201+
assert slice(2, 10000, 10) == slice(2, 10000, 10)
202+
assert slice(None, 12345, 10) == slice(None, 12345, 10)
203+
assert slice(1, 10000, 10) != slice(None, 10000, 10)
204+
assert slice(2, 10000, 10) != slice(2, 10000, 1)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -517,7 +517,7 @@ Object doByteArrayMultiCtx(@SuppressWarnings("unused") Object object,
517517
}
518518

519519
@Specialization(guards = "!hasByteArrayContent(object)", replaces = "doPtrArray")
520-
Object doPtrArrayMultiCtx(@SuppressWarnings("unused") PSequence object,
520+
Object doPtrArrayMultiCtx(@SuppressWarnings("unused") Object object,
521521
@Shared("callUnaryNode") @Cached PCallCapiFunction callUnaryNode) {
522522
return callUnaryNode.call(FUN_GET_PTR_ARRAY_TYPE_ID, 0);
523523
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/slice/PIntSlice.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2020, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -42,6 +42,7 @@
4242

4343
import com.oracle.graal.python.PythonLanguage;
4444
import com.oracle.graal.python.builtins.objects.PNone;
45+
import com.oracle.truffle.api.CompilerAsserts;
4546

4647
public final class PIntSlice extends PSlice {
4748

@@ -99,4 +100,18 @@ public final Object getStep() {
99100
public SliceInfo computeIndices(int length) {
100101
return computeIndices(getStart(), stop, getStep(), length);
101102
}
103+
104+
public boolean equals(PIntSlice other) {
105+
return start == other.start && stop == other.stop && step == other.step && startIsNone == other.startIsNone && stepIsNone == other.stepIsNone;
106+
}
107+
108+
@Override
109+
public boolean equals(Object obj) {
110+
CompilerAsserts.neverPartOfCompilation();
111+
if (obj instanceof PIntSlice) {
112+
return equals((PIntSlice) obj);
113+
} else {
114+
return super.equals(obj);
115+
}
116+
}
102117
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/slice/PSlice.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2021, Oracle and/or its affiliates.
2+
* Copyright (c) 2017, 2022, Oracle and/or its affiliates.
33
* Copyright (c) 2013, Regents of the University of California
44
*
55
* All rights reserved.
@@ -64,18 +64,20 @@ public String toString() {
6464

6565
@Override
6666
public boolean equals(Object obj) {
67+
CompilerAsserts.neverPartOfCompilation();
6768
if (!(obj instanceof PSlice)) {
6869
return false;
6970
}
7071
if (this == obj) {
7172
return true;
7273
}
7374
PSlice other = (PSlice) obj;
74-
return (this.getStart() == other.getStart() && this.getStop() == other.getStop() && this.getStep() == other.getStep());
75+
return (this.getStart().equals(other.getStart()) && this.getStop().equals(other.getStop()) && this.getStep().equals(other.getStep()));
7576
}
7677

7778
@Override
7879
public int hashCode() {
80+
CompilerAsserts.neverPartOfCompilation();
7981
return Objects.hash(this.getStart(), this.getStop(), this.getStep());
8082
}
8183

0 commit comments

Comments
 (0)