Skip to content

Commit

Permalink
fix issue python#124442: make __static_attributes__ deterministic b…
Browse files Browse the repository at this point in the history
…y sorting

Signed-off-by: kp2pml30 <kp2pml30@gmail.com>
  • Loading branch information
kp2pml30 committed Sep 25, 2024
1 parent 54dd77f commit 3beb5e9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Make `compile` builtin function deterministic by sorting
`__static_attributes__` before dumping to the bytecode #.. section: Library
#.. section: Documentation #.. section: Tests #.. section: Build #..
section: Windows #.. section: macOS #.. section: IDLE #.. section:
Tools/Demos #.. section: C API

# Write your Misc/NEWS.d entry below. It should be a simple ReST paragraph.
# Don't start with "- Issue #<n>: " or "- gh-issue-<n>: " or that sort of
stuff.
###########################################################################
9 changes: 8 additions & 1 deletion Python/compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -911,7 +911,14 @@ PyObject *
_PyCompile_StaticAttributesAsTuple(compiler *c)
{
assert(c->u->u_static_attributes);
return PySequence_Tuple(c->u->u_static_attributes);
PyObject *static_attributes_unsorted = PySequence_List(c->u->u_static_attributes);
if (static_attributes_unsorted == NULL) {
return NULL;
}
PyList_Sort(static_attributes_unsorted);
PyObject *static_attributes = PySequence_Tuple(static_attributes_unsorted);
Py_DECREF(static_attributes_unsorted);
return static_attributes;
}

int
Expand Down

0 comments on commit 3beb5e9

Please sign in to comment.