Skip to content

Commit b35a234

Browse files
committed
pythongh-144175: Add PyArg_ParseVector() function
1 parent 8f45925 commit b35a234

File tree

4 files changed

+31
-0
lines changed

4 files changed

+31
-0
lines changed

Doc/c-api/arg.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,17 @@ API Functions
516516
}
517517
518518
519+
.. c:function:: int PyArg_ParseVector(PyObject *const *args, Py_ssize_t nargs, const char *format, ...)
520+
521+
Parse the parameters of a function that takes only vector parameters into
522+
local variables; function using the :c:macro:`METH_FASTCALL` calling
523+
convention.
524+
Returns true on success; on failure, it returns false and raises the
525+
appropriate exception.
526+
527+
.. versionadded:: 3.15
528+
529+
519530
.. c:function:: int PyArg_UnpackTuple(PyObject *args, const char *name, Py_ssize_t min, Py_ssize_t max, ...)
520531
521532
A simpler form of parameter retrieval which does not use a format string to

Doc/whatsnew/3.15.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1255,6 +1255,10 @@ C API changes
12551255
New features
12561256
------------
12571257

1258+
* Add :c:func:`PyArg_ParseVector` function to parse arguments of functions
1259+
using the :c:macro:`METH_FASTCALL` calling convention.
1260+
(Contributed by Victor Stinner in :gh:`144175`.)
1261+
12581262
* Add :c:func:`PySys_GetAttr`, :c:func:`PySys_GetAttrString`,
12591263
:c:func:`PySys_GetOptionalAttr`, and :c:func:`PySys_GetOptionalAttrString`
12601264
functions as replacements for :c:func:`PySys_GetObject`.

Include/cpython/modsupport.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
# error "this header file must not be included directly"
33
#endif
44

5+
PyAPI_FUNC(int) PyArg_ParseVector(
6+
PyObject *const *args,
7+
Py_ssize_t nargs,
8+
const char *format,
9+
...);
10+
511
// A data structure that can be used to run initialization code once in a
612
// thread-safe manner. The C++11 equivalent is std::call_once.
713
typedef struct {

Python/getargs.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,16 @@ _PyArg_ParseStack(PyObject *const *args, Py_ssize_t nargs, const char *format, .
129129
return retval;
130130
}
131131

132+
int
133+
PyArg_ParseVector(PyObject *const *args, Py_ssize_t nargs, const char *format, ...)
134+
{
135+
va_list va;
136+
va_start(va, format);
137+
int retval = vgetargs1_impl(NULL, args, nargs, format, &va, 0);
138+
va_end(va);
139+
return retval;
140+
}
141+
132142
int
133143
PyArg_VaParse(PyObject *args, const char *format, va_list va)
134144
{

0 commit comments

Comments
 (0)