Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1f77739

Browse files
gh-122943: Rework support of var-positional parameter in Argument Clinic (GH-122945)
Move creation of a tuple for var-positional parameter out of _PyArg_UnpackKeywordsWithVararg(). Merge _PyArg_UnpackKeywordsWithVararg() with _PyArg_UnpackKeywords(). Add a new parameter in _PyArg_UnpackKeywords(). The "parameters" and "converters" attributes of ParseArgsCodeGen no longer contain the var-positional parameter. It is now available as the "varpos" attribute. Optimize code generation for var-positional parameter and reuse the same generating code for functions with and without keyword parameters. Add special converters for var-positional parameter. "tuple" represents it as a Python tuple and "array" represents it as a continuous array of PyObject*. "object" is a temporary alias of "tuple".
1 parent 09d6f5d commit 1f77739

File tree

22 files changed

+1597
-662
lines changed

22 files changed

+1597
-662
lines changed

Include/internal/pycore_modsupport.h

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ PyAPI_FUNC(int) _PyArg_ParseStackAndKeywords(
7676
...);
7777

7878
// Export for 'math' shared extension
79-
PyAPI_FUNC(PyObject * const *) _PyArg_UnpackKeywords(
79+
PyAPI_FUNC(PyObject * const *) _PyArg_UnpackKeywordsEx(
8080
PyObject *const *args,
8181
Py_ssize_t nargs,
8282
PyObject *kwargs,
@@ -85,20 +85,19 @@ PyAPI_FUNC(PyObject * const *) _PyArg_UnpackKeywords(
8585
int minpos,
8686
int maxpos,
8787
int minkw,
88+
int varpos,
8889
PyObject **buf);
8990
#define _PyArg_UnpackKeywords(args, nargs, kwargs, kwnames, parser, minpos, maxpos, minkw, buf) \
9091
(((minkw) == 0 && (kwargs) == NULL && (kwnames) == NULL && \
91-
(minpos) <= (nargs) && (nargs) <= (maxpos) && (args) != NULL) ? (args) : \
92-
_PyArg_UnpackKeywords((args), (nargs), (kwargs), (kwnames), (parser), \
93-
(minpos), (maxpos), (minkw), (buf)))
94-
95-
// Export for '_testclinic' shared extension
96-
PyAPI_FUNC(PyObject * const *) _PyArg_UnpackKeywordsWithVararg(
97-
PyObject *const *args, Py_ssize_t nargs,
98-
PyObject *kwargs, PyObject *kwnames,
99-
struct _PyArg_Parser *parser,
100-
int minpos, int maxpos, int minkw,
101-
int vararg, PyObject **buf);
92+
(minpos) <= (nargs) && (nargs) <= (maxpos) && (args) != NULL) ? \
93+
(args) : \
94+
_PyArg_UnpackKeywordsEx((args), (nargs), (kwargs), (kwnames), (parser), \
95+
(minpos), (maxpos), (minkw), 0, (buf)))
96+
#define _PyArg_UnpackKeywordsWithVararg(args, nargs, kwargs, kwnames, parser, minpos, maxpos, minkw, buf) \
97+
(((minkw) == 0 && (kwargs) == NULL && (kwnames) == NULL && \
98+
(minpos) <= (nargs) && (args) != NULL) ? (args) : \
99+
_PyArg_UnpackKeywordsEx((args), (nargs), (kwargs), (kwnames), (parser), \
100+
(minpos), (maxpos), (minkw), 1, (buf)))
102101

103102
#ifdef __cplusplus
104103
}

Include/internal/pycore_tuple.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ extern PyStatus _PyTuple_InitGlobalObjects(PyInterpreterState *);
2020

2121
#define _PyTuple_ITEMS(op) _Py_RVALUE(_PyTuple_CAST(op)->ob_item)
2222

23-
extern PyObject *_PyTuple_FromArray(PyObject *const *, Py_ssize_t);
23+
PyAPI_FUNC(PyObject *)_PyTuple_FromArray(PyObject *const *, Py_ssize_t);
2424
PyAPI_FUNC(PyObject *)_PyTuple_FromStackRefSteal(const union _PyStackRef *, Py_ssize_t);
2525
PyAPI_FUNC(PyObject *)_PyTuple_FromArraySteal(PyObject *const *, Py_ssize_t);
2626

0 commit comments

Comments
 (0)