Commit 4fa95910 authored by Serhiy Storchaka's avatar Serhiy Storchaka Committed by GitHub

bpo-35582: Argument Clinic: inline parsing code for positional parameters. (GH-11313)

parent 5485085b
......@@ -66,7 +66,12 @@ PyAPI_FUNC(int) _PyArg_NoPositional(const char *funcname, PyObject *args);
#define _PyArg_NoPositional(funcname, args) \
((args) == NULL || _PyArg_NoPositional((funcname), (args)))
PyAPI_FUNC(void) _PyArg_BadArgument(const char *, const char *, PyObject *);
PyAPI_FUNC(void) _PyArg_BadArgument(const char *, int, const char *, PyObject *);
PyAPI_FUNC(int) _PyArg_CheckPositional(const char *, Py_ssize_t,
Py_ssize_t, Py_ssize_t);
#define _PyArg_CheckPositional(funcname, nargs, min, max) \
(((min) <= (nargs) && (nargs) <= (max)) \
|| _PyArg_CheckPositional((funcname), (nargs), (min), (max)))
#endif
......
This diff is collapsed.
......@@ -21,11 +21,11 @@ _io__BufferedIOBase_readinto(PyObject *self, PyObject *arg)
if (PyObject_GetBuffer(arg, &buffer, PyBUF_WRITABLE) < 0) {
PyErr_Clear();
_PyArg_BadArgument("readinto", "read-write bytes-like object", arg);
_PyArg_BadArgument("readinto", 0, "read-write bytes-like object", arg);
goto exit;
}
if (!PyBuffer_IsContiguous(&buffer, 'C')) {
_PyArg_BadArgument("readinto", "contiguous buffer", arg);
_PyArg_BadArgument("readinto", 0, "contiguous buffer", arg);
goto exit;
}
return_value = _io__BufferedIOBase_readinto_impl(self, &buffer);
......@@ -58,11 +58,11 @@ _io__BufferedIOBase_readinto1(PyObject *self, PyObject *arg)
if (PyObject_GetBuffer(arg, &buffer, PyBUF_WRITABLE) < 0) {
PyErr_Clear();
_PyArg_BadArgument("readinto1", "read-write bytes-like object", arg);
_PyArg_BadArgument("readinto1", 0, "read-write bytes-like object", arg);
goto exit;
}
if (!PyBuffer_IsContiguous(&buffer, 'C')) {
_PyArg_BadArgument("readinto1", "contiguous buffer", arg);
_PyArg_BadArgument("readinto1", 0, "contiguous buffer", arg);
goto exit;
}
return_value = _io__BufferedIOBase_readinto1_impl(self, &buffer);
......@@ -114,10 +114,30 @@ _io__Buffered_peek(buffered *self, PyObject *const *args, Py_ssize_t nargs)
PyObject *return_value = NULL;
Py_ssize_t size = 0;
if (!_PyArg_ParseStack(args, nargs, "|n:peek",
&size)) {
if (!_PyArg_CheckPositional("peek", 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;
}
{
Py_ssize_t ival = -1;
PyObject *iobj = PyNumber_Index(args[0]);
if (iobj != NULL) {
ival = PyLong_AsSsize_t(iobj);
Py_DECREF(iobj);
}
if (ival == -1 && PyErr_Occurred()) {
goto exit;
}
size = ival;
}
skip_optional:
return_value = _io__Buffered_peek_impl(self, size);
exit:
......@@ -141,10 +161,16 @@ _io__Buffered_read(buffered *self, PyObject *const *args, Py_ssize_t nargs)
PyObject *return_value = NULL;
Py_ssize_t n = -1;
if (!_PyArg_ParseStack(args, nargs, "|O&:read",
_Py_convert_optional_to_ssize_t, &n)) {
if (!_PyArg_CheckPositional("read", nargs, 0, 1)) {
goto exit;
}
if (nargs < 1) {
goto skip_optional;
}
if (!_Py_convert_optional_to_ssize_t(args[0], &n)) {
goto exit;
}
skip_optional:
return_value = _io__Buffered_read_impl(self, n);
exit:
......@@ -168,10 +194,30 @@ _io__Buffered_read1(buffered *self, PyObject *const *args, Py_ssize_t nargs)
PyObject *return_value = NULL;
Py_ssize_t n = -1;
if (!_PyArg_ParseStack(args, nargs, "|n:read1",
&n)) {
if (!_PyArg_CheckPositional("read1", 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;
}
{
Py_ssize_t ival = -1;
PyObject *iobj = PyNumber_Index(args[0]);
if (iobj != NULL) {
ival = PyLong_AsSsize_t(iobj);
Py_DECREF(iobj);
}
if (ival == -1 && PyErr_Occurred()) {
goto exit;
}
n = ival;
}
skip_optional:
return_value = _io__Buffered_read1_impl(self, n);
exit:
......@@ -197,11 +243,11 @@ _io__Buffered_readinto(buffered *self, PyObject *arg)
if (PyObject_GetBuffer(arg, &buffer, PyBUF_WRITABLE) < 0) {
PyErr_Clear();
_PyArg_BadArgument("readinto", "read-write bytes-like object", arg);
_PyArg_BadArgument("readinto", 0, "read-write bytes-like object", arg);
goto exit;
}
if (!PyBuffer_IsContiguous(&buffer, 'C')) {
_PyArg_BadArgument("readinto", "contiguous buffer", arg);
_PyArg_BadArgument("readinto", 0, "contiguous buffer", arg);
goto exit;
}
return_value = _io__Buffered_readinto_impl(self, &buffer);
......@@ -234,11 +280,11 @@ _io__Buffered_readinto1(buffered *self, PyObject *arg)
if (PyObject_GetBuffer(arg, &buffer, PyBUF_WRITABLE) < 0) {
PyErr_Clear();
_PyArg_BadArgument("readinto1", "read-write bytes-like object", arg);
_PyArg_BadArgument("readinto1", 0, "read-write bytes-like object", arg);
goto exit;
}
if (!PyBuffer_IsContiguous(&buffer, 'C')) {
_PyArg_BadArgument("readinto1", "contiguous buffer", arg);
_PyArg_BadArgument("readinto1", 0, "contiguous buffer", arg);
goto exit;
}
return_value = _io__Buffered_readinto1_impl(self, &buffer);
......@@ -269,10 +315,16 @@ _io__Buffered_readline(buffered *self, PyObject *const *args, Py_ssize_t nargs)
PyObject *return_value = NULL;
Py_ssize_t size = -1;
if (!_PyArg_ParseStack(args, nargs, "|O&:readline",
_Py_convert_optional_to_ssize_t, &size)) {
if (!_PyArg_CheckPositional("readline", nargs, 0, 1)) {
goto exit;
}
if (nargs < 1) {
goto skip_optional;
}
if (!_Py_convert_optional_to_ssize_t(args[0], &size)) {
goto exit;
}
skip_optional:
return_value = _io__Buffered_readline_impl(self, size);
exit:
......@@ -297,10 +349,23 @@ _io__Buffered_seek(buffered *self, PyObject *const *args, Py_ssize_t nargs)
PyObject *targetobj;
int whence = 0;
if (!_PyArg_ParseStack(args, nargs, "O|i:seek",
&targetobj, &whence)) {
if (!_PyArg_CheckPositional("seek", nargs, 1, 2)) {
goto exit;
}
targetobj = args[0];
if (nargs < 2) {
goto skip_optional;
}
if (PyFloat_Check(args[1])) {
PyErr_SetString(PyExc_TypeError,
"integer argument expected, got float" );
goto exit;
}
whence = _PyLong_AsInt(args[1]);
if (whence == -1 && PyErr_Occurred()) {
goto exit;
}
skip_optional:
return_value = _io__Buffered_seek_impl(self, targetobj, whence);
exit:
......@@ -418,7 +483,7 @@ _io_BufferedWriter_write(buffered *self, PyObject *arg)
goto exit;
}
if (!PyBuffer_IsContiguous(&buffer, 'C')) {
_PyArg_BadArgument("write", "contiguous buffer", arg);
_PyArg_BadArgument("write", 0, "contiguous buffer", arg);
goto exit;
}
return_value = _io_BufferedWriter_write_impl(self, &buffer);
......@@ -462,10 +527,32 @@ _io_BufferedRWPair___init__(PyObject *self, PyObject *args, PyObject *kwargs)
!_PyArg_NoKeywords("BufferedRWPair", kwargs)) {
goto exit;
}
if (!PyArg_ParseTuple(args, "OO|n:BufferedRWPair",
&reader, &writer, &buffer_size)) {
if (!_PyArg_CheckPositional("BufferedRWPair", PyTuple_GET_SIZE(args), 2, 3)) {
goto exit;
}
reader = PyTuple_GET_ITEM(args, 0);
writer = PyTuple_GET_ITEM(args, 1);
if (PyTuple_GET_SIZE(args) < 3) {
goto skip_optional;
}
if (PyFloat_Check(PyTuple_GET_ITEM(args, 2))) {
PyErr_SetString(PyExc_TypeError,
"integer argument expected, got float" );
goto exit;
}
{
Py_ssize_t ival = -1;
PyObject *iobj = PyNumber_Index(PyTuple_GET_ITEM(args, 2));
if (iobj != NULL) {
ival = PyLong_AsSsize_t(iobj);
Py_DECREF(iobj);
}
if (ival == -1 && PyErr_Occurred()) {
goto exit;
}
buffer_size = ival;
}
skip_optional:
return_value = _io_BufferedRWPair___init___impl((rwpair *)self, reader, writer, buffer_size);
exit:
......@@ -504,4 +591,4 @@ _io_BufferedRandom___init__(PyObject *self, PyObject *args, PyObject *kwargs)
exit:
return return_value;
}
/*[clinic end generated code: output=40de95d461a20782 input=a9049054013a1b77]*/
/*[clinic end generated code: output=a85f61f495feff5c input=a9049054013a1b77]*/
......@@ -169,10 +169,16 @@ _io_BytesIO_read(bytesio *self, PyObject *const *args, Py_ssize_t nargs)
PyObject *return_value = NULL;
Py_ssize_t size = -1;
if (!_PyArg_ParseStack(args, nargs, "|O&:read",
_Py_convert_optional_to_ssize_t, &size)) {
if (!_PyArg_CheckPositional("read", nargs, 0, 1)) {
goto exit;
}
if (nargs < 1) {
goto skip_optional;
}
if (!_Py_convert_optional_to_ssize_t(args[0], &size)) {
goto exit;
}
skip_optional:
return_value = _io_BytesIO_read_impl(self, size);
exit:
......@@ -200,10 +206,16 @@ _io_BytesIO_read1(bytesio *self, PyObject *const *args, Py_ssize_t nargs)
PyObject *return_value = NULL;
Py_ssize_t size = -1;
if (!_PyArg_ParseStack(args, nargs, "|O&:read1",
_Py_convert_optional_to_ssize_t, &size)) {
if (!_PyArg_CheckPositional("read1", nargs, 0, 1)) {
goto exit;
}
if (nargs < 1) {
goto skip_optional;
}
if (!_Py_convert_optional_to_ssize_t(args[0], &size)) {
goto exit;
}
skip_optional:
return_value = _io_BytesIO_read1_impl(self, size);
exit:
......@@ -232,10 +244,16 @@ _io_BytesIO_readline(bytesio *self, PyObject *const *args, Py_ssize_t nargs)
PyObject *return_value = NULL;
Py_ssize_t size = -1;
if (!_PyArg_ParseStack(args, nargs, "|O&:readline",
_Py_convert_optional_to_ssize_t, &size)) {
if (!_PyArg_CheckPositional("readline", nargs, 0, 1)) {
goto exit;
}
if (nargs < 1) {
goto skip_optional;
}
if (!_Py_convert_optional_to_ssize_t(args[0], &size)) {
goto exit;
}
skip_optional:
return_value = _io_BytesIO_readline_impl(self, size);
exit:
......@@ -298,11 +316,11 @@ _io_BytesIO_readinto(bytesio *self, PyObject *arg)
if (PyObject_GetBuffer(arg, &buffer, PyBUF_WRITABLE) < 0) {
PyErr_Clear();
_PyArg_BadArgument("readinto", "read-write bytes-like object", arg);
_PyArg_BadArgument("readinto", 0, "read-write bytes-like object", arg);
goto exit;
}
if (!PyBuffer_IsContiguous(&buffer, 'C')) {
_PyArg_BadArgument("readinto", "contiguous buffer", arg);
_PyArg_BadArgument("readinto", 0, "contiguous buffer", arg);
goto exit;
}
return_value = _io_BytesIO_readinto_impl(self, &buffer);
......@@ -337,10 +355,16 @@ _io_BytesIO_truncate(bytesio *self, PyObject *const *args, Py_ssize_t nargs)
PyObject *return_value = NULL;
Py_ssize_t size = self->pos;
if (!_PyArg_ParseStack(args, nargs, "|O&:truncate",
_Py_convert_optional_to_ssize_t, &size)) {
if (!_PyArg_CheckPositional("truncate", nargs, 0, 1)) {
goto exit;
}
if (nargs < 1) {
goto skip_optional;
}
if (!_Py_convert_optional_to_ssize_t(args[0], &size)) {
goto exit;
}
skip_optional:
return_value = _io_BytesIO_truncate_impl(self, size);
exit:
......@@ -372,10 +396,39 @@ _io_BytesIO_seek(bytesio *self, PyObject *const *args, Py_ssize_t nargs)
Py_ssize_t pos;
int whence = 0;
if (!_PyArg_ParseStack(args, nargs, "n|i:seek",
&pos, &whence)) {
if (!_PyArg_CheckPositional("seek", nargs, 1, 2)) {
goto exit;
}
if (PyFloat_Check(args[0])) {
PyErr_SetString(PyExc_TypeError,
"integer argument expected, got float" );
goto exit;
}
{
Py_ssize_t ival = -1;
PyObject *iobj = PyNumber_Index(args[0]);
if (iobj != NULL) {
ival = PyLong_AsSsize_t(iobj);
Py_DECREF(iobj);
}
if (ival == -1 && PyErr_Occurred()) {
goto exit;
}
pos = ival;
}
if (nargs < 2) {
goto skip_optional;
}
if (PyFloat_Check(args[1])) {
PyErr_SetString(PyExc_TypeError,
"integer argument expected, got float" );
goto exit;
}
whence = _PyLong_AsInt(args[1]);
if (whence == -1 && PyErr_Occurred()) {
goto exit;
}
skip_optional:
return_value = _io_BytesIO_seek_impl(self, pos, whence);
exit:
......@@ -450,4 +503,4 @@ _io_BytesIO___init__(PyObject *self, PyObject *args, PyObject *kwargs)
exit:
return return_value;
}
/*[clinic end generated code: output=f6e720f38fc6e3cd input=a9049054013a1b77]*/
/*[clinic end generated code: output=5c68eb481fa960bf input=a9049054013a1b77]*/
......@@ -158,11 +158,11 @@ _io_FileIO_readinto(fileio *self, PyObject *arg)
if (PyObject_GetBuffer(arg, &buffer, PyBUF_WRITABLE) < 0) {
PyErr_Clear();
_PyArg_BadArgument("readinto", "read-write bytes-like object", arg);
_PyArg_BadArgument("readinto", 0, "read-write bytes-like object", arg);
goto exit;
}
if (!PyBuffer_IsContiguous(&buffer, 'C')) {
_PyArg_BadArgument("readinto", "contiguous buffer", arg);
_PyArg_BadArgument("readinto", 0, "contiguous buffer", arg);
goto exit;
}
return_value = _io_FileIO_readinto_impl(self, &buffer);
......@@ -219,10 +219,16 @@ _io_FileIO_read(fileio *self, PyObject *const *args, Py_ssize_t nargs)
PyObject *return_value = NULL;
Py_ssize_t size = -1;
if (!_PyArg_ParseStack(args, nargs, "|O&:read",
_Py_convert_optional_to_ssize_t, &size)) {
if (!_PyArg_CheckPositional("read", nargs, 0, 1)) {
goto exit;
}
if (nargs < 1) {
goto skip_optional;
}
if (!_Py_convert_optional_to_ssize_t(args[0], &size)) {
goto exit;
}
skip_optional:
return_value = _io_FileIO_read_impl(self, size);
exit:
......@@ -255,7 +261,7 @@ _io_FileIO_write(fileio *self, PyObject *arg)
goto exit;
}
if (!PyBuffer_IsContiguous(&b, 'C')) {
_PyArg_BadArgument("write", "contiguous buffer", arg);
_PyArg_BadArgument("write", 0, "contiguous buffer", arg);
goto exit;
}
return_value = _io_FileIO_write_impl(self, &b);
......@@ -296,10 +302,23 @@ _io_FileIO_seek(fileio *self, PyObject *const *args, Py_ssize_t nargs)
PyObject *pos;
int whence = 0;
if (!_PyArg_ParseStack(args, nargs, "O|i:seek",
&pos, &whence)) {
if (!_PyArg_CheckPositional("seek", nargs, 1, 2)) {
goto exit;
}
pos = args[0];
if (nargs < 2) {
goto skip_optional;
}
if (PyFloat_Check(args[1])) {
PyErr_SetString(PyExc_TypeError,
"integer argument expected, got float" );
goto exit;
}
whence = _PyLong_AsInt(args[1]);
if (whence == -1 && PyErr_Occurred()) {
goto exit;
}
skip_optional:
return_value = _io_FileIO_seek_impl(self, pos, whence);
exit:
......@@ -383,4 +402,4 @@ _io_FileIO_isatty(fileio *self, PyObject *Py_UNUSED(ignored))
#ifndef _IO_FILEIO_TRUNCATE_METHODDEF
#define _IO_FILEIO_TRUNCATE_METHODDEF
#endif /* !defined(_IO_FILEIO_TRUNCATE_METHODDEF) */
/*[clinic end generated code: output=8be0ea9a5ac7aa43 input=a9049054013a1b77]*/
/*[clinic end generated code: output=4cf4e5f0cd656b11 input=a9049054013a1b77]*/
......@@ -185,10 +185,16 @@ _io__IOBase_readline(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
PyObject *return_value = NULL;
Py_ssize_t limit = -1;
if (!_PyArg_ParseStack(args, nargs, "|O&:readline",
_Py_convert_optional_to_ssize_t, &limit)) {
if (!_PyArg_CheckPositional("readline", nargs, 0, 1)) {
goto exit;
}
if (nargs < 1) {
goto skip_optional;
}
if (!_Py_convert_optional_to_ssize_t(args[0], &limit)) {
goto exit;
}
skip_optional:
return_value = _io__IOBase_readline_impl(self, limit);
exit:
......@@ -217,10 +223,16 @@ _io__IOBase_readlines(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
PyObject *return_value = NULL;
Py_ssize_t hint = -1;
if (!_PyArg_ParseStack(args, nargs, "|O&:readlines",
_Py_convert_optional_to_ssize_t, &hint)) {
if (!_PyArg_CheckPositional("readlines", nargs, 0, 1)) {
goto exit;
}
if (nargs < 1) {
goto skip_optional;
}
if (!_Py_convert_optional_to_ssize_t(args[0], &hint)) {
goto exit;
}
skip_optional:
return_value = _io__IOBase_readlines_impl(self, hint);
exit:
......@@ -252,10 +264,30 @@ _io__RawIOBase_read(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
PyObject *return_value = NULL;
Py_ssize_t n = -1;
if (!_PyArg_ParseStack(args, nargs, "|n:read",
&n)) {
if (!_PyArg_CheckPositional("read", 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;
}
{
Py_ssize_t ival = -1;
PyObject *iobj = PyNumber_Index(args[0]);
if (iobj != NULL) {
ival = PyLong_AsSsize_t(iobj);
Py_DECREF(iobj);
}
if (ival == -1 && PyErr_Occurred()) {
goto exit;
}
n = ival;
}
skip_optional:
return_value = _io__RawIOBase_read_impl(self, n);
exit:
......@@ -279,4 +311,4 @@ _io__RawIOBase_readall(PyObject *self, PyObject *Py_UNUSED(ignored))
{
return _io__RawIOBase_readall_impl(self);
}
/*[clinic end generated code: output=cde4b0e96a4e69e3 input=a9049054013a1b77]*/
/*[clinic end generated code: output=60e43a7cbd9f314e input=a9049054013a1b77]*/
......@@ -59,10 +59,16 @@ _io_StringIO_read(stringio *self, PyObject *const *args, Py_ssize_t nargs)
PyObject *return_value = NULL;
Py_ssize_t size = -1;
if (!_PyArg_ParseStack(args, nargs, "|O&:read",
_Py_convert_optional_to_ssize_t, &size)) {
if (!_PyArg_CheckPositional("read", nargs, 0, 1)) {
goto exit;
}
if (nargs < 1) {
goto skip_optional;
}
if (!_Py_convert_optional_to_ssize_t(args[0], &size)) {
goto exit;
}
skip_optional:
return_value = _io_StringIO_read_impl(self, size);
exit:
......@@ -89,10 +95,16 @@ _io_StringIO_readline(stringio *self, PyObject *const *args, Py_ssize_t nargs)
PyObject *return_value = NULL;
Py_ssize_t size = -1;
if (!_PyArg_ParseStack(args, nargs, "|O&:readline",
_Py_convert_optional_to_ssize_t, &size)) {
if (!_PyArg_CheckPositional("readline", nargs, 0, 1)) {
goto exit;
}
if (nargs < 1) {
goto skip_optional;
}
if (!_Py_convert_optional_to_ssize_t(args[0], &size)) {
goto exit;
}
skip_optional:
return_value = _io_StringIO_readline_impl(self, size);
exit:
......@@ -121,10 +133,16 @@ _io_StringIO_truncate(stringio *self, PyObject *const *args, Py_ssize_t nargs)
PyObject *return_value = NULL;
Py_ssize_t size = self->pos;
if (!_PyArg_ParseStack(args, nargs, "|O&:truncate",
_Py_convert_optional_to_ssize_t, &size)) {
if (!_PyArg_CheckPositional("truncate", nargs, 0, 1)) {
goto exit;
}
if (nargs < 1) {
goto skip_optional;
}
if (!_Py_convert_optional_to_ssize_t(args[0], &size)) {
goto exit;
}
skip_optional:
return_value = _io_StringIO_truncate_impl(self, size);
exit:
......@@ -156,10 +174,39 @@ _io_StringIO_seek(stringio *self, PyObject *const *args, Py_ssize_t nargs)
Py_ssize_t pos;
int whence = 0;
if (!_PyArg_ParseStack(args, nargs, "n|i:seek",
&pos, &whence)) {
if (!_PyArg_CheckPositional("seek", nargs, 1, 2)) {
goto exit;
}
if (PyFloat_Check(args[0])) {
PyErr_SetString(PyExc_TypeError,
"integer argument expected, got float" );
goto exit;
}
{
Py_ssize_t ival = -1;
PyObject *iobj = PyNumber_Index(args[0]);
if (iobj != NULL) {
ival = PyLong_AsSsize_t(iobj);
Py_DECREF(iobj);
}
if (ival == -1 && PyErr_Occurred()) {
goto exit;
}
pos = ival;
}
if (nargs < 2) {
goto skip_optional;
}
if (PyFloat_Check(args[1])) {
PyErr_SetString(PyExc_TypeError,
"integer argument expected, got float" );
goto exit;
}
whence = _PyLong_AsInt(args[1]);
if (whence == -1 && PyErr_Occurred()) {
goto exit;
}
skip_optional:
return_value = _io_StringIO_seek_impl(self, pos, whence);
exit:
......@@ -286,4 +333,4 @@ _io_StringIO_seekable(stringio *self, PyObject *Py_UNUSED(ignored))
{
return _io_StringIO_seekable_impl(self);
}
/*[clinic end generated code: output=00c3c7a1c6ea6773 input=a9049054013a1b77]*/
/*[clinic end generated code: output=db5e51dcc4dae8d5 input=a9049054013a1b77]*/
......@@ -251,7 +251,7 @@ _io_TextIOWrapper_write(textio *self, PyObject *arg)
PyObject *text;
if (!PyUnicode_Check(arg)) {
_PyArg_BadArgument("write", "str", arg);
_PyArg_BadArgument("write", 0, "str", arg);
goto exit;
}
if (PyUnicode_READY(arg) == -1) {
......@@ -281,10 +281,16 @@ _io_TextIOWrapper_read(textio *self, PyObject *const *args, Py_ssize_t nargs)
PyObject *return_value = NULL;
Py_ssize_t n = -1;
if (!_PyArg_ParseStack(args, nargs, "|O&:read",
_Py_convert_optional_to_ssize_t, &n)) {
if (!_PyArg_CheckPositional("read", nargs, 0, 1)) {
goto exit;
}
if (nargs < 1) {
goto skip_optional;
}
if (!_Py_convert_optional_to_ssize_t(args[0], &n)) {
goto exit;
}
skip_optional:
return_value = _io_TextIOWrapper_read_impl(self, n);
exit:
......@@ -308,10 +314,30 @@ _io_TextIOWrapper_readline(textio *self, PyObject *const *args, Py_ssize_t nargs
PyObject *return_value = NULL;
Py_ssize_t size = -1;
if (!_PyArg_ParseStack(args, nargs, "|n:readline",
&size)) {
if (!_PyArg_CheckPositional("readline", 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;
}
{
Py_ssize_t ival = -1;
PyObject *iobj = PyNumber_Index(args[0]);
if (iobj != NULL) {
ival = PyLong_AsSsize_t(iobj);
Py_DECREF(iobj);
}
if (ival == -1 && PyErr_Occurred()) {
goto exit;
}
size = ival;
}
skip_optional:
return_value = _io_TextIOWrapper_readline_impl(self, size);
exit:
......@@ -336,10 +362,23 @@ _io_TextIOWrapper_seek(textio *self, PyObject *const *args, Py_ssize_t nargs)
PyObject *cookieObj;
int whence = 0;
if (!_PyArg_ParseStack(args, nargs, "O|i:seek",
&cookieObj, &whence)) {
if (!_PyArg_CheckPositional("seek", nargs, 1, 2)) {
goto exit;
}
cookieObj = args[0];
if (nargs < 2) {
goto skip_optional;
}
if (PyFloat_Check(args[1])) {
PyErr_SetString(PyExc_TypeError,
"integer argument expected, got float" );
goto exit;
}
whence = _PyLong_AsInt(args[1]);
if (whence == -1 && PyErr_Occurred()) {
goto exit;
}
skip_optional:
return_value = _io_TextIOWrapper_seek_impl(self, cookieObj, whence);
exit:
......@@ -509,4 +548,4 @@ _io_TextIOWrapper_close(textio *self, PyObject *Py_UNUSED(ignored))
{
return _io_TextIOWrapper_close_impl(self);
}
/*[clinic end generated code: output=b933f08c2f2d85cd input=a9049054013a1b77]*/
/*[clinic end generated code: output=8bdd1035bf878d6f input=a9049054013a1b77]*/
......@@ -158,11 +158,11 @@ _io__WindowsConsoleIO_readinto(winconsoleio *self, PyObject *arg)
if (PyObject_GetBuffer(arg, &buffer, PyBUF_WRITABLE) < 0) {
PyErr_Clear();
_PyArg_BadArgument("readinto", "read-write bytes-like object", arg);
_PyArg_BadArgument("readinto", 0, "read-write bytes-like object", arg);
goto exit;
}
if (!PyBuffer_IsContiguous(&buffer, 'C')) {
_PyArg_BadArgument("readinto", "contiguous buffer", arg);
_PyArg_BadArgument("readinto", 0, "contiguous buffer", arg);
goto exit;
}
return_value = _io__WindowsConsoleIO_readinto_impl(self, &buffer);
......@@ -226,10 +226,16 @@ _io__WindowsConsoleIO_read(winconsoleio *self, PyObject *const *args, Py_ssize_t
PyObject *return_value = NULL;
Py_ssize_t size = -1;
if (!_PyArg_ParseStack(args, nargs, "|O&:read",
_Py_convert_optional_to_ssize_t, &size)) {
if (!_PyArg_CheckPositional("read", nargs, 0, 1)) {
goto exit;
}
if (nargs < 1) {
goto skip_optional;
}
if (!_Py_convert_optional_to_ssize_t(args[0], &size)) {
goto exit;
}
skip_optional:
return_value = _io__WindowsConsoleIO_read_impl(self, size);
exit:
......@@ -265,7 +271,7 @@ _io__WindowsConsoleIO_write(winconsoleio *self, PyObject *arg)
goto exit;
}
if (!PyBuffer_IsContiguous(&b, 'C')) {
_PyArg_BadArgument("write", "contiguous buffer", arg);
_PyArg_BadArgument("write", 0, "contiguous buffer", arg);
goto exit;
}
return_value = _io__WindowsConsoleIO_write_impl(self, &b);
......@@ -338,4 +344,4 @@ _io__WindowsConsoleIO_isatty(winconsoleio *self, PyObject *Py_UNUSED(ignored))
#ifndef _IO__WINDOWSCONSOLEIO_ISATTY_METHODDEF
#define _IO__WINDOWSCONSOLEIO_ISATTY_METHODDEF
#endif /* !defined(_IO__WINDOWSCONSOLEIO_ISATTY_METHODDEF) */
/*[clinic end generated code: output=4337e8de65915a1e input=a9049054013a1b77]*/
/*[clinic end generated code: output=ab0f0ee8062eecb3 input=a9049054013a1b77]*/
......@@ -151,7 +151,7 @@ _multibytecodec_MultibyteIncrementalEncoder_setstate(MultibyteIncrementalEncoder
PyLongObject *statelong;
if (!PyLong_Check(arg)) {
_PyArg_BadArgument("setstate", "int", arg);
_PyArg_BadArgument("setstate", 0, "int", arg);
goto exit;
}
statelong = (PyLongObject *)arg;
......@@ -251,7 +251,7 @@ _multibytecodec_MultibyteIncrementalDecoder_setstate(MultibyteIncrementalDecoder
PyObject *state;
if (!PyTuple_Check(arg)) {
_PyArg_BadArgument("setstate", "tuple", arg);
_PyArg_BadArgument("setstate", 0, "tuple", arg);
goto exit;
}
state = arg;
......@@ -422,4 +422,4 @@ PyDoc_STRVAR(_multibytecodec___create_codec__doc__,
#define _MULTIBYTECODEC___CREATE_CODEC_METHODDEF \
{"__create_codec", (PyCFunction)_multibytecodec___create_codec, METH_O, _multibytecodec___create_codec__doc__},
/*[clinic end generated code: output=a94364d0965adf1d input=a9049054013a1b77]*/
/*[clinic end generated code: output=2ed7030b28a79029 input=a9049054013a1b77]*/
......@@ -29,7 +29,7 @@ _bz2_BZ2Compressor_compress(BZ2Compressor *self, PyObject *arg)
goto exit;
}
if (!PyBuffer_IsContiguous(&data, 'C')) {
_PyArg_BadArgument("compress", "contiguous buffer", arg);
_PyArg_BadArgument("compress", 0, "contiguous buffer", arg);
goto exit;
}
return_value = _bz2_BZ2Compressor_compress_impl(self, &data);
......@@ -89,10 +89,22 @@ _bz2_BZ2Compressor___init__(PyObject *self, PyObject *args, PyObject *kwargs)
!_PyArg_NoKeywords("BZ2Compressor", kwargs)) {
goto exit;
}
if (!PyArg_ParseTuple(args, "|i:BZ2Compressor",
&compresslevel)) {
if (!_PyArg_CheckPositional("BZ2Compressor", PyTuple_GET_SIZE(args), 0, 1)) {
goto exit;
}
if (PyTuple_GET_SIZE(args) < 1) {
goto skip_optional;
}
if (PyFloat_Check(PyTuple_GET_ITEM(args, 0))) {
PyErr_SetString(PyExc_TypeError,
"integer argument expected, got float" );
goto exit;
}
compresslevel = _PyLong_AsInt(PyTuple_GET_ITEM(args, 0));
if (compresslevel == -1 && PyErr_Occurred()) {
goto exit;
}
skip_optional:
return_value = _bz2_BZ2Compressor___init___impl((BZ2Compressor *)self, compresslevel);
exit:
......@@ -178,4 +190,4 @@ _bz2_BZ2Decompressor___init__(PyObject *self, PyObject *args, PyObject *kwargs)
exit:
return return_value;
}
/*[clinic end generated code: output=8549cccdb82f57d9 input=a9049054013a1b77]*/
/*[clinic end generated code: output=892c6133e97ff840 input=a9049054013a1b77]*/
This diff is collapsed.
......@@ -16,13 +16,30 @@ tuplegetter_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
!_PyArg_NoKeywords("_tuplegetter", kwargs)) {
goto exit;
}
if (!PyArg_ParseTuple(args, "nO:_tuplegetter",
&index, &doc)) {
if (!_PyArg_CheckPositional("_tuplegetter", PyTuple_GET_SIZE(args), 2, 2)) {
goto exit;
}
if (PyFloat_Check(PyTuple_GET_ITEM(args, 0))) {
PyErr_SetString(PyExc_TypeError,
"integer argument expected, got float" );
goto exit;
}
{
Py_ssize_t ival = -1;
PyObject *iobj = PyNumber_Index(PyTuple_GET_ITEM(args, 0));
if (iobj != NULL) {
ival = PyLong_AsSsize_t(iobj);
Py_DECREF(iobj);
}
if (ival == -1 && PyErr_Occurred()) {
goto exit;
}
index = ival;
}
doc = PyTuple_GET_ITEM(args, 1);
return_value = tuplegetter_new_impl(type, index, doc);
exit:
return return_value;
}
/*[clinic end generated code: output=83746071eacc28d3 input=a9049054013a1b77]*/
/*[clinic end generated code: output=51bd572577ca7111 input=a9049054013a1b77]*/
......@@ -26,8 +26,33 @@ crypt_crypt(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
const char *word;
const char *salt;
if (!_PyArg_ParseStack(args, nargs, "ss:crypt",
&word, &salt)) {
if (!_PyArg_CheckPositional("crypt", nargs, 2, 2)) {
goto exit;
}
if (!PyUnicode_Check(args[0])) {
_PyArg_BadArgument("crypt", 1, "str", args[0]);
goto exit;
}
Py_ssize_t word_length;
word = PyUnicode_AsUTF8AndSize(args[0], &word_length);
if (word == NULL) {
goto exit;
}
if (strlen(word) != (size_t)word_length) {
PyErr_SetString(PyExc_ValueError, "embedded null character");
goto exit;
}
if (!PyUnicode_Check(args[1])) {
_PyArg_BadArgument("crypt", 2, "str", args[1]);
goto exit;
}
Py_ssize_t salt_length;
salt = PyUnicode_AsUTF8AndSize(args[1], &salt_length);
if (salt == NULL) {
goto exit;
}
if (strlen(salt) != (size_t)salt_length) {
PyErr_SetString(PyExc_ValueError, "embedded null character");
goto exit;
}
return_value = crypt_crypt_impl(module, word, salt);
......@@ -35,4 +60,4 @@ crypt_crypt(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
exit:
return return_value;
}
/*[clinic end generated code: output=79001dbfdd623ff9 input=a9049054013a1b77]*/
/*[clinic end generated code: output=3f75d4d4be4dddbb input=a9049054013a1b77]*/
......@@ -149,8 +149,25 @@ _curses_panel_panel_move(PyCursesPanelObject *self, PyObject *const *args, Py_ss
int y;
int x;
if (!_PyArg_ParseStack(args, nargs, "ii:move",
&y, &x)) {
if (!_PyArg_CheckPositional("move", nargs, 2, 2)) {
goto exit;
}
if (PyFloat_Check(args[0])) {
PyErr_SetString(PyExc_TypeError,
"integer argument expected, got float" );
goto exit;
}
y = _PyLong_AsInt(args[0]);
if (y == -1 && PyErr_Occurred()) {
goto exit;
}
if (PyFloat_Check(args[1])) {
PyErr_SetString(PyExc_TypeError,
"integer argument expected, got float" );
goto exit;
}
x = _PyLong_AsInt(args[1]);
if (x == -1 && PyErr_Occurred()) {
goto exit;
}
return_value = _curses_panel_panel_move_impl(self, y, x);
......@@ -197,7 +214,7 @@ _curses_panel_panel_replace(PyCursesPanelObject *self, PyObject *arg)
PyCursesWindowObject *win;
if (!PyObject_TypeCheck(arg, &PyCursesWindow_Type)) {
_PyArg_BadArgument("replace", (&PyCursesWindow_Type)->tp_name, arg);
_PyArg_BadArgument("replace", 0, (&PyCursesWindow_Type)->tp_name, arg);
goto exit;
}
win = (PyCursesWindowObject *)arg;
......@@ -271,7 +288,7 @@ _curses_panel_new_panel(PyObject *module, PyObject *arg)
PyCursesWindowObject *win;
if (!PyObject_TypeCheck(arg, &PyCursesWindow_Type)) {
_PyArg_BadArgument("new_panel", (&PyCursesWindow_Type)->tp_name, arg);
_PyArg_BadArgument("new_panel", 0, (&PyCursesWindow_Type)->tp_name, arg);
goto exit;
}
win = (PyCursesWindowObject *)arg;
......@@ -318,4 +335,4 @@ _curses_panel_update_panels(PyObject *module, PyObject *Py_UNUSED(ignored))
{
return _curses_panel_update_panels_impl(module);
}
/*[clinic end generated code: output=4b211b4015e29100 input=a9049054013a1b77]*/
/*[clinic end generated code: output=ac1f56e6c3d4cc57 input=a9049054013a1b77]*/
This diff is collapsed.
......@@ -132,13 +132,49 @@ dbmopen(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
const char *flags = "r";
int mode = 438;
if (!_PyArg_ParseStack(args, nargs, "U|si:open",
&filename, &flags, &mode)) {
if (!_PyArg_CheckPositional("open", nargs, 1, 3)) {
goto exit;
}
if (!PyUnicode_Check(args[0])) {
_PyArg_BadArgument("open", 1, "str", args[0]);
goto exit;
}
if (PyUnicode_READY(args[0]) == -1) {
goto exit;
}
filename = args[0];
if (nargs < 2) {
goto skip_optional;
}
if (!PyUnicode_Check(args[1])) {
_PyArg_BadArgument("open", 2, "str", args[1]);
goto exit;
}
Py_ssize_t flags_length;
flags = PyUnicode_AsUTF8AndSize(args[1], &flags_length);
if (flags == NULL) {
goto exit;
}
if (strlen(flags) != (size_t)flags_length) {
PyErr_SetString(PyExc_ValueError, "embedded null character");
goto exit;
}
if (nargs < 3) {
goto skip_optional;
}
if (PyFloat_Check(args[2])) {
PyErr_SetString(PyExc_TypeError,
"integer argument expected, got float" );
goto exit;
}
mode = _PyLong_AsInt(args[2]);
if (mode == -1 && PyErr_Occurred()) {
goto exit;
}
skip_optional:
return_value = dbmopen_impl(module, filename, flags, mode);
exit:
return return_value;
}
/*[clinic end generated code: output=e4585e78f5821b5b input=a9049054013a1b77]*/
/*[clinic end generated code: output=7f5d30ef5d820b8a input=a9049054013a1b77]*/
......@@ -20,7 +20,7 @@ _elementtree_Element_append(ElementObject *self, PyObject *arg)
PyObject *subelement;
if (!PyObject_TypeCheck(arg, &Element_Type)) {
_PyArg_BadArgument("append", (&Element_Type)->tp_name, arg);
_PyArg_BadArgument("append", 0, (&Element_Type)->tp_name, arg);
goto exit;
}
subelement = arg;
......@@ -82,7 +82,7 @@ _elementtree_Element___deepcopy__(ElementObject *self, PyObject *arg)
PyObject *memo;
if (!PyDict_Check(arg)) {
_PyArg_BadArgument("__deepcopy__", "dict", arg);
_PyArg_BadArgument("__deepcopy__", 0, "dict", arg);
goto exit;
}
memo = arg;
......@@ -420,10 +420,31 @@ _elementtree_Element_insert(ElementObject *self, PyObject *const *args, Py_ssize
Py_ssize_t index;
PyObject *subelement;
if (!_PyArg_ParseStack(args, nargs, "nO!:insert",
&index, &Element_Type, &subelement)) {
if (!_PyArg_CheckPositional("insert", nargs, 2, 2)) {
goto exit;
}
if (PyFloat_Check(args[0])) {
PyErr_SetString(PyExc_TypeError,
"integer argument expected, got float" );
goto exit;
}
{
Py_ssize_t ival = -1;
PyObject *iobj = PyNumber_Index(args[0]);
if (iobj != NULL) {
ival = PyLong_AsSsize_t(iobj);
Py_DECREF(iobj);
}
if (ival == -1 && PyErr_Occurred()) {
goto exit;
}
index = ival;
}
if (!PyObject_TypeCheck(args[1], &Element_Type)) {
_PyArg_BadArgument("insert", 2, (&Element_Type)->tp_name, args[1]);
goto exit;
}
subelement = args[1];
return_value = _elementtree_Element_insert_impl(self, index, subelement);
exit:
......@@ -512,7 +533,7 @@ _elementtree_Element_remove(ElementObject *self, PyObject *arg)
PyObject *subelement;
if (!PyObject_TypeCheck(arg, &Element_Type)) {
_PyArg_BadArgument("remove", (&Element_Type)->tp_name, arg);
_PyArg_BadArgument("remove", 0, (&Element_Type)->tp_name, arg);
goto exit;
}
subelement = arg;
......@@ -723,4 +744,4 @@ _elementtree_XMLParser__setevents(XMLParserObject *self, PyObject *const *args,
exit:
return return_value;
}
/*[clinic end generated code: output=398640585689c5ed input=a9049054013a1b77]*/
/*[clinic end generated code: output=6bbedd24b709dc00 input=a9049054013a1b77]*/
......@@ -245,13 +245,49 @@ dbmopen(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
const char *flags = "r";
int mode = 438;
if (!_PyArg_ParseStack(args, nargs, "U|si:open",
&filename, &flags, &mode)) {
if (!_PyArg_CheckPositional("open", nargs, 1, 3)) {
goto exit;
}
if (!PyUnicode_Check(args[0])) {
_PyArg_BadArgument("open", 1, "str", args[0]);
goto exit;
}
if (PyUnicode_READY(args[0]) == -1) {
goto exit;
}
filename = args[0];
if (nargs < 2) {
goto skip_optional;
}
if (!PyUnicode_Check(args[1])) {
_PyArg_BadArgument("open", 2, "str", args[1]);
goto exit;
}
Py_ssize_t flags_length;
flags = PyUnicode_AsUTF8AndSize(args[1], &flags_length);
if (flags == NULL) {
goto exit;
}
if (strlen(flags) != (size_t)flags_length) {
PyErr_SetString(PyExc_ValueError, "embedded null character");
goto exit;
}
if (nargs < 3) {
goto skip_optional;
}
if (PyFloat_Check(args[2])) {
PyErr_SetString(PyExc_TypeError,
"integer argument expected, got float" );
goto exit;
}
mode = _PyLong_AsInt(args[2]);
if (mode == -1 && PyErr_Occurred()) {
goto exit;
}
skip_optional:
return_value = dbmopen_impl(module, filename, flags, mode);
exit:
return return_value;
}
/*[clinic end generated code: output=5ca4361417bf96cb input=a9049054013a1b77]*/
/*[clinic end generated code: output=05f06065d2dc1f9e input=a9049054013a1b77]*/
......@@ -29,7 +29,7 @@ _lzma_LZMACompressor_compress(Compressor *self, PyObject *arg)
goto exit;
}
if (!PyBuffer_IsContiguous(&data, 'C')) {
_PyArg_BadArgument("compress", "contiguous buffer", arg);
_PyArg_BadArgument("compress", 0, "contiguous buffer", arg);
goto exit;
}
return_value = _lzma_LZMACompressor_compress_impl(self, &data);
......@@ -252,8 +252,17 @@ _lzma__decode_filter_properties(PyObject *module, PyObject *const *args, Py_ssiz
lzma_vli filter_id;
Py_buffer encoded_props = {NULL, NULL};
if (!_PyArg_ParseStack(args, nargs, "O&y*:_decode_filter_properties",
lzma_vli_converter, &filter_id, &encoded_props)) {
if (!_PyArg_CheckPositional("_decode_filter_properties", nargs, 2, 2)) {
goto exit;
}
if (!lzma_vli_converter(args[0], &filter_id)) {
goto exit;
}
if (PyObject_GetBuffer(args[1], &encoded_props, PyBUF_SIMPLE) != 0) {
goto exit;
}
if (!PyBuffer_IsContiguous(&encoded_props, 'C')) {
_PyArg_BadArgument("_decode_filter_properties", 2, "contiguous buffer", args[1]);
goto exit;
}
return_value = _lzma__decode_filter_properties_impl(module, filter_id, &encoded_props);
......@@ -266,4 +275,4 @@ exit:
return return_value;
}
/*[clinic end generated code: output=df061bfc2067a90a input=a9049054013a1b77]*/
/*[clinic end generated code: output=47e4732df79509ad input=a9049054013a1b77]*/
......@@ -1416,10 +1416,31 @@ _operator_length_hint(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Py_ssize_t default_value = 0;
Py_ssize_t _return_value;
if (!_PyArg_ParseStack(args, nargs, "O|n:length_hint",
&obj, &default_value)) {
if (!_PyArg_CheckPositional("length_hint", nargs, 1, 2)) {
goto exit;
}
obj = args[0];
if (nargs < 2) {
goto skip_optional;
}
if (PyFloat_Check(args[1])) {
PyErr_SetString(PyExc_TypeError,
"integer argument expected, got float" );
goto exit;
}
{
Py_ssize_t ival = -1;
PyObject *iobj = PyNumber_Index(args[1]);
if (iobj != NULL) {
ival = PyLong_AsSsize_t(iobj);
Py_DECREF(iobj);
}
if (ival == -1 && PyErr_Occurred()) {
goto exit;
}
default_value = ival;
}
skip_optional:
_return_value = _operator_length_hint_impl(module, obj, default_value);
if ((_return_value == -1) && PyErr_Occurred()) {
goto exit;
......@@ -1469,4 +1490,4 @@ _operator__compare_digest(PyObject *module, PyObject *const *args, Py_ssize_t na
exit:
return return_value;
}
/*[clinic end generated code: output=424b884884ab20b7 input=a9049054013a1b77]*/
/*[clinic end generated code: output=b382bece80a5a254 input=a9049054013a1b77]*/
......@@ -71,10 +71,17 @@ _ssl__SSLSocket_getpeercert(PySSLSocket *self, PyObject *const *args, Py_ssize_t
PyObject *return_value = NULL;
int binary_mode = 0;
if (!_PyArg_ParseStack(args, nargs, "|p:getpeercert",
&binary_mode)) {
if (!_PyArg_CheckPositional("getpeercert", nargs, 0, 1)) {
goto exit;
}
if (nargs < 1) {
goto skip_optional;
}
binary_mode = PyObject_IsTrue(args[0]);
if (binary_mode < 0) {
goto exit;
}
skip_optional:
return_value = _ssl__SSLSocket_getpeercert_impl(self, binary_mode);
exit:
......@@ -215,7 +222,7 @@ _ssl__SSLSocket_write(PySSLSocket *self, PyObject *arg)
goto exit;
}
if (!PyBuffer_IsContiguous(&b, 'C')) {
_PyArg_BadArgument("write", "contiguous buffer", arg);
_PyArg_BadArgument("write", 0, "contiguous buffer", arg);
goto exit;
}
return_value = _ssl__SSLSocket_write_impl(self, &b);
......@@ -377,8 +384,16 @@ _ssl__SSLContext(PyTypeObject *type, PyObject *args, PyObject *kwargs)
!_PyArg_NoKeywords("_SSLContext", kwargs)) {
goto exit;
}
if (!PyArg_ParseTuple(args, "i:_SSLContext",
&proto_version)) {
if (!_PyArg_CheckPositional("_SSLContext", PyTuple_GET_SIZE(args), 1, 1)) {
goto exit;
}
if (PyFloat_Check(PyTuple_GET_ITEM(args, 0))) {
PyErr_SetString(PyExc_TypeError,
"integer argument expected, got float" );
goto exit;
}
proto_version = _PyLong_AsInt(PyTuple_GET_ITEM(args, 0));
if (proto_version == -1 && PyErr_Occurred()) {
goto exit;
}
return_value = _ssl__SSLContext_impl(type, proto_version);
......@@ -405,7 +420,7 @@ _ssl__SSLContext_set_ciphers(PySSLContext *self, PyObject *arg)
const char *cipherlist;
if (!PyUnicode_Check(arg)) {
_PyArg_BadArgument("set_ciphers", "str", arg);
_PyArg_BadArgument("set_ciphers", 0, "str", arg);
goto exit;
}
Py_ssize_t cipherlist_length;
......@@ -466,7 +481,7 @@ _ssl__SSLContext__set_npn_protocols(PySSLContext *self, PyObject *arg)
goto exit;
}
if (!PyBuffer_IsContiguous(&protos, 'C')) {
_PyArg_BadArgument("_set_npn_protocols", "contiguous buffer", arg);
_PyArg_BadArgument("_set_npn_protocols", 0, "contiguous buffer", arg);
goto exit;
}
return_value = _ssl__SSLContext__set_npn_protocols_impl(self, &protos);
......@@ -502,7 +517,7 @@ _ssl__SSLContext__set_alpn_protocols(PySSLContext *self, PyObject *arg)
goto exit;
}
if (!PyBuffer_IsContiguous(&protos, 'C')) {
_PyArg_BadArgument("_set_alpn_protocols", "contiguous buffer", arg);
_PyArg_BadArgument("_set_alpn_protocols", 0, "contiguous buffer", arg);
goto exit;
}
return_value = _ssl__SSLContext__set_alpn_protocols_impl(self, &protos);
......@@ -815,10 +830,22 @@ _ssl_MemoryBIO_read(PySSLMemoryBIO *self, PyObject *const *args, Py_ssize_t narg
PyObject *return_value = NULL;
int len = -1;
if (!_PyArg_ParseStack(args, nargs, "|i:read",
&len)) {
if (!_PyArg_CheckPositional("read", 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;
}
len = _PyLong_AsInt(args[0]);
if (len == -1 && PyErr_Occurred()) {
goto exit;
}
skip_optional:
return_value = _ssl_MemoryBIO_read_impl(self, len);
exit:
......@@ -849,7 +876,7 @@ _ssl_MemoryBIO_write(PySSLMemoryBIO *self, PyObject *arg)
goto exit;
}
if (!PyBuffer_IsContiguous(&b, 'C')) {
_PyArg_BadArgument("write", "contiguous buffer", arg);
_PyArg_BadArgument("write", 0, "contiguous buffer", arg);
goto exit;
}
return_value = _ssl_MemoryBIO_write_impl(self, &b);
......@@ -905,8 +932,28 @@ _ssl_RAND_add(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Py_buffer view = {NULL, NULL};
double entropy;
if (!_PyArg_ParseStack(args, nargs, "s*d:RAND_add",
&view, &entropy)) {
if (!_PyArg_CheckPositional("RAND_add", nargs, 2, 2)) {
goto exit;
}
if (PyUnicode_Check(args[0])) {
Py_ssize_t len;
const char *ptr = PyUnicode_AsUTF8AndSize(args[0], &len);
if (ptr == NULL) {
goto exit;
}
PyBuffer_FillInfo(&view, args[0], (void *)ptr, len, 1, 0);
}
else { /* any bytes-like object */
if (PyObject_GetBuffer(args[0], &view, PyBUF_SIMPLE) != 0) {
goto exit;
}
if (!PyBuffer_IsContiguous(&view, 'C')) {
_PyArg_BadArgument("RAND_add", 1, "contiguous buffer", args[0]);
goto exit;
}
}
entropy = PyFloat_AsDouble(args[1]);
if (PyErr_Occurred()) {
goto exit;
}
return_value = _ssl_RAND_add_impl(module, &view, entropy);
......@@ -1237,4 +1284,4 @@ exit:
#ifndef _SSL_ENUM_CRLS_METHODDEF
#define _SSL_ENUM_CRLS_METHODDEF
#endif /* !defined(_SSL_ENUM_CRLS_METHODDEF) */
/*[clinic end generated code: output=c2dca2ef4cbef4e2 input=a9049054013a1b77]*/
/*[clinic end generated code: output=ac3fb15ca27500f2 input=a9049054013a1b77]*/
......@@ -61,7 +61,7 @@ Struct_unpack(PyStructObject *self, PyObject *arg)
goto exit;
}
if (!PyBuffer_IsContiguous(&buffer, 'C')) {
_PyArg_BadArgument("unpack", "contiguous buffer", arg);
_PyArg_BadArgument("unpack", 0, "contiguous buffer", arg);
goto exit;
}
return_value = Struct_unpack_impl(self, &buffer);
......@@ -209,8 +209,17 @@ unpack(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
PyStructObject *s_object = NULL;
Py_buffer buffer = {NULL, NULL};
if (!_PyArg_ParseStack(args, nargs, "O&y*:unpack",
cache_struct_converter, &s_object, &buffer)) {
if (!_PyArg_CheckPositional("unpack", nargs, 2, 2)) {
goto exit;
}
if (!cache_struct_converter(args[0], &s_object)) {
goto exit;
}
if (PyObject_GetBuffer(args[1], &buffer, PyBUF_SIMPLE) != 0) {
goto exit;
}
if (!PyBuffer_IsContiguous(&buffer, 'C')) {
_PyArg_BadArgument("unpack", 2, "contiguous buffer", args[1]);
goto exit;
}
return_value = unpack_impl(module, s_object, &buffer);
......@@ -295,10 +304,13 @@ iter_unpack(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
PyStructObject *s_object = NULL;
PyObject *buffer;
if (!_PyArg_ParseStack(args, nargs, "O&O:iter_unpack",
cache_struct_converter, &s_object, &buffer)) {
if (!_PyArg_CheckPositional("iter_unpack", nargs, 2, 2)) {
goto exit;
}
if (!cache_struct_converter(args[0], &s_object)) {
goto exit;
}
buffer = args[1];
return_value = iter_unpack_impl(module, s_object, buffer);
exit:
......@@ -307,4 +319,4 @@ exit:
return return_value;
}
/*[clinic end generated code: output=01516bea2641fe01 input=a9049054013a1b77]*/
/*[clinic end generated code: output=ac595db9d2b271aa input=a9049054013a1b77]*/
This diff is collapsed.
......@@ -95,10 +95,22 @@ _tracemalloc_start(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
PyObject *return_value = NULL;
int nframe = 1;
if (!_PyArg_ParseStack(args, nargs, "|i:start",
&nframe)) {
if (!_PyArg_CheckPositional("start", 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;
}
nframe = _PyLong_AsInt(args[0]);
if (nframe == -1 && PyErr_Occurred()) {
goto exit;
}
skip_optional:
return_value = _tracemalloc_start_impl(module, nframe);
exit:
......@@ -185,4 +197,4 @@ _tracemalloc_get_traced_memory(PyObject *module, PyObject *Py_UNUSED(ignored))
{
return _tracemalloc_get_traced_memory_impl(module);
}
/*[clinic end generated code: output=d4a2dd3eaba9f72d input=a9049054013a1b77]*/
/*[clinic end generated code: output=1bc96dc569706afa input=a9049054013a1b77]*/
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -34,7 +34,7 @@ pwd_getpwnam(PyObject *module, PyObject *arg)
PyObject *name;
if (!PyUnicode_Check(arg)) {
_PyArg_BadArgument("getpwnam", "str", arg);
_PyArg_BadArgument("getpwnam", 0, "str", arg);
goto exit;
}
if (PyUnicode_READY(arg) == -1) {
......@@ -74,4 +74,4 @@ pwd_getpwall(PyObject *module, PyObject *Py_UNUSED(ignored))
#ifndef PWD_GETPWALL_METHODDEF
#define PWD_GETPWALL_METHODDEF
#endif /* !defined(PWD_GETPWALL_METHODDEF) */
/*[clinic end generated code: output=9e86e23d6ad9cd08 input=a9049054013a1b77]*/
/*[clinic end generated code: output=f9412bdedc69706c input=a9049054013a1b77]*/
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment