Skip to content

Commit 04d871d

Browse files
gh-155218: 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 3874ad1 commit 04d871d

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
@@ -341,7 +341,9 @@ def render_option_group_parsing(
341341
""")
342342
continue
343343

344-
group_ids = {p.group for p in subset} # eliminate duplicates
344+
# A set would eliminate duplicates too, but the iteration
345+
# order of small negative integers depends on the platform.
346+
group_ids = dict.fromkeys(p.group for p in subset)
345347
d: dict[str, str | int] = {}
346348
d['count'] = count
347349
d['name'] = f.name
@@ -356,7 +358,7 @@ def render_option_group_parsing(
356358
p.converter.parse_argument(parse_arguments)
357359
d['parse_arguments'] = ", ".join(parse_arguments)
358360

359-
group_ids.discard(0)
361+
group_ids.pop(0, None)
360362
lines = "\n".join([
361363
self.group_to_variable_name(g) + " = 1;"
362364
for g in group_ids

0 commit comments

Comments
 (0)