summaryrefslogtreecommitdiffstats
path: root/contrib/tools/python3/src/Python/getargs.c
diff options
context:
space:
mode:
authorshadchin <[email protected]>2022-02-10 16:44:39 +0300
committerDaniil Cherednik <[email protected]>2022-02-10 16:44:39 +0300
commite9656aae26e0358d5378e5b63dcac5c8dbe0e4d0 (patch)
tree64175d5cadab313b3e7039ebaa06c5bc3295e274 /contrib/tools/python3/src/Python/getargs.c
parent2598ef1d0aee359b4b6d5fdd1758916d5907d04f (diff)
Restoring authorship annotation for <[email protected]>. Commit 2 of 2.
Diffstat (limited to 'contrib/tools/python3/src/Python/getargs.c')
-rw-r--r--contrib/tools/python3/src/Python/getargs.c910
1 files changed, 455 insertions, 455 deletions
diff --git a/contrib/tools/python3/src/Python/getargs.c b/contrib/tools/python3/src/Python/getargs.c
index 2362fbbc561..d4a531a5efb 100644
--- a/contrib/tools/python3/src/Python/getargs.c
+++ b/contrib/tools/python3/src/Python/getargs.c
@@ -2,7 +2,7 @@
/* New getargs implementation */
#include "Python.h"
-#include "pycore_tupleobject.h"
+#include "pycore_tupleobject.h"
#include <ctype.h>
#include <float.h>
@@ -106,7 +106,7 @@ PyArg_Parse(PyObject *args, const char *format, ...)
return retval;
}
-PyAPI_FUNC(int)
+PyAPI_FUNC(int)
_PyArg_Parse_SizeT(PyObject *args, const char *format, ...)
{
int retval;
@@ -131,7 +131,7 @@ PyArg_ParseTuple(PyObject *args, const char *format, ...)
return retval;
}
-PyAPI_FUNC(int)
+PyAPI_FUNC(int)
_PyArg_ParseTuple_SizeT(PyObject *args, const char *format, ...)
{
int retval;
@@ -156,7 +156,7 @@ _PyArg_ParseStack(PyObject *const *args, Py_ssize_t nargs, const char *format, .
return retval;
}
-PyAPI_FUNC(int)
+PyAPI_FUNC(int)
_PyArg_ParseStack_SizeT(PyObject *const *args, Py_ssize_t nargs, const char *format, ...)
{
int retval;
@@ -182,7 +182,7 @@ PyArg_VaParse(PyObject *args, const char *format, va_list va)
return retval;
}
-PyAPI_FUNC(int)
+PyAPI_FUNC(int)
_PyArg_VaParse_SizeT(PyObject *args, const char *format, va_list va)
{
va_list lva;
@@ -312,7 +312,7 @@ vgetargs1_impl(PyObject *compat_args, PyObject *const *stack, Py_ssize_t nargs,
break;
default:
if (level == 0) {
- if (Py_ISALPHA(c))
+ if (Py_ISALPHA(c))
if (c != 'e') /* skip encoded */
max++;
}
@@ -372,14 +372,14 @@ vgetargs1_impl(PyObject *compat_args, PyObject *const *stack, Py_ssize_t nargs,
if (nargs < min || max < nargs) {
if (message == NULL)
PyErr_Format(PyExc_TypeError,
- "%.150s%s takes %s %d argument%s (%zd given)",
+ "%.150s%s takes %s %d argument%s (%zd given)",
fname==NULL ? "function" : fname,
fname==NULL ? "" : "()",
min==max ? "exactly"
: nargs < min ? "at least" : "at most",
nargs < min ? min : max,
(nargs < min ? min : max) == 1 ? "" : "s",
- nargs);
+ nargs);
else
PyErr_SetString(PyExc_TypeError, message);
return cleanreturn(0, &freelist);
@@ -397,7 +397,7 @@ vgetargs1_impl(PyObject *compat_args, PyObject *const *stack, Py_ssize_t nargs,
}
}
- if (*format != '\0' && !Py_ISALPHA(*format) &&
+ if (*format != '\0' && !Py_ISALPHA(*format) &&
*format != '(' &&
*format != '|' && *format != ':' && *format != ';') {
PyErr_Format(PyExc_SystemError,
@@ -423,7 +423,7 @@ vgetargs1(PyObject *args, const char *format, va_list *p_va, int flags)
return 0;
}
- stack = _PyTuple_ITEMS(args);
+ stack = _PyTuple_ITEMS(args);
nargs = PyTuple_GET_SIZE(args);
}
else {
@@ -521,7 +521,7 @@ converttuple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
}
else if (c == ':' || c == ';' || c == '\0')
break;
- else if (level == 0 && Py_ISALPHA(c))
+ else if (level == 0 && Py_ISALPHA(c))
n++;
}
@@ -531,7 +531,7 @@ converttuple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
toplevel ? "expected %d arguments, not %.50s" :
"must be %d-item sequence, not %.50s",
n,
- arg == Py_None ? "None" : Py_TYPE(arg)->tp_name);
+ arg == Py_None ? "None" : Py_TYPE(arg)->tp_name);
return msgbuf;
}
@@ -540,10 +540,10 @@ converttuple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
levels[0] = 0;
if (toplevel) {
PyOS_snprintf(msgbuf, bufsize,
- "expected %d argument%s, not %" PY_FORMAT_SIZE_T "d",
- n,
- n == 1 ? "" : "s",
- len);
+ "expected %d argument%s, not %" PY_FORMAT_SIZE_T "d",
+ n,
+ n == 1 ? "" : "s",
+ len);
}
else {
PyOS_snprintf(msgbuf, bufsize,
@@ -610,20 +610,20 @@ convertitem(PyObject *arg, const char **p_format, va_list *p_va, int flags,
-/* Format an error message generated by convertsimple().
- displayname must be UTF-8 encoded.
-*/
+/* Format an error message generated by convertsimple().
+ displayname must be UTF-8 encoded.
+*/
+
+void
+_PyArg_BadArgument(const char *fname, const char *displayname,
+ const char *expected, PyObject *arg)
+{
+ PyErr_Format(PyExc_TypeError,
+ "%.200s() %.200s must be %.50s, not %.50s",
+ fname, displayname, expected,
+ arg == Py_None ? "None" : Py_TYPE(arg)->tp_name);
+}
-void
-_PyArg_BadArgument(const char *fname, const char *displayname,
- const char *expected, PyObject *arg)
-{
- PyErr_Format(PyExc_TypeError,
- "%.200s() %.200s must be %.50s, not %.50s",
- fname, displayname, expected,
- arg == Py_None ? "None" : Py_TYPE(arg)->tp_name);
-}
-
static const char *
converterr(const char *expected, PyObject *arg, char *msgbuf, size_t bufsize)
{
@@ -636,7 +636,7 @@ converterr(const char *expected, PyObject *arg, char *msgbuf, size_t bufsize)
else {
PyOS_snprintf(msgbuf, bufsize,
"must be %.50s, not %.50s", expected,
- arg == Py_None ? "None" : Py_TYPE(arg)->tp_name);
+ arg == Py_None ? "None" : Py_TYPE(arg)->tp_name);
}
return msgbuf;
}
@@ -644,9 +644,9 @@ converterr(const char *expected, PyObject *arg, char *msgbuf, size_t bufsize)
#define CONV_UNICODE "(unicode conversion error)"
/* Explicitly check for float arguments when integers are expected.
- Return 1 for error, 0 if ok.
- XXX Should be removed after the end of the deprecation period in
- _PyLong_FromNbIndexOrNbInt. */
+ Return 1 for error, 0 if ok.
+ XXX Should be removed after the end of the deprecation period in
+ _PyLong_FromNbIndexOrNbInt. */
static int
float_argument_error(PyObject *arg)
{
@@ -675,13 +675,13 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
/* For # codes */
#define FETCH_SIZE int *q=NULL;Py_ssize_t *q2=NULL;\
if (flags & FLAG_SIZE_T) q2=va_arg(*p_va, Py_ssize_t*); \
- else { \
- if (PyErr_WarnEx(PyExc_DeprecationWarning, \
- "PY_SSIZE_T_CLEAN will be required for '#' formats", 1)) { \
- return NULL; \
- } \
- q=va_arg(*p_va, int*); \
- }
+ else { \
+ if (PyErr_WarnEx(PyExc_DeprecationWarning, \
+ "PY_SSIZE_T_CLEAN will be required for '#' formats", 1)) { \
+ return NULL; \
+ } \
+ q=va_arg(*p_va, int*); \
+ }
#define STORE_SIZE(s) \
if (flags & FLAG_SIZE_T) \
*q2=s; \
@@ -881,7 +881,7 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
case 'f': {/* float */
float *p = va_arg(*p_va, float *);
double dval = PyFloat_AsDouble(arg);
- if (dval == -1.0 && PyErr_Occurred())
+ if (dval == -1.0 && PyErr_Occurred())
RETURN_ERR_OCCURRED;
else
*p = (float) dval;
@@ -891,7 +891,7 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
case 'd': {/* double */
double *p = va_arg(*p_va, double *);
double dval = PyFloat_AsDouble(arg);
- if (dval == -1.0 && PyErr_Occurred())
+ if (dval == -1.0 && PyErr_Occurred())
RETURN_ERR_OCCURRED;
else
*p = dval;
@@ -923,7 +923,7 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
case 'C': {/* unicode char */
int *p = va_arg(*p_va, int *);
int kind;
- const void *data;
+ const void *data;
if (!PyUnicode_Check(arg))
return converterr("a unicode character", arg, msgbuf, bufsize);
@@ -1070,9 +1070,9 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
case 'u': /* raw unicode buffer (Py_UNICODE *) */
case 'Z': /* raw unicode buffer or None */
{
- // TODO: Raise DeprecationWarning
-_Py_COMP_DIAG_PUSH
-_Py_COMP_DIAG_IGNORE_DEPR_DECLS
+ // TODO: Raise DeprecationWarning
+_Py_COMP_DIAG_PUSH
+_Py_COMP_DIAG_IGNORE_DEPR_DECLS
Py_UNICODE **p = va_arg(*p_va, Py_UNICODE **);
if (*format == '#') {
@@ -1112,7 +1112,7 @@ _Py_COMP_DIAG_IGNORE_DEPR_DECLS
arg, msgbuf, bufsize);
}
break;
-_Py_COMP_DIAG_POP
+_Py_COMP_DIAG_POP
}
case 'e': {/* encoded string */
@@ -1203,19 +1203,19 @@ _Py_COMP_DIAG_POP
trailing 0-byte
*/
- int *q = NULL; Py_ssize_t *q2 = NULL;
- if (flags & FLAG_SIZE_T) {
- q2 = va_arg(*p_va, Py_ssize_t*);
- }
- else {
- if (PyErr_WarnEx(PyExc_DeprecationWarning,
- "PY_SSIZE_T_CLEAN will be required for '#' formats", 1))
- {
- Py_DECREF(s);
- return NULL;
- }
- q = va_arg(*p_va, int*);
- }
+ int *q = NULL; Py_ssize_t *q2 = NULL;
+ if (flags & FLAG_SIZE_T) {
+ q2 = va_arg(*p_va, Py_ssize_t*);
+ }
+ else {
+ if (PyErr_WarnEx(PyExc_DeprecationWarning,
+ "PY_SSIZE_T_CLEAN will be required for '#' formats", 1))
+ {
+ Py_DECREF(s);
+ return NULL;
+ }
+ q = va_arg(*p_va, int*);
+ }
format++;
if (q == NULL && q2 == NULL) {
@@ -1248,19 +1248,19 @@ _Py_COMP_DIAG_POP
}
}
memcpy(*buffer, ptr, size+1);
-
- if (flags & FLAG_SIZE_T) {
- *q2 = size;
- }
- else {
- if (INT_MAX < size) {
- Py_DECREF(s);
- PyErr_SetString(PyExc_OverflowError,
- "size does not fit in an int");
- return converterr("", arg, msgbuf, bufsize);
- }
- *q = (int)size;
- }
+
+ if (flags & FLAG_SIZE_T) {
+ *q2 = size;
+ }
+ else {
+ if (INT_MAX < size) {
+ Py_DECREF(s);
+ PyErr_SetString(PyExc_OverflowError,
+ "size does not fit in an int");
+ return converterr("", arg, msgbuf, bufsize);
+ }
+ *q = (int)size;
+ }
} else {
/* Using a 0-terminated buffer:
@@ -1335,7 +1335,7 @@ _Py_COMP_DIAG_POP
type = va_arg(*p_va, PyTypeObject*);
p = va_arg(*p_va, PyObject **);
format++;
- if (PyType_IsSubtype(Py_TYPE(arg), type))
+ if (PyType_IsSubtype(Py_TYPE(arg), type))
*p = arg;
else
return converterr(type->tp_name, arg, msgbuf, bufsize);
@@ -1470,7 +1470,7 @@ PyArg_ParseTupleAndKeywords(PyObject *args,
return retval;
}
-PyAPI_FUNC(int)
+PyAPI_FUNC(int)
_PyArg_ParseTupleAndKeywords_SizeT(PyObject *args,
PyObject *keywords,
const char *format,
@@ -1521,7 +1521,7 @@ PyArg_VaParseTupleAndKeywords(PyObject *args,
return retval;
}
-PyAPI_FUNC(int)
+PyAPI_FUNC(int)
_PyArg_VaParseTupleAndKeywords_SizeT(PyObject *args,
PyObject *keywords,
const char *format,
@@ -1547,7 +1547,7 @@ _PyArg_VaParseTupleAndKeywords_SizeT(PyObject *args,
return retval;
}
-PyAPI_FUNC(int)
+PyAPI_FUNC(int)
_PyArg_ParseTupleAndKeywordsFast(PyObject *args, PyObject *keywords,
struct _PyArg_Parser *parser, ...)
{
@@ -1560,7 +1560,7 @@ _PyArg_ParseTupleAndKeywordsFast(PyObject *args, PyObject *keywords,
return retval;
}
-PyAPI_FUNC(int)
+PyAPI_FUNC(int)
_PyArg_ParseTupleAndKeywordsFast_SizeT(PyObject *args, PyObject *keywords,
struct _PyArg_Parser *parser, ...)
{
@@ -1573,7 +1573,7 @@ _PyArg_ParseTupleAndKeywordsFast_SizeT(PyObject *args, PyObject *keywords,
return retval;
}
-PyAPI_FUNC(int)
+PyAPI_FUNC(int)
_PyArg_ParseStackAndKeywords(PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames,
struct _PyArg_Parser *parser, ...)
{
@@ -1586,7 +1586,7 @@ _PyArg_ParseStackAndKeywords(PyObject *const *args, Py_ssize_t nargs, PyObject *
return retval;
}
-PyAPI_FUNC(int)
+PyAPI_FUNC(int)
_PyArg_ParseStackAndKeywords_SizeT(PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames,
struct _PyArg_Parser *parser, ...)
{
@@ -1600,7 +1600,7 @@ _PyArg_ParseStackAndKeywords_SizeT(PyObject *const *args, Py_ssize_t nargs, PyOb
}
-PyAPI_FUNC(int)
+PyAPI_FUNC(int)
_PyArg_VaParseTupleAndKeywordsFast(PyObject *args, PyObject *keywords,
struct _PyArg_Parser *parser, va_list va)
{
@@ -1614,7 +1614,7 @@ _PyArg_VaParseTupleAndKeywordsFast(PyObject *args, PyObject *keywords,
return retval;
}
-PyAPI_FUNC(int)
+PyAPI_FUNC(int)
_PyArg_VaParseTupleAndKeywordsFast_SizeT(PyObject *args, PyObject *keywords,
struct _PyArg_Parser *parser, va_list va)
{
@@ -1768,14 +1768,14 @@ vgetargskeywords(PyObject *args, PyObject *kwargs, const char *format,
}
else {
PyErr_Format(PyExc_TypeError,
- "%.200s%s takes %s %d positional argument%s"
- " (%zd given)",
+ "%.200s%s takes %s %d positional argument%s"
+ " (%zd given)",
(fname == NULL) ? "function" : fname,
(fname == NULL) ? "" : "()",
(min != INT_MAX) ? "at most" : "exactly",
- max,
- max == 1 ? "" : "s",
- nargs);
+ max,
+ max == 1 ? "" : "s",
+ nargs);
}
return cleanreturn(0, &freelist);
}
@@ -1791,13 +1791,13 @@ vgetargskeywords(PyObject *args, PyObject *kwargs, const char *format,
current_arg = PyTuple_GET_ITEM(args, i);
}
else if (nkwargs && i >= pos) {
- current_arg = _PyDict_GetItemStringWithError(kwargs, kwlist[i]);
- if (current_arg) {
+ current_arg = _PyDict_GetItemStringWithError(kwargs, kwlist[i]);
+ if (current_arg) {
--nkwargs;
- }
- else if (PyErr_Occurred()) {
- return cleanreturn(0, &freelist);
- }
+ }
+ else if (PyErr_Occurred()) {
+ return cleanreturn(0, &freelist);
+ }
}
else {
current_arg = NULL;
@@ -1853,14 +1853,14 @@ vgetargskeywords(PyObject *args, PyObject *kwargs, const char *format,
if (skip) {
PyErr_Format(PyExc_TypeError,
- "%.200s%s takes %s %d positional argument%s"
- " (%zd given)",
+ "%.200s%s takes %s %d positional argument%s"
+ " (%zd given)",
(fname == NULL) ? "function" : fname,
(fname == NULL) ? "" : "()",
(Py_MIN(pos, min) < i) ? "at least" : "exactly",
- Py_MIN(pos, min),
- Py_MIN(pos, min) == 1 ? "" : "s",
- nargs);
+ Py_MIN(pos, min),
+ Py_MIN(pos, min) == 1 ? "" : "s",
+ nargs);
return cleanreturn(0, &freelist);
}
@@ -1876,7 +1876,7 @@ vgetargskeywords(PyObject *args, PyObject *kwargs, const char *format,
Py_ssize_t j;
/* make sure there are no arguments given by name and position */
for (i = pos; i < nargs; i++) {
- current_arg = _PyDict_GetItemStringWithError(kwargs, kwlist[i]);
+ current_arg = _PyDict_GetItemStringWithError(kwargs, kwlist[i]);
if (current_arg) {
/* arg present in tuple and in dict */
PyErr_Format(PyExc_TypeError,
@@ -1887,9 +1887,9 @@ vgetargskeywords(PyObject *args, PyObject *kwargs, const char *format,
kwlist[i], i+1);
return cleanreturn(0, &freelist);
}
- else if (PyErr_Occurred()) {
- return cleanreturn(0, &freelist);
- }
+ else if (PyErr_Occurred()) {
+ return cleanreturn(0, &freelist);
+ }
}
/* make sure there are no extraneous keyword arguments */
j = 0;
@@ -1954,70 +1954,70 @@ parser_init(struct _PyArg_Parser *parser)
len = i;
format = parser->format;
- if (format) {
- /* grab the function name or custom error msg first (mutually exclusive) */
- parser->fname = strchr(parser->format, ':');
- if (parser->fname) {
- parser->fname++;
- parser->custom_msg = NULL;
- }
- else {
- parser->custom_msg = strchr(parser->format,';');
- if (parser->custom_msg)
- parser->custom_msg++;
- }
-
- min = max = INT_MAX;
- for (i = 0; i < len; i++) {
- if (*format == '|') {
- if (min != INT_MAX) {
- PyErr_SetString(PyExc_SystemError,
- "Invalid format string (| specified twice)");
- return 0;
- }
- if (max != INT_MAX) {
- PyErr_SetString(PyExc_SystemError,
- "Invalid format string ($ before |)");
- return 0;
- }
- min = i;
- format++;
+ if (format) {
+ /* grab the function name or custom error msg first (mutually exclusive) */
+ parser->fname = strchr(parser->format, ':');
+ if (parser->fname) {
+ parser->fname++;
+ parser->custom_msg = NULL;
+ }
+ else {
+ parser->custom_msg = strchr(parser->format,';');
+ if (parser->custom_msg)
+ parser->custom_msg++;
+ }
+
+ min = max = INT_MAX;
+ for (i = 0; i < len; i++) {
+ if (*format == '|') {
+ if (min != INT_MAX) {
+ PyErr_SetString(PyExc_SystemError,
+ "Invalid format string (| specified twice)");
+ return 0;
+ }
+ if (max != INT_MAX) {
+ PyErr_SetString(PyExc_SystemError,
+ "Invalid format string ($ before |)");
+ return 0;
+ }
+ min = i;
+ format++;
}
- if (*format == '$') {
- if (max != INT_MAX) {
- PyErr_SetString(PyExc_SystemError,
- "Invalid format string ($ specified twice)");
- return 0;
- }
- if (i < parser->pos) {
- PyErr_SetString(PyExc_SystemError,
- "Empty parameter name after $");
- return 0;
- }
- max = i;
- format++;
+ if (*format == '$') {
+ if (max != INT_MAX) {
+ PyErr_SetString(PyExc_SystemError,
+ "Invalid format string ($ specified twice)");
+ return 0;
+ }
+ if (i < parser->pos) {
+ PyErr_SetString(PyExc_SystemError,
+ "Empty parameter name after $");
+ return 0;
+ }
+ max = i;
+ format++;
}
- if (IS_END_OF_FORMAT(*format)) {
- PyErr_Format(PyExc_SystemError,
- "More keyword list entries (%d) than "
- "format specifiers (%d)", len, i);
+ if (IS_END_OF_FORMAT(*format)) {
+ PyErr_Format(PyExc_SystemError,
+ "More keyword list entries (%d) than "
+ "format specifiers (%d)", len, i);
return 0;
}
-
- msg = skipitem(&format, NULL, 0);
- if (msg) {
- PyErr_Format(PyExc_SystemError, "%s: '%s'", msg,
- format);
+
+ msg = skipitem(&format, NULL, 0);
+ if (msg) {
+ PyErr_Format(PyExc_SystemError, "%s: '%s'", msg,
+ format);
return 0;
}
}
- parser->min = Py_MIN(min, len);
- parser->max = Py_MIN(max, len);
-
- if (!IS_END_OF_FORMAT(*format) && (*format != '|') && (*format != '$')) {
+ parser->min = Py_MIN(min, len);
+ parser->max = Py_MIN(max, len);
+
+ if (!IS_END_OF_FORMAT(*format) && (*format != '|') && (*format != '$')) {
PyErr_Format(PyExc_SystemError,
- "more argument specifiers than keyword list entries "
- "(remaining format:'%s')", format);
+ "more argument specifiers than keyword list entries "
+ "(remaining format:'%s')", format);
return 0;
}
}
@@ -2052,24 +2052,24 @@ parser_clear(struct _PyArg_Parser *parser)
}
static PyObject*
-find_keyword(PyObject *kwnames, PyObject *const *kwstack, PyObject *key)
+find_keyword(PyObject *kwnames, PyObject *const *kwstack, PyObject *key)
{
Py_ssize_t i, nkwargs;
nkwargs = PyTuple_GET_SIZE(kwnames);
- for (i = 0; i < nkwargs; i++) {
+ for (i = 0; i < nkwargs; i++) {
PyObject *kwname = PyTuple_GET_ITEM(kwnames, i);
- /* kwname == key will normally find a match in since keyword keys
- should be interned strings; if not retry below in a new loop. */
+ /* kwname == key will normally find a match in since keyword keys
+ should be interned strings; if not retry below in a new loop. */
if (kwname == key) {
return kwstack[i];
}
- }
-
- for (i = 0; i < nkwargs; i++) {
- PyObject *kwname = PyTuple_GET_ITEM(kwnames, i);
- assert(PyUnicode_Check(kwname));
+ }
+
+ for (i = 0; i < nkwargs; i++) {
+ PyObject *kwname = PyTuple_GET_ITEM(kwnames, i);
+ assert(PyUnicode_Check(kwname));
if (_PyUnicode_EQ(kwname, key)) {
return kwstack[i];
}
@@ -2163,13 +2163,13 @@ vgetargskeywordsfast_impl(PyObject *const *args, Py_ssize_t nargs,
}
else {
PyErr_Format(PyExc_TypeError,
- "%.200s%s takes %s %d positional argument%s (%zd given)",
+ "%.200s%s takes %s %d positional argument%s (%zd given)",
(parser->fname == NULL) ? "function" : parser->fname,
(parser->fname == NULL) ? "" : "()",
- (parser->min < parser->max) ? "at most" : "exactly",
- parser->max,
- parser->max == 1 ? "" : "s",
- nargs);
+ (parser->min < parser->max) ? "at most" : "exactly",
+ parser->max,
+ parser->max == 1 ? "" : "s",
+ nargs);
}
return cleanreturn(0, &freelist);
}
@@ -2190,18 +2190,18 @@ vgetargskeywordsfast_impl(PyObject *const *args, Py_ssize_t nargs,
}
else if (nkwargs && i >= pos) {
keyword = PyTuple_GET_ITEM(kwtuple, i - pos);
- if (kwargs != NULL) {
- current_arg = PyDict_GetItemWithError(kwargs, keyword);
- if (!current_arg && PyErr_Occurred()) {
- return cleanreturn(0, &freelist);
- }
- }
- else {
- current_arg = find_keyword(kwnames, kwstack, keyword);
- }
- if (current_arg) {
+ if (kwargs != NULL) {
+ current_arg = PyDict_GetItemWithError(kwargs, keyword);
+ if (!current_arg && PyErr_Occurred()) {
+ return cleanreturn(0, &freelist);
+ }
+ }
+ else {
+ current_arg = find_keyword(kwnames, kwstack, keyword);
+ }
+ if (current_arg) {
--nkwargs;
- }
+ }
}
else {
current_arg = NULL;
@@ -2222,14 +2222,14 @@ vgetargskeywordsfast_impl(PyObject *const *args, Py_ssize_t nargs,
if (i < pos) {
Py_ssize_t min = Py_MIN(pos, parser->min);
PyErr_Format(PyExc_TypeError,
- "%.200s%s takes %s %d positional argument%s"
- " (%zd given)",
+ "%.200s%s takes %s %d positional argument%s"
+ " (%zd given)",
(parser->fname == NULL) ? "function" : parser->fname,
(parser->fname == NULL) ? "" : "()",
min < parser->max ? "at least" : "exactly",
- min,
- min == 1 ? "" : "s",
- nargs);
+ min,
+ min == 1 ? "" : "s",
+ nargs);
}
else {
keyword = PyTuple_GET_ITEM(kwtuple, i - pos);
@@ -2262,15 +2262,15 @@ vgetargskeywordsfast_impl(PyObject *const *args, Py_ssize_t nargs,
/* make sure there are no arguments given by name and position */
for (i = pos; i < nargs; i++) {
keyword = PyTuple_GET_ITEM(kwtuple, i - pos);
- if (kwargs != NULL) {
- current_arg = PyDict_GetItemWithError(kwargs, keyword);
- if (!current_arg && PyErr_Occurred()) {
- return cleanreturn(0, &freelist);
- }
- }
- else {
- current_arg = find_keyword(kwnames, kwstack, keyword);
- }
+ if (kwargs != NULL) {
+ current_arg = PyDict_GetItemWithError(kwargs, keyword);
+ if (!current_arg && PyErr_Occurred()) {
+ return cleanreturn(0, &freelist);
+ }
+ }
+ else {
+ current_arg = find_keyword(kwnames, kwstack, keyword);
+ }
if (current_arg) {
/* arg present in tuple and in dict */
PyErr_Format(PyExc_TypeError,
@@ -2301,7 +2301,7 @@ vgetargskeywordsfast_impl(PyObject *const *args, Py_ssize_t nargs,
if (match <= 0) {
if (!match) {
PyErr_Format(PyExc_TypeError,
- "'%S' is an invalid keyword "
+ "'%S' is an invalid keyword "
"argument for %.200s%s",
keyword,
(parser->fname == NULL) ? "this function" : parser->fname,
@@ -2330,217 +2330,217 @@ vgetargskeywordsfast(PyObject *args, PyObject *keywords,
return 0;
}
- stack = _PyTuple_ITEMS(args);
+ stack = _PyTuple_ITEMS(args);
nargs = PyTuple_GET_SIZE(args);
return vgetargskeywordsfast_impl(stack, nargs, keywords, NULL,
parser, p_va, flags);
}
-#undef _PyArg_UnpackKeywords
-
-PyObject * const *
-_PyArg_UnpackKeywords(PyObject *const *args, Py_ssize_t nargs,
- PyObject *kwargs, PyObject *kwnames,
- struct _PyArg_Parser *parser,
- int minpos, int maxpos, int minkw,
- PyObject **buf)
-{
- PyObject *kwtuple;
- PyObject *keyword;
- int i, posonly, minposonly, maxargs;
- int reqlimit = minkw ? maxpos + minkw : minpos;
- Py_ssize_t nkwargs;
- PyObject *current_arg;
- PyObject * const *kwstack = NULL;
-
- assert(kwargs == NULL || PyDict_Check(kwargs));
- assert(kwargs == NULL || kwnames == NULL);
-
- if (parser == NULL) {
- PyErr_BadInternalCall();
- return NULL;
- }
-
- if (kwnames != NULL && !PyTuple_Check(kwnames)) {
- PyErr_BadInternalCall();
- return NULL;
- }
-
- if (args == NULL && nargs == 0) {
- args = buf;
- }
-
- if (!parser_init(parser)) {
- return NULL;
- }
-
- kwtuple = parser->kwtuple;
- posonly = parser->pos;
- minposonly = Py_MIN(posonly, minpos);
- maxargs = posonly + (int)PyTuple_GET_SIZE(kwtuple);
-
- if (kwargs != NULL) {
- nkwargs = PyDict_GET_SIZE(kwargs);
- }
- else if (kwnames != NULL) {
- nkwargs = PyTuple_GET_SIZE(kwnames);
- kwstack = args + nargs;
- }
- else {
- nkwargs = 0;
- }
- if (nkwargs == 0 && minkw == 0 && minpos <= nargs && nargs <= maxpos) {
- /* Fast path. */
- return args;
- }
- if (nargs + nkwargs > maxargs) {
- /* Adding "keyword" (when nargs == 0) prevents producing wrong error
- messages in some special cases (see bpo-31229). */
- PyErr_Format(PyExc_TypeError,
- "%.200s%s takes at most %d %sargument%s (%zd given)",
- (parser->fname == NULL) ? "function" : parser->fname,
- (parser->fname == NULL) ? "" : "()",
- maxargs,
- (nargs == 0) ? "keyword " : "",
- (maxargs == 1) ? "" : "s",
- nargs + nkwargs);
- return NULL;
- }
- if (nargs > maxpos) {
- if (maxpos == 0) {
- PyErr_Format(PyExc_TypeError,
- "%.200s%s takes no positional arguments",
- (parser->fname == NULL) ? "function" : parser->fname,
- (parser->fname == NULL) ? "" : "()");
- }
- else {
- PyErr_Format(PyExc_TypeError,
- "%.200s%s takes %s %d positional argument%s (%zd given)",
- (parser->fname == NULL) ? "function" : parser->fname,
- (parser->fname == NULL) ? "" : "()",
- (minpos < maxpos) ? "at most" : "exactly",
- maxpos,
- (maxpos == 1) ? "" : "s",
- nargs);
- }
- return NULL;
- }
- if (nargs < minposonly) {
- PyErr_Format(PyExc_TypeError,
- "%.200s%s takes %s %d positional argument%s"
- " (%zd given)",
- (parser->fname == NULL) ? "function" : parser->fname,
- (parser->fname == NULL) ? "" : "()",
- minposonly < maxpos ? "at least" : "exactly",
- minposonly,
- minposonly == 1 ? "" : "s",
- nargs);
- return NULL;
- }
-
- /* copy tuple args */
- for (i = 0; i < nargs; i++) {
- buf[i] = args[i];
- }
-
- /* copy keyword args using kwtuple to drive process */
- for (i = Py_MAX((int)nargs, posonly); i < maxargs; i++) {
- if (nkwargs) {
- keyword = PyTuple_GET_ITEM(kwtuple, i - posonly);
- if (kwargs != NULL) {
- current_arg = PyDict_GetItemWithError(kwargs, keyword);
- if (!current_arg && PyErr_Occurred()) {
- return NULL;
- }
- }
- else {
- current_arg = find_keyword(kwnames, kwstack, keyword);
- }
- }
- else if (i >= reqlimit) {
- break;
- }
- else {
- current_arg = NULL;
- }
-
- buf[i] = current_arg;
-
- if (current_arg) {
- --nkwargs;
- }
- else if (i < minpos || (maxpos <= i && i < reqlimit)) {
- /* Less arguments than required */
- keyword = PyTuple_GET_ITEM(kwtuple, i - posonly);
- PyErr_Format(PyExc_TypeError, "%.200s%s missing required "
- "argument '%U' (pos %d)",
- (parser->fname == NULL) ? "function" : parser->fname,
- (parser->fname == NULL) ? "" : "()",
- keyword, i+1);
- return NULL;
- }
- }
-
- if (nkwargs > 0) {
- Py_ssize_t j;
- /* make sure there are no arguments given by name and position */
- for (i = posonly; i < nargs; i++) {
- keyword = PyTuple_GET_ITEM(kwtuple, i - posonly);
- if (kwargs != NULL) {
- current_arg = PyDict_GetItemWithError(kwargs, keyword);
- if (!current_arg && PyErr_Occurred()) {
- return NULL;
- }
- }
- else {
- current_arg = find_keyword(kwnames, kwstack, keyword);
- }
- if (current_arg) {
- /* arg present in tuple and in dict */
- PyErr_Format(PyExc_TypeError,
- "argument for %.200s%s given by name ('%U') "
- "and position (%d)",
- (parser->fname == NULL) ? "function" : parser->fname,
- (parser->fname == NULL) ? "" : "()",
- keyword, i+1);
- return NULL;
- }
- }
- /* make sure there are no extraneous keyword arguments */
- j = 0;
- while (1) {
- int match;
- if (kwargs != NULL) {
- if (!PyDict_Next(kwargs, &j, &keyword, NULL))
- break;
- }
- else {
- if (j >= PyTuple_GET_SIZE(kwnames))
- break;
- keyword = PyTuple_GET_ITEM(kwnames, j);
- j++;
- }
-
- match = PySequence_Contains(kwtuple, keyword);
- if (match <= 0) {
- if (!match) {
- PyErr_Format(PyExc_TypeError,
- "'%S' is an invalid keyword "
- "argument for %.200s%s",
- keyword,
- (parser->fname == NULL) ? "this function" : parser->fname,
- (parser->fname == NULL) ? "" : "()");
- }
- return NULL;
- }
- }
- }
-
- return buf;
-}
-
-
+#undef _PyArg_UnpackKeywords
+
+PyObject * const *
+_PyArg_UnpackKeywords(PyObject *const *args, Py_ssize_t nargs,
+ PyObject *kwargs, PyObject *kwnames,
+ struct _PyArg_Parser *parser,
+ int minpos, int maxpos, int minkw,
+ PyObject **buf)
+{
+ PyObject *kwtuple;
+ PyObject *keyword;
+ int i, posonly, minposonly, maxargs;
+ int reqlimit = minkw ? maxpos + minkw : minpos;
+ Py_ssize_t nkwargs;
+ PyObject *current_arg;
+ PyObject * const *kwstack = NULL;
+
+ assert(kwargs == NULL || PyDict_Check(kwargs));
+ assert(kwargs == NULL || kwnames == NULL);
+
+ if (parser == NULL) {
+ PyErr_BadInternalCall();
+ return NULL;
+ }
+
+ if (kwnames != NULL && !PyTuple_Check(kwnames)) {
+ PyErr_BadInternalCall();
+ return NULL;
+ }
+
+ if (args == NULL && nargs == 0) {
+ args = buf;
+ }
+
+ if (!parser_init(parser)) {
+ return NULL;
+ }
+
+ kwtuple = parser->kwtuple;
+ posonly = parser->pos;
+ minposonly = Py_MIN(posonly, minpos);
+ maxargs = posonly + (int)PyTuple_GET_SIZE(kwtuple);
+
+ if (kwargs != NULL) {
+ nkwargs = PyDict_GET_SIZE(kwargs);
+ }
+ else if (kwnames != NULL) {
+ nkwargs = PyTuple_GET_SIZE(kwnames);
+ kwstack = args + nargs;
+ }
+ else {
+ nkwargs = 0;
+ }
+ if (nkwargs == 0 && minkw == 0 && minpos <= nargs && nargs <= maxpos) {
+ /* Fast path. */
+ return args;
+ }
+ if (nargs + nkwargs > maxargs) {
+ /* Adding "keyword" (when nargs == 0) prevents producing wrong error
+ messages in some special cases (see bpo-31229). */
+ PyErr_Format(PyExc_TypeError,
+ "%.200s%s takes at most %d %sargument%s (%zd given)",
+ (parser->fname == NULL) ? "function" : parser->fname,
+ (parser->fname == NULL) ? "" : "()",
+ maxargs,
+ (nargs == 0) ? "keyword " : "",
+ (maxargs == 1) ? "" : "s",
+ nargs + nkwargs);
+ return NULL;
+ }
+ if (nargs > maxpos) {
+ if (maxpos == 0) {
+ PyErr_Format(PyExc_TypeError,
+ "%.200s%s takes no positional arguments",
+ (parser->fname == NULL) ? "function" : parser->fname,
+ (parser->fname == NULL) ? "" : "()");
+ }
+ else {
+ PyErr_Format(PyExc_TypeError,
+ "%.200s%s takes %s %d positional argument%s (%zd given)",
+ (parser->fname == NULL) ? "function" : parser->fname,
+ (parser->fname == NULL) ? "" : "()",
+ (minpos < maxpos) ? "at most" : "exactly",
+ maxpos,
+ (maxpos == 1) ? "" : "s",
+ nargs);
+ }
+ return NULL;
+ }
+ if (nargs < minposonly) {
+ PyErr_Format(PyExc_TypeError,
+ "%.200s%s takes %s %d positional argument%s"
+ " (%zd given)",
+ (parser->fname == NULL) ? "function" : parser->fname,
+ (parser->fname == NULL) ? "" : "()",
+ minposonly < maxpos ? "at least" : "exactly",
+ minposonly,
+ minposonly == 1 ? "" : "s",
+ nargs);
+ return NULL;
+ }
+
+ /* copy tuple args */
+ for (i = 0; i < nargs; i++) {
+ buf[i] = args[i];
+ }
+
+ /* copy keyword args using kwtuple to drive process */
+ for (i = Py_MAX((int)nargs, posonly); i < maxargs; i++) {
+ if (nkwargs) {
+ keyword = PyTuple_GET_ITEM(kwtuple, i - posonly);
+ if (kwargs != NULL) {
+ current_arg = PyDict_GetItemWithError(kwargs, keyword);
+ if (!current_arg && PyErr_Occurred()) {
+ return NULL;
+ }
+ }
+ else {
+ current_arg = find_keyword(kwnames, kwstack, keyword);
+ }
+ }
+ else if (i >= reqlimit) {
+ break;
+ }
+ else {
+ current_arg = NULL;
+ }
+
+ buf[i] = current_arg;
+
+ if (current_arg) {
+ --nkwargs;
+ }
+ else if (i < minpos || (maxpos <= i && i < reqlimit)) {
+ /* Less arguments than required */
+ keyword = PyTuple_GET_ITEM(kwtuple, i - posonly);
+ PyErr_Format(PyExc_TypeError, "%.200s%s missing required "
+ "argument '%U' (pos %d)",
+ (parser->fname == NULL) ? "function" : parser->fname,
+ (parser->fname == NULL) ? "" : "()",
+ keyword, i+1);
+ return NULL;
+ }
+ }
+
+ if (nkwargs > 0) {
+ Py_ssize_t j;
+ /* make sure there are no arguments given by name and position */
+ for (i = posonly; i < nargs; i++) {
+ keyword = PyTuple_GET_ITEM(kwtuple, i - posonly);
+ if (kwargs != NULL) {
+ current_arg = PyDict_GetItemWithError(kwargs, keyword);
+ if (!current_arg && PyErr_Occurred()) {
+ return NULL;
+ }
+ }
+ else {
+ current_arg = find_keyword(kwnames, kwstack, keyword);
+ }
+ if (current_arg) {
+ /* arg present in tuple and in dict */
+ PyErr_Format(PyExc_TypeError,
+ "argument for %.200s%s given by name ('%U') "
+ "and position (%d)",
+ (parser->fname == NULL) ? "function" : parser->fname,
+ (parser->fname == NULL) ? "" : "()",
+ keyword, i+1);
+ return NULL;
+ }
+ }
+ /* make sure there are no extraneous keyword arguments */
+ j = 0;
+ while (1) {
+ int match;
+ if (kwargs != NULL) {
+ if (!PyDict_Next(kwargs, &j, &keyword, NULL))
+ break;
+ }
+ else {
+ if (j >= PyTuple_GET_SIZE(kwnames))
+ break;
+ keyword = PyTuple_GET_ITEM(kwnames, j);
+ j++;
+ }
+
+ match = PySequence_Contains(kwtuple, keyword);
+ if (match <= 0) {
+ if (!match) {
+ PyErr_Format(PyExc_TypeError,
+ "'%S' is an invalid keyword "
+ "argument for %.200s%s",
+ keyword,
+ (parser->fname == NULL) ? "this function" : parser->fname,
+ (parser->fname == NULL) ? "" : "()");
+ }
+ return NULL;
+ }
+ }
+ }
+
+ return buf;
+}
+
+
static const char *
skipitem(const char **p_format, va_list *p_va, int flags)
{
@@ -2609,13 +2609,13 @@ skipitem(const char **p_format, va_list *p_va, int flags)
if (p_va != NULL) {
if (flags & FLAG_SIZE_T)
(void) va_arg(*p_va, Py_ssize_t *);
- else {
- if (PyErr_WarnEx(PyExc_DeprecationWarning,
- "PY_SSIZE_T_CLEAN will be required for '#' formats", 1)) {
- return NULL;
- }
+ else {
+ if (PyErr_WarnEx(PyExc_DeprecationWarning,
+ "PY_SSIZE_T_CLEAN will be required for '#' formats", 1)) {
+ return NULL;
+ }
(void) va_arg(*p_va, int *);
- }
+ }
}
format++;
} else if ((c == 's' || c == 'z' || c == 'y' || c == 'w')
@@ -2682,11 +2682,11 @@ err:
}
-#undef _PyArg_CheckPositional
-
-int
-_PyArg_CheckPositional(const char *name, Py_ssize_t nargs,
- Py_ssize_t min, Py_ssize_t max)
+#undef _PyArg_CheckPositional
+
+int
+_PyArg_CheckPositional(const char *name, Py_ssize_t nargs,
+ Py_ssize_t min, Py_ssize_t max)
{
assert(min >= 0);
assert(min <= max);
@@ -2695,14 +2695,14 @@ _PyArg_CheckPositional(const char *name, Py_ssize_t nargs,
if (name != NULL)
PyErr_Format(
PyExc_TypeError,
- "%.200s expected %s%zd argument%s, got %zd",
- name, (min == max ? "" : "at least "), min, min == 1 ? "" : "s", nargs);
+ "%.200s expected %s%zd argument%s, got %zd",
+ name, (min == max ? "" : "at least "), min, min == 1 ? "" : "s", nargs);
else
PyErr_Format(
PyExc_TypeError,
- "unpacked tuple should have %s%zd element%s,"
+ "unpacked tuple should have %s%zd element%s,"
" but has %zd",
- (min == max ? "" : "at least "), min, min == 1 ? "" : "s", nargs);
+ (min == max ? "" : "at least "), min, min == 1 ? "" : "s", nargs);
return 0;
}
@@ -2714,31 +2714,31 @@ _PyArg_CheckPositional(const char *name, Py_ssize_t nargs,
if (name != NULL)
PyErr_Format(
PyExc_TypeError,
- "%.200s expected %s%zd argument%s, got %zd",
- name, (min == max ? "" : "at most "), max, max == 1 ? "" : "s", nargs);
+ "%.200s expected %s%zd argument%s, got %zd",
+ name, (min == max ? "" : "at most "), max, max == 1 ? "" : "s", nargs);
else
PyErr_Format(
PyExc_TypeError,
- "unpacked tuple should have %s%zd element%s,"
+ "unpacked tuple should have %s%zd element%s,"
" but has %zd",
- (min == max ? "" : "at most "), max, max == 1 ? "" : "s", nargs);
+ (min == max ? "" : "at most "), max, max == 1 ? "" : "s", nargs);
+ return 0;
+ }
+
+ return 1;
+}
+
+static int
+unpack_stack(PyObject *const *args, Py_ssize_t nargs, const char *name,
+ Py_ssize_t min, Py_ssize_t max, va_list vargs)
+{
+ Py_ssize_t i;
+ PyObject **o;
+
+ if (!_PyArg_CheckPositional(name, nargs, min, max)) {
return 0;
}
- return 1;
-}
-
-static int
-unpack_stack(PyObject *const *args, Py_ssize_t nargs, const char *name,
- Py_ssize_t min, Py_ssize_t max, va_list vargs)
-{
- Py_ssize_t i;
- PyObject **o;
-
- if (!_PyArg_CheckPositional(name, nargs, min, max)) {
- return 0;
- }
-
for (i = 0; i < nargs; i++) {
o = va_arg(vargs, PyObject **);
*o = args[i];
@@ -2759,7 +2759,7 @@ PyArg_UnpackTuple(PyObject *args, const char *name, Py_ssize_t min, Py_ssize_t m
"PyArg_UnpackTuple() argument list is not a tuple");
return 0;
}
- stack = _PyTuple_ITEMS(args);
+ stack = _PyTuple_ITEMS(args);
nargs = PyTuple_GET_SIZE(args);
#ifdef HAVE_STDARG_PROTOTYPES
@@ -2791,7 +2791,7 @@ _PyArg_UnpackStack(PyObject *const *args, Py_ssize_t nargs, const char *name,
#undef _PyArg_NoKeywords
-#undef _PyArg_NoKwnames
+#undef _PyArg_NoKwnames
#undef _PyArg_NoPositional
/* For type constructors that don't take keyword args
@@ -2835,23 +2835,23 @@ _PyArg_NoPositional(const char *funcname, PyObject *args)
return 0;
}
-int
-_PyArg_NoKwnames(const char *funcname, PyObject *kwnames)
-{
- if (kwnames == NULL) {
- return 1;
- }
-
- assert(PyTuple_CheckExact(kwnames));
-
- if (PyTuple_GET_SIZE(kwnames) == 0) {
- return 1;
- }
-
- PyErr_Format(PyExc_TypeError, "%s() takes no keyword arguments", funcname);
- return 0;
-}
-
+int
+_PyArg_NoKwnames(const char *funcname, PyObject *kwnames)
+{
+ if (kwnames == NULL) {
+ return 1;
+ }
+
+ assert(PyTuple_CheckExact(kwnames));
+
+ if (PyTuple_GET_SIZE(kwnames) == 0) {
+ return 1;
+ }
+
+ PyErr_Format(PyExc_TypeError, "%s() takes no keyword arguments", funcname);
+ return 0;
+}
+
void
_PyArg_Fini(void)
{