Skip to content

Commit

Permalink
pythongh-108494: Argument Clinic: fix option group for Limited C API
Browse files Browse the repository at this point in the history
Use PyTuple_Size() instead of PyTuple_GET_SIZE().
  • Loading branch information
vstinner committed Aug 28, 2023
1 parent 4116592 commit f6f3b19
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions Tools/clinic/clinic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1664,8 +1664,9 @@ def group_to_variable_name(group: int) -> str:

def render_option_group_parsing(
self,
clinic: Clinic,
f: Function,
template_dict: TemplateDict
template_dict: TemplateDict,
) -> None:
# positional only, grouped, optional arguments!
# can be optional on the left or right.
Expand Down Expand Up @@ -1713,7 +1714,11 @@ def render_option_group_parsing(
count_min = sys.maxsize
count_max = -1

add("switch (PyTuple_GET_SIZE(args)) {\n")
if clinic.limited_capi:
nargs = 'PyTuple_Size(args)'
else:
nargs = 'PyTuple_GET_SIZE(args)'
add(f"switch ({nargs}) {{\n")
for subset in permute_optional_groups(left, required, right):
count = len(subset)
count_min = min(count_min, count)
Expand Down Expand Up @@ -1870,7 +1875,7 @@ def render_function(
template_dict['unpack_max'] = str(unpack_max)

if has_option_groups:
self.render_option_group_parsing(f, template_dict)
self.render_option_group_parsing(clinic, f, template_dict)

# buffers, not destination
for name, destination in clinic.destination_buffers.items():
Expand Down

0 comments on commit f6f3b19

Please sign in to comment.