Skip to content

Commit 0ba2932

Browse files
gh-64502: Generate the option group flags in a stable order
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. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent c8bee19 commit 0ba2932

2 files changed

Lines changed: 14 additions & 11 deletions

File tree

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: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,10 @@ def render_option_group_parsing(
356356
""")
357357
continue
358358

359-
group_ids = {p.group for p in subset} # eliminate duplicates
359+
# Deduplicate the groups, but keep the order of parameters:
360+
# the iteration order of a set of small negative integers
361+
# depends on the platform.
362+
group_ids = dict.fromkeys(p.group for p in subset)
360363
d: dict[str, str | int] = {}
361364
d['count'] = count
362365
d['name'] = f.name
@@ -371,7 +374,7 @@ def render_option_group_parsing(
371374
p.converter.parse_argument(parse_arguments)
372375
d['parse_arguments'] = ", ".join(parse_arguments)
373376

374-
group_ids.discard(0)
377+
group_ids.pop(0, None)
375378
lines = "\n".join([
376379
self.group_to_variable_name(g) + " = 1;"
377380
for g in group_ids

0 commit comments

Comments
 (0)