Skip to content

Commit 2d684b1

Browse files
[3.14] gh-155218: Generate the option group flags in a stable order (GH-155219) (GH-155224)
They were emitted in the iteration order of a set of group identifiers. The identifiers of the groups before the required parameters are small negative integers, -1 and -2 have the same hash, so their order depended on the size of Py_hash_t, and the code generated on a 32-bit platform differed from the checked in one. They are now emitted in the order of the parameters. (cherry picked from commit 7aec160) Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent bfb9db3 commit 2d684b1

3 files changed

Lines changed: 15 additions & 11 deletions

File tree

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix Argument Clinic generating the flags of the optional groups in
2+
different order on 32-bit and 64-bit platforms.

Modules/clinic/_cursesmodule.c.h

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Tools/clinic/libclinic/clanguage.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,9 @@ def render_option_group_parsing(
320320
""")
321321
continue
322322

323-
group_ids = {p.group for p in subset} # eliminate duplicates
323+
# A set would eliminate duplicates too, but the iteration
324+
# order of small negative integers depends on the platform.
325+
group_ids = dict.fromkeys(p.group for p in subset)
324326
d: dict[str, str | int] = {}
325327
d['count'] = count
326328
d['name'] = f.name
@@ -331,7 +333,7 @@ def render_option_group_parsing(
331333
p.converter.parse_argument(parse_arguments)
332334
d['parse_arguments'] = ", ".join(parse_arguments)
333335

334-
group_ids.discard(0)
336+
group_ids.pop(0, None)
335337
lines = "\n".join([
336338
self.group_to_variable_name(g) + " = 1;"
337339
for g in group_ids

0 commit comments

Comments
 (0)