Skip to content

Commit

Permalink
gh-122943: Add the varpos parameter in _PyArg_UnpackKeywords (GH-126564)
Browse files Browse the repository at this point in the history
Remove _PyArg_UnpackKeywordsWithVararg.
Add comments for integer arguments of _PyArg_UnpackKeywords.
  • Loading branch information
serhiy-storchaka authored Nov 8, 2024
1 parent ee0746a commit 061e50f
Show file tree
Hide file tree
Showing 94 changed files with 1,220 additions and 685 deletions.
15 changes: 5 additions & 10 deletions Include/internal/pycore_modsupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ PyAPI_FUNC(int) _PyArg_ParseStackAndKeywords(
...);

// Export for 'math' shared extension
PyAPI_FUNC(PyObject * const *) _PyArg_UnpackKeywordsEx(
PyAPI_FUNC(PyObject * const *) _PyArg_UnpackKeywords(
PyObject *const *args,
Py_ssize_t nargs,
PyObject *kwargs,
Expand All @@ -87,17 +87,12 @@ PyAPI_FUNC(PyObject * const *) _PyArg_UnpackKeywordsEx(
int minkw,
int varpos,
PyObject **buf);
#define _PyArg_UnpackKeywords(args, nargs, kwargs, kwnames, parser, minpos, maxpos, minkw, buf) \
#define _PyArg_UnpackKeywords(args, nargs, kwargs, kwnames, parser, minpos, maxpos, minkw, varpos, buf) \
(((minkw) == 0 && (kwargs) == NULL && (kwnames) == NULL && \
(minpos) <= (nargs) && (nargs) <= (maxpos) && (args) != NULL) ? \
(minpos) <= (nargs) && ((varpos) || (nargs) <= (maxpos)) && (args) != NULL) ? \
(args) : \
_PyArg_UnpackKeywordsEx((args), (nargs), (kwargs), (kwnames), (parser), \
(minpos), (maxpos), (minkw), 0, (buf)))
#define _PyArg_UnpackKeywordsWithVararg(args, nargs, kwargs, kwnames, parser, minpos, maxpos, minkw, buf) \
(((minkw) == 0 && (kwargs) == NULL && (kwnames) == NULL && \
(minpos) <= (nargs) && (args) != NULL) ? (args) : \
_PyArg_UnpackKeywordsEx((args), (nargs), (kwargs), (kwnames), (parser), \
(minpos), (maxpos), (minkw), 1, (buf)))
_PyArg_UnpackKeywords((args), (nargs), (kwargs), (kwnames), (parser), \
(minpos), (maxpos), (minkw), (varpos), (buf)))

#ifdef __cplusplus
}
Expand Down
155 changes: 93 additions & 62 deletions Lib/test/clinic.test.c

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Lib/test/test_call.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def test_varargs17_kw(self):
print, 0, sep=1, end=2, file=3, flush=4, foo=5)

def test_varargs18_kw(self):
# _PyArg_UnpackKeywordsWithVararg()
# _PyArg_UnpackKeywords() with varpos
msg = r"invalid keyword argument for print\(\)$"
with self.assertRaisesRegex(TypeError, msg):
print(0, 1, **{BadStr('foo'): ','})
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_clinic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2703,7 +2703,7 @@ def test_cli_force(self):
# Verify by checking the checksum.
checksum = (
"/*[clinic end generated code: "
"output=0acbef4794cb933e input=9543a8d2da235301]*/\n"
"output=00512eb783a9b748 input=9543a8d2da235301]*/\n"
)
with open(fn, encoding='utf-8') as f:
generated = f.read()
Expand Down
35 changes: 23 additions & 12 deletions Modules/_ctypes/clinic/_ctypes.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions Modules/_ctypes/clinic/cfield.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions Modules/_io/clinic/_iomodule.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 15 additions & 8 deletions Modules/_io/clinic/bufferedio.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions Modules/_io/clinic/bytesio.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 11 additions & 6 deletions Modules/_io/clinic/fileio.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions Modules/_io/clinic/iobase.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions Modules/_io/clinic/stringio.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 061e50f

Please sign in to comment.