Skip to content

Commit 4c6a394

Browse files
[3.15] gh-155218: Generate the option group flags in a stable order (GH-155219) (GH-155226)
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 3416e12 commit 4c6a394

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
@@ -321,7 +321,9 @@ def render_option_group_parsing(
321321
""")
322322
continue
323323

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

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

0 commit comments

Comments
 (0)