8000 gh-119004: fix a crash in equality testing between `OrderedDict` by picnixz · Pull Request #121329 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-119004: fix a crash in equality testing between OrderedDict #121329

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
Sep 23, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
improve Python implementation
  • Loading branch information
picnixz committed Jul 4, 2024
commit dad3ef1917e31823907b6606b61deaf2a3f07a2a
22 changes: 13 additions & 9 deletions Lib/collections/__init__.py
4E92
Original file line number Diff line number Diff line change
Expand Up @@ -327,15 +327,16 @@ def __eq__(self, other):
if isinstance(other, OrderedDict):
if not dict.__eq__(self, other):
return False
state_a, count_a = self.__state, len(self)
root_a, curr_a = self.__root, self.__root.next
state_b, count_b = other.__state, len(other)
root_b, curr_b = other.__root, other.__root.next
while True:
if curr_a is root_a and curr_b is root_b:
return True
if curr_a is root_a or curr_b is root_b:
return False

count_a, count_b = len(self), len(other)
if count_a != count_b:
return False

state_a, state_b = self.__state, other.__state
root_a, root_b = self.__root, other.__root
curr_a, curr_b = root_a.next, root_b.next

while (curr_a is not root_a and curr_b is not root_b):
# With the C implementation, calling '==' might have side
# effects that would end in segmentation faults, thus the
# state and size of the operands need to be checked.
Expand All @@ -348,6 +349,9 @@ def __eq__(self, other):
elif not res:
return False
curr_a, curr_b = curr_a.next, curr_b.next
# we stopped simultaneously (size was unchanged)
assert curr_a is root_a and curr_b is root_b
return True
return dict.__eq__(self, other)

def __ior__(self, other):
Expand Down
0