mirror of
https://github.com/python/cpython.git
synced 2025-08-30 21:48:47 +00:00
bpo-35582: Argument Clinic: inline parsing code for positional parameters. (GH-11313)
This commit is contained in:
parent
5485085b32
commit
4fa9591025
60 changed files with 6194 additions and 778 deletions
18
Python/clinic/bltinmodule.c.h
generated
18
Python/clinic/bltinmodule.c.h
generated
|
@ -94,10 +94,22 @@ builtin_format(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
|
|||
PyObject *value;
|
||||
PyObject *format_spec = NULL;
|
||||
|
||||
if (!_PyArg_ParseStack(args, nargs, "O|U:format",
|
||||
&value, &format_spec)) {
|
||||
if (!_PyArg_CheckPositional("format", nargs, 1, 2)) {
|
||||
goto exit;
|
||||
}
|
||||
value = args[0];
|
||||
if (nargs < 2) {
|
||||
goto skip_optional;
|
||||
}
|
||||
if (!PyUnicode_Check(args[1])) {
|
||||
_PyArg_BadArgument("format", 2, "str", args[1]);
|
||||
goto exit;
|
||||
}
|
||||
if (PyUnicode_READY(args[1]) == -1) {
|
||||
goto exit;
|
||||
}
|
||||
format_spec = args[1];
|
||||
skip_optional:
|
||||
return_value = builtin_format_impl(module, value, format_spec);
|
||||
|
||||
exit:
|
||||
|
@ -717,4 +729,4 @@ builtin_issubclass(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
|
|||
exit:
|
||||
return return_value;
|
||||
}
|
||||
/*[clinic end generated code: output=ed300ebf3f6db530 input=a9049054013a1b77]*/
|
||||
/*[clinic end generated code: output=11b5cd918bd7eb18 input=a9049054013a1b77]*/
|
||||
|
|
28
Python/clinic/import.c.h
generated
28
Python/clinic/import.c.h
generated
|
@ -88,10 +88,22 @@ _imp__fix_co_filename(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
|
|||
PyCodeObject *code;
|
||||
PyObject *path;
|
||||
|
||||
if (!_PyArg_ParseStack(args, nargs, "O!U:_fix_co_filename",
|
||||
&PyCode_Type, &code, &path)) {
|
||||
if (!_PyArg_CheckPositional("_fix_co_filename", nargs, 2, 2)) {
|
||||
goto exit;
|
||||
}
|
||||
if (!PyObject_TypeCheck(args[0], &PyCode_Type)) {
|
||||
_PyArg_BadArgument("_fix_co_filename", 1, (&PyCode_Type)->tp_name, args[0]);
|
||||
goto exit;
|
||||
}
|
||||
code = (PyCodeObject *)args[0];
|
||||
if (!PyUnicode_Check(args[1])) {
|
||||
_PyArg_BadArgument("_fix_co_filename", 2, "str", args[1]);
|
||||
goto exit;
|
||||
}
|
||||
if (PyUnicode_READY(args[1]) == -1) {
|
||||
goto exit;
|
||||
}
|
||||
path = args[1];
|
||||
return_value = _imp__fix_co_filename_impl(module, code, path);
|
||||
|
||||
exit:
|
||||
|
@ -144,7 +156,7 @@ _imp_init_frozen(PyObject *module, PyObject *arg)
|
|||
PyObject *name;
|
||||
|
||||
if (!PyUnicode_Check(arg)) {
|
||||
_PyArg_BadArgument("init_frozen", "str", arg);
|
||||
_PyArg_BadArgument("init_frozen", 0, "str", arg);
|
||||
goto exit;
|
||||
}
|
||||
if (PyUnicode_READY(arg) == -1) {
|
||||
|
@ -176,7 +188,7 @@ _imp_get_frozen_object(PyObject *module, PyObject *arg)
|
|||
PyObject *name;
|
||||
|
||||
if (!PyUnicode_Check(arg)) {
|
||||
_PyArg_BadArgument("get_frozen_object", "str", arg);
|
||||
_PyArg_BadArgument("get_frozen_object", 0, "str", arg);
|
||||
goto exit;
|
||||
}
|
||||
if (PyUnicode_READY(arg) == -1) {
|
||||
|
@ -208,7 +220,7 @@ _imp_is_frozen_package(PyObject *module, PyObject *arg)
|
|||
PyObject *name;
|
||||
|
||||
if (!PyUnicode_Check(arg)) {
|
||||
_PyArg_BadArgument("is_frozen_package", "str", arg);
|
||||
_PyArg_BadArgument("is_frozen_package", 0, "str", arg);
|
||||
goto exit;
|
||||
}
|
||||
if (PyUnicode_READY(arg) == -1) {
|
||||
|
@ -240,7 +252,7 @@ _imp_is_builtin(PyObject *module, PyObject *arg)
|
|||
PyObject *name;
|
||||
|
||||
if (!PyUnicode_Check(arg)) {
|
||||
_PyArg_BadArgument("is_builtin", "str", arg);
|
||||
_PyArg_BadArgument("is_builtin", 0, "str", arg);
|
||||
goto exit;
|
||||
}
|
||||
if (PyUnicode_READY(arg) == -1) {
|
||||
|
@ -272,7 +284,7 @@ _imp_is_frozen(PyObject *module, PyObject *arg)
|
|||
PyObject *name;
|
||||
|
||||
if (!PyUnicode_Check(arg)) {
|
||||
_PyArg_BadArgument("is_frozen", "str", arg);
|
||||
_PyArg_BadArgument("is_frozen", 0, "str", arg);
|
||||
goto exit;
|
||||
}
|
||||
if (PyUnicode_READY(arg) == -1) {
|
||||
|
@ -421,4 +433,4 @@ exit:
|
|||
#ifndef _IMP_EXEC_DYNAMIC_METHODDEF
|
||||
#define _IMP_EXEC_DYNAMIC_METHODDEF
|
||||
#endif /* !defined(_IMP_EXEC_DYNAMIC_METHODDEF) */
|
||||
/*[clinic end generated code: output=d8be58c9541122f1 input=a9049054013a1b77]*/
|
||||
/*[clinic end generated code: output=22062cee6e8ba7f3 input=a9049054013a1b77]*/
|
||||
|
|
39
Python/clinic/marshal.c.h
generated
39
Python/clinic/marshal.c.h
generated
|
@ -34,10 +34,24 @@ marshal_dump(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
|
|||
PyObject *file;
|
||||
int version = Py_MARSHAL_VERSION;
|
||||
|
||||
if (!_PyArg_ParseStack(args, nargs, "OO|i:dump",
|
||||
&value, &file, &version)) {
|
||||
if (!_PyArg_CheckPositional("dump", nargs, 2, 3)) {
|
||||
goto exit;
|
||||
}
|
||||
value = args[0];
|
||||
file = args[1];
|
||||
if (nargs < 3) {
|
||||
goto skip_optional;
|
||||
}
|
||||
if (PyFloat_Check(args[2])) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"integer argument expected, got float" );
|
||||
goto exit;
|
||||
}
|
||||
version = _PyLong_AsInt(args[2]);
|
||||
if (version == -1 && PyErr_Occurred()) {
|
||||
goto exit;
|
||||
}
|
||||
skip_optional:
|
||||
return_value = marshal_dump_impl(module, value, file, version);
|
||||
|
||||
exit:
|
||||
|
@ -90,10 +104,23 @@ marshal_dumps(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
|
|||
PyObject *value;
|
||||
int version = Py_MARSHAL_VERSION;
|
||||
|
||||
if (!_PyArg_ParseStack(args, nargs, "O|i:dumps",
|
||||
&value, &version)) {
|
||||
if (!_PyArg_CheckPositional("dumps", nargs, 1, 2)) {
|
||||
goto exit;
|
||||
}
|
||||
value = args[0];
|
||||
if (nargs < 2) {
|
||||
goto skip_optional;
|
||||
}
|
||||
if (PyFloat_Check(args[1])) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"integer argument expected, got float" );
|
||||
goto exit;
|
||||
}
|
||||
version = _PyLong_AsInt(args[1]);
|
||||
if (version == -1 && PyErr_Occurred()) {
|
||||
goto exit;
|
||||
}
|
||||
skip_optional:
|
||||
return_value = marshal_dumps_impl(module, value, version);
|
||||
|
||||
exit:
|
||||
|
@ -125,7 +152,7 @@ marshal_loads(PyObject *module, PyObject *arg)
|
|||
goto exit;
|
||||
}
|
||||
if (!PyBuffer_IsContiguous(&bytes, 'C')) {
|
||||
_PyArg_BadArgument("loads", "contiguous buffer", arg);
|
||||
_PyArg_BadArgument("loads", 0, "contiguous buffer", arg);
|
||||
goto exit;
|
||||
}
|
||||
return_value = marshal_loads_impl(module, &bytes);
|
||||
|
@ -138,4 +165,4 @@ exit:
|
|||
|
||||
return return_value;
|
||||
}
|
||||
/*[clinic end generated code: output=8262e7e6c8cbc1ef input=a9049054013a1b77]*/
|
||||
/*[clinic end generated code: output=ae2bca1aa239e095 input=a9049054013a1b77]*/
|
||||
|
|
29
Python/clinic/sysmodule.c.h
generated
29
Python/clinic/sysmodule.c.h
generated
|
@ -175,7 +175,7 @@ sys_intern(PyObject *module, PyObject *arg)
|
|||
PyObject *s;
|
||||
|
||||
if (!PyUnicode_Check(arg)) {
|
||||
_PyArg_BadArgument("intern", "str", arg);
|
||||
_PyArg_BadArgument("intern", 0, "str", arg);
|
||||
goto exit;
|
||||
}
|
||||
if (PyUnicode_READY(arg) == -1) {
|
||||
|
@ -819,10 +819,22 @@ sys__getframe(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
|
|||
PyObject *return_value = NULL;
|
||||
int depth = 0;
|
||||
|
||||
if (!_PyArg_ParseStack(args, nargs, "|i:_getframe",
|
||||
&depth)) {
|
||||
if (!_PyArg_CheckPositional("_getframe", nargs, 0, 1)) {
|
||||
goto exit;
|
||||
}
|
||||
if (nargs < 1) {
|
||||
goto skip_optional;
|
||||
}
|
||||
if (PyFloat_Check(args[0])) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"integer argument expected, got float" );
|
||||
goto exit;
|
||||
}
|
||||
depth = _PyLong_AsInt(args[0]);
|
||||
if (depth == -1 && PyErr_Occurred()) {
|
||||
goto exit;
|
||||
}
|
||||
skip_optional:
|
||||
return_value = sys__getframe_impl(module, depth);
|
||||
|
||||
exit:
|
||||
|
@ -872,10 +884,15 @@ sys_call_tracing(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
|
|||
PyObject *func;
|
||||
PyObject *funcargs;
|
||||
|
||||
if (!_PyArg_ParseStack(args, nargs, "OO!:call_tracing",
|
||||
&func, &PyTuple_Type, &funcargs)) {
|
||||
if (!_PyArg_CheckPositional("call_tracing", nargs, 2, 2)) {
|
||||
goto exit;
|
||||
}
|
||||
func = args[0];
|
||||
if (!PyTuple_Check(args[1])) {
|
||||
_PyArg_BadArgument("call_tracing", 2, "tuple", args[1]);
|
||||
goto exit;
|
||||
}
|
||||
funcargs = args[1];
|
||||
return_value = sys_call_tracing_impl(module, func, funcargs);
|
||||
|
||||
exit:
|
||||
|
@ -1029,4 +1046,4 @@ sys_getandroidapilevel(PyObject *module, PyObject *Py_UNUSED(ignored))
|
|||
#ifndef SYS_GETANDROIDAPILEVEL_METHODDEF
|
||||
#define SYS_GETANDROIDAPILEVEL_METHODDEF
|
||||
#endif /* !defined(SYS_GETANDROIDAPILEVEL_METHODDEF) */
|
||||
/*[clinic end generated code: output=0e662f2e19293d57 input=a9049054013a1b77]*/
|
||||
/*[clinic end generated code: output=6a5202e5bfe5e6bd input=a9049054013a1b77]*/
|
||||
|
|
|
@ -613,11 +613,21 @@ convertitem(PyObject *arg, const char **p_format, va_list *p_va, int flags,
|
|||
/* Format an error message generated by convertsimple(). */
|
||||
|
||||
void
|
||||
_PyArg_BadArgument(const char *fname, const char *expected, PyObject *arg)
|
||||
_PyArg_BadArgument(const char *fname, int iarg,
|
||||
const char *expected, PyObject *arg)
|
||||
{
|
||||
PyErr_Format(PyExc_TypeError, "%.200s() argument must be %.50s, not %.50s",
|
||||
fname, expected,
|
||||
arg == Py_None ? "None" : arg->ob_type->tp_name);
|
||||
if (iarg) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"%.200s() argument %d must be %.50s, not %.50s",
|
||||
fname, iarg, expected,
|
||||
arg == Py_None ? "None" : arg->ob_type->tp_name);
|
||||
}
|
||||
else {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"%.200s() argument must be %.50s, not %.50s",
|
||||
fname, expected,
|
||||
arg == Py_None ? "None" : arg->ob_type->tp_name);
|
||||
}
|
||||
}
|
||||
|
||||
static const char *
|
||||
|
@ -2416,13 +2426,12 @@ err:
|
|||
}
|
||||
|
||||
|
||||
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;
|
||||
#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);
|
||||
|
||||
|
@ -2460,6 +2469,20 @@ unpack_stack(PyObject *const *args, Py_ssize_t nargs, const char *name,
|
|||
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];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue