From 4fa9591025b6a098f3d6402e5413ee6740ede6c5 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Fri, 11 Jan 2019 16:01:14 +0200 Subject: bpo-35582: Argument Clinic: inline parsing code for positional parameters. (GH-11313) --- Include/modsupport.h | 7 +- Lib/test/clinic.test | 731 +++++++++++-- Modules/_io/clinic/bufferedio.c.h | 131 ++- Modules/_io/clinic/bytesio.c.h | 79 +- Modules/_io/clinic/fileio.c.h | 35 +- Modules/_io/clinic/iobase.c.h | 46 +- Modules/_io/clinic/stringio.c.h | 65 +- Modules/_io/clinic/textio.c.h | 55 +- Modules/_io/clinic/winconsoleio.c.h | 18 +- Modules/cjkcodecs/clinic/multibytecodec.c.h | 6 +- Modules/clinic/_bz2module.c.h | 20 +- Modules/clinic/_codecsmodule.c.h | 1547 +++++++++++++++++++++++++-- Modules/clinic/_collectionsmodule.c.h | 23 +- Modules/clinic/_cryptmodule.c.h | 31 +- Modules/clinic/_curses_panel.c.h | 27 +- Modules/clinic/_cursesmodule.c.h | 542 +++++++++- Modules/clinic/_dbmmodule.c.h | 42 +- Modules/clinic/_elementtree.c.h | 33 +- Modules/clinic/_gdbmmodule.c.h | 42 +- Modules/clinic/_lzmamodule.c.h | 17 +- Modules/clinic/_operator.c.h | 27 +- Modules/clinic/_ssl.c.h | 75 +- Modules/clinic/_struct.c.h | 24 +- Modules/clinic/_tkinter.c.h | 222 +++- Modules/clinic/_tracemalloc.c.h | 18 +- Modules/clinic/_weakref.c.h | 11 +- Modules/clinic/arraymodule.c.h | 98 +- Modules/clinic/audioop.c.h | 617 ++++++++++- Modules/clinic/binascii.c.h | 54 +- Modules/clinic/cmathmodule.c.h | 25 +- Modules/clinic/fcntlmodule.c.h | 100 +- Modules/clinic/itertoolsmodule.c.h | 46 +- Modules/clinic/mathmodule.c.h | 32 +- Modules/clinic/posixmodule.c.h | 527 ++++++++- Modules/clinic/pwdmodule.c.h | 4 +- Modules/clinic/pyexpat.c.h | 70 +- Modules/clinic/resource.c.h | 15 +- Modules/clinic/selectmodule.c.h | 68 +- Modules/clinic/signalmodule.c.h | 93 +- Modules/clinic/spwdmodule.c.h | 4 +- Modules/clinic/symtablemodule.c.h | 34 +- Modules/clinic/unicodedata.c.h | 144 ++- Modules/clinic/zlibmodule.c.h | 76 +- Objects/clinic/bytearrayobject.c.h | 122 ++- Objects/clinic/bytesobject.c.h | 63 +- Objects/clinic/floatobject.c.h | 35 +- Objects/clinic/listobject.c.h | 64 +- Objects/clinic/longobject.c.h | 4 +- Objects/clinic/tupleobject.c.h | 19 +- Objects/clinic/typeobject.c.h | 4 +- Objects/clinic/unicodeobject.c.h | 152 ++- Objects/stringlib/clinic/transmogrify.h.h | 104 +- PC/clinic/msvcrtmodule.c.h | 86 +- PC/clinic/winreg.c.h | 32 +- Python/clinic/bltinmodule.c.h | 18 +- Python/clinic/import.c.h | 28 +- Python/clinic/marshal.c.h | 39 +- Python/clinic/sysmodule.c.h | 29 +- Python/getargs.c | 43 +- Tools/clinic/clinic.py | 249 +++-- 60 files changed, 6194 insertions(+), 778 deletions(-) diff --git a/Include/modsupport.h b/Include/modsupport.h index ed24b2b..f17060c 100644 --- a/Include/modsupport.h +++ b/Include/modsupport.h @@ -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 diff --git a/Lib/test/clinic.test b/Lib/test/clinic.test index 03571a8..7ae8f96 100644 --- a/Lib/test/clinic.test +++ b/Lib/test/clinic.test @@ -35,10 +35,19 @@ test_object_converter(PyObject *module, PyObject *const *args, Py_ssize_t nargs) PyObject *c; PyUnicode_Object *d; - if (!_PyArg_ParseStack(args, nargs, "OO&O!O:test_object_converter", - &a, PyUnicode_FSConverter, &b, &PyUnicode_Type, &c, &d)) { + if (!_PyArg_CheckPositional("test_object_converter", nargs, 4, 4)) { goto exit; } + a = args[0]; + if (!PyUnicode_FSConverter(args[1], &b)) { + goto exit; + } + if (!PyUnicode_Check(args[2])) { + _PyArg_BadArgument("test_object_converter", 3, "str", args[2]); + goto exit; + } + c = args[2]; + d = (PyUnicode_Object *)args[3]; return_value = test_object_converter_impl(module, a, b, c, d); exit: @@ -48,7 +57,7 @@ exit: static PyObject * test_object_converter_impl(PyObject *module, PyObject *a, PyObject *b, PyObject *c, PyUnicode_Object *d) -/*[clinic end generated code: output=ac25517226de46c8 input=005e6a8a711a869b]*/ +/*[clinic end generated code: output=f2c26174b3d46e94 input=005e6a8a711a869b]*/ /*[clinic input] test_object_converter_one_arg @@ -159,10 +168,59 @@ test_object_converter_subclass_of(PyObject *module, PyObject *const *args, Py_ss PyObject *i; PyObject *j; - if (!_PyArg_ParseStack(args, nargs, "O!O!O!O!O!O!O!O!O!O!:test_object_converter_subclass_of", - &PyLong_Type, &a, &PyTuple_Type, &b, &PyList_Type, &c, &PySet_Type, &d, &PyFrozenSet_Type, &e, &PyDict_Type, &f, &PyUnicode_Type, &g, &PyBytes_Type, &h, &PyByteArray_Type, &i, &MyType, &j)) { + if (!_PyArg_CheckPositional("test_object_converter_subclass_of", nargs, 10, 10)) { + goto exit; + } + if (!PyLong_Check(args[0])) { + _PyArg_BadArgument("test_object_converter_subclass_of", 1, "int", args[0]); + goto exit; + } + a = args[0]; + if (!PyTuple_Check(args[1])) { + _PyArg_BadArgument("test_object_converter_subclass_of", 2, "tuple", args[1]); + goto exit; + } + b = args[1]; + if (!PyList_Check(args[2])) { + _PyArg_BadArgument("test_object_converter_subclass_of", 3, "list", args[2]); + goto exit; + } + c = args[2]; + if (!PySet_Check(args[3])) { + _PyArg_BadArgument("test_object_converter_subclass_of", 4, "set", args[3]); + goto exit; + } + d = args[3]; + if (!PyFrozenSet_Check(args[4])) { + _PyArg_BadArgument("test_object_converter_subclass_of", 5, "frozenset", args[4]); goto exit; } + e = args[4]; + if (!PyDict_Check(args[5])) { + _PyArg_BadArgument("test_object_converter_subclass_of", 6, "dict", args[5]); + goto exit; + } + f = args[5]; + if (!PyUnicode_Check(args[6])) { + _PyArg_BadArgument("test_object_converter_subclass_of", 7, "str", args[6]); + goto exit; + } + g = args[6]; + if (!PyBytes_Check(args[7])) { + _PyArg_BadArgument("test_object_converter_subclass_of", 8, "bytes", args[7]); + goto exit; + } + h = args[7]; + if (!PyByteArray_Check(args[8])) { + _PyArg_BadArgument("test_object_converter_subclass_of", 9, "bytearray", args[8]); + goto exit; + } + i = args[8]; + if (!PyObject_TypeCheck(args[9], &MyType)) { + _PyArg_BadArgument("test_object_converter_subclass_of", 10, (&MyType)->tp_name, args[9]); + goto exit; + } + j = args[9]; return_value = test_object_converter_subclass_of_impl(module, a, b, c, d, e, f, g, h, i, j); exit: @@ -174,7 +232,7 @@ test_object_converter_subclass_of_impl(PyObject *module, PyObject *a, PyObject *b, PyObject *c, PyObject *d, PyObject *e, PyObject *f, PyObject *g, PyObject *h, PyObject *i, PyObject *j) -/*[clinic end generated code: output=b26bcdc31dfc7872 input=31b06b772d5f983e]*/ +/*[clinic end generated code: output=99691bda8eeda6d6 input=31b06b772d5f983e]*/ /*[clinic input] test_PyBytesObject_converter @@ -202,7 +260,7 @@ test_PyBytesObject_converter(PyObject *module, PyObject *arg) PyBytesObject *a; if (!PyBytes_Check(arg)) { - _PyArg_BadArgument("test_PyBytesObject_converter", "bytes", arg); + _PyArg_BadArgument("test_PyBytesObject_converter", 0, "bytes", arg); goto exit; } a = (PyBytesObject *)arg; @@ -214,7 +272,7 @@ exit: static PyObject * test_PyBytesObject_converter_impl(PyObject *module, PyBytesObject *a) -/*[clinic end generated code: output=fd69d6df4d26c853 input=12b10c7cb5750400]*/ +/*[clinic end generated code: output=5d9a301c1df24eb5 input=12b10c7cb5750400]*/ /*[clinic input] test_PyByteArrayObject_converter @@ -242,7 +300,7 @@ test_PyByteArrayObject_converter(PyObject *module, PyObject *arg) PyByteArrayObject *a; if (!PyByteArray_Check(arg)) { - _PyArg_BadArgument("test_PyByteArrayObject_converter", "bytearray", arg); + _PyArg_BadArgument("test_PyByteArrayObject_converter", 0, "bytearray", arg); goto exit; } a = (PyByteArrayObject *)arg; @@ -254,7 +312,7 @@ exit: static PyObject * test_PyByteArrayObject_converter_impl(PyObject *module, PyByteArrayObject *a) -/*[clinic end generated code: output=d309c909182c4183 input=5a657da535d194ae]*/ +/*[clinic end generated code: output=9455d06f4f09637b input=5a657da535d194ae]*/ /*[clinic input] test_unicode_converter @@ -282,7 +340,7 @@ test_unicode_converter(PyObject *module, PyObject *arg) PyObject *a; if (!PyUnicode_Check(arg)) { - _PyArg_BadArgument("test_unicode_converter", "str", arg); + _PyArg_BadArgument("test_unicode_converter", 0, "str", arg); goto exit; } if (PyUnicode_READY(arg) == -1) { @@ -297,7 +355,7 @@ exit: static PyObject * test_unicode_converter_impl(PyObject *module, PyObject *a) -/*[clinic end generated code: output=ca603454e1f8f764 input=aa33612df92aa9c5]*/ +/*[clinic end generated code: output=9275c04fe204f4c5 input=aa33612df92aa9c5]*/ /*[clinic input] test_bool_converter @@ -328,10 +386,36 @@ test_bool_converter(PyObject *module, PyObject *const *args, Py_ssize_t nargs) int b = 1; int c = 1; - if (!_PyArg_ParseStack(args, nargs, "|ppi:test_bool_converter", - &a, &b, &c)) { + if (!_PyArg_CheckPositional("test_bool_converter", nargs, 0, 3)) { + goto exit; + } + if (nargs < 1) { + goto skip_optional; + } + a = PyObject_IsTrue(args[0]); + if (a < 0) { + goto exit; + } + if (nargs < 2) { + goto skip_optional; + } + b = PyObject_IsTrue(args[1]); + if (b < 0) { + goto exit; + } + if (nargs < 3) { + goto skip_optional; + } + if (PyFloat_Check(args[2])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + c = _PyLong_AsInt(args[2]); + if (c == -1 && PyErr_Occurred()) { goto exit; } +skip_optional: return_value = test_bool_converter_impl(module, a, b, c); exit: @@ -340,7 +424,7 @@ exit: static PyObject * test_bool_converter_impl(PyObject *module, int a, int b, int c) -/*[clinic end generated code: output=f08a22d3390ab6f7 input=939854fa9f248c60]*/ +/*[clinic end generated code: output=25f20963894256a1 input=939854fa9f248c60]*/ /*[clinic input] test_char_converter @@ -397,10 +481,192 @@ test_char_converter(PyObject *module, PyObject *const *args, Py_ssize_t nargs) char m = '\x00'; char n = '\xff'; - if (!_PyArg_ParseStack(args, nargs, "|cccccccccccccc:test_char_converter", - &a, &b, &c, &d, &e, &f, &g, &h, &i, &j, &k, &l, &m, &n)) { + if (!_PyArg_CheckPositional("test_char_converter", nargs, 0, 14)) { + goto exit; + } + if (nargs < 1) { + goto skip_optional; + } + if (PyBytes_Check(args[0]) && PyBytes_GET_SIZE(args[0]) == 1) { + a = PyBytes_AS_STRING(args[0])[0]; + } + else if (PyByteArray_Check(args[0]) && PyByteArray_GET_SIZE(args[0]) == 1) { + a = PyByteArray_AS_STRING(args[0])[0]; + } + else { + _PyArg_BadArgument("test_char_converter", 1, "a byte string of length 1", args[0]); + goto exit; + } + if (nargs < 2) { + goto skip_optional; + } + if (PyBytes_Check(args[1]) && PyBytes_GET_SIZE(args[1]) == 1) { + b = PyBytes_AS_STRING(args[1])[0]; + } + else if (PyByteArray_Check(args[1]) && PyByteArray_GET_SIZE(args[1]) == 1) { + b = PyByteArray_AS_STRING(args[1])[0]; + } + else { + _PyArg_BadArgument("test_char_converter", 2, "a byte string of length 1", args[1]); + goto exit; + } + if (nargs < 3) { + goto skip_optional; + } + if (PyBytes_Check(args[2]) && PyBytes_GET_SIZE(args[2]) == 1) { + c = PyBytes_AS_STRING(args[2])[0]; + } + else if (PyByteArray_Check(args[2]) && PyByteArray_GET_SIZE(args[2]) == 1) { + c = PyByteArray_AS_STRING(args[2])[0]; + } + else { + _PyArg_BadArgument("test_char_converter", 3, "a byte string of length 1", args[2]); + goto exit; + } + if (nargs < 4) { + goto skip_optional; + } + if (PyBytes_Check(args[3]) && PyBytes_GET_SIZE(args[3]) == 1) { + d = PyBytes_AS_STRING(args[3])[0]; + } + else if (PyByteArray_Check(args[3]) && PyByteArray_GET_SIZE(args[3]) == 1) { + d = PyByteArray_AS_STRING(args[3])[0]; + } + else { + _PyArg_BadArgument("test_char_converter", 4, "a byte string of length 1", args[3]); + goto exit; + } + if (nargs < 5) { + goto skip_optional; + } + if (PyBytes_Check(args[4]) && PyBytes_GET_SIZE(args[4]) == 1) { + e = PyBytes_AS_STRING(args[4])[0]; + } + else if (PyByteArray_Check(args[4]) && PyByteArray_GET_SIZE(args[4]) == 1) { + e = PyByteArray_AS_STRING(args[4])[0]; + } + else { + _PyArg_BadArgument("test_char_converter", 5, "a byte string of length 1", args[4]); + goto exit; + } + if (nargs < 6) { + goto skip_optional; + } + if (PyBytes_Check(args[5]) && PyBytes_GET_SIZE(args[5]) == 1) { + f = PyBytes_AS_STRING(args[5])[0]; + } + else if (PyByteArray_Check(args[5]) && PyByteArray_GET_SIZE(args[5]) == 1) { + f = PyByteArray_AS_STRING(args[5])[0]; + } + else { + _PyArg_BadArgument("test_char_converter", 6, "a byte string of length 1", args[5]); + goto exit; + } + if (nargs < 7) { + goto skip_optional; + } + if (PyBytes_Check(args[6]) && PyBytes_GET_SIZE(args[6]) == 1) { + g = PyBytes_AS_STRING(args[6])[0]; + } + else if (PyByteArray_Check(args[6]) && PyByteArray_GET_SIZE(args[6]) == 1) { + g = PyByteArray_AS_STRING(args[6])[0]; + } + else { + _PyArg_BadArgument("test_char_converter", 7, "a byte string of length 1", args[6]); + goto exit; + } + if (nargs < 8) { + goto skip_optional; + } + if (PyBytes_Check(args[7]) && PyBytes_GET_SIZE(args[7]) == 1) { + h = PyBytes_AS_STRING(args[7])[0]; + } + else if (PyByteArray_Check(args[7]) && PyByteArray_GET_SIZE(args[7]) == 1) { + h = PyByteArray_AS_STRING(args[7])[0]; + } + else { + _PyArg_BadArgument("test_char_converter", 8, "a byte string of length 1", args[7]); + goto exit; + } + if (nargs < 9) { + goto skip_optional; + } + if (PyBytes_Check(args[8]) && PyBytes_GET_SIZE(args[8]) == 1) { + i = PyBytes_AS_STRING(args[8])[0]; + } + else if (PyByteArray_Check(args[8]) && PyByteArray_GET_SIZE(args[8]) == 1) { + i = PyByteArray_AS_STRING(args[8])[0]; + } + else { + _PyArg_BadArgument("test_char_converter", 9, "a byte string of length 1", args[8]); + goto exit; + } + if (nargs < 10) { + goto skip_optional; + } + if (PyBytes_Check(args[9]) && PyBytes_GET_SIZE(args[9]) == 1) { + j = PyBytes_AS_STRING(args[9])[0]; + } + else if (PyByteArray_Check(args[9]) && PyByteArray_GET_SIZE(args[9]) == 1) { + j = PyByteArray_AS_STRING(args[9])[0]; + } + else { + _PyArg_BadArgument("test_char_converter", 10, "a byte string of length 1", args[9]); + goto exit; + } + if (nargs < 11) { + goto skip_optional; + } + if (PyBytes_Check(args[10]) && PyBytes_GET_SIZE(args[10]) == 1) { + k = PyBytes_AS_STRING(args[10])[0]; + } + else if (PyByteArray_Check(args[10]) && PyByteArray_GET_SIZE(args[10]) == 1) { + k = PyByteArray_AS_STRING(args[10])[0]; + } + else { + _PyArg_BadArgument("test_char_converter", 11, "a byte string of length 1", args[10]); + goto exit; + } + if (nargs < 12) { + goto skip_optional; + } + if (PyBytes_Check(args[11]) && PyBytes_GET_SIZE(args[11]) == 1) { + l = PyBytes_AS_STRING(args[11])[0]; + } + else if (PyByteArray_Check(args[11]) && PyByteArray_GET_SIZE(args[11]) == 1) { + l = PyByteArray_AS_STRING(args[11])[0]; + } + else { + _PyArg_BadArgument("test_char_converter", 12, "a byte string of length 1", args[11]); + goto exit; + } + if (nargs < 13) { + goto skip_optional; + } + if (PyBytes_Check(args[12]) && PyBytes_GET_SIZE(args[12]) == 1) { + m = PyBytes_AS_STRING(args[12])[0]; + } + else if (PyByteArray_Check(args[12]) && PyByteArray_GET_SIZE(args[12]) == 1) { + m = PyByteArray_AS_STRING(args[12])[0]; + } + else { + _PyArg_BadArgument("test_char_converter", 13, "a byte string of length 1", args[12]); + goto exit; + } + if (nargs < 14) { + goto skip_optional; + } + if (PyBytes_Check(args[13]) && PyBytes_GET_SIZE(args[13]) == 1) { + n = PyBytes_AS_STRING(args[13])[0]; + } + else if (PyByteArray_Check(args[13]) && PyByteArray_GET_SIZE(args[13]) == 1) { + n = PyByteArray_AS_STRING(args[13])[0]; + } + else { + _PyArg_BadArgument("test_char_converter", 14, "a byte string of length 1", args[13]); goto exit; } +skip_optional: return_value = test_char_converter_impl(module, a, b, c, d, e, f, g, h, i, j, k, l, m, n); exit: @@ -411,7 +677,7 @@ static PyObject * test_char_converter_impl(PyObject *module, char a, char b, char c, char d, char e, char f, char g, char h, char i, char j, char k, char l, char m, char n) -/*[clinic end generated code: output=14c61e8ee78f3d47 input=e42330417a44feac]*/ +/*[clinic end generated code: output=e041d687555e0a5d input=e42330417a44feac]*/ /*[clinic input] test_unsigned_char_converter @@ -443,10 +709,81 @@ test_unsigned_char_converter(PyObject *module, PyObject *const *args, Py_ssize_t unsigned char b = 34; unsigned char c = 56; - if (!_PyArg_ParseStack(args, nargs, "|bbB:test_unsigned_char_converter", - &a, &b, &c)) { + if (!_PyArg_CheckPositional("test_unsigned_char_converter", nargs, 0, 3)) { + goto exit; + } + if (nargs < 1) { + goto skip_optional; + } + if (PyFloat_Check(args[0])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + { + long ival = PyLong_AsLong(args[0]); + if (ival == -1 && PyErr_Occurred()) { + goto exit; + } + else if (ival < 0) { + PyErr_SetString(PyExc_OverflowError, + "unsigned byte integer is less than minimum"); + goto exit; + } + else if (ival > UCHAR_MAX) { + PyErr_SetString(PyExc_OverflowError, + "unsigned byte integer is greater than maximum"); + goto exit; + } + else { + a = (unsigned char) ival; + } + } + if (nargs < 2) { + goto skip_optional; + } + if (PyFloat_Check(args[1])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); goto exit; } + { + long ival = PyLong_AsLong(args[1]); + if (ival == -1 && PyErr_Occurred()) { + goto exit; + } + else if (ival < 0) { + PyErr_SetString(PyExc_OverflowError, + "unsigned byte integer is less than minimum"); + goto exit; + } + else if (ival > UCHAR_MAX) { + PyErr_SetString(PyExc_OverflowError, + "unsigned byte integer is greater than maximum"); + goto exit; + } + else { + b = (unsigned char) ival; + } + } + if (nargs < 3) { + goto skip_optional; + } + if (PyFloat_Check(args[2])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + { + long ival = PyLong_AsUnsignedLongMask(args[2]); + if (ival == -1 && PyErr_Occurred()) { + goto exit; + } + else { + c = (unsigned char) ival; + } + } +skip_optional: return_value = test_unsigned_char_converter_impl(module, a, b, c); exit: @@ -456,7 +793,7 @@ exit: static PyObject * test_unsigned_char_converter_impl(PyObject *module, unsigned char a, unsigned char b, unsigned char c) -/*[clinic end generated code: output=a4fd7ad26077dcfc input=021414060993e289]*/ +/*[clinic end generated code: output=ebf905c5c9414762 input=021414060993e289]*/ /*[clinic input] test_short_converter @@ -483,10 +820,37 @@ test_short_converter(PyObject *module, PyObject *const *args, Py_ssize_t nargs) PyObject *return_value = NULL; short a = 12; - if (!_PyArg_ParseStack(args, nargs, "|h:test_short_converter", - &a)) { + if (!_PyArg_CheckPositional("test_short_converter", 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; } + { + long ival = PyLong_AsLong(args[0]); + if (ival == -1 && PyErr_Occurred()) { + goto exit; + } + else if (ival < SHRT_MIN) { + PyErr_SetString(PyExc_OverflowError, + "signed short integer is less than minimum"); + goto exit; + } + else if (ival > SHRT_MAX) { + PyErr_SetString(PyExc_OverflowError, + "signed short integer is greater than maximum"); + goto exit; + } + else { + a = (short) ival; + } + } +skip_optional: return_value = test_short_converter_impl(module, a); exit: @@ -495,7 +859,7 @@ exit: static PyObject * test_short_converter_impl(PyObject *module, short a) -/*[clinic end generated code: output=08259a92c12890b1 input=6a8a7a509a498ff4]*/ +/*[clinic end generated code: output=86fe1a1496a7ff20 input=6a8a7a509a498ff4]*/ /*[clinic input] test_unsigned_short_converter @@ -527,10 +891,34 @@ test_unsigned_short_converter(PyObject *module, PyObject *const *args, Py_ssize_ unsigned short b = 34; unsigned short c = 56; - if (!_PyArg_ParseStack(args, nargs, "|O&O&H:test_unsigned_short_converter", - _PyLong_UnsignedShort_Converter, &a, _PyLong_UnsignedShort_Converter, &b, &c)) { + if (!_PyArg_CheckPositional("test_unsigned_short_converter", nargs, 0, 3)) { + goto exit; + } + if (nargs < 1) { + goto skip_optional; + } + if (!_PyLong_UnsignedShort_Converter(args[0], &a)) { + goto exit; + } + if (nargs < 2) { + goto skip_optional; + } + if (!_PyLong_UnsignedShort_Converter(args[1], &b)) { + goto exit; + } + if (nargs < 3) { + goto skip_optional; + } + if (PyFloat_Check(args[2])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); goto exit; } + c = (unsigned short)PyLong_AsUnsignedLongMask(args[2]); + if (c == (unsigned short)-1 && PyErr_Occurred()) { + goto exit; + } +skip_optional: return_value = test_unsigned_short_converter_impl(module, a, b, c); exit: @@ -540,7 +928,7 @@ exit: static PyObject * test_unsigned_short_converter_impl(PyObject *module, unsigned short a, unsigned short b, unsigned short c) -/*[clinic end generated code: output=d714bceb98c1fe84 input=cdfd8eff3d9176b4]*/ +/*[clinic end generated code: output=3779fe104319e3ae input=cdfd8eff3d9176b4]*/ /*[clinic input] test_int_converter @@ -573,10 +961,61 @@ test_int_converter(PyObject *module, PyObject *const *args, Py_ssize_t nargs) int c = 45; myenum d = 67; - if (!_PyArg_ParseStack(args, nargs, "|iiCi:test_int_converter", - &a, &b, &c, &d)) { + if (!_PyArg_CheckPositional("test_int_converter", nargs, 0, 4)) { + goto exit; + } + if (nargs < 1) { + goto skip_optional; + } + if (PyFloat_Check(args[0])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + a = _PyLong_AsInt(args[0]); + if (a == -1 && PyErr_Occurred()) { + goto exit; + } + if (nargs < 2) { + goto skip_optional; + } + if (PyFloat_Check(args[1])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); goto exit; } + b = _PyLong_AsInt(args[1]); + if (b == -1 && PyErr_Occurred()) { + goto exit; + } + if (nargs < 3) { + goto skip_optional; + } + if (!PyUnicode_Check(args[2])) { + _PyArg_BadArgument("test_int_converter", 3, "a unicode character", args[2]); + goto exit; + } + if (PyUnicode_READY(args[2])) { + goto exit; + } + if (PyUnicode_GET_LENGTH(args[2]) != 1) { + _PyArg_BadArgument("test_int_converter", 3, "a unicode character", args[2]); + goto exit; + } + c = PyUnicode_READ_CHAR(args[2], 0); + if (nargs < 4) { + goto skip_optional; + } + if (PyFloat_Check(args[3])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + d = _PyLong_AsInt(args[3]); + if (d == -1 && PyErr_Occurred()) { + goto exit; + } +skip_optional: return_value = test_int_converter_impl(module, a, b, c, d); exit: @@ -585,7 +1024,7 @@ exit: static PyObject * test_int_converter_impl(PyObject *module, int a, int b, int c, myenum d) -/*[clinic end generated code: output=1995799d5264e4a5 input=d20541fc1ca0553e]*/ +/*[clinic end generated code: output=de74e24e85a669a5 input=d20541fc1ca0553e]*/ /*[clinic input] test_unsigned_int_converter @@ -617,10 +1056,34 @@ test_unsigned_int_converter(PyObject *module, PyObject *const *args, Py_ssize_t unsigned int b = 34; unsigned int c = 56; - if (!_PyArg_ParseStack(args, nargs, "|O&O&I:test_unsigned_int_converter", - _PyLong_UnsignedInt_Converter, &a, _PyLong_UnsignedInt_Converter, &b, &c)) { + if (!_PyArg_CheckPositional("test_unsigned_int_converter", nargs, 0, 3)) { goto exit; } + if (nargs < 1) { + goto skip_optional; + } + if (!_PyLong_UnsignedInt_Converter(args[0], &a)) { + goto exit; + } + if (nargs < 2) { + goto skip_optional; + } + if (!_PyLong_UnsignedInt_Converter(args[1], &b)) { + goto exit; + } + if (nargs < 3) { + goto skip_optional; + } + if (PyFloat_Check(args[2])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + c = (unsigned int)PyLong_AsUnsignedLongMask(args[2]); + if (c == (unsigned int)-1 && PyErr_Occurred()) { + goto exit; + } +skip_optional: return_value = test_unsigned_int_converter_impl(module, a, b, c); exit: @@ -630,7 +1093,7 @@ exit: static PyObject * test_unsigned_int_converter_impl(PyObject *module, unsigned int a, unsigned int b, unsigned int c) -/*[clinic end generated code: output=3cdb7a3ef2b369a3 input=5533534828b62fc0]*/ +/*[clinic end generated code: output=189176ce67c7d2e7 input=5533534828b62fc0]*/ /*[clinic input] test_long_converter @@ -657,10 +1120,22 @@ test_long_converter(PyObject *module, PyObject *const *args, Py_ssize_t nargs) PyObject *return_value = NULL; long a = 12; - if (!_PyArg_ParseStack(args, nargs, "|l:test_long_converter", - &a)) { + if (!_PyArg_CheckPositional("test_long_converter", 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; } + a = PyLong_AsLong(args[0]); + if (a == -1 && PyErr_Occurred()) { + goto exit; + } +skip_optional: return_value = test_long_converter_impl(module, a); exit: @@ -669,7 +1144,7 @@ exit: static PyObject * test_long_converter_impl(PyObject *module, long a) -/*[clinic end generated code: output=65a8092a1dc10de6 input=d2179e3c9cdcde89]*/ +/*[clinic end generated code: output=44cd8823f59d116b input=d2179e3c9cdcde89]*/ /*[clinic input] test_unsigned_long_converter @@ -701,10 +1176,30 @@ test_unsigned_long_converter(PyObject *module, PyObject *const *args, Py_ssize_t unsigned long b = 34; unsigned long c = 56; - if (!_PyArg_ParseStack(args, nargs, "|O&O&k:test_unsigned_long_converter", - _PyLong_UnsignedLong_Converter, &a, _PyLong_UnsignedLong_Converter, &b, &c)) { + if (!_PyArg_CheckPositional("test_unsigned_long_converter", nargs, 0, 3)) { + goto exit; + } + if (nargs < 1) { + goto skip_optional; + } + if (!_PyLong_UnsignedLong_Converter(args[0], &a)) { + goto exit; + } + if (nargs < 2) { + goto skip_optional; + } + if (!_PyLong_UnsignedLong_Converter(args[1], &b)) { + goto exit; + } + if (nargs < 3) { + goto skip_optional; + } + if (!PyLong_Check(args[2])) { + _PyArg_BadArgument("test_unsigned_long_converter", 3, "int", args[2]); goto exit; } + c = PyLong_AsUnsignedLongMask(args[2]); +skip_optional: return_value = test_unsigned_long_converter_impl(module, a, b, c); exit: @@ -714,7 +1209,7 @@ exit: static PyObject * test_unsigned_long_converter_impl(PyObject *module, unsigned long a, unsigned long b, unsigned long c) -/*[clinic end generated code: output=81fd66d8981abeb2 input=f450d94cae1ef73b]*/ +/*[clinic end generated code: output=1c05c871c0309e08 input=f450d94cae1ef73b]*/ /*[clinic input] test_long_long_converter @@ -741,10 +1236,22 @@ test_long_long_converter(PyObject *module, PyObject *const *args, Py_ssize_t nar PyObject *return_value = NULL; long long a = 12; - if (!_PyArg_ParseStack(args, nargs, "|L:test_long_long_converter", - &a)) { + if (!_PyArg_CheckPositional("test_long_long_converter", 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; } + a = PyLong_AsLongLong(args[0]); + if (a == (PY_LONG_LONG)-1 && PyErr_Occurred()) { + goto exit; + } +skip_optional: return_value = test_long_long_converter_impl(module, a); exit: @@ -753,7 +1260,7 @@ exit: static PyObject * test_long_long_converter_impl(PyObject *module, long long a) -/*[clinic end generated code: output=9412f5800661b0c0 input=d5fc81577ff4dd02]*/ +/*[clinic end generated code: output=3e8083f3aee4f18a input=d5fc81577ff4dd02]*/ /*[clinic input] test_unsigned_long_long_converter @@ -787,10 +1294,30 @@ test_unsigned_long_long_converter(PyObject *module, PyObject *const *args, Py_ss unsigned long long b = 34; unsigned long long c = 56; - if (!_PyArg_ParseStack(args, nargs, "|O&O&K:test_unsigned_long_long_converter", - _PyLong_UnsignedLongLong_Converter, &a, _PyLong_UnsignedLongLong_Converter, &b, &c)) { + if (!_PyArg_CheckPositional("test_unsigned_long_long_converter", nargs, 0, 3)) { + goto exit; + } + if (nargs < 1) { + goto skip_optional; + } + if (!_PyLong_UnsignedLongLong_Converter(args[0], &a)) { + goto exit; + } + if (nargs < 2) { + goto skip_optional; + } + if (!_PyLong_UnsignedLongLong_Converter(args[1], &b)) { + goto exit; + } + if (nargs < 3) { + goto skip_optional; + } + if (!PyLong_Check(args[2])) { + _PyArg_BadArgument("test_unsigned_long_long_converter", 3, "int", args[2]); goto exit; } + c = PyLong_AsUnsignedLongLongMask(args[2]); +skip_optional: return_value = test_unsigned_long_long_converter_impl(module, a, b, c); exit: @@ -802,7 +1329,7 @@ test_unsigned_long_long_converter_impl(PyObject *module, unsigned long long a, unsigned long long b, unsigned long long c) -/*[clinic end generated code: output=f5a57e0ccc048a32 input=a15115dc41866ff4]*/ +/*[clinic end generated code: output=0a9b17fb824e28eb input=a15115dc41866ff4]*/ /*[clinic input] test_Py_ssize_t_converter @@ -834,10 +1361,56 @@ test_Py_ssize_t_converter(PyObject *module, PyObject *const *args, Py_ssize_t na Py_ssize_t b = 34; Py_ssize_t c = 56; - if (!_PyArg_ParseStack(args, nargs, "|nnO&:test_Py_ssize_t_converter", - &a, &b, _Py_convert_optional_to_ssize_t, &c)) { + if (!_PyArg_CheckPositional("test_Py_ssize_t_converter", nargs, 0, 3)) { + 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; + } + a = ival; + } + 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; + } + b = ival; + } + if (nargs < 3) { + goto skip_optional; + } + if (!_Py_convert_optional_to_ssize_t(args[2], &c)) { + goto exit; + } +skip_optional: return_value = test_Py_ssize_t_converter_impl(module, a, b, c); exit: @@ -847,7 +1420,7 @@ exit: static PyObject * test_Py_ssize_t_converter_impl(PyObject *module, Py_ssize_t a, Py_ssize_t b, Py_ssize_t c) -/*[clinic end generated code: output=50bc360c57b40e3f input=3855f184bb3f299d]*/ +/*[clinic end generated code: output=a46d2aaf40c10398 input=3855f184bb3f299d]*/ /*[clinic input] test_slice_index_converter @@ -879,10 +1452,28 @@ test_slice_index_converter(PyObject *module, PyObject *const *args, Py_ssize_t n Py_ssize_t b = 34; Py_ssize_t c = 56; - if (!_PyArg_ParseStack(args, nargs, "|O&O&O&:test_slice_index_converter", - _PyEval_SliceIndex, &a, _PyEval_SliceIndexNotNone, &b, _PyEval_SliceIndex, &c)) { + if (!_PyArg_CheckPositional("test_slice_index_converter", nargs, 0, 3)) { + goto exit; + } + if (nargs < 1) { + goto skip_optional; + } + if (!_PyEval_SliceIndex(args[0], &a)) { + goto exit; + } + if (nargs < 2) { + goto skip_optional; + } + if (!_PyEval_SliceIndexNotNone(args[1], &b)) { goto exit; } + if (nargs < 3) { + goto skip_optional; + } + if (!_PyEval_SliceIndex(args[2], &c)) { + goto exit; + } +skip_optional: return_value = test_slice_index_converter_impl(module, a, b, c); exit: @@ -892,7 +1483,7 @@ exit: static PyObject * test_slice_index_converter_impl(PyObject *module, Py_ssize_t a, Py_ssize_t b, Py_ssize_t c) -/*[clinic end generated code: output=33b9152bf3c5963a input=edeadb0ee126f531]*/ +/*[clinic end generated code: output=2148703cd3c6e941 input=edeadb0ee126f531]*/ /*[clinic input] test_size_t_converter @@ -919,10 +1510,16 @@ test_size_t_converter(PyObject *module, PyObject *const *args, Py_ssize_t nargs) PyObject *return_value = NULL; size_t a = 12; - if (!_PyArg_ParseStack(args, nargs, "|O&:test_size_t_converter", - _PyLong_Size_t_Converter, &a)) { + if (!_PyArg_CheckPositional("test_size_t_converter", nargs, 0, 1)) { goto exit; } + if (nargs < 1) { + goto skip_optional; + } + if (!_PyLong_Size_t_Converter(args[0], &a)) { + goto exit; + } +skip_optional: return_value = test_size_t_converter_impl(module, a); exit: @@ -931,7 +1528,7 @@ exit: static PyObject * test_size_t_converter_impl(PyObject *module, size_t a) -/*[clinic end generated code: output=02fe6bf4c5a139d5 input=52e93a0fed0f1fb3]*/ +/*[clinic end generated code: output=8a91a9ca8a92dabb input=52e93a0fed0f1fb3]*/ /*[clinic input] test_float_converter @@ -958,10 +1555,17 @@ test_float_converter(PyObject *module, PyObject *const *args, Py_ssize_t nargs) PyObject *return_value = NULL; float a = 12.5; - if (!_PyArg_ParseStack(args, nargs, "|f:test_float_converter", - &a)) { + if (!_PyArg_CheckPositional("test_float_converter", nargs, 0, 1)) { + goto exit; + } + if (nargs < 1) { + goto skip_optional; + } + a = (float) PyFloat_AsDouble(args[0]); + if (PyErr_Occurred()) { goto exit; } +skip_optional: return_value = test_float_converter_impl(module, a); exit: @@ -970,7 +1574,7 @@ exit: static PyObject * test_float_converter_impl(PyObject *module, float a) -/*[clinic end generated code: output=a0689b5ee76673ad input=259c0d98eca35034]*/ +/*[clinic end generated code: output=8293566b2ec1fc52 input=259c0d98eca35034]*/ /*[clinic input] test_double_converter @@ -997,10 +1601,17 @@ test_double_converter(PyObject *module, PyObject *const *args, Py_ssize_t nargs) PyObject *return_value = NULL; double a = 12.5; - if (!_PyArg_ParseStack(args, nargs, "|d:test_double_converter", - &a)) { + if (!_PyArg_CheckPositional("test_double_converter", nargs, 0, 1)) { + goto exit; + } + if (nargs < 1) { + goto skip_optional; + } + a = PyFloat_AsDouble(args[0]); + if (PyErr_Occurred()) { goto exit; } +skip_optional: return_value = test_double_converter_impl(module, a); exit: @@ -1009,7 +1620,7 @@ exit: static PyObject * test_double_converter_impl(PyObject *module, double a) -/*[clinic end generated code: output=b78d23bd37b40681 input=c6a9945706a41c27]*/ +/*[clinic end generated code: output=487081a9b8da67ab input=c6a9945706a41c27]*/ /*[clinic input] test_Py_complex_converter diff --git a/Modules/_io/clinic/bufferedio.c.h b/Modules/_io/clinic/bufferedio.c.h index 6569e02..6345b9e 100644 --- a/Modules/_io/clinic/bufferedio.c.h +++ b/Modules/_io/clinic/bufferedio.c.h @@ -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]*/ diff --git a/Modules/_io/clinic/bytesio.c.h b/Modules/_io/clinic/bytesio.c.h index 07c8866..5588416 100644 --- a/Modules/_io/clinic/bytesio.c.h +++ b/Modules/_io/clinic/bytesio.c.h @@ -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]*/ diff --git a/Modules/_io/clinic/fileio.c.h b/Modules/_io/clinic/fileio.c.h index bf40f7f..280549e 100644 --- a/Modules/_io/clinic/fileio.c.h +++ b/Modules/_io/clinic/fileio.c.h @@ -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]*/ diff --git a/Modules/_io/clinic/iobase.c.h b/Modules/_io/clinic/iobase.c.h index 68eaadd..a5c8eea 100644 --- a/Modules/_io/clinic/iobase.c.h +++ b/Modules/_io/clinic/iobase.c.h @@ -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]*/ diff --git a/Modules/_io/clinic/stringio.c.h b/Modules/_io/clinic/stringio.c.h index 3181688..1757d83 100644 --- a/Modules/_io/clinic/stringio.c.h +++ b/Modules/_io/clinic/stringio.c.h @@ -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]*/ diff --git a/Modules/_io/clinic/textio.c.h b/Modules/_io/clinic/textio.c.h index f056416e..0ff0324 100644 --- a/Modules/_io/clinic/textio.c.h +++ b/Modules/_io/clinic/textio.c.h @@ -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]*/ diff --git a/Modules/_io/clinic/winconsoleio.c.h b/Modules/_io/clinic/winconsoleio.c.h index 65cac66..e7cd854 100644 --- a/Modules/_io/clinic/winconsoleio.c.h +++ b/Modules/_io/clinic/winconsoleio.c.h @@ -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]*/ diff --git a/Modules/cjkcodecs/clinic/multibytecodec.c.h b/Modules/cjkcodecs/clinic/multibytecodec.c.h index 1fef185..871bf33 100644 --- a/Modules/cjkcodecs/clinic/multibytecodec.c.h +++ b/Modules/cjkcodecs/clinic/multibytecodec.c.h @@ -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]*/ diff --git a/Modules/clinic/_bz2module.c.h b/Modules/clinic/_bz2module.c.h index dce746d..fb64333 100644 --- a/Modules/clinic/_bz2module.c.h +++ b/Modules/clinic/_bz2module.c.h @@ -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]*/ diff --git a/Modules/clinic/_codecsmodule.c.h b/Modules/clinic/_codecsmodule.c.h index 360a134..a8223ad 100644 --- a/Modules/clinic/_codecsmodule.c.h +++ b/Modules/clinic/_codecsmodule.c.h @@ -34,7 +34,7 @@ _codecs_lookup(PyObject *module, PyObject *arg) const char *encoding; if (!PyUnicode_Check(arg)) { - _PyArg_BadArgument("lookup", "str", arg); + _PyArg_BadArgument("lookup", 0, "str", arg); goto exit; } Py_ssize_t encoding_length; @@ -149,7 +149,7 @@ _codecs__forget_codec(PyObject *module, PyObject *arg) const char *encoding; if (!PyUnicode_Check(arg)) { - _PyArg_BadArgument("_forget_codec", "str", arg); + _PyArg_BadArgument("_forget_codec", 0, "str", arg); goto exit; } Py_ssize_t encoding_length; @@ -186,10 +186,48 @@ _codecs_escape_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) Py_buffer data = {NULL, NULL}; const char *errors = NULL; - if (!_PyArg_ParseStack(args, nargs, "s*|z:escape_decode", - &data, &errors)) { + if (!_PyArg_CheckPositional("escape_decode", nargs, 1, 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(&data, args[0], (void *)ptr, len, 1, 0); + } + else { /* any bytes-like object */ + if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) { + goto exit; + } + if (!PyBuffer_IsContiguous(&data, 'C')) { + _PyArg_BadArgument("escape_decode", 1, "contiguous buffer", args[0]); + goto exit; + } + } + if (nargs < 2) { + goto skip_optional; + } + if (args[1] == Py_None) { + errors = NULL; + } + else if (PyUnicode_Check(args[1])) { + Py_ssize_t errors_length; + errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); + if (errors == NULL) { + goto exit; + } + if (strlen(errors) != (size_t)errors_length) { + PyErr_SetString(PyExc_ValueError, "embedded null character"); + goto exit; + } + } + else { + _PyArg_BadArgument("escape_decode", 2, "str or None", args[1]); + goto exit; + } +skip_optional: return_value = _codecs_escape_decode_impl(module, &data, errors); exit: @@ -220,10 +258,36 @@ _codecs_escape_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) PyObject *data; const char *errors = NULL; - if (!_PyArg_ParseStack(args, nargs, "O!|z:escape_encode", - &PyBytes_Type, &data, &errors)) { + if (!_PyArg_CheckPositional("escape_encode", nargs, 1, 2)) { + goto exit; + } + if (!PyBytes_Check(args[0])) { + _PyArg_BadArgument("escape_encode", 1, "bytes", args[0]); + goto exit; + } + data = args[0]; + if (nargs < 2) { + goto skip_optional; + } + if (args[1] == Py_None) { + errors = NULL; + } + else if (PyUnicode_Check(args[1])) { + Py_ssize_t errors_length; + errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); + if (errors == NULL) { + goto exit; + } + if (strlen(errors) != (size_t)errors_length) { + PyErr_SetString(PyExc_ValueError, "embedded null character"); + goto exit; + } + } + else { + _PyArg_BadArgument("escape_encode", 2, "str or None", args[1]); goto exit; } +skip_optional: return_value = _codecs_escape_encode_impl(module, data, errors); exit: @@ -249,10 +313,32 @@ _codecs_unicode_internal_decode(PyObject *module, PyObject *const *args, Py_ssiz PyObject *obj; const char *errors = NULL; - if (!_PyArg_ParseStack(args, nargs, "O|z:unicode_internal_decode", - &obj, &errors)) { + if (!_PyArg_CheckPositional("unicode_internal_decode", nargs, 1, 2)) { + goto exit; + } + obj = args[0]; + if (nargs < 2) { + goto skip_optional; + } + if (args[1] == Py_None) { + errors = NULL; + } + else if (PyUnicode_Check(args[1])) { + Py_ssize_t errors_length; + errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); + if (errors == NULL) { + goto exit; + } + if (strlen(errors) != (size_t)errors_length) { + PyErr_SetString(PyExc_ValueError, "embedded null character"); + goto exit; + } + } + else { + _PyArg_BadArgument("unicode_internal_decode", 2, "str or None", args[1]); goto exit; } +skip_optional: return_value = _codecs_unicode_internal_decode_impl(module, obj, errors); exit: @@ -279,10 +365,50 @@ _codecs_utf_7_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) const char *errors = NULL; int final = 0; - if (!_PyArg_ParseStack(args, nargs, "y*|zi:utf_7_decode", - &data, &errors, &final)) { + if (!_PyArg_CheckPositional("utf_7_decode", nargs, 1, 3)) { + goto exit; + } + if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) { goto exit; } + if (!PyBuffer_IsContiguous(&data, 'C')) { + _PyArg_BadArgument("utf_7_decode", 1, "contiguous buffer", args[0]); + goto exit; + } + if (nargs < 2) { + goto skip_optional; + } + if (args[1] == Py_None) { + errors = NULL; + } + else if (PyUnicode_Check(args[1])) { + Py_ssize_t errors_length; + errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); + if (errors == NULL) { + goto exit; + } + if (strlen(errors) != (size_t)errors_length) { + PyErr_SetString(PyExc_ValueError, "embedded null character"); + goto exit; + } + } + else { + _PyArg_BadArgument("utf_7_decode", 2, "str or None", args[1]); + goto exit; + } + if (nargs < 3) { + goto skip_optional; + } + if (PyFloat_Check(args[2])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + final = _PyLong_AsInt(args[2]); + if (final == -1 && PyErr_Occurred()) { + goto exit; + } +skip_optional: return_value = _codecs_utf_7_decode_impl(module, &data, errors, final); exit: @@ -314,10 +440,50 @@ _codecs_utf_8_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) const char *errors = NULL; int final = 0; - if (!_PyArg_ParseStack(args, nargs, "y*|zi:utf_8_decode", - &data, &errors, &final)) { + if (!_PyArg_CheckPositional("utf_8_decode", nargs, 1, 3)) { goto exit; } + if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) { + goto exit; + } + if (!PyBuffer_IsContiguous(&data, 'C')) { + _PyArg_BadArgument("utf_8_decode", 1, "contiguous buffer", args[0]); + goto exit; + } + if (nargs < 2) { + goto skip_optional; + } + if (args[1] == Py_None) { + errors = NULL; + } + else if (PyUnicode_Check(args[1])) { + Py_ssize_t errors_length; + errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); + if (errors == NULL) { + goto exit; + } + if (strlen(errors) != (size_t)errors_length) { + PyErr_SetString(PyExc_ValueError, "embedded null character"); + goto exit; + } + } + else { + _PyArg_BadArgument("utf_8_decode", 2, "str or None", args[1]); + goto exit; + } + if (nargs < 3) { + goto skip_optional; + } + if (PyFloat_Check(args[2])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + final = _PyLong_AsInt(args[2]); + if (final == -1 && PyErr_Occurred()) { + goto exit; + } +skip_optional: return_value = _codecs_utf_8_decode_impl(module, &data, errors, final); exit: @@ -349,10 +515,50 @@ _codecs_utf_16_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) const char *errors = NULL; int final = 0; - if (!_PyArg_ParseStack(args, nargs, "y*|zi:utf_16_decode", - &data, &errors, &final)) { + if (!_PyArg_CheckPositional("utf_16_decode", nargs, 1, 3)) { + goto exit; + } + if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) { + goto exit; + } + if (!PyBuffer_IsContiguous(&data, 'C')) { + _PyArg_BadArgument("utf_16_decode", 1, "contiguous buffer", args[0]); + goto exit; + } + if (nargs < 2) { + goto skip_optional; + } + if (args[1] == Py_None) { + errors = NULL; + } + else if (PyUnicode_Check(args[1])) { + Py_ssize_t errors_length; + errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); + if (errors == NULL) { + goto exit; + } + if (strlen(errors) != (size_t)errors_length) { + PyErr_SetString(PyExc_ValueError, "embedded null character"); + goto exit; + } + } + else { + _PyArg_BadArgument("utf_16_decode", 2, "str or None", args[1]); + goto exit; + } + if (nargs < 3) { + goto skip_optional; + } + if (PyFloat_Check(args[2])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); goto exit; } + final = _PyLong_AsInt(args[2]); + if (final == -1 && PyErr_Occurred()) { + goto exit; + } +skip_optional: return_value = _codecs_utf_16_decode_impl(module, &data, errors, final); exit: @@ -384,10 +590,50 @@ _codecs_utf_16_le_decode(PyObject *module, PyObject *const *args, Py_ssize_t nar const char *errors = NULL; int final = 0; - if (!_PyArg_ParseStack(args, nargs, "y*|zi:utf_16_le_decode", - &data, &errors, &final)) { + if (!_PyArg_CheckPositional("utf_16_le_decode", nargs, 1, 3)) { + goto exit; + } + if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) { + goto exit; + } + if (!PyBuffer_IsContiguous(&data, 'C')) { + _PyArg_BadArgument("utf_16_le_decode", 1, "contiguous buffer", args[0]); + goto exit; + } + if (nargs < 2) { + goto skip_optional; + } + if (args[1] == Py_None) { + errors = NULL; + } + else if (PyUnicode_Check(args[1])) { + Py_ssize_t errors_length; + errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); + if (errors == NULL) { + goto exit; + } + if (strlen(errors) != (size_t)errors_length) { + PyErr_SetString(PyExc_ValueError, "embedded null character"); + goto exit; + } + } + else { + _PyArg_BadArgument("utf_16_le_decode", 2, "str or None", args[1]); + goto exit; + } + if (nargs < 3) { + goto skip_optional; + } + if (PyFloat_Check(args[2])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + final = _PyLong_AsInt(args[2]); + if (final == -1 && PyErr_Occurred()) { goto exit; } +skip_optional: return_value = _codecs_utf_16_le_decode_impl(module, &data, errors, final); exit: @@ -419,10 +665,50 @@ _codecs_utf_16_be_decode(PyObject *module, PyObject *const *args, Py_ssize_t nar const char *errors = NULL; int final = 0; - if (!_PyArg_ParseStack(args, nargs, "y*|zi:utf_16_be_decode", - &data, &errors, &final)) { + if (!_PyArg_CheckPositional("utf_16_be_decode", nargs, 1, 3)) { + goto exit; + } + if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) { goto exit; } + if (!PyBuffer_IsContiguous(&data, 'C')) { + _PyArg_BadArgument("utf_16_be_decode", 1, "contiguous buffer", args[0]); + goto exit; + } + if (nargs < 2) { + goto skip_optional; + } + if (args[1] == Py_None) { + errors = NULL; + } + else if (PyUnicode_Check(args[1])) { + Py_ssize_t errors_length; + errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); + if (errors == NULL) { + goto exit; + } + if (strlen(errors) != (size_t)errors_length) { + PyErr_SetString(PyExc_ValueError, "embedded null character"); + goto exit; + } + } + else { + _PyArg_BadArgument("utf_16_be_decode", 2, "str or None", args[1]); + goto exit; + } + if (nargs < 3) { + goto skip_optional; + } + if (PyFloat_Check(args[2])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + final = _PyLong_AsInt(args[2]); + if (final == -1 && PyErr_Occurred()) { + goto exit; + } +skip_optional: return_value = _codecs_utf_16_be_decode_impl(module, &data, errors, final); exit: @@ -456,10 +742,62 @@ _codecs_utf_16_ex_decode(PyObject *module, PyObject *const *args, Py_ssize_t nar int byteorder = 0; int final = 0; - if (!_PyArg_ParseStack(args, nargs, "y*|zii:utf_16_ex_decode", - &data, &errors, &byteorder, &final)) { + if (!_PyArg_CheckPositional("utf_16_ex_decode", nargs, 1, 4)) { + goto exit; + } + if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) { + goto exit; + } + if (!PyBuffer_IsContiguous(&data, 'C')) { + _PyArg_BadArgument("utf_16_ex_decode", 1, "contiguous buffer", args[0]); + goto exit; + } + if (nargs < 2) { + goto skip_optional; + } + if (args[1] == Py_None) { + errors = NULL; + } + else if (PyUnicode_Check(args[1])) { + Py_ssize_t errors_length; + errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); + if (errors == NULL) { + goto exit; + } + if (strlen(errors) != (size_t)errors_length) { + PyErr_SetString(PyExc_ValueError, "embedded null character"); + goto exit; + } + } + else { + _PyArg_BadArgument("utf_16_ex_decode", 2, "str or None", args[1]); goto exit; } + if (nargs < 3) { + goto skip_optional; + } + if (PyFloat_Check(args[2])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + byteorder = _PyLong_AsInt(args[2]); + if (byteorder == -1 && PyErr_Occurred()) { + goto exit; + } + if (nargs < 4) { + goto skip_optional; + } + if (PyFloat_Check(args[3])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + final = _PyLong_AsInt(args[3]); + if (final == -1 && PyErr_Occurred()) { + goto exit; + } +skip_optional: return_value = _codecs_utf_16_ex_decode_impl(module, &data, errors, byteorder, final); exit: @@ -491,10 +829,50 @@ _codecs_utf_32_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) const char *errors = NULL; int final = 0; - if (!_PyArg_ParseStack(args, nargs, "y*|zi:utf_32_decode", - &data, &errors, &final)) { + if (!_PyArg_CheckPositional("utf_32_decode", nargs, 1, 3)) { + goto exit; + } + if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) { + goto exit; + } + if (!PyBuffer_IsContiguous(&data, 'C')) { + _PyArg_BadArgument("utf_32_decode", 1, "contiguous buffer", args[0]); + goto exit; + } + if (nargs < 2) { + goto skip_optional; + } + if (args[1] == Py_None) { + errors = NULL; + } + else if (PyUnicode_Check(args[1])) { + Py_ssize_t errors_length; + errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); + if (errors == NULL) { + goto exit; + } + if (strlen(errors) != (size_t)errors_length) { + PyErr_SetString(PyExc_ValueError, "embedded null character"); + goto exit; + } + } + else { + _PyArg_BadArgument("utf_32_decode", 2, "str or None", args[1]); + goto exit; + } + if (nargs < 3) { + goto skip_optional; + } + if (PyFloat_Check(args[2])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); goto exit; } + final = _PyLong_AsInt(args[2]); + if (final == -1 && PyErr_Occurred()) { + goto exit; + } +skip_optional: return_value = _codecs_utf_32_decode_impl(module, &data, errors, final); exit: @@ -526,10 +904,50 @@ _codecs_utf_32_le_decode(PyObject *module, PyObject *const *args, Py_ssize_t nar const char *errors = NULL; int final = 0; - if (!_PyArg_ParseStack(args, nargs, "y*|zi:utf_32_le_decode", - &data, &errors, &final)) { + if (!_PyArg_CheckPositional("utf_32_le_decode", nargs, 1, 3)) { + goto exit; + } + if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) { + goto exit; + } + if (!PyBuffer_IsContiguous(&data, 'C')) { + _PyArg_BadArgument("utf_32_le_decode", 1, "contiguous buffer", args[0]); + goto exit; + } + if (nargs < 2) { + goto skip_optional; + } + if (args[1] == Py_None) { + errors = NULL; + } + else if (PyUnicode_Check(args[1])) { + Py_ssize_t errors_length; + errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); + if (errors == NULL) { + goto exit; + } + if (strlen(errors) != (size_t)errors_length) { + PyErr_SetString(PyExc_ValueError, "embedded null character"); + goto exit; + } + } + else { + _PyArg_BadArgument("utf_32_le_decode", 2, "str or None", args[1]); goto exit; } + if (nargs < 3) { + goto skip_optional; + } + if (PyFloat_Check(args[2])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + final = _PyLong_AsInt(args[2]); + if (final == -1 && PyErr_Occurred()) { + goto exit; + } +skip_optional: return_value = _codecs_utf_32_le_decode_impl(module, &data, errors, final); exit: @@ -561,10 +979,50 @@ _codecs_utf_32_be_decode(PyObject *module, PyObject *const *args, Py_ssize_t nar const char *errors = NULL; int final = 0; - if (!_PyArg_ParseStack(args, nargs, "y*|zi:utf_32_be_decode", - &data, &errors, &final)) { + if (!_PyArg_CheckPositional("utf_32_be_decode", nargs, 1, 3)) { + goto exit; + } + if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) { goto exit; } + if (!PyBuffer_IsContiguous(&data, 'C')) { + _PyArg_BadArgument("utf_32_be_decode", 1, "contiguous buffer", args[0]); + goto exit; + } + if (nargs < 2) { + goto skip_optional; + } + if (args[1] == Py_None) { + errors = NULL; + } + else if (PyUnicode_Check(args[1])) { + Py_ssize_t errors_length; + errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); + if (errors == NULL) { + goto exit; + } + if (strlen(errors) != (size_t)errors_length) { + PyErr_SetString(PyExc_ValueError, "embedded null character"); + goto exit; + } + } + else { + _PyArg_BadArgument("utf_32_be_decode", 2, "str or None", args[1]); + goto exit; + } + if (nargs < 3) { + goto skip_optional; + } + if (PyFloat_Check(args[2])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + final = _PyLong_AsInt(args[2]); + if (final == -1 && PyErr_Occurred()) { + goto exit; + } +skip_optional: return_value = _codecs_utf_32_be_decode_impl(module, &data, errors, final); exit: @@ -598,10 +1056,62 @@ _codecs_utf_32_ex_decode(PyObject *module, PyObject *const *args, Py_ssize_t nar int byteorder = 0; int final = 0; - if (!_PyArg_ParseStack(args, nargs, "y*|zii:utf_32_ex_decode", - &data, &errors, &byteorder, &final)) { + if (!_PyArg_CheckPositional("utf_32_ex_decode", nargs, 1, 4)) { goto exit; } + if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) { + goto exit; + } + if (!PyBuffer_IsContiguous(&data, 'C')) { + _PyArg_BadArgument("utf_32_ex_decode", 1, "contiguous buffer", args[0]); + goto exit; + } + if (nargs < 2) { + goto skip_optional; + } + if (args[1] == Py_None) { + errors = NULL; + } + else if (PyUnicode_Check(args[1])) { + Py_ssize_t errors_length; + errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); + if (errors == NULL) { + goto exit; + } + if (strlen(errors) != (size_t)errors_length) { + PyErr_SetString(PyExc_ValueError, "embedded null character"); + goto exit; + } + } + else { + _PyArg_BadArgument("utf_32_ex_decode", 2, "str or None", args[1]); + goto exit; + } + if (nargs < 3) { + goto skip_optional; + } + if (PyFloat_Check(args[2])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + byteorder = _PyLong_AsInt(args[2]); + if (byteorder == -1 && PyErr_Occurred()) { + goto exit; + } + if (nargs < 4) { + goto skip_optional; + } + if (PyFloat_Check(args[3])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + final = _PyLong_AsInt(args[3]); + if (final == -1 && PyErr_Occurred()) { + goto exit; + } +skip_optional: return_value = _codecs_utf_32_ex_decode_impl(module, &data, errors, byteorder, final); exit: @@ -632,10 +1142,48 @@ _codecs_unicode_escape_decode(PyObject *module, PyObject *const *args, Py_ssize_ Py_buffer data = {NULL, NULL}; const char *errors = NULL; - if (!_PyArg_ParseStack(args, nargs, "s*|z:unicode_escape_decode", - &data, &errors)) { + if (!_PyArg_CheckPositional("unicode_escape_decode", nargs, 1, 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(&data, args[0], (void *)ptr, len, 1, 0); + } + else { /* any bytes-like object */ + if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) { + goto exit; + } + if (!PyBuffer_IsContiguous(&data, 'C')) { + _PyArg_BadArgument("unicode_escape_decode", 1, "contiguous buffer", args[0]); + goto exit; + } + } + if (nargs < 2) { + goto skip_optional; + } + if (args[1] == Py_None) { + errors = NULL; + } + else if (PyUnicode_Check(args[1])) { + Py_ssize_t errors_length; + errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); + if (errors == NULL) { + goto exit; + } + if (strlen(errors) != (size_t)errors_length) { + PyErr_SetString(PyExc_ValueError, "embedded null character"); + goto exit; + } + } + else { + _PyArg_BadArgument("unicode_escape_decode", 2, "str or None", args[1]); goto exit; } +skip_optional: return_value = _codecs_unicode_escape_decode_impl(module, &data, errors); exit: @@ -666,10 +1214,48 @@ _codecs_raw_unicode_escape_decode(PyObject *module, PyObject *const *args, Py_ss Py_buffer data = {NULL, NULL}; const char *errors = NULL; - if (!_PyArg_ParseStack(args, nargs, "s*|z:raw_unicode_escape_decode", - &data, &errors)) { + if (!_PyArg_CheckPositional("raw_unicode_escape_decode", nargs, 1, 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(&data, args[0], (void *)ptr, len, 1, 0); + } + else { /* any bytes-like object */ + if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) { + goto exit; + } + if (!PyBuffer_IsContiguous(&data, 'C')) { + _PyArg_BadArgument("raw_unicode_escape_decode", 1, "contiguous buffer", args[0]); + goto exit; + } + } + if (nargs < 2) { + goto skip_optional; + } + if (args[1] == Py_None) { + errors = NULL; + } + else if (PyUnicode_Check(args[1])) { + Py_ssize_t errors_length; + errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); + if (errors == NULL) { + goto exit; + } + if (strlen(errors) != (size_t)errors_length) { + PyErr_SetString(PyExc_ValueError, "embedded null character"); + goto exit; + } + } + else { + _PyArg_BadArgument("raw_unicode_escape_decode", 2, "str or None", args[1]); goto exit; } +skip_optional: return_value = _codecs_raw_unicode_escape_decode_impl(module, &data, errors); exit: @@ -700,10 +1286,38 @@ _codecs_latin_1_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs Py_buffer data = {NULL, NULL}; const char *errors = NULL; - if (!_PyArg_ParseStack(args, nargs, "y*|z:latin_1_decode", - &data, &errors)) { + if (!_PyArg_CheckPositional("latin_1_decode", nargs, 1, 2)) { + goto exit; + } + if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) { + goto exit; + } + if (!PyBuffer_IsContiguous(&data, 'C')) { + _PyArg_BadArgument("latin_1_decode", 1, "contiguous buffer", args[0]); goto exit; } + if (nargs < 2) { + goto skip_optional; + } + if (args[1] == Py_None) { + errors = NULL; + } + else if (PyUnicode_Check(args[1])) { + Py_ssize_t errors_length; + errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); + if (errors == NULL) { + goto exit; + } + if (strlen(errors) != (size_t)errors_length) { + PyErr_SetString(PyExc_ValueError, "embedded null character"); + goto exit; + } + } + else { + _PyArg_BadArgument("latin_1_decode", 2, "str or None", args[1]); + goto exit; + } +skip_optional: return_value = _codecs_latin_1_decode_impl(module, &data, errors); exit: @@ -734,10 +1348,38 @@ _codecs_ascii_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) Py_buffer data = {NULL, NULL}; const char *errors = NULL; - if (!_PyArg_ParseStack(args, nargs, "y*|z:ascii_decode", - &data, &errors)) { + if (!_PyArg_CheckPositional("ascii_decode", nargs, 1, 2)) { + goto exit; + } + if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) { + goto exit; + } + if (!PyBuffer_IsContiguous(&data, 'C')) { + _PyArg_BadArgument("ascii_decode", 1, "contiguous buffer", args[0]); + goto exit; + } + if (nargs < 2) { + goto skip_optional; + } + if (args[1] == Py_None) { + errors = NULL; + } + else if (PyUnicode_Check(args[1])) { + Py_ssize_t errors_length; + errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); + if (errors == NULL) { + goto exit; + } + if (strlen(errors) != (size_t)errors_length) { + PyErr_SetString(PyExc_ValueError, "embedded null character"); + goto exit; + } + } + else { + _PyArg_BadArgument("ascii_decode", 2, "str or None", args[1]); goto exit; } +skip_optional: return_value = _codecs_ascii_decode_impl(module, &data, errors); exit: @@ -769,10 +1411,42 @@ _codecs_charmap_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs const char *errors = NULL; PyObject *mapping = NULL; - if (!_PyArg_ParseStack(args, nargs, "y*|zO:charmap_decode", - &data, &errors, &mapping)) { + if (!_PyArg_CheckPositional("charmap_decode", nargs, 1, 3)) { + goto exit; + } + if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) { goto exit; } + if (!PyBuffer_IsContiguous(&data, 'C')) { + _PyArg_BadArgument("charmap_decode", 1, "contiguous buffer", args[0]); + goto exit; + } + if (nargs < 2) { + goto skip_optional; + } + if (args[1] == Py_None) { + errors = NULL; + } + else if (PyUnicode_Check(args[1])) { + Py_ssize_t errors_length; + errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); + if (errors == NULL) { + goto exit; + } + if (strlen(errors) != (size_t)errors_length) { + PyErr_SetString(PyExc_ValueError, "embedded null character"); + goto exit; + } + } + else { + _PyArg_BadArgument("charmap_decode", 2, "str or None", args[1]); + goto exit; + } + if (nargs < 3) { + goto skip_optional; + } + mapping = args[2]; +skip_optional: return_value = _codecs_charmap_decode_impl(module, &data, errors, mapping); exit: @@ -806,10 +1480,50 @@ _codecs_mbcs_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) const char *errors = NULL; int final = 0; - if (!_PyArg_ParseStack(args, nargs, "y*|zi:mbcs_decode", - &data, &errors, &final)) { + if (!_PyArg_CheckPositional("mbcs_decode", nargs, 1, 3)) { + goto exit; + } + if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) { + goto exit; + } + if (!PyBuffer_IsContiguous(&data, 'C')) { + _PyArg_BadArgument("mbcs_decode", 1, "contiguous buffer", args[0]); goto exit; } + if (nargs < 2) { + goto skip_optional; + } + if (args[1] == Py_None) { + errors = NULL; + } + else if (PyUnicode_Check(args[1])) { + Py_ssize_t errors_length; + errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); + if (errors == NULL) { + goto exit; + } + if (strlen(errors) != (size_t)errors_length) { + PyErr_SetString(PyExc_ValueError, "embedded null character"); + goto exit; + } + } + else { + _PyArg_BadArgument("mbcs_decode", 2, "str or None", args[1]); + goto exit; + } + if (nargs < 3) { + goto skip_optional; + } + if (PyFloat_Check(args[2])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + final = _PyLong_AsInt(args[2]); + if (final == -1 && PyErr_Occurred()) { + goto exit; + } +skip_optional: return_value = _codecs_mbcs_decode_impl(module, &data, errors, final); exit: @@ -845,10 +1559,50 @@ _codecs_oem_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) const char *errors = NULL; int final = 0; - if (!_PyArg_ParseStack(args, nargs, "y*|zi:oem_decode", - &data, &errors, &final)) { + if (!_PyArg_CheckPositional("oem_decode", nargs, 1, 3)) { + goto exit; + } + if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) { + goto exit; + } + if (!PyBuffer_IsContiguous(&data, 'C')) { + _PyArg_BadArgument("oem_decode", 1, "contiguous buffer", args[0]); + goto exit; + } + if (nargs < 2) { + goto skip_optional; + } + if (args[1] == Py_None) { + errors = NULL; + } + else if (PyUnicode_Check(args[1])) { + Py_ssize_t errors_length; + errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); + if (errors == NULL) { + goto exit; + } + if (strlen(errors) != (size_t)errors_length) { + PyErr_SetString(PyExc_ValueError, "embedded null character"); + goto exit; + } + } + else { + _PyArg_BadArgument("oem_decode", 2, "str or None", args[1]); + goto exit; + } + if (nargs < 3) { + goto skip_optional; + } + if (PyFloat_Check(args[2])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + final = _PyLong_AsInt(args[2]); + if (final == -1 && PyErr_Occurred()) { goto exit; } +skip_optional: return_value = _codecs_oem_decode_impl(module, &data, errors, final); exit: @@ -885,10 +1639,59 @@ _codecs_code_page_decode(PyObject *module, PyObject *const *args, Py_ssize_t nar const char *errors = NULL; int final = 0; - if (!_PyArg_ParseStack(args, nargs, "iy*|zi:code_page_decode", - &codepage, &data, &errors, &final)) { + if (!_PyArg_CheckPositional("code_page_decode", nargs, 2, 4)) { + goto exit; + } + if (PyFloat_Check(args[0])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); goto exit; } + codepage = _PyLong_AsInt(args[0]); + if (codepage == -1 && PyErr_Occurred()) { + goto exit; + } + if (PyObject_GetBuffer(args[1], &data, PyBUF_SIMPLE) != 0) { + goto exit; + } + if (!PyBuffer_IsContiguous(&data, 'C')) { + _PyArg_BadArgument("code_page_decode", 2, "contiguous buffer", args[1]); + goto exit; + } + if (nargs < 3) { + goto skip_optional; + } + if (args[2] == Py_None) { + errors = NULL; + } + else if (PyUnicode_Check(args[2])) { + Py_ssize_t errors_length; + errors = PyUnicode_AsUTF8AndSize(args[2], &errors_length); + if (errors == NULL) { + goto exit; + } + if (strlen(errors) != (size_t)errors_length) { + PyErr_SetString(PyExc_ValueError, "embedded null character"); + goto exit; + } + } + else { + _PyArg_BadArgument("code_page_decode", 3, "str or None", args[2]); + goto exit; + } + if (nargs < 4) { + goto skip_optional; + } + if (PyFloat_Check(args[3])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + final = _PyLong_AsInt(args[3]); + if (final == -1 && PyErr_Occurred()) { + goto exit; + } +skip_optional: return_value = _codecs_code_page_decode_impl(module, codepage, &data, errors, final); exit: @@ -921,10 +1724,48 @@ _codecs_readbuffer_encode(PyObject *module, PyObject *const *args, Py_ssize_t na Py_buffer data = {NULL, NULL}; const char *errors = NULL; - if (!_PyArg_ParseStack(args, nargs, "s*|z:readbuffer_encode", - &data, &errors)) { + if (!_PyArg_CheckPositional("readbuffer_encode", nargs, 1, 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(&data, args[0], (void *)ptr, len, 1, 0); + } + else { /* any bytes-like object */ + if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) { + goto exit; + } + if (!PyBuffer_IsContiguous(&data, 'C')) { + _PyArg_BadArgument("readbuffer_encode", 1, "contiguous buffer", args[0]); + goto exit; + } + } + if (nargs < 2) { + goto skip_optional; + } + if (args[1] == Py_None) { + errors = NULL; + } + else if (PyUnicode_Check(args[1])) { + Py_ssize_t errors_length; + errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); + if (errors == NULL) { + goto exit; + } + if (strlen(errors) != (size_t)errors_length) { + PyErr_SetString(PyExc_ValueError, "embedded null character"); + goto exit; + } + } + else { + _PyArg_BadArgument("readbuffer_encode", 2, "str or None", args[1]); goto exit; } +skip_optional: return_value = _codecs_readbuffer_encode_impl(module, &data, errors); exit: @@ -955,10 +1796,32 @@ _codecs_unicode_internal_encode(PyObject *module, PyObject *const *args, Py_ssiz PyObject *obj; const char *errors = NULL; - if (!_PyArg_ParseStack(args, nargs, "O|z:unicode_internal_encode", - &obj, &errors)) { + if (!_PyArg_CheckPositional("unicode_internal_encode", nargs, 1, 2)) { goto exit; } + obj = args[0]; + if (nargs < 2) { + goto skip_optional; + } + if (args[1] == Py_None) { + errors = NULL; + } + else if (PyUnicode_Check(args[1])) { + Py_ssize_t errors_length; + errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); + if (errors == NULL) { + goto exit; + } + if (strlen(errors) != (size_t)errors_length) { + PyErr_SetString(PyExc_ValueError, "embedded null character"); + goto exit; + } + } + else { + _PyArg_BadArgument("unicode_internal_encode", 2, "str or None", args[1]); + goto exit; + } +skip_optional: return_value = _codecs_unicode_internal_encode_impl(module, obj, errors); exit: @@ -984,10 +1847,39 @@ _codecs_utf_7_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) PyObject *str; const char *errors = NULL; - if (!_PyArg_ParseStack(args, nargs, "U|z:utf_7_encode", - &str, &errors)) { + if (!_PyArg_CheckPositional("utf_7_encode", nargs, 1, 2)) { + goto exit; + } + if (!PyUnicode_Check(args[0])) { + _PyArg_BadArgument("utf_7_encode", 1, "str", args[0]); goto exit; } + if (PyUnicode_READY(args[0]) == -1) { + goto exit; + } + str = args[0]; + if (nargs < 2) { + goto skip_optional; + } + if (args[1] == Py_None) { + errors = NULL; + } + else if (PyUnicode_Check(args[1])) { + Py_ssize_t errors_length; + errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); + if (errors == NULL) { + goto exit; + } + if (strlen(errors) != (size_t)errors_length) { + PyErr_SetString(PyExc_ValueError, "embedded null character"); + goto exit; + } + } + else { + _PyArg_BadArgument("utf_7_encode", 2, "str or None", args[1]); + goto exit; + } +skip_optional: return_value = _codecs_utf_7_encode_impl(module, str, errors); exit: @@ -1013,10 +1905,39 @@ _codecs_utf_8_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) PyObject *str; const char *errors = NULL; - if (!_PyArg_ParseStack(args, nargs, "U|z:utf_8_encode", - &str, &errors)) { + if (!_PyArg_CheckPositional("utf_8_encode", nargs, 1, 2)) { + goto exit; + } + if (!PyUnicode_Check(args[0])) { + _PyArg_BadArgument("utf_8_encode", 1, "str", args[0]); + goto exit; + } + if (PyUnicode_READY(args[0]) == -1) { + goto exit; + } + str = args[0]; + if (nargs < 2) { + goto skip_optional; + } + if (args[1] == Py_None) { + errors = NULL; + } + else if (PyUnicode_Check(args[1])) { + Py_ssize_t errors_length; + errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); + if (errors == NULL) { + goto exit; + } + if (strlen(errors) != (size_t)errors_length) { + PyErr_SetString(PyExc_ValueError, "embedded null character"); + goto exit; + } + } + else { + _PyArg_BadArgument("utf_8_encode", 2, "str or None", args[1]); goto exit; } +skip_optional: return_value = _codecs_utf_8_encode_impl(module, str, errors); exit: @@ -1043,10 +1964,51 @@ _codecs_utf_16_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) const char *errors = NULL; int byteorder = 0; - if (!_PyArg_ParseStack(args, nargs, "U|zi:utf_16_encode", - &str, &errors, &byteorder)) { + if (!_PyArg_CheckPositional("utf_16_encode", nargs, 1, 3)) { goto exit; } + if (!PyUnicode_Check(args[0])) { + _PyArg_BadArgument("utf_16_encode", 1, "str", args[0]); + goto exit; + } + if (PyUnicode_READY(args[0]) == -1) { + goto exit; + } + str = args[0]; + if (nargs < 2) { + goto skip_optional; + } + if (args[1] == Py_None) { + errors = NULL; + } + else if (PyUnicode_Check(args[1])) { + Py_ssize_t errors_length; + errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); + if (errors == NULL) { + goto exit; + } + if (strlen(errors) != (size_t)errors_length) { + PyErr_SetString(PyExc_ValueError, "embedded null character"); + goto exit; + } + } + else { + _PyArg_BadArgument("utf_16_encode", 2, "str or None", args[1]); + goto exit; + } + if (nargs < 3) { + goto skip_optional; + } + if (PyFloat_Check(args[2])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + byteorder = _PyLong_AsInt(args[2]); + if (byteorder == -1 && PyErr_Occurred()) { + goto exit; + } +skip_optional: return_value = _codecs_utf_16_encode_impl(module, str, errors, byteorder); exit: @@ -1072,10 +2034,39 @@ _codecs_utf_16_le_encode(PyObject *module, PyObject *const *args, Py_ssize_t nar PyObject *str; const char *errors = NULL; - if (!_PyArg_ParseStack(args, nargs, "U|z:utf_16_le_encode", - &str, &errors)) { + if (!_PyArg_CheckPositional("utf_16_le_encode", nargs, 1, 2)) { + goto exit; + } + if (!PyUnicode_Check(args[0])) { + _PyArg_BadArgument("utf_16_le_encode", 1, "str", args[0]); + goto exit; + } + if (PyUnicode_READY(args[0]) == -1) { goto exit; } + str = args[0]; + if (nargs < 2) { + goto skip_optional; + } + if (args[1] == Py_None) { + errors = NULL; + } + else if (PyUnicode_Check(args[1])) { + Py_ssize_t errors_length; + errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); + if (errors == NULL) { + goto exit; + } + if (strlen(errors) != (size_t)errors_length) { + PyErr_SetString(PyExc_ValueError, "embedded null character"); + goto exit; + } + } + else { + _PyArg_BadArgument("utf_16_le_encode", 2, "str or None", args[1]); + goto exit; + } +skip_optional: return_value = _codecs_utf_16_le_encode_impl(module, str, errors); exit: @@ -1101,10 +2092,39 @@ _codecs_utf_16_be_encode(PyObject *module, PyObject *const *args, Py_ssize_t nar PyObject *str; const char *errors = NULL; - if (!_PyArg_ParseStack(args, nargs, "U|z:utf_16_be_encode", - &str, &errors)) { + if (!_PyArg_CheckPositional("utf_16_be_encode", nargs, 1, 2)) { goto exit; } + if (!PyUnicode_Check(args[0])) { + _PyArg_BadArgument("utf_16_be_encode", 1, "str", args[0]); + goto exit; + } + if (PyUnicode_READY(args[0]) == -1) { + goto exit; + } + str = args[0]; + if (nargs < 2) { + goto skip_optional; + } + if (args[1] == Py_None) { + errors = NULL; + } + else if (PyUnicode_Check(args[1])) { + Py_ssize_t errors_length; + errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); + if (errors == NULL) { + goto exit; + } + if (strlen(errors) != (size_t)errors_length) { + PyErr_SetString(PyExc_ValueError, "embedded null character"); + goto exit; + } + } + else { + _PyArg_BadArgument("utf_16_be_encode", 2, "str or None", args[1]); + goto exit; + } +skip_optional: return_value = _codecs_utf_16_be_encode_impl(module, str, errors); exit: @@ -1131,10 +2151,51 @@ _codecs_utf_32_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) const char *errors = NULL; int byteorder = 0; - if (!_PyArg_ParseStack(args, nargs, "U|zi:utf_32_encode", - &str, &errors, &byteorder)) { + if (!_PyArg_CheckPositional("utf_32_encode", nargs, 1, 3)) { + goto exit; + } + if (!PyUnicode_Check(args[0])) { + _PyArg_BadArgument("utf_32_encode", 1, "str", args[0]); + goto exit; + } + if (PyUnicode_READY(args[0]) == -1) { + goto exit; + } + str = args[0]; + if (nargs < 2) { + goto skip_optional; + } + if (args[1] == Py_None) { + errors = NULL; + } + else if (PyUnicode_Check(args[1])) { + Py_ssize_t errors_length; + errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); + if (errors == NULL) { + goto exit; + } + if (strlen(errors) != (size_t)errors_length) { + PyErr_SetString(PyExc_ValueError, "embedded null character"); + goto exit; + } + } + else { + _PyArg_BadArgument("utf_32_encode", 2, "str or None", args[1]); goto exit; } + if (nargs < 3) { + goto skip_optional; + } + if (PyFloat_Check(args[2])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + byteorder = _PyLong_AsInt(args[2]); + if (byteorder == -1 && PyErr_Occurred()) { + goto exit; + } +skip_optional: return_value = _codecs_utf_32_encode_impl(module, str, errors, byteorder); exit: @@ -1160,10 +2221,39 @@ _codecs_utf_32_le_encode(PyObject *module, PyObject *const *args, Py_ssize_t nar PyObject *str; const char *errors = NULL; - if (!_PyArg_ParseStack(args, nargs, "U|z:utf_32_le_encode", - &str, &errors)) { + if (!_PyArg_CheckPositional("utf_32_le_encode", nargs, 1, 2)) { + goto exit; + } + if (!PyUnicode_Check(args[0])) { + _PyArg_BadArgument("utf_32_le_encode", 1, "str", args[0]); + goto exit; + } + if (PyUnicode_READY(args[0]) == -1) { + goto exit; + } + str = args[0]; + if (nargs < 2) { + goto skip_optional; + } + if (args[1] == Py_None) { + errors = NULL; + } + else if (PyUnicode_Check(args[1])) { + Py_ssize_t errors_length; + errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); + if (errors == NULL) { + goto exit; + } + if (strlen(errors) != (size_t)errors_length) { + PyErr_SetString(PyExc_ValueError, "embedded null character"); + goto exit; + } + } + else { + _PyArg_BadArgument("utf_32_le_encode", 2, "str or None", args[1]); goto exit; } +skip_optional: return_value = _codecs_utf_32_le_encode_impl(module, str, errors); exit: @@ -1189,10 +2279,39 @@ _codecs_utf_32_be_encode(PyObject *module, PyObject *const *args, Py_ssize_t nar PyObject *str; const char *errors = NULL; - if (!_PyArg_ParseStack(args, nargs, "U|z:utf_32_be_encode", - &str, &errors)) { + if (!_PyArg_CheckPositional("utf_32_be_encode", nargs, 1, 2)) { + goto exit; + } + if (!PyUnicode_Check(args[0])) { + _PyArg_BadArgument("utf_32_be_encode", 1, "str", args[0]); + goto exit; + } + if (PyUnicode_READY(args[0]) == -1) { goto exit; } + str = args[0]; + if (nargs < 2) { + goto skip_optional; + } + if (args[1] == Py_None) { + errors = NULL; + } + else if (PyUnicode_Check(args[1])) { + Py_ssize_t errors_length; + errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); + if (errors == NULL) { + goto exit; + } + if (strlen(errors) != (size_t)errors_length) { + PyErr_SetString(PyExc_ValueError, "embedded null character"); + goto exit; + } + } + else { + _PyArg_BadArgument("utf_32_be_encode", 2, "str or None", args[1]); + goto exit; + } +skip_optional: return_value = _codecs_utf_32_be_encode_impl(module, str, errors); exit: @@ -1218,10 +2337,39 @@ _codecs_unicode_escape_encode(PyObject *module, PyObject *const *args, Py_ssize_ PyObject *str; const char *errors = NULL; - if (!_PyArg_ParseStack(args, nargs, "U|z:unicode_escape_encode", - &str, &errors)) { + if (!_PyArg_CheckPositional("unicode_escape_encode", nargs, 1, 2)) { goto exit; } + if (!PyUnicode_Check(args[0])) { + _PyArg_BadArgument("unicode_escape_encode", 1, "str", args[0]); + goto exit; + } + if (PyUnicode_READY(args[0]) == -1) { + goto exit; + } + str = args[0]; + if (nargs < 2) { + goto skip_optional; + } + if (args[1] == Py_None) { + errors = NULL; + } + else if (PyUnicode_Check(args[1])) { + Py_ssize_t errors_length; + errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); + if (errors == NULL) { + goto exit; + } + if (strlen(errors) != (size_t)errors_length) { + PyErr_SetString(PyExc_ValueError, "embedded null character"); + goto exit; + } + } + else { + _PyArg_BadArgument("unicode_escape_encode", 2, "str or None", args[1]); + goto exit; + } +skip_optional: return_value = _codecs_unicode_escape_encode_impl(module, str, errors); exit: @@ -1247,10 +2395,39 @@ _codecs_raw_unicode_escape_encode(PyObject *module, PyObject *const *args, Py_ss PyObject *str; const char *errors = NULL; - if (!_PyArg_ParseStack(args, nargs, "U|z:raw_unicode_escape_encode", - &str, &errors)) { + if (!_PyArg_CheckPositional("raw_unicode_escape_encode", nargs, 1, 2)) { + goto exit; + } + if (!PyUnicode_Check(args[0])) { + _PyArg_BadArgument("raw_unicode_escape_encode", 1, "str", args[0]); goto exit; } + if (PyUnicode_READY(args[0]) == -1) { + goto exit; + } + str = args[0]; + if (nargs < 2) { + goto skip_optional; + } + if (args[1] == Py_None) { + errors = NULL; + } + else if (PyUnicode_Check(args[1])) { + Py_ssize_t errors_length; + errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); + if (errors == NULL) { + goto exit; + } + if (strlen(errors) != (size_t)errors_length) { + PyErr_SetString(PyExc_ValueError, "embedded null character"); + goto exit; + } + } + else { + _PyArg_BadArgument("raw_unicode_escape_encode", 2, "str or None", args[1]); + goto exit; + } +skip_optional: return_value = _codecs_raw_unicode_escape_encode_impl(module, str, errors); exit: @@ -1276,10 +2453,39 @@ _codecs_latin_1_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs PyObject *str; const char *errors = NULL; - if (!_PyArg_ParseStack(args, nargs, "U|z:latin_1_encode", - &str, &errors)) { + if (!_PyArg_CheckPositional("latin_1_encode", nargs, 1, 2)) { goto exit; } + if (!PyUnicode_Check(args[0])) { + _PyArg_BadArgument("latin_1_encode", 1, "str", args[0]); + goto exit; + } + if (PyUnicode_READY(args[0]) == -1) { + goto exit; + } + str = args[0]; + if (nargs < 2) { + goto skip_optional; + } + if (args[1] == Py_None) { + errors = NULL; + } + else if (PyUnicode_Check(args[1])) { + Py_ssize_t errors_length; + errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); + if (errors == NULL) { + goto exit; + } + if (strlen(errors) != (size_t)errors_length) { + PyErr_SetString(PyExc_ValueError, "embedded null character"); + goto exit; + } + } + else { + _PyArg_BadArgument("latin_1_encode", 2, "str or None", args[1]); + goto exit; + } +skip_optional: return_value = _codecs_latin_1_encode_impl(module, str, errors); exit: @@ -1305,10 +2511,39 @@ _codecs_ascii_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) PyObject *str; const char *errors = NULL; - if (!_PyArg_ParseStack(args, nargs, "U|z:ascii_encode", - &str, &errors)) { + if (!_PyArg_CheckPositional("ascii_encode", nargs, 1, 2)) { + goto exit; + } + if (!PyUnicode_Check(args[0])) { + _PyArg_BadArgument("ascii_encode", 1, "str", args[0]); + goto exit; + } + if (PyUnicode_READY(args[0]) == -1) { goto exit; } + str = args[0]; + if (nargs < 2) { + goto skip_optional; + } + if (args[1] == Py_None) { + errors = NULL; + } + else if (PyUnicode_Check(args[1])) { + Py_ssize_t errors_length; + errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); + if (errors == NULL) { + goto exit; + } + if (strlen(errors) != (size_t)errors_length) { + PyErr_SetString(PyExc_ValueError, "embedded null character"); + goto exit; + } + } + else { + _PyArg_BadArgument("ascii_encode", 2, "str or None", args[1]); + goto exit; + } +skip_optional: return_value = _codecs_ascii_encode_impl(module, str, errors); exit: @@ -1335,10 +2570,43 @@ _codecs_charmap_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs const char *errors = NULL; PyObject *mapping = NULL; - if (!_PyArg_ParseStack(args, nargs, "U|zO:charmap_encode", - &str, &errors, &mapping)) { + if (!_PyArg_CheckPositional("charmap_encode", nargs, 1, 3)) { + goto exit; + } + if (!PyUnicode_Check(args[0])) { + _PyArg_BadArgument("charmap_encode", 1, "str", args[0]); + goto exit; + } + if (PyUnicode_READY(args[0]) == -1) { + goto exit; + } + str = args[0]; + if (nargs < 2) { + goto skip_optional; + } + if (args[1] == Py_None) { + errors = NULL; + } + else if (PyUnicode_Check(args[1])) { + Py_ssize_t errors_length; + errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); + if (errors == NULL) { + goto exit; + } + if (strlen(errors) != (size_t)errors_length) { + PyErr_SetString(PyExc_ValueError, "embedded null character"); + goto exit; + } + } + else { + _PyArg_BadArgument("charmap_encode", 2, "str or None", args[1]); goto exit; } + if (nargs < 3) { + goto skip_optional; + } + mapping = args[2]; +skip_optional: return_value = _codecs_charmap_encode_impl(module, str, errors, mapping); exit: @@ -1363,7 +2631,7 @@ _codecs_charmap_build(PyObject *module, PyObject *arg) PyObject *map; if (!PyUnicode_Check(arg)) { - _PyArg_BadArgument("charmap_build", "str", arg); + _PyArg_BadArgument("charmap_build", 0, "str", arg); goto exit; } if (PyUnicode_READY(arg) == -1) { @@ -1396,10 +2664,39 @@ _codecs_mbcs_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) PyObject *str; const char *errors = NULL; - if (!_PyArg_ParseStack(args, nargs, "U|z:mbcs_encode", - &str, &errors)) { + if (!_PyArg_CheckPositional("mbcs_encode", nargs, 1, 2)) { goto exit; } + if (!PyUnicode_Check(args[0])) { + _PyArg_BadArgument("mbcs_encode", 1, "str", args[0]); + goto exit; + } + if (PyUnicode_READY(args[0]) == -1) { + goto exit; + } + str = args[0]; + if (nargs < 2) { + goto skip_optional; + } + if (args[1] == Py_None) { + errors = NULL; + } + else if (PyUnicode_Check(args[1])) { + Py_ssize_t errors_length; + errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); + if (errors == NULL) { + goto exit; + } + if (strlen(errors) != (size_t)errors_length) { + PyErr_SetString(PyExc_ValueError, "embedded null character"); + goto exit; + } + } + else { + _PyArg_BadArgument("mbcs_encode", 2, "str or None", args[1]); + goto exit; + } +skip_optional: return_value = _codecs_mbcs_encode_impl(module, str, errors); exit: @@ -1428,10 +2725,39 @@ _codecs_oem_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) PyObject *str; const char *errors = NULL; - if (!_PyArg_ParseStack(args, nargs, "U|z:oem_encode", - &str, &errors)) { + if (!_PyArg_CheckPositional("oem_encode", nargs, 1, 2)) { + goto exit; + } + if (!PyUnicode_Check(args[0])) { + _PyArg_BadArgument("oem_encode", 1, "str", args[0]); + goto exit; + } + if (PyUnicode_READY(args[0]) == -1) { goto exit; } + str = args[0]; + if (nargs < 2) { + goto skip_optional; + } + if (args[1] == Py_None) { + errors = NULL; + } + else if (PyUnicode_Check(args[1])) { + Py_ssize_t errors_length; + errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); + if (errors == NULL) { + goto exit; + } + if (strlen(errors) != (size_t)errors_length) { + PyErr_SetString(PyExc_ValueError, "embedded null character"); + goto exit; + } + } + else { + _PyArg_BadArgument("oem_encode", 2, "str or None", args[1]); + goto exit; + } +skip_optional: return_value = _codecs_oem_encode_impl(module, str, errors); exit: @@ -1462,10 +2788,48 @@ _codecs_code_page_encode(PyObject *module, PyObject *const *args, Py_ssize_t nar PyObject *str; const char *errors = NULL; - if (!_PyArg_ParseStack(args, nargs, "iU|z:code_page_encode", - &code_page, &str, &errors)) { + if (!_PyArg_CheckPositional("code_page_encode", nargs, 2, 3)) { + goto exit; + } + if (PyFloat_Check(args[0])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + code_page = _PyLong_AsInt(args[0]); + if (code_page == -1 && PyErr_Occurred()) { + goto exit; + } + if (!PyUnicode_Check(args[1])) { + _PyArg_BadArgument("code_page_encode", 2, "str", args[1]); + goto exit; + } + if (PyUnicode_READY(args[1]) == -1) { goto exit; } + str = args[1]; + if (nargs < 3) { + goto skip_optional; + } + if (args[2] == Py_None) { + errors = NULL; + } + else if (PyUnicode_Check(args[2])) { + Py_ssize_t errors_length; + errors = PyUnicode_AsUTF8AndSize(args[2], &errors_length); + if (errors == NULL) { + goto exit; + } + if (strlen(errors) != (size_t)errors_length) { + PyErr_SetString(PyExc_ValueError, "embedded null character"); + goto exit; + } + } + else { + _PyArg_BadArgument("code_page_encode", 3, "str or None", args[2]); + goto exit; + } +skip_optional: return_value = _codecs_code_page_encode_impl(module, code_page, str, errors); exit: @@ -1498,10 +2862,23 @@ _codecs_register_error(PyObject *module, PyObject *const *args, Py_ssize_t nargs const char *errors; PyObject *handler; - if (!_PyArg_ParseStack(args, nargs, "sO:register_error", - &errors, &handler)) { + if (!_PyArg_CheckPositional("register_error", nargs, 2, 2)) { + goto exit; + } + if (!PyUnicode_Check(args[0])) { + _PyArg_BadArgument("register_error", 1, "str", args[0]); + goto exit; + } + Py_ssize_t errors_length; + errors = PyUnicode_AsUTF8AndSize(args[0], &errors_length); + if (errors == NULL) { + goto exit; + } + if (strlen(errors) != (size_t)errors_length) { + PyErr_SetString(PyExc_ValueError, "embedded null character"); goto exit; } + handler = args[1]; return_value = _codecs_register_error_impl(module, errors, handler); exit: @@ -1530,7 +2907,7 @@ _codecs_lookup_error(PyObject *module, PyObject *arg) const char *name; if (!PyUnicode_Check(arg)) { - _PyArg_BadArgument("lookup_error", "str", arg); + _PyArg_BadArgument("lookup_error", 0, "str", arg); goto exit; } Py_ssize_t name_length; @@ -1571,4 +2948,4 @@ exit: #ifndef _CODECS_CODE_PAGE_ENCODE_METHODDEF #define _CODECS_CODE_PAGE_ENCODE_METHODDEF #endif /* !defined(_CODECS_CODE_PAGE_ENCODE_METHODDEF) */ -/*[clinic end generated code: output=c2d2b917b78a4c45 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=85ea29db163ee74c input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_collectionsmodule.c.h b/Modules/clinic/_collectionsmodule.c.h index 12626c1..ed3b1b5 100644 --- a/Modules/clinic/_collectionsmodule.c.h +++ b/Modules/clinic/_collectionsmodule.c.h @@ -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]*/ diff --git a/Modules/clinic/_cryptmodule.c.h b/Modules/clinic/_cryptmodule.c.h index baa31e2..2fcb0c1 100644 --- a/Modules/clinic/_cryptmodule.c.h +++ b/Modules/clinic/_cryptmodule.c.h @@ -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]*/ diff --git a/Modules/clinic/_curses_panel.c.h b/Modules/clinic/_curses_panel.c.h index 2e569c5..ed59c3b 100644 --- a/Modules/clinic/_curses_panel.c.h +++ b/Modules/clinic/_curses_panel.c.h @@ -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]*/ diff --git a/Modules/clinic/_cursesmodule.c.h b/Modules/clinic/_cursesmodule.c.h index 01c7097..0988581 100644 --- a/Modules/clinic/_cursesmodule.c.h +++ b/Modules/clinic/_cursesmodule.c.h @@ -245,10 +245,23 @@ _curses_window_bkgd(PyCursesWindowObject *self, PyObject *const *args, Py_ssize_ PyObject *ch; long attr = A_NORMAL; - if (!_PyArg_ParseStack(args, nargs, "O|l:bkgd", - &ch, &attr)) { + if (!_PyArg_CheckPositional("bkgd", nargs, 1, 2)) { goto exit; } + ch = args[0]; + if (nargs < 2) { + goto skip_optional; + } + if (PyFloat_Check(args[1])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + attr = PyLong_AsLong(args[1]); + if (attr == -1 && PyErr_Occurred()) { + goto exit; + } +skip_optional: return_value = _curses_window_bkgd_impl(self, ch, attr); exit: @@ -379,10 +392,23 @@ _curses_window_bkgdset(PyCursesWindowObject *self, PyObject *const *args, Py_ssi PyObject *ch; long attr = A_NORMAL; - if (!_PyArg_ParseStack(args, nargs, "O|l:bkgdset", - &ch, &attr)) { + if (!_PyArg_CheckPositional("bkgdset", nargs, 1, 2)) { + goto exit; + } + ch = args[0]; + if (nargs < 2) { + goto skip_optional; + } + if (PyFloat_Check(args[1])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + attr = PyLong_AsLong(args[1]); + if (attr == -1 && PyErr_Occurred()) { goto exit; } +skip_optional: return_value = _curses_window_bkgdset_impl(self, ch, attr); exit: @@ -623,10 +649,23 @@ _curses_window_echochar(PyCursesWindowObject *self, PyObject *const *args, Py_ss PyObject *ch; long attr = A_NORMAL; - if (!_PyArg_ParseStack(args, nargs, "O|l:echochar", - &ch, &attr)) { + if (!_PyArg_CheckPositional("echochar", nargs, 1, 2)) { + goto exit; + } + ch = args[0]; + if (nargs < 2) { + goto skip_optional; + } + if (PyFloat_Check(args[1])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + attr = PyLong_AsLong(args[1]); + if (attr == -1 && PyErr_Occurred()) { goto exit; } +skip_optional: return_value = _curses_window_echochar_impl(self, ch, attr); exit: @@ -660,8 +699,25 @@ _curses_window_enclose(PyCursesWindowObject *self, PyObject *const *args, Py_ssi int x; long _return_value; - if (!_PyArg_ParseStack(args, nargs, "ii:enclose", - &y, &x)) { + if (!_PyArg_CheckPositional("enclose", 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_window_enclose_impl(self, y, x); @@ -1462,8 +1518,25 @@ _curses_window_redrawln(PyCursesWindowObject *self, PyObject *const *args, Py_ss int beg; int num; - if (!_PyArg_ParseStack(args, nargs, "ii:redrawln", - &beg, &num)) { + if (!_PyArg_CheckPositional("redrawln", nargs, 2, 2)) { + goto exit; + } + if (PyFloat_Check(args[0])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + beg = _PyLong_AsInt(args[0]); + if (beg == -1 && PyErr_Occurred()) { + goto exit; + } + if (PyFloat_Check(args[1])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + num = _PyLong_AsInt(args[1]); + if (num == -1 && PyErr_Occurred()) { goto exit; } return_value = _curses_window_redrawln_impl(self, beg, num); @@ -1554,8 +1627,25 @@ _curses_window_setscrreg(PyCursesWindowObject *self, PyObject *const *args, Py_s int top; int bottom; - if (!_PyArg_ParseStack(args, nargs, "ii:setscrreg", - &top, &bottom)) { + if (!_PyArg_CheckPositional("setscrreg", nargs, 2, 2)) { + goto exit; + } + if (PyFloat_Check(args[0])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + top = _PyLong_AsInt(args[0]); + if (top == -1 && PyErr_Occurred()) { + goto exit; + } + if (PyFloat_Check(args[1])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + bottom = _PyLong_AsInt(args[1]); + if (bottom == -1 && PyErr_Occurred()) { goto exit; } return_value = _curses_window_setscrreg_impl(self, top, bottom); @@ -1878,10 +1968,22 @@ _curses_cbreak(PyObject *module, PyObject *const *args, Py_ssize_t nargs) PyObject *return_value = NULL; int flag = 1; - if (!_PyArg_ParseStack(args, nargs, "|i:cbreak", - &flag)) { + if (!_PyArg_CheckPositional("cbreak", 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; + } + flag = _PyLong_AsInt(args[0]); + if (flag == -1 && PyErr_Occurred()) { goto exit; } +skip_optional: return_value = _curses_cbreak_impl(module, flag); exit: @@ -2158,10 +2260,22 @@ _curses_echo(PyObject *module, PyObject *const *args, Py_ssize_t nargs) PyObject *return_value = NULL; int flag = 1; - if (!_PyArg_ParseStack(args, nargs, "|i:echo", - &flag)) { + if (!_PyArg_CheckPositional("echo", 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; + } + flag = _PyLong_AsInt(args[0]); + if (flag == -1 && PyErr_Occurred()) { + goto exit; + } +skip_optional: return_value = _curses_echo_impl(module, flag); exit: @@ -2321,10 +2435,65 @@ _curses_ungetmouse(PyObject *module, PyObject *const *args, Py_ssize_t nargs) int z; unsigned long bstate; - if (!_PyArg_ParseStack(args, nargs, "hiiik:ungetmouse", - &id, &x, &y, &z, &bstate)) { + if (!_PyArg_CheckPositional("ungetmouse", nargs, 5, 5)) { + goto exit; + } + if (PyFloat_Check(args[0])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); goto exit; } + { + long ival = PyLong_AsLong(args[0]); + if (ival == -1 && PyErr_Occurred()) { + goto exit; + } + else if (ival < SHRT_MIN) { + PyErr_SetString(PyExc_OverflowError, + "signed short integer is less than minimum"); + goto exit; + } + else if (ival > SHRT_MAX) { + PyErr_SetString(PyExc_OverflowError, + "signed short integer is greater than maximum"); + goto exit; + } + else { + id = (short) ival; + } + } + 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; + } + if (PyFloat_Check(args[2])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + y = _PyLong_AsInt(args[2]); + if (y == -1 && PyErr_Occurred()) { + goto exit; + } + if (PyFloat_Check(args[3])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + z = _PyLong_AsInt(args[3]); + if (z == -1 && PyErr_Occurred()) { + goto exit; + } + if (!PyLong_Check(args[4])) { + _PyArg_BadArgument("ungetmouse", 5, "int", args[4]); + goto exit; + } + bstate = PyLong_AsUnsignedLongMask(args[4]); return_value = _curses_ungetmouse_impl(module, id, x, y, z, bstate); exit: @@ -2527,10 +2696,105 @@ _curses_init_color(PyObject *module, PyObject *const *args, Py_ssize_t nargs) short g; short b; - if (!_PyArg_ParseStack(args, nargs, "hhhh:init_color", - &color_number, &r, &g, &b)) { + if (!_PyArg_CheckPositional("init_color", nargs, 4, 4)) { + goto exit; + } + if (PyFloat_Check(args[0])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + { + long ival = PyLong_AsLong(args[0]); + if (ival == -1 && PyErr_Occurred()) { + goto exit; + } + else if (ival < SHRT_MIN) { + PyErr_SetString(PyExc_OverflowError, + "signed short integer is less than minimum"); + goto exit; + } + else if (ival > SHRT_MAX) { + PyErr_SetString(PyExc_OverflowError, + "signed short integer is greater than maximum"); + goto exit; + } + else { + color_number = (short) ival; + } + } + if (PyFloat_Check(args[1])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + { + long ival = PyLong_AsLong(args[1]); + if (ival == -1 && PyErr_Occurred()) { + goto exit; + } + else if (ival < SHRT_MIN) { + PyErr_SetString(PyExc_OverflowError, + "signed short integer is less than minimum"); + goto exit; + } + else if (ival > SHRT_MAX) { + PyErr_SetString(PyExc_OverflowError, + "signed short integer is greater than maximum"); + goto exit; + } + else { + r = (short) ival; + } + } + if (PyFloat_Check(args[2])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + { + long ival = PyLong_AsLong(args[2]); + if (ival == -1 && PyErr_Occurred()) { + goto exit; + } + else if (ival < SHRT_MIN) { + PyErr_SetString(PyExc_OverflowError, + "signed short integer is less than minimum"); + goto exit; + } + else if (ival > SHRT_MAX) { + PyErr_SetString(PyExc_OverflowError, + "signed short integer is greater than maximum"); + goto exit; + } + else { + g = (short) ival; + } + } + if (PyFloat_Check(args[3])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); goto exit; } + { + long ival = PyLong_AsLong(args[3]); + if (ival == -1 && PyErr_Occurred()) { + goto exit; + } + else if (ival < SHRT_MIN) { + PyErr_SetString(PyExc_OverflowError, + "signed short integer is less than minimum"); + goto exit; + } + else if (ival > SHRT_MAX) { + PyErr_SetString(PyExc_OverflowError, + "signed short integer is greater than maximum"); + goto exit; + } + else { + b = (short) ival; + } + } return_value = _curses_init_color_impl(module, color_number, r, g, b); exit: @@ -2568,10 +2832,81 @@ _curses_init_pair(PyObject *module, PyObject *const *args, Py_ssize_t nargs) short fg; short bg; - if (!_PyArg_ParseStack(args, nargs, "hhh:init_pair", - &pair_number, &fg, &bg)) { + if (!_PyArg_CheckPositional("init_pair", nargs, 3, 3)) { + goto exit; + } + if (PyFloat_Check(args[0])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + { + long ival = PyLong_AsLong(args[0]); + if (ival == -1 && PyErr_Occurred()) { + goto exit; + } + else if (ival < SHRT_MIN) { + PyErr_SetString(PyExc_OverflowError, + "signed short integer is less than minimum"); + goto exit; + } + else if (ival > SHRT_MAX) { + PyErr_SetString(PyExc_OverflowError, + "signed short integer is greater than maximum"); + goto exit; + } + else { + pair_number = (short) ival; + } + } + if (PyFloat_Check(args[1])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + { + long ival = PyLong_AsLong(args[1]); + if (ival == -1 && PyErr_Occurred()) { + goto exit; + } + else if (ival < SHRT_MIN) { + PyErr_SetString(PyExc_OverflowError, + "signed short integer is less than minimum"); + goto exit; + } + else if (ival > SHRT_MAX) { + PyErr_SetString(PyExc_OverflowError, + "signed short integer is greater than maximum"); + goto exit; + } + else { + fg = (short) ival; + } + } + if (PyFloat_Check(args[2])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); goto exit; } + { + long ival = PyLong_AsLong(args[2]); + if (ival == -1 && PyErr_Occurred()) { + goto exit; + } + else if (ival < SHRT_MIN) { + PyErr_SetString(PyExc_OverflowError, + "signed short integer is less than minimum"); + goto exit; + } + else if (ival > SHRT_MAX) { + PyErr_SetString(PyExc_OverflowError, + "signed short integer is greater than maximum"); + goto exit; + } + else { + bg = (short) ival; + } + } return_value = _curses_init_pair_impl(module, pair_number, fg, bg); exit: @@ -2712,8 +3047,25 @@ _curses_is_term_resized(PyObject *module, PyObject *const *args, Py_ssize_t narg int nlines; int ncols; - if (!_PyArg_ParseStack(args, nargs, "ii:is_term_resized", - &nlines, &ncols)) { + if (!_PyArg_CheckPositional("is_term_resized", nargs, 2, 2)) { + goto exit; + } + if (PyFloat_Check(args[0])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + nlines = _PyLong_AsInt(args[0]); + if (nlines == -1 && PyErr_Occurred()) { + goto exit; + } + if (PyFloat_Check(args[1])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + ncols = _PyLong_AsInt(args[1]); + if (ncols == -1 && PyErr_Occurred()) { goto exit; } return_value = _curses_is_term_resized_impl(module, nlines, ncols); @@ -2905,7 +3257,7 @@ _curses_mousemask(PyObject *module, PyObject *arg) unsigned long newmask; if (!PyLong_Check(arg)) { - _PyArg_BadArgument("mousemask", "int", arg); + _PyArg_BadArgument("mousemask", 0, "int", arg); goto exit; } newmask = PyLong_AsUnsignedLongMask(arg); @@ -2977,8 +3329,25 @@ _curses_newpad(PyObject *module, PyObject *const *args, Py_ssize_t nargs) int nlines; int ncols; - if (!_PyArg_ParseStack(args, nargs, "ii:newpad", - &nlines, &ncols)) { + if (!_PyArg_CheckPositional("newpad", nargs, 2, 2)) { + goto exit; + } + if (PyFloat_Check(args[0])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + nlines = _PyLong_AsInt(args[0]); + if (nlines == -1 && PyErr_Occurred()) { + goto exit; + } + if (PyFloat_Check(args[1])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + ncols = _PyLong_AsInt(args[1]); + if (ncols == -1 && PyErr_Occurred()) { goto exit; } return_value = _curses_newpad_impl(module, nlines, ncols); @@ -3066,10 +3435,22 @@ _curses_nl(PyObject *module, PyObject *const *args, Py_ssize_t nargs) PyObject *return_value = NULL; int flag = 1; - if (!_PyArg_ParseStack(args, nargs, "|i:nl", - &flag)) { + if (!_PyArg_CheckPositional("nl", 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; + } + flag = _PyLong_AsInt(args[0]); + if (flag == -1 && PyErr_Occurred()) { goto exit; } +skip_optional: return_value = _curses_nl_impl(module, flag); exit: @@ -3317,10 +3698,22 @@ _curses_qiflush(PyObject *module, PyObject *const *args, Py_ssize_t nargs) PyObject *return_value = NULL; int flag = 1; - if (!_PyArg_ParseStack(args, nargs, "|i:qiflush", - &flag)) { + if (!_PyArg_CheckPositional("qiflush", 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; + } + flag = _PyLong_AsInt(args[0]); + if (flag == -1 && PyErr_Occurred()) { + goto exit; + } +skip_optional: return_value = _curses_qiflush_impl(module, flag); exit: @@ -3383,10 +3776,22 @@ _curses_raw(PyObject *module, PyObject *const *args, Py_ssize_t nargs) PyObject *return_value = NULL; int flag = 1; - if (!_PyArg_ParseStack(args, nargs, "|i:raw", - &flag)) { + if (!_PyArg_CheckPositional("raw", 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; + } + flag = _PyLong_AsInt(args[0]); + if (flag == -1 && PyErr_Occurred()) { + goto exit; + } +skip_optional: return_value = _curses_raw_impl(module, flag); exit: @@ -3476,8 +3881,25 @@ _curses_resizeterm(PyObject *module, PyObject *const *args, Py_ssize_t nargs) int nlines; int ncols; - if (!_PyArg_ParseStack(args, nargs, "ii:resizeterm", - &nlines, &ncols)) { + if (!_PyArg_CheckPositional("resizeterm", nargs, 2, 2)) { + goto exit; + } + if (PyFloat_Check(args[0])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + nlines = _PyLong_AsInt(args[0]); + if (nlines == -1 && PyErr_Occurred()) { + goto exit; + } + if (PyFloat_Check(args[1])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + ncols = _PyLong_AsInt(args[1]); + if (ncols == -1 && PyErr_Occurred()) { goto exit; } return_value = _curses_resizeterm_impl(module, nlines, ncols); @@ -3520,8 +3942,25 @@ _curses_resize_term(PyObject *module, PyObject *const *args, Py_ssize_t nargs) int nlines; int ncols; - if (!_PyArg_ParseStack(args, nargs, "ii:resize_term", - &nlines, &ncols)) { + if (!_PyArg_CheckPositional("resize_term", nargs, 2, 2)) { + goto exit; + } + if (PyFloat_Check(args[0])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + nlines = _PyLong_AsInt(args[0]); + if (nlines == -1 && PyErr_Occurred()) { + goto exit; + } + if (PyFloat_Check(args[1])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + ncols = _PyLong_AsInt(args[1]); + if (ncols == -1 && PyErr_Occurred()) { goto exit; } return_value = _curses_resize_term_impl(module, nlines, ncols); @@ -3578,8 +4017,25 @@ _curses_setsyx(PyObject *module, PyObject *const *args, Py_ssize_t nargs) int y; int x; - if (!_PyArg_ParseStack(args, nargs, "ii:setsyx", - &y, &x)) { + if (!_PyArg_CheckPositional("setsyx", 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_setsyx_impl(module, y, x); @@ -3676,7 +4132,7 @@ _curses_tigetflag(PyObject *module, PyObject *arg) const char *capname; if (!PyUnicode_Check(arg)) { - _PyArg_BadArgument("tigetflag", "str", arg); + _PyArg_BadArgument("tigetflag", 0, "str", arg); goto exit; } Py_ssize_t capname_length; @@ -3719,7 +4175,7 @@ _curses_tigetnum(PyObject *module, PyObject *arg) const char *capname; if (!PyUnicode_Check(arg)) { - _PyArg_BadArgument("tigetnum", "str", arg); + _PyArg_BadArgument("tigetnum", 0, "str", arg); goto exit; } Py_ssize_t capname_length; @@ -3762,7 +4218,7 @@ _curses_tigetstr(PyObject *module, PyObject *arg) const char *capname; if (!PyUnicode_Check(arg)) { - _PyArg_BadArgument("tigetstr", "str", arg); + _PyArg_BadArgument("tigetstr", 0, "str", arg); goto exit; } Py_ssize_t capname_length; @@ -4044,4 +4500,4 @@ _curses_use_default_colors(PyObject *module, PyObject *Py_UNUSED(ignored)) #ifndef _CURSES_USE_DEFAULT_COLORS_METHODDEF #define _CURSES_USE_DEFAULT_COLORS_METHODDEF #endif /* !defined(_CURSES_USE_DEFAULT_COLORS_METHODDEF) */ -/*[clinic end generated code: output=a2bbced3c5d29d64 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=ceb2e32ee1370033 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_dbmmodule.c.h b/Modules/clinic/_dbmmodule.c.h index c090862..e54c69c 100644 --- a/Modules/clinic/_dbmmodule.c.h +++ b/Modules/clinic/_dbmmodule.c.h @@ -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]*/ diff --git a/Modules/clinic/_elementtree.c.h b/Modules/clinic/_elementtree.c.h index e5107eb..8968983 100644 --- a/Modules/clinic/_elementtree.c.h +++ b/Modules/clinic/_elementtree.c.h @@ -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]*/ diff --git a/Modules/clinic/_gdbmmodule.c.h b/Modules/clinic/_gdbmmodule.c.h index 5edc440..9475264 100644 --- a/Modules/clinic/_gdbmmodule.c.h +++ b/Modules/clinic/_gdbmmodule.c.h @@ -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]*/ diff --git a/Modules/clinic/_lzmamodule.c.h b/Modules/clinic/_lzmamodule.c.h index 46d2988..aeb98a6 100644 --- a/Modules/clinic/_lzmamodule.c.h +++ b/Modules/clinic/_lzmamodule.c.h @@ -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]*/ diff --git a/Modules/clinic/_operator.c.h b/Modules/clinic/_operator.c.h index 9d7b20c..72c0e57 100644 --- a/Modules/clinic/_operator.c.h +++ b/Modules/clinic/_operator.c.h @@ -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]*/ diff --git a/Modules/clinic/_ssl.c.h b/Modules/clinic/_ssl.c.h index e149077..3ec30c3 100644 --- a/Modules/clinic/_ssl.c.h +++ b/Modules/clinic/_ssl.c.h @@ -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]*/ diff --git a/Modules/clinic/_struct.c.h b/Modules/clinic/_struct.c.h index 3a186e4..2cc2d21 100644 --- a/Modules/clinic/_struct.c.h +++ b/Modules/clinic/_struct.c.h @@ -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]*/ diff --git a/Modules/clinic/_tkinter.c.h b/Modules/clinic/_tkinter.c.h index 1eedd2b..0a3e7ff 100644 --- a/Modules/clinic/_tkinter.c.h +++ b/Modules/clinic/_tkinter.c.h @@ -20,7 +20,7 @@ _tkinter_tkapp_eval(TkappObject *self, PyObject *arg) const char *script; if (!PyUnicode_Check(arg)) { - _PyArg_BadArgument("eval", "str", arg); + _PyArg_BadArgument("eval", 0, "str", arg); goto exit; } Py_ssize_t script_length; @@ -56,7 +56,7 @@ _tkinter_tkapp_evalfile(TkappObject *self, PyObject *arg) const char *fileName; if (!PyUnicode_Check(arg)) { - _PyArg_BadArgument("evalfile", "str", arg); + _PyArg_BadArgument("evalfile", 0, "str", arg); goto exit; } Py_ssize_t fileName_length; @@ -92,7 +92,7 @@ _tkinter_tkapp_record(TkappObject *self, PyObject *arg) const char *script; if (!PyUnicode_Check(arg)) { - _PyArg_BadArgument("record", "str", arg); + _PyArg_BadArgument("record", 0, "str", arg); goto exit; } Py_ssize_t script_length; @@ -128,7 +128,7 @@ _tkinter_tkapp_adderrorinfo(TkappObject *self, PyObject *arg) const char *msg; if (!PyUnicode_Check(arg)) { - _PyArg_BadArgument("adderrorinfo", "str", arg); + _PyArg_BadArgument("adderrorinfo", 0, "str", arg); goto exit; } Py_ssize_t msg_length; @@ -188,7 +188,7 @@ _tkinter_tkapp_exprstring(TkappObject *self, PyObject *arg) const char *s; if (!PyUnicode_Check(arg)) { - _PyArg_BadArgument("exprstring", "str", arg); + _PyArg_BadArgument("exprstring", 0, "str", arg); goto exit; } Py_ssize_t s_length; @@ -224,7 +224,7 @@ _tkinter_tkapp_exprlong(TkappObject *self, PyObject *arg) const char *s; if (!PyUnicode_Check(arg)) { - _PyArg_BadArgument("exprlong", "str", arg); + _PyArg_BadArgument("exprlong", 0, "str", arg); goto exit; } Py_ssize_t s_length; @@ -260,7 +260,7 @@ _tkinter_tkapp_exprdouble(TkappObject *self, PyObject *arg) const char *s; if (!PyUnicode_Check(arg)) { - _PyArg_BadArgument("exprdouble", "str", arg); + _PyArg_BadArgument("exprdouble", 0, "str", arg); goto exit; } Py_ssize_t s_length; @@ -296,7 +296,7 @@ _tkinter_tkapp_exprboolean(TkappObject *self, PyObject *arg) const char *s; if (!PyUnicode_Check(arg)) { - _PyArg_BadArgument("exprboolean", "str", arg); + _PyArg_BadArgument("exprboolean", 0, "str", arg); goto exit; } Py_ssize_t s_length; @@ -349,10 +349,23 @@ _tkinter_tkapp_createcommand(TkappObject *self, PyObject *const *args, Py_ssize_ const char *name; PyObject *func; - if (!_PyArg_ParseStack(args, nargs, "sO:createcommand", - &name, &func)) { + if (!_PyArg_CheckPositional("createcommand", nargs, 2, 2)) { goto exit; } + if (!PyUnicode_Check(args[0])) { + _PyArg_BadArgument("createcommand", 1, "str", args[0]); + goto exit; + } + Py_ssize_t name_length; + name = PyUnicode_AsUTF8AndSize(args[0], &name_length); + if (name == NULL) { + goto exit; + } + if (strlen(name) != (size_t)name_length) { + PyErr_SetString(PyExc_ValueError, "embedded null character"); + goto exit; + } + func = args[1]; return_value = _tkinter_tkapp_createcommand_impl(self, name, func); exit: @@ -377,7 +390,7 @@ _tkinter_tkapp_deletecommand(TkappObject *self, PyObject *arg) const char *name; if (!PyUnicode_Check(arg)) { - _PyArg_BadArgument("deletecommand", "str", arg); + _PyArg_BadArgument("deletecommand", 0, "str", arg); goto exit; } Py_ssize_t name_length; @@ -417,10 +430,20 @@ _tkinter_tkapp_createfilehandler(TkappObject *self, PyObject *const *args, Py_ss int mask; PyObject *func; - if (!_PyArg_ParseStack(args, nargs, "OiO:createfilehandler", - &file, &mask, &func)) { + if (!_PyArg_CheckPositional("createfilehandler", nargs, 3, 3)) { goto exit; } + file = args[0]; + if (PyFloat_Check(args[1])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + mask = _PyLong_AsInt(args[1]); + if (mask == -1 && PyErr_Occurred()) { + goto exit; + } + func = args[2]; return_value = _tkinter_tkapp_createfilehandler_impl(self, file, mask, func); exit: @@ -477,10 +500,19 @@ _tkinter_tkapp_createtimerhandler(TkappObject *self, PyObject *const *args, Py_s int milliseconds; PyObject *func; - if (!_PyArg_ParseStack(args, nargs, "iO:createtimerhandler", - &milliseconds, &func)) { + if (!_PyArg_CheckPositional("createtimerhandler", nargs, 2, 2)) { goto exit; } + if (PyFloat_Check(args[0])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + milliseconds = _PyLong_AsInt(args[0]); + if (milliseconds == -1 && PyErr_Occurred()) { + goto exit; + } + func = args[1]; return_value = _tkinter_tkapp_createtimerhandler_impl(self, milliseconds, func); exit: @@ -504,10 +536,22 @@ _tkinter_tkapp_mainloop(TkappObject *self, PyObject *const *args, Py_ssize_t nar PyObject *return_value = NULL; int threshold = 0; - if (!_PyArg_ParseStack(args, nargs, "|i:mainloop", - &threshold)) { + if (!_PyArg_CheckPositional("mainloop", 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; + } + threshold = _PyLong_AsInt(args[0]); + if (threshold == -1 && PyErr_Occurred()) { + goto exit; + } +skip_optional: return_value = _tkinter_tkapp_mainloop_impl(self, threshold); exit: @@ -531,10 +575,22 @@ _tkinter_tkapp_dooneevent(TkappObject *self, PyObject *const *args, Py_ssize_t n PyObject *return_value = NULL; int flags = 0; - if (!_PyArg_ParseStack(args, nargs, "|i:dooneevent", - &flags)) { + if (!_PyArg_CheckPositional("dooneevent", 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; } + flags = _PyLong_AsInt(args[0]); + if (flags == -1 && PyErr_Occurred()) { + goto exit; + } +skip_optional: return_value = _tkinter_tkapp_dooneevent_impl(self, flags); exit: @@ -654,10 +710,132 @@ _tkinter_create(PyObject *module, PyObject *const *args, Py_ssize_t nargs) int sync = 0; const char *use = NULL; - if (!_PyArg_ParseStack(args, nargs, "|zssiiiiz:create", - &screenName, &baseName, &className, &interactive, &wantobjects, &wantTk, &sync, &use)) { + if (!_PyArg_CheckPositional("create", nargs, 0, 8)) { + goto exit; + } + if (nargs < 1) { + goto skip_optional; + } + if (args[0] == Py_None) { + screenName = NULL; + } + else if (PyUnicode_Check(args[0])) { + Py_ssize_t screenName_length; + screenName = PyUnicode_AsUTF8AndSize(args[0], &screenName_length); + if (screenName == NULL) { + goto exit; + } + if (strlen(screenName) != (size_t)screenName_length) { + PyErr_SetString(PyExc_ValueError, "embedded null character"); + goto exit; + } + } + else { + _PyArg_BadArgument("create", 1, "str or None", args[0]); + goto exit; + } + if (nargs < 2) { + goto skip_optional; + } + if (!PyUnicode_Check(args[1])) { + _PyArg_BadArgument("create", 2, "str", args[1]); + goto exit; + } + Py_ssize_t baseName_length; + baseName = PyUnicode_AsUTF8AndSize(args[1], &baseName_length); + if (baseName == NULL) { + goto exit; + } + if (strlen(baseName) != (size_t)baseName_length) { + PyErr_SetString(PyExc_ValueError, "embedded null character"); + goto exit; + } + if (nargs < 3) { + goto skip_optional; + } + if (!PyUnicode_Check(args[2])) { + _PyArg_BadArgument("create", 3, "str", args[2]); + goto exit; + } + Py_ssize_t className_length; + className = PyUnicode_AsUTF8AndSize(args[2], &className_length); + if (className == NULL) { + goto exit; + } + if (strlen(className) != (size_t)className_length) { + PyErr_SetString(PyExc_ValueError, "embedded null character"); + goto exit; + } + if (nargs < 4) { + goto skip_optional; + } + if (PyFloat_Check(args[3])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + interactive = _PyLong_AsInt(args[3]); + if (interactive == -1 && PyErr_Occurred()) { + goto exit; + } + if (nargs < 5) { + goto skip_optional; + } + if (PyFloat_Check(args[4])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + wantobjects = _PyLong_AsInt(args[4]); + if (wantobjects == -1 && PyErr_Occurred()) { + goto exit; + } + if (nargs < 6) { + goto skip_optional; + } + if (PyFloat_Check(args[5])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + wantTk = _PyLong_AsInt(args[5]); + if (wantTk == -1 && PyErr_Occurred()) { + goto exit; + } + if (nargs < 7) { + goto skip_optional; + } + if (PyFloat_Check(args[6])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + sync = _PyLong_AsInt(args[6]); + if (sync == -1 && PyErr_Occurred()) { + goto exit; + } + if (nargs < 8) { + goto skip_optional; + } + if (args[7] == Py_None) { + use = NULL; + } + else if (PyUnicode_Check(args[7])) { + Py_ssize_t use_length; + use = PyUnicode_AsUTF8AndSize(args[7], &use_length); + if (use == NULL) { + goto exit; + } + if (strlen(use) != (size_t)use_length) { + PyErr_SetString(PyExc_ValueError, "embedded null character"); + goto exit; + } + } + else { + _PyArg_BadArgument("create", 8, "str or None", args[7]); goto exit; } +skip_optional: return_value = _tkinter_create_impl(module, screenName, baseName, className, interactive, wantobjects, wantTk, sync, use); exit: @@ -734,4 +912,4 @@ exit: #ifndef _TKINTER_TKAPP_DELETEFILEHANDLER_METHODDEF #define _TKINTER_TKAPP_DELETEFILEHANDLER_METHODDEF #endif /* !defined(_TKINTER_TKAPP_DELETEFILEHANDLER_METHODDEF) */ -/*[clinic end generated code: output=d84b0e794824c511 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=2cf95f0101f3dbca input=a9049054013a1b77]*/ diff --git a/Modules/clinic/_tracemalloc.c.h b/Modules/clinic/_tracemalloc.c.h index aa736ec..68fafdc 100644 --- a/Modules/clinic/_tracemalloc.c.h +++ b/Modules/clinic/_tracemalloc.c.h @@ -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]*/ diff --git a/Modules/clinic/_weakref.c.h b/Modules/clinic/_weakref.c.h index 21f00ff..aa0d77f 100644 --- a/Modules/clinic/_weakref.c.h +++ b/Modules/clinic/_weakref.c.h @@ -50,13 +50,18 @@ _weakref__remove_dead_weakref(PyObject *module, PyObject *const *args, Py_ssize_ PyObject *dct; PyObject *key; - if (!_PyArg_ParseStack(args, nargs, "O!O:_remove_dead_weakref", - &PyDict_Type, &dct, &key)) { + if (!_PyArg_CheckPositional("_remove_dead_weakref", nargs, 2, 2)) { goto exit; } + if (!PyDict_Check(args[0])) { + _PyArg_BadArgument("_remove_dead_weakref", 1, "dict", args[0]); + goto exit; + } + dct = args[0]; + key = args[1]; return_value = _weakref__remove_dead_weakref_impl(module, dct, key); exit: return return_value; } -/*[clinic end generated code: output=927e889feb8a7dc4 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=eae22e2d2e43120e input=a9049054013a1b77]*/ diff --git a/Modules/clinic/arraymodule.c.h b/Modules/clinic/arraymodule.c.h index eb081ad..5f45b7c 100644 --- a/Modules/clinic/arraymodule.c.h +++ b/Modules/clinic/arraymodule.c.h @@ -76,10 +76,30 @@ array_array_pop(arrayobject *self, PyObject *const *args, Py_ssize_t nargs) PyObject *return_value = NULL; Py_ssize_t i = -1; - if (!_PyArg_ParseStack(args, nargs, "|n:pop", - &i)) { + if (!_PyArg_CheckPositional("pop", 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; + } + i = ival; + } +skip_optional: return_value = array_array_pop_impl(self, i); exit: @@ -114,10 +134,27 @@ array_array_insert(arrayobject *self, PyObject *const *args, Py_ssize_t nargs) Py_ssize_t i; PyObject *v; - if (!_PyArg_ParseStack(args, nargs, "nO:insert", - &i, &v)) { + 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; + } + i = ival; + } + v = args[1]; return_value = array_array_insert_impl(self, i, v); exit: @@ -212,10 +249,27 @@ array_array_fromfile(arrayobject *self, PyObject *const *args, Py_ssize_t nargs) PyObject *f; Py_ssize_t n; - if (!_PyArg_ParseStack(args, nargs, "On:fromfile", - &f, &n)) { + if (!_PyArg_CheckPositional("fromfile", nargs, 2, 2)) { + goto exit; + } + f = args[0]; + 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; + } + n = ival; + } return_value = array_array_fromfile_impl(self, f, n); exit: @@ -291,7 +345,7 @@ array_array_fromstring(arrayobject *self, PyObject *arg) goto exit; } if (!PyBuffer_IsContiguous(&buffer, 'C')) { - _PyArg_BadArgument("fromstring", "contiguous buffer", arg); + _PyArg_BadArgument("fromstring", 0, "contiguous buffer", arg); goto exit; } } @@ -328,7 +382,7 @@ array_array_frombytes(arrayobject *self, PyObject *arg) goto exit; } if (!PyBuffer_IsContiguous(&buffer, 'C')) { - _PyArg_BadArgument("frombytes", "contiguous buffer", arg); + _PyArg_BadArgument("frombytes", 0, "contiguous buffer", arg); goto exit; } return_value = array_array_frombytes_impl(self, &buffer); @@ -478,10 +532,32 @@ array__array_reconstructor(PyObject *module, PyObject *const *args, Py_ssize_t n enum machine_format_code mformat_code; PyObject *items; - if (!_PyArg_ParseStack(args, nargs, "OCiO:_array_reconstructor", - &arraytype, &typecode, &mformat_code, &items)) { + if (!_PyArg_CheckPositional("_array_reconstructor", nargs, 4, 4)) { + goto exit; + } + arraytype = (PyTypeObject *)args[0]; + if (!PyUnicode_Check(args[1])) { + _PyArg_BadArgument("_array_reconstructor", 2, "a unicode character", args[1]); + goto exit; + } + if (PyUnicode_READY(args[1])) { + goto exit; + } + if (PyUnicode_GET_LENGTH(args[1]) != 1) { + _PyArg_BadArgument("_array_reconstructor", 2, "a unicode character", args[1]); + goto exit; + } + typecode = PyUnicode_READ_CHAR(args[1], 0); + if (PyFloat_Check(args[2])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + mformat_code = _PyLong_AsInt(args[2]); + if (mformat_code == -1 && PyErr_Occurred()) { goto exit; } + items = args[3]; return_value = array__array_reconstructor_impl(module, arraytype, typecode, mformat_code, items); exit: @@ -523,4 +599,4 @@ PyDoc_STRVAR(array_arrayiterator___setstate____doc__, #define ARRAY_ARRAYITERATOR___SETSTATE___METHODDEF \ {"__setstate__", (PyCFunction)array_arrayiterator___setstate__, METH_O, array_arrayiterator___setstate____doc__}, -/*[clinic end generated code: output=15da19d2ece09d22 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=c9a40f11f1a866fb input=a9049054013a1b77]*/ diff --git a/Modules/clinic/audioop.c.h b/Modules/clinic/audioop.c.h index 1eae9aa..4ea7155 100644 --- a/Modules/clinic/audioop.c.h +++ b/Modules/clinic/audioop.c.h @@ -23,10 +23,42 @@ audioop_getsample(PyObject *module, PyObject *const *args, Py_ssize_t nargs) int width; Py_ssize_t index; - if (!_PyArg_ParseStack(args, nargs, "y*in:getsample", - &fragment, &width, &index)) { + if (!_PyArg_CheckPositional("getsample", nargs, 3, 3)) { goto exit; } + if (PyObject_GetBuffer(args[0], &fragment, PyBUF_SIMPLE) != 0) { + goto exit; + } + if (!PyBuffer_IsContiguous(&fragment, 'C')) { + _PyArg_BadArgument("getsample", 1, "contiguous buffer", args[0]); + goto exit; + } + if (PyFloat_Check(args[1])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + width = _PyLong_AsInt(args[1]); + if (width == -1 && PyErr_Occurred()) { + goto exit; + } + if (PyFloat_Check(args[2])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + { + Py_ssize_t ival = -1; + PyObject *iobj = PyNumber_Index(args[2]); + if (iobj != NULL) { + ival = PyLong_AsSsize_t(iobj); + Py_DECREF(iobj); + } + if (ival == -1 && PyErr_Occurred()) { + goto exit; + } + index = ival; + } return_value = audioop_getsample_impl(module, &fragment, width, index); exit: @@ -57,8 +89,23 @@ audioop_max(PyObject *module, PyObject *const *args, Py_ssize_t nargs) Py_buffer fragment = {NULL, NULL}; int width; - if (!_PyArg_ParseStack(args, nargs, "y*i:max", - &fragment, &width)) { + if (!_PyArg_CheckPositional("max", nargs, 2, 2)) { + goto exit; + } + if (PyObject_GetBuffer(args[0], &fragment, PyBUF_SIMPLE) != 0) { + goto exit; + } + if (!PyBuffer_IsContiguous(&fragment, 'C')) { + _PyArg_BadArgument("max", 1, "contiguous buffer", args[0]); + goto exit; + } + if (PyFloat_Check(args[1])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + width = _PyLong_AsInt(args[1]); + if (width == -1 && PyErr_Occurred()) { goto exit; } return_value = audioop_max_impl(module, &fragment, width); @@ -91,8 +138,23 @@ audioop_minmax(PyObject *module, PyObject *const *args, Py_ssize_t nargs) Py_buffer fragment = {NULL, NULL}; int width; - if (!_PyArg_ParseStack(args, nargs, "y*i:minmax", - &fragment, &width)) { + if (!_PyArg_CheckPositional("minmax", nargs, 2, 2)) { + goto exit; + } + if (PyObject_GetBuffer(args[0], &fragment, PyBUF_SIMPLE) != 0) { + goto exit; + } + if (!PyBuffer_IsContiguous(&fragment, 'C')) { + _PyArg_BadArgument("minmax", 1, "contiguous buffer", args[0]); + goto exit; + } + if (PyFloat_Check(args[1])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + width = _PyLong_AsInt(args[1]); + if (width == -1 && PyErr_Occurred()) { goto exit; } return_value = audioop_minmax_impl(module, &fragment, width); @@ -125,8 +187,23 @@ audioop_avg(PyObject *module, PyObject *const *args, Py_ssize_t nargs) Py_buffer fragment = {NULL, NULL}; int width; - if (!_PyArg_ParseStack(args, nargs, "y*i:avg", - &fragment, &width)) { + if (!_PyArg_CheckPositional("avg", nargs, 2, 2)) { + goto exit; + } + if (PyObject_GetBuffer(args[0], &fragment, PyBUF_SIMPLE) != 0) { + goto exit; + } + if (!PyBuffer_IsContiguous(&fragment, 'C')) { + _PyArg_BadArgument("avg", 1, "contiguous buffer", args[0]); + goto exit; + } + if (PyFloat_Check(args[1])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + width = _PyLong_AsInt(args[1]); + if (width == -1 && PyErr_Occurred()) { goto exit; } return_value = audioop_avg_impl(module, &fragment, width); @@ -159,8 +236,23 @@ audioop_rms(PyObject *module, PyObject *const *args, Py_ssize_t nargs) Py_buffer fragment = {NULL, NULL}; int width; - if (!_PyArg_ParseStack(args, nargs, "y*i:rms", - &fragment, &width)) { + if (!_PyArg_CheckPositional("rms", nargs, 2, 2)) { + goto exit; + } + if (PyObject_GetBuffer(args[0], &fragment, PyBUF_SIMPLE) != 0) { + goto exit; + } + if (!PyBuffer_IsContiguous(&fragment, 'C')) { + _PyArg_BadArgument("rms", 1, "contiguous buffer", args[0]); + goto exit; + } + if (PyFloat_Check(args[1])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + width = _PyLong_AsInt(args[1]); + if (width == -1 && PyErr_Occurred()) { goto exit; } return_value = audioop_rms_impl(module, &fragment, width); @@ -194,8 +286,21 @@ audioop_findfit(PyObject *module, PyObject *const *args, Py_ssize_t nargs) Py_buffer fragment = {NULL, NULL}; Py_buffer reference = {NULL, NULL}; - if (!_PyArg_ParseStack(args, nargs, "y*y*:findfit", - &fragment, &reference)) { + if (!_PyArg_CheckPositional("findfit", nargs, 2, 2)) { + goto exit; + } + if (PyObject_GetBuffer(args[0], &fragment, PyBUF_SIMPLE) != 0) { + goto exit; + } + if (!PyBuffer_IsContiguous(&fragment, 'C')) { + _PyArg_BadArgument("findfit", 1, "contiguous buffer", args[0]); + goto exit; + } + if (PyObject_GetBuffer(args[1], &reference, PyBUF_SIMPLE) != 0) { + goto exit; + } + if (!PyBuffer_IsContiguous(&reference, 'C')) { + _PyArg_BadArgument("findfit", 2, "contiguous buffer", args[1]); goto exit; } return_value = audioop_findfit_impl(module, &fragment, &reference); @@ -233,8 +338,21 @@ audioop_findfactor(PyObject *module, PyObject *const *args, Py_ssize_t nargs) Py_buffer fragment = {NULL, NULL}; Py_buffer reference = {NULL, NULL}; - if (!_PyArg_ParseStack(args, nargs, "y*y*:findfactor", - &fragment, &reference)) { + if (!_PyArg_CheckPositional("findfactor", nargs, 2, 2)) { + goto exit; + } + if (PyObject_GetBuffer(args[0], &fragment, PyBUF_SIMPLE) != 0) { + goto exit; + } + if (!PyBuffer_IsContiguous(&fragment, 'C')) { + _PyArg_BadArgument("findfactor", 1, "contiguous buffer", args[0]); + goto exit; + } + if (PyObject_GetBuffer(args[1], &reference, PyBUF_SIMPLE) != 0) { + goto exit; + } + if (!PyBuffer_IsContiguous(&reference, 'C')) { + _PyArg_BadArgument("findfactor", 2, "contiguous buffer", args[1]); goto exit; } return_value = audioop_findfactor_impl(module, &fragment, &reference); @@ -272,10 +390,33 @@ audioop_findmax(PyObject *module, PyObject *const *args, Py_ssize_t nargs) Py_buffer fragment = {NULL, NULL}; Py_ssize_t length; - if (!_PyArg_ParseStack(args, nargs, "y*n:findmax", - &fragment, &length)) { + if (!_PyArg_CheckPositional("findmax", nargs, 2, 2)) { + goto exit; + } + if (PyObject_GetBuffer(args[0], &fragment, PyBUF_SIMPLE) != 0) { + goto exit; + } + if (!PyBuffer_IsContiguous(&fragment, 'C')) { + _PyArg_BadArgument("findmax", 1, "contiguous buffer", args[0]); goto exit; } + 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; + } + length = ival; + } return_value = audioop_findmax_impl(module, &fragment, length); exit: @@ -306,8 +447,23 @@ audioop_avgpp(PyObject *module, PyObject *const *args, Py_ssize_t nargs) Py_buffer fragment = {NULL, NULL}; int width; - if (!_PyArg_ParseStack(args, nargs, "y*i:avgpp", - &fragment, &width)) { + if (!_PyArg_CheckPositional("avgpp", nargs, 2, 2)) { + goto exit; + } + if (PyObject_GetBuffer(args[0], &fragment, PyBUF_SIMPLE) != 0) { + goto exit; + } + if (!PyBuffer_IsContiguous(&fragment, 'C')) { + _PyArg_BadArgument("avgpp", 1, "contiguous buffer", args[0]); + goto exit; + } + if (PyFloat_Check(args[1])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + width = _PyLong_AsInt(args[1]); + if (width == -1 && PyErr_Occurred()) { goto exit; } return_value = audioop_avgpp_impl(module, &fragment, width); @@ -340,8 +496,23 @@ audioop_maxpp(PyObject *module, PyObject *const *args, Py_ssize_t nargs) Py_buffer fragment = {NULL, NULL}; int width; - if (!_PyArg_ParseStack(args, nargs, "y*i:maxpp", - &fragment, &width)) { + if (!_PyArg_CheckPositional("maxpp", nargs, 2, 2)) { + goto exit; + } + if (PyObject_GetBuffer(args[0], &fragment, PyBUF_SIMPLE) != 0) { + goto exit; + } + if (!PyBuffer_IsContiguous(&fragment, 'C')) { + _PyArg_BadArgument("maxpp", 1, "contiguous buffer", args[0]); + goto exit; + } + if (PyFloat_Check(args[1])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + width = _PyLong_AsInt(args[1]); + if (width == -1 && PyErr_Occurred()) { goto exit; } return_value = audioop_maxpp_impl(module, &fragment, width); @@ -374,8 +545,23 @@ audioop_cross(PyObject *module, PyObject *const *args, Py_ssize_t nargs) Py_buffer fragment = {NULL, NULL}; int width; - if (!_PyArg_ParseStack(args, nargs, "y*i:cross", - &fragment, &width)) { + if (!_PyArg_CheckPositional("cross", nargs, 2, 2)) { + goto exit; + } + if (PyObject_GetBuffer(args[0], &fragment, PyBUF_SIMPLE) != 0) { + goto exit; + } + if (!PyBuffer_IsContiguous(&fragment, 'C')) { + _PyArg_BadArgument("cross", 1, "contiguous buffer", args[0]); + goto exit; + } + if (PyFloat_Check(args[1])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + width = _PyLong_AsInt(args[1]); + if (width == -1 && PyErr_Occurred()) { goto exit; } return_value = audioop_cross_impl(module, &fragment, width); @@ -410,8 +596,27 @@ audioop_mul(PyObject *module, PyObject *const *args, Py_ssize_t nargs) int width; double factor; - if (!_PyArg_ParseStack(args, nargs, "y*id:mul", - &fragment, &width, &factor)) { + if (!_PyArg_CheckPositional("mul", nargs, 3, 3)) { + goto exit; + } + if (PyObject_GetBuffer(args[0], &fragment, PyBUF_SIMPLE) != 0) { + goto exit; + } + if (!PyBuffer_IsContiguous(&fragment, 'C')) { + _PyArg_BadArgument("mul", 1, "contiguous buffer", args[0]); + goto exit; + } + if (PyFloat_Check(args[1])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + width = _PyLong_AsInt(args[1]); + if (width == -1 && PyErr_Occurred()) { + goto exit; + } + factor = PyFloat_AsDouble(args[2]); + if (PyErr_Occurred()) { goto exit; } return_value = audioop_mul_impl(module, &fragment, width, factor); @@ -447,8 +652,31 @@ audioop_tomono(PyObject *module, PyObject *const *args, Py_ssize_t nargs) double lfactor; double rfactor; - if (!_PyArg_ParseStack(args, nargs, "y*idd:tomono", - &fragment, &width, &lfactor, &rfactor)) { + if (!_PyArg_CheckPositional("tomono", nargs, 4, 4)) { + goto exit; + } + if (PyObject_GetBuffer(args[0], &fragment, PyBUF_SIMPLE) != 0) { + goto exit; + } + if (!PyBuffer_IsContiguous(&fragment, 'C')) { + _PyArg_BadArgument("tomono", 1, "contiguous buffer", args[0]); + goto exit; + } + if (PyFloat_Check(args[1])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + width = _PyLong_AsInt(args[1]); + if (width == -1 && PyErr_Occurred()) { + goto exit; + } + lfactor = PyFloat_AsDouble(args[2]); + if (PyErr_Occurred()) { + goto exit; + } + rfactor = PyFloat_AsDouble(args[3]); + if (PyErr_Occurred()) { goto exit; } return_value = audioop_tomono_impl(module, &fragment, width, lfactor, rfactor); @@ -484,8 +712,31 @@ audioop_tostereo(PyObject *module, PyObject *const *args, Py_ssize_t nargs) double lfactor; double rfactor; - if (!_PyArg_ParseStack(args, nargs, "y*idd:tostereo", - &fragment, &width, &lfactor, &rfactor)) { + if (!_PyArg_CheckPositional("tostereo", nargs, 4, 4)) { + goto exit; + } + if (PyObject_GetBuffer(args[0], &fragment, PyBUF_SIMPLE) != 0) { + goto exit; + } + if (!PyBuffer_IsContiguous(&fragment, 'C')) { + _PyArg_BadArgument("tostereo", 1, "contiguous buffer", args[0]); + goto exit; + } + if (PyFloat_Check(args[1])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + width = _PyLong_AsInt(args[1]); + if (width == -1 && PyErr_Occurred()) { + goto exit; + } + lfactor = PyFloat_AsDouble(args[2]); + if (PyErr_Occurred()) { + goto exit; + } + rfactor = PyFloat_AsDouble(args[3]); + if (PyErr_Occurred()) { goto exit; } return_value = audioop_tostereo_impl(module, &fragment, width, lfactor, rfactor); @@ -520,8 +771,30 @@ audioop_add(PyObject *module, PyObject *const *args, Py_ssize_t nargs) Py_buffer fragment2 = {NULL, NULL}; int width; - if (!_PyArg_ParseStack(args, nargs, "y*y*i:add", - &fragment1, &fragment2, &width)) { + if (!_PyArg_CheckPositional("add", nargs, 3, 3)) { + goto exit; + } + if (PyObject_GetBuffer(args[0], &fragment1, PyBUF_SIMPLE) != 0) { + goto exit; + } + if (!PyBuffer_IsContiguous(&fragment1, 'C')) { + _PyArg_BadArgument("add", 1, "contiguous buffer", args[0]); + goto exit; + } + if (PyObject_GetBuffer(args[1], &fragment2, PyBUF_SIMPLE) != 0) { + goto exit; + } + if (!PyBuffer_IsContiguous(&fragment2, 'C')) { + _PyArg_BadArgument("add", 2, "contiguous buffer", args[1]); + goto exit; + } + if (PyFloat_Check(args[2])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + width = _PyLong_AsInt(args[2]); + if (width == -1 && PyErr_Occurred()) { goto exit; } return_value = audioop_add_impl(module, &fragment1, &fragment2, width); @@ -559,8 +832,32 @@ audioop_bias(PyObject *module, PyObject *const *args, Py_ssize_t nargs) int width; int bias; - if (!_PyArg_ParseStack(args, nargs, "y*ii:bias", - &fragment, &width, &bias)) { + if (!_PyArg_CheckPositional("bias", nargs, 3, 3)) { + goto exit; + } + if (PyObject_GetBuffer(args[0], &fragment, PyBUF_SIMPLE) != 0) { + goto exit; + } + if (!PyBuffer_IsContiguous(&fragment, 'C')) { + _PyArg_BadArgument("bias", 1, "contiguous buffer", args[0]); + goto exit; + } + if (PyFloat_Check(args[1])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + width = _PyLong_AsInt(args[1]); + if (width == -1 && PyErr_Occurred()) { + goto exit; + } + if (PyFloat_Check(args[2])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + bias = _PyLong_AsInt(args[2]); + if (bias == -1 && PyErr_Occurred()) { goto exit; } return_value = audioop_bias_impl(module, &fragment, width, bias); @@ -593,8 +890,23 @@ audioop_reverse(PyObject *module, PyObject *const *args, Py_ssize_t nargs) Py_buffer fragment = {NULL, NULL}; int width; - if (!_PyArg_ParseStack(args, nargs, "y*i:reverse", - &fragment, &width)) { + if (!_PyArg_CheckPositional("reverse", nargs, 2, 2)) { + goto exit; + } + if (PyObject_GetBuffer(args[0], &fragment, PyBUF_SIMPLE) != 0) { + goto exit; + } + if (!PyBuffer_IsContiguous(&fragment, 'C')) { + _PyArg_BadArgument("reverse", 1, "contiguous buffer", args[0]); + goto exit; + } + if (PyFloat_Check(args[1])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + width = _PyLong_AsInt(args[1]); + if (width == -1 && PyErr_Occurred()) { goto exit; } return_value = audioop_reverse_impl(module, &fragment, width); @@ -627,8 +939,23 @@ audioop_byteswap(PyObject *module, PyObject *const *args, Py_ssize_t nargs) Py_buffer fragment = {NULL, NULL}; int width; - if (!_PyArg_ParseStack(args, nargs, "y*i:byteswap", - &fragment, &width)) { + if (!_PyArg_CheckPositional("byteswap", nargs, 2, 2)) { + goto exit; + } + if (PyObject_GetBuffer(args[0], &fragment, PyBUF_SIMPLE) != 0) { + goto exit; + } + if (!PyBuffer_IsContiguous(&fragment, 'C')) { + _PyArg_BadArgument("byteswap", 1, "contiguous buffer", args[0]); + goto exit; + } + if (PyFloat_Check(args[1])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + width = _PyLong_AsInt(args[1]); + if (width == -1 && PyErr_Occurred()) { goto exit; } return_value = audioop_byteswap_impl(module, &fragment, width); @@ -663,8 +990,32 @@ audioop_lin2lin(PyObject *module, PyObject *const *args, Py_ssize_t nargs) int width; int newwidth; - if (!_PyArg_ParseStack(args, nargs, "y*ii:lin2lin", - &fragment, &width, &newwidth)) { + if (!_PyArg_CheckPositional("lin2lin", nargs, 3, 3)) { + goto exit; + } + if (PyObject_GetBuffer(args[0], &fragment, PyBUF_SIMPLE) != 0) { + goto exit; + } + if (!PyBuffer_IsContiguous(&fragment, 'C')) { + _PyArg_BadArgument("lin2lin", 1, "contiguous buffer", args[0]); + goto exit; + } + if (PyFloat_Check(args[1])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + width = _PyLong_AsInt(args[1]); + if (width == -1 && PyErr_Occurred()) { + goto exit; + } + if (PyFloat_Check(args[2])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + newwidth = _PyLong_AsInt(args[2]); + if (newwidth == -1 && PyErr_Occurred()) { goto exit; } return_value = audioop_lin2lin_impl(module, &fragment, width, newwidth); @@ -706,10 +1057,78 @@ audioop_ratecv(PyObject *module, PyObject *const *args, Py_ssize_t nargs) int weightA = 1; int weightB = 0; - if (!_PyArg_ParseStack(args, nargs, "y*iiiiO|ii:ratecv", - &fragment, &width, &nchannels, &inrate, &outrate, &state, &weightA, &weightB)) { + if (!_PyArg_CheckPositional("ratecv", nargs, 6, 8)) { + goto exit; + } + if (PyObject_GetBuffer(args[0], &fragment, PyBUF_SIMPLE) != 0) { + goto exit; + } + if (!PyBuffer_IsContiguous(&fragment, 'C')) { + _PyArg_BadArgument("ratecv", 1, "contiguous buffer", args[0]); + goto exit; + } + if (PyFloat_Check(args[1])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + width = _PyLong_AsInt(args[1]); + if (width == -1 && PyErr_Occurred()) { + goto exit; + } + if (PyFloat_Check(args[2])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + nchannels = _PyLong_AsInt(args[2]); + if (nchannels == -1 && PyErr_Occurred()) { + goto exit; + } + if (PyFloat_Check(args[3])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); goto exit; } + inrate = _PyLong_AsInt(args[3]); + if (inrate == -1 && PyErr_Occurred()) { + goto exit; + } + if (PyFloat_Check(args[4])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + outrate = _PyLong_AsInt(args[4]); + if (outrate == -1 && PyErr_Occurred()) { + goto exit; + } + state = args[5]; + if (nargs < 7) { + goto skip_optional; + } + if (PyFloat_Check(args[6])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + weightA = _PyLong_AsInt(args[6]); + if (weightA == -1 && PyErr_Occurred()) { + goto exit; + } + if (nargs < 8) { + goto skip_optional; + } + if (PyFloat_Check(args[7])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + weightB = _PyLong_AsInt(args[7]); + if (weightB == -1 && PyErr_Occurred()) { + goto exit; + } +skip_optional: return_value = audioop_ratecv_impl(module, &fragment, width, nchannels, inrate, outrate, state, weightA, weightB); exit: @@ -740,8 +1159,23 @@ audioop_lin2ulaw(PyObject *module, PyObject *const *args, Py_ssize_t nargs) Py_buffer fragment = {NULL, NULL}; int width; - if (!_PyArg_ParseStack(args, nargs, "y*i:lin2ulaw", - &fragment, &width)) { + if (!_PyArg_CheckPositional("lin2ulaw", nargs, 2, 2)) { + goto exit; + } + if (PyObject_GetBuffer(args[0], &fragment, PyBUF_SIMPLE) != 0) { + goto exit; + } + if (!PyBuffer_IsContiguous(&fragment, 'C')) { + _PyArg_BadArgument("lin2ulaw", 1, "contiguous buffer", args[0]); + goto exit; + } + if (PyFloat_Check(args[1])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + width = _PyLong_AsInt(args[1]); + if (width == -1 && PyErr_Occurred()) { goto exit; } return_value = audioop_lin2ulaw_impl(module, &fragment, width); @@ -774,8 +1208,23 @@ audioop_ulaw2lin(PyObject *module, PyObject *const *args, Py_ssize_t nargs) Py_buffer fragment = {NULL, NULL}; int width; - if (!_PyArg_ParseStack(args, nargs, "y*i:ulaw2lin", - &fragment, &width)) { + if (!_PyArg_CheckPositional("ulaw2lin", nargs, 2, 2)) { + goto exit; + } + if (PyObject_GetBuffer(args[0], &fragment, PyBUF_SIMPLE) != 0) { + goto exit; + } + if (!PyBuffer_IsContiguous(&fragment, 'C')) { + _PyArg_BadArgument("ulaw2lin", 1, "contiguous buffer", args[0]); + goto exit; + } + if (PyFloat_Check(args[1])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + width = _PyLong_AsInt(args[1]); + if (width == -1 && PyErr_Occurred()) { goto exit; } return_value = audioop_ulaw2lin_impl(module, &fragment, width); @@ -808,8 +1257,23 @@ audioop_lin2alaw(PyObject *module, PyObject *const *args, Py_ssize_t nargs) Py_buffer fragment = {NULL, NULL}; int width; - if (!_PyArg_ParseStack(args, nargs, "y*i:lin2alaw", - &fragment, &width)) { + if (!_PyArg_CheckPositional("lin2alaw", nargs, 2, 2)) { + goto exit; + } + if (PyObject_GetBuffer(args[0], &fragment, PyBUF_SIMPLE) != 0) { + goto exit; + } + if (!PyBuffer_IsContiguous(&fragment, 'C')) { + _PyArg_BadArgument("lin2alaw", 1, "contiguous buffer", args[0]); + goto exit; + } + if (PyFloat_Check(args[1])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + width = _PyLong_AsInt(args[1]); + if (width == -1 && PyErr_Occurred()) { goto exit; } return_value = audioop_lin2alaw_impl(module, &fragment, width); @@ -842,8 +1306,23 @@ audioop_alaw2lin(PyObject *module, PyObject *const *args, Py_ssize_t nargs) Py_buffer fragment = {NULL, NULL}; int width; - if (!_PyArg_ParseStack(args, nargs, "y*i:alaw2lin", - &fragment, &width)) { + if (!_PyArg_CheckPositional("alaw2lin", nargs, 2, 2)) { + goto exit; + } + if (PyObject_GetBuffer(args[0], &fragment, PyBUF_SIMPLE) != 0) { + goto exit; + } + if (!PyBuffer_IsContiguous(&fragment, 'C')) { + _PyArg_BadArgument("alaw2lin", 1, "contiguous buffer", args[0]); + goto exit; + } + if (PyFloat_Check(args[1])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + width = _PyLong_AsInt(args[1]); + if (width == -1 && PyErr_Occurred()) { goto exit; } return_value = audioop_alaw2lin_impl(module, &fragment, width); @@ -878,10 +1357,26 @@ audioop_lin2adpcm(PyObject *module, PyObject *const *args, Py_ssize_t nargs) int width; PyObject *state; - if (!_PyArg_ParseStack(args, nargs, "y*iO:lin2adpcm", - &fragment, &width, &state)) { + if (!_PyArg_CheckPositional("lin2adpcm", nargs, 3, 3)) { goto exit; } + if (PyObject_GetBuffer(args[0], &fragment, PyBUF_SIMPLE) != 0) { + goto exit; + } + if (!PyBuffer_IsContiguous(&fragment, 'C')) { + _PyArg_BadArgument("lin2adpcm", 1, "contiguous buffer", args[0]); + goto exit; + } + if (PyFloat_Check(args[1])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + width = _PyLong_AsInt(args[1]); + if (width == -1 && PyErr_Occurred()) { + goto exit; + } + state = args[2]; return_value = audioop_lin2adpcm_impl(module, &fragment, width, state); exit: @@ -914,10 +1409,26 @@ audioop_adpcm2lin(PyObject *module, PyObject *const *args, Py_ssize_t nargs) int width; PyObject *state; - if (!_PyArg_ParseStack(args, nargs, "y*iO:adpcm2lin", - &fragment, &width, &state)) { + if (!_PyArg_CheckPositional("adpcm2lin", nargs, 3, 3)) { + goto exit; + } + if (PyObject_GetBuffer(args[0], &fragment, PyBUF_SIMPLE) != 0) { + goto exit; + } + if (!PyBuffer_IsContiguous(&fragment, 'C')) { + _PyArg_BadArgument("adpcm2lin", 1, "contiguous buffer", args[0]); + goto exit; + } + if (PyFloat_Check(args[1])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + width = _PyLong_AsInt(args[1]); + if (width == -1 && PyErr_Occurred()) { goto exit; } + state = args[2]; return_value = audioop_adpcm2lin_impl(module, &fragment, width, state); exit: @@ -928,4 +1439,4 @@ exit: return return_value; } -/*[clinic end generated code: output=d197b1559196a48a input=a9049054013a1b77]*/ +/*[clinic end generated code: output=2b173a25726252e9 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/binascii.c.h b/Modules/clinic/binascii.c.h index 91f261c..3295833 100644 --- a/Modules/clinic/binascii.c.h +++ b/Modules/clinic/binascii.c.h @@ -189,7 +189,7 @@ binascii_rlecode_hqx(PyObject *module, PyObject *arg) goto exit; } if (!PyBuffer_IsContiguous(&data, 'C')) { - _PyArg_BadArgument("rlecode_hqx", "contiguous buffer", arg); + _PyArg_BadArgument("rlecode_hqx", 0, "contiguous buffer", arg); goto exit; } return_value = binascii_rlecode_hqx_impl(module, &data); @@ -225,7 +225,7 @@ binascii_b2a_hqx(PyObject *module, PyObject *arg) goto exit; } if (!PyBuffer_IsContiguous(&data, 'C')) { - _PyArg_BadArgument("b2a_hqx", "contiguous buffer", arg); + _PyArg_BadArgument("b2a_hqx", 0, "contiguous buffer", arg); goto exit; } return_value = binascii_b2a_hqx_impl(module, &data); @@ -261,7 +261,7 @@ binascii_rledecode_hqx(PyObject *module, PyObject *arg) goto exit; } if (!PyBuffer_IsContiguous(&data, 'C')) { - _PyArg_BadArgument("rledecode_hqx", "contiguous buffer", arg); + _PyArg_BadArgument("rledecode_hqx", 0, "contiguous buffer", arg); goto exit; } return_value = binascii_rledecode_hqx_impl(module, &data); @@ -295,8 +295,23 @@ binascii_crc_hqx(PyObject *module, PyObject *const *args, Py_ssize_t nargs) unsigned int crc; unsigned int _return_value; - if (!_PyArg_ParseStack(args, nargs, "y*I:crc_hqx", - &data, &crc)) { + if (!_PyArg_CheckPositional("crc_hqx", nargs, 2, 2)) { + goto exit; + } + if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) { + goto exit; + } + if (!PyBuffer_IsContiguous(&data, 'C')) { + _PyArg_BadArgument("crc_hqx", 1, "contiguous buffer", args[0]); + goto exit; + } + if (PyFloat_Check(args[1])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + crc = (unsigned int)PyLong_AsUnsignedLongMask(args[1]); + if (crc == (unsigned int)-1 && PyErr_Occurred()) { goto exit; } _return_value = binascii_crc_hqx_impl(module, &data, crc); @@ -334,10 +349,29 @@ binascii_crc32(PyObject *module, PyObject *const *args, Py_ssize_t nargs) unsigned int crc = 0; unsigned int _return_value; - if (!_PyArg_ParseStack(args, nargs, "y*|I:crc32", - &data, &crc)) { + if (!_PyArg_CheckPositional("crc32", nargs, 1, 2)) { + goto exit; + } + if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) { + goto exit; + } + if (!PyBuffer_IsContiguous(&data, 'C')) { + _PyArg_BadArgument("crc32", 1, "contiguous buffer", args[0]); + goto exit; + } + if (nargs < 2) { + goto skip_optional; + } + if (PyFloat_Check(args[1])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + crc = (unsigned int)PyLong_AsUnsignedLongMask(args[1]); + if (crc == (unsigned int)-1 && PyErr_Occurred()) { goto exit; } +skip_optional: _return_value = binascii_crc32_impl(module, &data, crc); if ((_return_value == (unsigned int)-1) && PyErr_Occurred()) { goto exit; @@ -378,7 +412,7 @@ binascii_b2a_hex(PyObject *module, PyObject *arg) goto exit; } if (!PyBuffer_IsContiguous(&data, 'C')) { - _PyArg_BadArgument("b2a_hex", "contiguous buffer", arg); + _PyArg_BadArgument("b2a_hex", 0, "contiguous buffer", arg); goto exit; } return_value = binascii_b2a_hex_impl(module, &data); @@ -416,7 +450,7 @@ binascii_hexlify(PyObject *module, PyObject *arg) goto exit; } if (!PyBuffer_IsContiguous(&data, 'C')) { - _PyArg_BadArgument("hexlify", "contiguous buffer", arg); + _PyArg_BadArgument("hexlify", 0, "contiguous buffer", arg); goto exit; } return_value = binascii_hexlify_impl(module, &data); @@ -574,4 +608,4 @@ exit: return return_value; } -/*[clinic end generated code: output=8ff0cb5717b15d1b input=a9049054013a1b77]*/ +/*[clinic end generated code: output=7210a01a718da4a0 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/cmathmodule.c.h b/Modules/clinic/cmathmodule.c.h index 30378c7..cc1b8f2 100644 --- a/Modules/clinic/cmathmodule.c.h +++ b/Modules/clinic/cmathmodule.c.h @@ -668,10 +668,18 @@ cmath_log(PyObject *module, PyObject *const *args, Py_ssize_t nargs) Py_complex x; PyObject *y_obj = NULL; - if (!_PyArg_ParseStack(args, nargs, "D|O:log", - &x, &y_obj)) { + if (!_PyArg_CheckPositional("log", nargs, 1, 2)) { goto exit; } + x = PyComplex_AsCComplex(args[0]); + if (PyErr_Occurred()) { + goto exit; + } + if (nargs < 2) { + goto skip_optional; + } + y_obj = args[1]; +skip_optional: return_value = cmath_log_impl(module, x, y_obj); exit: @@ -755,8 +763,15 @@ cmath_rect(PyObject *module, PyObject *const *args, Py_ssize_t nargs) double r; double phi; - if (!_PyArg_ParseStack(args, nargs, "dd:rect", - &r, &phi)) { + if (!_PyArg_CheckPositional("rect", nargs, 2, 2)) { + goto exit; + } + r = PyFloat_AsDouble(args[0]); + if (PyErr_Occurred()) { + goto exit; + } + phi = PyFloat_AsDouble(args[1]); + if (PyErr_Occurred()) { goto exit; } return_value = cmath_rect_impl(module, r, phi); @@ -902,4 +917,4 @@ cmath_isclose(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObjec exit: return return_value; } -/*[clinic end generated code: output=50a105aa2bc5308f input=a9049054013a1b77]*/ +/*[clinic end generated code: output=86a365d23f34aaff input=a9049054013a1b77]*/ diff --git a/Modules/clinic/fcntlmodule.c.h b/Modules/clinic/fcntlmodule.c.h index 7b5a280..024a44c 100644 --- a/Modules/clinic/fcntlmodule.c.h +++ b/Modules/clinic/fcntlmodule.c.h @@ -32,10 +32,26 @@ fcntl_fcntl(PyObject *module, PyObject *const *args, Py_ssize_t nargs) int code; PyObject *arg = NULL; - if (!_PyArg_ParseStack(args, nargs, "O&i|O:fcntl", - conv_descriptor, &fd, &code, &arg)) { + if (!_PyArg_CheckPositional("fcntl", nargs, 2, 3)) { goto exit; } + if (!conv_descriptor(args[0], &fd)) { + goto exit; + } + if (PyFloat_Check(args[1])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + code = _PyLong_AsInt(args[1]); + if (code == -1 && PyErr_Occurred()) { + goto exit; + } + if (nargs < 3) { + goto skip_optional; + } + arg = args[2]; +skip_optional: return_value = fcntl_fcntl_impl(module, fd, code, arg); exit: @@ -91,10 +107,33 @@ fcntl_ioctl(PyObject *module, PyObject *const *args, Py_ssize_t nargs) PyObject *ob_arg = NULL; int mutate_arg = 1; - if (!_PyArg_ParseStack(args, nargs, "O&I|Op:ioctl", - conv_descriptor, &fd, &code, &ob_arg, &mutate_arg)) { + if (!_PyArg_CheckPositional("ioctl", nargs, 2, 4)) { + goto exit; + } + if (!conv_descriptor(args[0], &fd)) { goto exit; } + if (PyFloat_Check(args[1])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + code = (unsigned int)PyLong_AsUnsignedLongMask(args[1]); + if (code == (unsigned int)-1 && PyErr_Occurred()) { + goto exit; + } + if (nargs < 3) { + goto skip_optional; + } + ob_arg = args[2]; + if (nargs < 4) { + goto skip_optional; + } + mutate_arg = PyObject_IsTrue(args[3]); + if (mutate_arg < 0) { + goto exit; + } +skip_optional: return_value = fcntl_ioctl_impl(module, fd, code, ob_arg, mutate_arg); exit: @@ -123,8 +162,19 @@ fcntl_flock(PyObject *module, PyObject *const *args, Py_ssize_t nargs) int fd; int code; - if (!_PyArg_ParseStack(args, nargs, "O&i:flock", - conv_descriptor, &fd, &code)) { + if (!_PyArg_CheckPositional("flock", nargs, 2, 2)) { + goto exit; + } + if (!conv_descriptor(args[0], &fd)) { + goto exit; + } + if (PyFloat_Check(args[1])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + code = _PyLong_AsInt(args[1]); + if (code == -1 && PyErr_Occurred()) { goto exit; } return_value = fcntl_flock_impl(module, fd, code); @@ -177,13 +227,45 @@ fcntl_lockf(PyObject *module, PyObject *const *args, Py_ssize_t nargs) PyObject *startobj = NULL; int whence = 0; - if (!_PyArg_ParseStack(args, nargs, "O&i|OOi:lockf", - conv_descriptor, &fd, &code, &lenobj, &startobj, &whence)) { + if (!_PyArg_CheckPositional("lockf", nargs, 2, 5)) { + goto exit; + } + if (!conv_descriptor(args[0], &fd)) { + goto exit; + } + if (PyFloat_Check(args[1])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + code = _PyLong_AsInt(args[1]); + if (code == -1 && PyErr_Occurred()) { + goto exit; + } + if (nargs < 3) { + goto skip_optional; + } + lenobj = args[2]; + if (nargs < 4) { + goto skip_optional; + } + startobj = args[3]; + if (nargs < 5) { + goto skip_optional; + } + if (PyFloat_Check(args[4])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + whence = _PyLong_AsInt(args[4]); + if (whence == -1 && PyErr_Occurred()) { goto exit; } +skip_optional: return_value = fcntl_lockf_impl(module, fd, code, lenobj, startobj, whence); exit: return return_value; } -/*[clinic end generated code: output=fc1a781750750a14 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=e912d25e28362c52 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/itertoolsmodule.c.h b/Modules/clinic/itertoolsmodule.c.h index b7d70a3..9fc429a 100644 --- a/Modules/clinic/itertoolsmodule.c.h +++ b/Modules/clinic/itertoolsmodule.c.h @@ -52,10 +52,15 @@ itertools__grouper(PyTypeObject *type, PyObject *args, PyObject *kwargs) !_PyArg_NoKeywords("_grouper", kwargs)) { goto exit; } - if (!PyArg_ParseTuple(args, "O!O:_grouper", - &groupby_type, &parent, &tgtkey)) { + if (!_PyArg_CheckPositional("_grouper", PyTuple_GET_SIZE(args), 2, 2)) { goto exit; } + if (!PyObject_TypeCheck(PyTuple_GET_ITEM(args, 0), &groupby_type)) { + _PyArg_BadArgument("_grouper", 1, (&groupby_type)->tp_name, PyTuple_GET_ITEM(args, 0)); + goto exit; + } + parent = PyTuple_GET_ITEM(args, 0); + tgtkey = PyTuple_GET_ITEM(args, 1); return_value = itertools__grouper_impl(type, parent, tgtkey); exit: @@ -84,10 +89,16 @@ itertools_teedataobject(PyTypeObject *type, PyObject *args, PyObject *kwargs) !_PyArg_NoKeywords("teedataobject", kwargs)) { goto exit; } - if (!PyArg_ParseTuple(args, "OO!O:teedataobject", - &it, &PyList_Type, &values, &next)) { + if (!_PyArg_CheckPositional("teedataobject", PyTuple_GET_SIZE(args), 3, 3)) { + goto exit; + } + it = PyTuple_GET_ITEM(args, 0); + if (!PyList_Check(PyTuple_GET_ITEM(args, 1))) { + _PyArg_BadArgument("teedataobject", 2, "list", PyTuple_GET_ITEM(args, 1)); goto exit; } + values = PyTuple_GET_ITEM(args, 1); + next = PyTuple_GET_ITEM(args, 2); return_value = itertools_teedataobject_impl(type, it, values, next); exit: @@ -143,10 +154,31 @@ itertools_tee(PyObject *module, PyObject *const *args, Py_ssize_t nargs) PyObject *iterable; Py_ssize_t n = 2; - if (!_PyArg_ParseStack(args, nargs, "O|n:tee", - &iterable, &n)) { + if (!_PyArg_CheckPositional("tee", nargs, 1, 2)) { goto exit; } + iterable = 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; + } + n = ival; + } +skip_optional: return_value = itertools_tee_impl(module, iterable, n); exit: @@ -510,4 +542,4 @@ itertools_count(PyTypeObject *type, PyObject *args, PyObject *kwargs) exit: return return_value; } -/*[clinic end generated code: output=916251f891fa84b9 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=f289354f54e04c13 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/mathmodule.c.h b/Modules/clinic/mathmodule.c.h index e436f59..1165789 100644 --- a/Modules/clinic/mathmodule.c.h +++ b/Modules/clinic/mathmodule.c.h @@ -139,10 +139,14 @@ math_ldexp(PyObject *module, PyObject *const *args, Py_ssize_t nargs) double x; PyObject *i; - if (!_PyArg_ParseStack(args, nargs, "dO:ldexp", - &x, &i)) { + if (!_PyArg_CheckPositional("ldexp", nargs, 2, 2)) { goto exit; } + x = PyFloat_AsDouble(args[0]); + if (PyErr_Occurred()) { + goto exit; + } + i = args[1]; return_value = math_ldexp_impl(module, x, i); exit: @@ -261,8 +265,15 @@ math_fmod(PyObject *module, PyObject *const *args, Py_ssize_t nargs) double x; double y; - if (!_PyArg_ParseStack(args, nargs, "dd:fmod", - &x, &y)) { + if (!_PyArg_CheckPositional("fmod", nargs, 2, 2)) { + goto exit; + } + x = PyFloat_AsDouble(args[0]); + if (PyErr_Occurred()) { + goto exit; + } + y = PyFloat_AsDouble(args[1]); + if (PyErr_Occurred()) { goto exit; } return_value = math_fmod_impl(module, x, y); @@ -326,8 +337,15 @@ math_pow(PyObject *module, PyObject *const *args, Py_ssize_t nargs) double x; double y; - if (!_PyArg_ParseStack(args, nargs, "dd:pow", - &x, &y)) { + if (!_PyArg_CheckPositional("pow", nargs, 2, 2)) { + goto exit; + } + x = PyFloat_AsDouble(args[0]); + if (PyErr_Occurred()) { + goto exit; + } + y = PyFloat_AsDouble(args[1]); + if (PyErr_Occurred()) { goto exit; } return_value = math_pow_impl(module, x, y); @@ -530,4 +548,4 @@ math_isclose(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject exit: return return_value; } -/*[clinic end generated code: output=da4b9940a5cb0188 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=2fe4fecd85585313 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/posixmodule.c.h b/Modules/clinic/posixmodule.c.h index e310d99..2c1ee97 100644 --- a/Modules/clinic/posixmodule.c.h +++ b/Modules/clinic/posixmodule.c.h @@ -1658,10 +1658,13 @@ os_execv(PyObject *module, PyObject *const *args, Py_ssize_t nargs) path_t path = PATH_T_INITIALIZE("execv", "path", 0, 0); PyObject *argv; - if (!_PyArg_ParseStack(args, nargs, "O&O:execv", - path_converter, &path, &argv)) { + if (!_PyArg_CheckPositional("execv", nargs, 2, 2)) { goto exit; } + if (!path_converter(args[0], &path)) { + goto exit; + } + argv = args[1]; return_value = os_execv_impl(module, &path, argv); exit: @@ -1817,10 +1820,22 @@ os_spawnv(PyObject *module, PyObject *const *args, Py_ssize_t nargs) path_t path = PATH_T_INITIALIZE("spawnv", "path", 0, 0); PyObject *argv; - if (!_PyArg_ParseStack(args, nargs, "iO&O:spawnv", - &mode, path_converter, &path, &argv)) { + if (!_PyArg_CheckPositional("spawnv", nargs, 3, 3)) { + goto exit; + } + if (PyFloat_Check(args[0])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + mode = _PyLong_AsInt(args[0]); + if (mode == -1 && PyErr_Occurred()) { + goto exit; + } + if (!path_converter(args[1], &path)) { goto exit; } + argv = args[2]; return_value = os_spawnv_impl(module, mode, &path, argv); exit: @@ -1865,10 +1880,23 @@ os_spawnve(PyObject *module, PyObject *const *args, Py_ssize_t nargs) PyObject *argv; PyObject *env; - if (!_PyArg_ParseStack(args, nargs, "iO&OO:spawnve", - &mode, path_converter, &path, &argv, &env)) { + if (!_PyArg_CheckPositional("spawnve", nargs, 4, 4)) { goto exit; } + if (PyFloat_Check(args[0])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + mode = _PyLong_AsInt(args[0]); + if (mode == -1 && PyErr_Occurred()) { + goto exit; + } + if (!path_converter(args[1], &path)) { + goto exit; + } + argv = args[2]; + env = args[3]; return_value = os_spawnve_impl(module, mode, &path, argv, env); exit: @@ -2874,8 +2902,13 @@ os_setreuid(PyObject *module, PyObject *const *args, Py_ssize_t nargs) uid_t ruid; uid_t euid; - if (!_PyArg_ParseStack(args, nargs, "O&O&:setreuid", - _Py_Uid_Converter, &ruid, _Py_Uid_Converter, &euid)) { + if (!_PyArg_CheckPositional("setreuid", nargs, 2, 2)) { + goto exit; + } + if (!_Py_Uid_Converter(args[0], &ruid)) { + goto exit; + } + if (!_Py_Uid_Converter(args[1], &euid)) { goto exit; } return_value = os_setreuid_impl(module, ruid, euid); @@ -2907,8 +2940,13 @@ os_setregid(PyObject *module, PyObject *const *args, Py_ssize_t nargs) gid_t rgid; gid_t egid; - if (!_PyArg_ParseStack(args, nargs, "O&O&:setregid", - _Py_Gid_Converter, &rgid, _Py_Gid_Converter, &egid)) { + if (!_PyArg_CheckPositional("setregid", nargs, 2, 2)) { + goto exit; + } + if (!_Py_Gid_Converter(args[0], &rgid)) { + goto exit; + } + if (!_Py_Gid_Converter(args[1], &egid)) { goto exit; } return_value = os_setregid_impl(module, rgid, egid); @@ -3558,8 +3596,25 @@ os_closerange(PyObject *module, PyObject *const *args, Py_ssize_t nargs) int fd_low; int fd_high; - if (!_PyArg_ParseStack(args, nargs, "ii:closerange", - &fd_low, &fd_high)) { + if (!_PyArg_CheckPositional("closerange", nargs, 2, 2)) { + goto exit; + } + if (PyFloat_Check(args[0])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + fd_low = _PyLong_AsInt(args[0]); + if (fd_low == -1 && PyErr_Occurred()) { + goto exit; + } + if (PyFloat_Check(args[1])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + fd_high = _PyLong_AsInt(args[1]); + if (fd_high == -1 && PyErr_Occurred()) { goto exit; } return_value = os_closerange_impl(module, fd_low, fd_high); @@ -3672,8 +3727,28 @@ os_lockf(PyObject *module, PyObject *const *args, Py_ssize_t nargs) int command; Py_off_t length; - if (!_PyArg_ParseStack(args, nargs, "iiO&:lockf", - &fd, &command, Py_off_t_converter, &length)) { + if (!_PyArg_CheckPositional("lockf", nargs, 3, 3)) { + goto exit; + } + if (PyFloat_Check(args[0])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + fd = _PyLong_AsInt(args[0]); + if (fd == -1 && PyErr_Occurred()) { + goto exit; + } + if (PyFloat_Check(args[1])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + command = _PyLong_AsInt(args[1]); + if (command == -1 && PyErr_Occurred()) { + goto exit; + } + if (!Py_off_t_converter(args[2], &length)) { goto exit; } return_value = os_lockf_impl(module, fd, command, length); @@ -3708,8 +3783,28 @@ os_lseek(PyObject *module, PyObject *const *args, Py_ssize_t nargs) int how; Py_off_t _return_value; - if (!_PyArg_ParseStack(args, nargs, "iO&i:lseek", - &fd, Py_off_t_converter, &position, &how)) { + if (!_PyArg_CheckPositional("lseek", nargs, 3, 3)) { + goto exit; + } + if (PyFloat_Check(args[0])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + fd = _PyLong_AsInt(args[0]); + if (fd == -1 && PyErr_Occurred()) { + goto exit; + } + if (!Py_off_t_converter(args[1], &position)) { + goto exit; + } + if (PyFloat_Check(args[2])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + how = _PyLong_AsInt(args[2]); + if (how == -1 && PyErr_Occurred()) { goto exit; } _return_value = os_lseek_impl(module, fd, position, how); @@ -3741,10 +3836,35 @@ os_read(PyObject *module, PyObject *const *args, Py_ssize_t nargs) int fd; Py_ssize_t length; - if (!_PyArg_ParseStack(args, nargs, "in:read", - &fd, &length)) { + if (!_PyArg_CheckPositional("read", nargs, 2, 2)) { + goto exit; + } + if (PyFloat_Check(args[0])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + fd = _PyLong_AsInt(args[0]); + if (fd == -1 && PyErr_Occurred()) { + goto exit; + } + 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; + } + length = ival; + } return_value = os_read_impl(module, fd, length); exit: @@ -3781,10 +3901,19 @@ os_readv(PyObject *module, PyObject *const *args, Py_ssize_t nargs) PyObject *buffers; Py_ssize_t _return_value; - if (!_PyArg_ParseStack(args, nargs, "iO:readv", - &fd, &buffers)) { + if (!_PyArg_CheckPositional("readv", nargs, 2, 2)) { + goto exit; + } + if (PyFloat_Check(args[0])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + fd = _PyLong_AsInt(args[0]); + if (fd == -1 && PyErr_Occurred()) { goto exit; } + buffers = args[1]; _return_value = os_readv_impl(module, fd, buffers); if ((_return_value == -1) && PyErr_Occurred()) { goto exit; @@ -3822,8 +3951,28 @@ os_pread(PyObject *module, PyObject *const *args, Py_ssize_t nargs) int length; Py_off_t offset; - if (!_PyArg_ParseStack(args, nargs, "iiO&:pread", - &fd, &length, Py_off_t_converter, &offset)) { + if (!_PyArg_CheckPositional("pread", nargs, 3, 3)) { + goto exit; + } + if (PyFloat_Check(args[0])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + fd = _PyLong_AsInt(args[0]); + if (fd == -1 && PyErr_Occurred()) { + goto exit; + } + if (PyFloat_Check(args[1])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + length = _PyLong_AsInt(args[1]); + if (length == -1 && PyErr_Occurred()) { + goto exit; + } + if (!Py_off_t_converter(args[2], &offset)) { goto exit; } return_value = os_pread_impl(module, fd, length, offset); @@ -3873,10 +4022,35 @@ os_preadv(PyObject *module, PyObject *const *args, Py_ssize_t nargs) int flags = 0; Py_ssize_t _return_value; - if (!_PyArg_ParseStack(args, nargs, "iOO&|i:preadv", - &fd, &buffers, Py_off_t_converter, &offset, &flags)) { + if (!_PyArg_CheckPositional("preadv", nargs, 3, 4)) { + goto exit; + } + if (PyFloat_Check(args[0])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + fd = _PyLong_AsInt(args[0]); + if (fd == -1 && PyErr_Occurred()) { + goto exit; + } + buffers = args[1]; + if (!Py_off_t_converter(args[2], &offset)) { goto exit; } + if (nargs < 4) { + goto skip_optional; + } + if (PyFloat_Check(args[3])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + flags = _PyLong_AsInt(args[3]); + if (flags == -1 && PyErr_Occurred()) { + goto exit; + } +skip_optional: _return_value = os_preadv_impl(module, fd, buffers, offset, flags); if ((_return_value == -1) && PyErr_Occurred()) { goto exit; @@ -3909,8 +4083,23 @@ os_write(PyObject *module, PyObject *const *args, Py_ssize_t nargs) Py_buffer data = {NULL, NULL}; Py_ssize_t _return_value; - if (!_PyArg_ParseStack(args, nargs, "iy*:write", - &fd, &data)) { + if (!_PyArg_CheckPositional("write", nargs, 2, 2)) { + goto exit; + } + if (PyFloat_Check(args[0])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + fd = _PyLong_AsInt(args[0]); + if (fd == -1 && PyErr_Occurred()) { + goto exit; + } + if (PyObject_GetBuffer(args[1], &data, PyBUF_SIMPLE) != 0) { + goto exit; + } + if (!PyBuffer_IsContiguous(&data, 'C')) { + _PyArg_BadArgument("write", 2, "contiguous buffer", args[1]); goto exit; } _return_value = os_write_impl(module, fd, &data); @@ -3950,8 +4139,34 @@ os__fcopyfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs) int outfd; int flags; - if (!_PyArg_ParseStack(args, nargs, "iii:_fcopyfile", - &infd, &outfd, &flags)) { + if (!_PyArg_CheckPositional("_fcopyfile", nargs, 3, 3)) { + goto exit; + } + if (PyFloat_Check(args[0])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + infd = _PyLong_AsInt(args[0]); + if (infd == -1 && PyErr_Occurred()) { + goto exit; + } + if (PyFloat_Check(args[1])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + outfd = _PyLong_AsInt(args[1]); + if (outfd == -1 && PyErr_Occurred()) { + goto exit; + } + if (PyFloat_Check(args[2])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + flags = _PyLong_AsInt(args[2]); + if (flags == -1 && PyErr_Occurred()) { goto exit; } return_value = os__fcopyfile_impl(module, infd, outfd, flags); @@ -4129,10 +4344,19 @@ os_writev(PyObject *module, PyObject *const *args, Py_ssize_t nargs) PyObject *buffers; Py_ssize_t _return_value; - if (!_PyArg_ParseStack(args, nargs, "iO:writev", - &fd, &buffers)) { + if (!_PyArg_CheckPositional("writev", nargs, 2, 2)) { + goto exit; + } + if (PyFloat_Check(args[0])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); goto exit; } + fd = _PyLong_AsInt(args[0]); + if (fd == -1 && PyErr_Occurred()) { + goto exit; + } + buffers = args[1]; _return_value = os_writev_impl(module, fd, buffers); if ((_return_value == -1) && PyErr_Occurred()) { goto exit; @@ -4172,8 +4396,26 @@ os_pwrite(PyObject *module, PyObject *const *args, Py_ssize_t nargs) Py_off_t offset; Py_ssize_t _return_value; - if (!_PyArg_ParseStack(args, nargs, "iy*O&:pwrite", - &fd, &buffer, Py_off_t_converter, &offset)) { + if (!_PyArg_CheckPositional("pwrite", nargs, 3, 3)) { + goto exit; + } + if (PyFloat_Check(args[0])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + fd = _PyLong_AsInt(args[0]); + if (fd == -1 && PyErr_Occurred()) { + goto exit; + } + if (PyObject_GetBuffer(args[1], &buffer, PyBUF_SIMPLE) != 0) { + goto exit; + } + if (!PyBuffer_IsContiguous(&buffer, 'C')) { + _PyArg_BadArgument("pwrite", 2, "contiguous buffer", args[1]); + goto exit; + } + if (!Py_off_t_converter(args[2], &offset)) { goto exit; } _return_value = os_pwrite_impl(module, fd, &buffer, offset); @@ -4232,10 +4474,35 @@ os_pwritev(PyObject *module, PyObject *const *args, Py_ssize_t nargs) int flags = 0; Py_ssize_t _return_value; - if (!_PyArg_ParseStack(args, nargs, "iOO&|i:pwritev", - &fd, &buffers, Py_off_t_converter, &offset, &flags)) { + if (!_PyArg_CheckPositional("pwritev", nargs, 3, 4)) { + goto exit; + } + if (PyFloat_Check(args[0])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + fd = _PyLong_AsInt(args[0]); + if (fd == -1 && PyErr_Occurred()) { + goto exit; + } + buffers = args[1]; + if (!Py_off_t_converter(args[2], &offset)) { + goto exit; + } + if (nargs < 4) { + goto skip_optional; + } + if (PyFloat_Check(args[3])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + flags = _PyLong_AsInt(args[3]); + if (flags == -1 && PyErr_Occurred()) { goto exit; } +skip_optional: _return_value = os_pwritev_impl(module, fd, buffers, offset, flags); if ((_return_value == -1) && PyErr_Occurred()) { goto exit; @@ -4439,8 +4706,25 @@ os_makedev(PyObject *module, PyObject *const *args, Py_ssize_t nargs) int minor; dev_t _return_value; - if (!_PyArg_ParseStack(args, nargs, "ii:makedev", - &major, &minor)) { + if (!_PyArg_CheckPositional("makedev", nargs, 2, 2)) { + goto exit; + } + if (PyFloat_Check(args[0])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + major = _PyLong_AsInt(args[0]); + if (major == -1 && PyErr_Occurred()) { + goto exit; + } + if (PyFloat_Check(args[1])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + minor = _PyLong_AsInt(args[1]); + if (minor == -1 && PyErr_Occurred()) { goto exit; } _return_value = os_makedev_impl(module, major, minor); @@ -4476,8 +4760,19 @@ os_ftruncate(PyObject *module, PyObject *const *args, Py_ssize_t nargs) int fd; Py_off_t length; - if (!_PyArg_ParseStack(args, nargs, "iO&:ftruncate", - &fd, Py_off_t_converter, &length)) { + if (!_PyArg_CheckPositional("ftruncate", nargs, 2, 2)) { + goto exit; + } + if (PyFloat_Check(args[0])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + fd = _PyLong_AsInt(args[0]); + if (fd == -1 && PyErr_Occurred()) { + goto exit; + } + if (!Py_off_t_converter(args[1], &length)) { goto exit; } return_value = os_ftruncate_impl(module, fd, length); @@ -4555,8 +4850,22 @@ os_posix_fallocate(PyObject *module, PyObject *const *args, Py_ssize_t nargs) Py_off_t offset; Py_off_t length; - if (!_PyArg_ParseStack(args, nargs, "iO&O&:posix_fallocate", - &fd, Py_off_t_converter, &offset, Py_off_t_converter, &length)) { + if (!_PyArg_CheckPositional("posix_fallocate", nargs, 3, 3)) { + goto exit; + } + if (PyFloat_Check(args[0])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + fd = _PyLong_AsInt(args[0]); + if (fd == -1 && PyErr_Occurred()) { + goto exit; + } + if (!Py_off_t_converter(args[1], &offset)) { + goto exit; + } + if (!Py_off_t_converter(args[2], &length)) { goto exit; } return_value = os_posix_fallocate_impl(module, fd, offset, length); @@ -4599,8 +4908,31 @@ os_posix_fadvise(PyObject *module, PyObject *const *args, Py_ssize_t nargs) Py_off_t length; int advice; - if (!_PyArg_ParseStack(args, nargs, "iO&O&i:posix_fadvise", - &fd, Py_off_t_converter, &offset, Py_off_t_converter, &length, &advice)) { + if (!_PyArg_CheckPositional("posix_fadvise", nargs, 4, 4)) { + goto exit; + } + if (PyFloat_Check(args[0])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + fd = _PyLong_AsInt(args[0]); + if (fd == -1 && PyErr_Occurred()) { + goto exit; + } + if (!Py_off_t_converter(args[1], &offset)) { + goto exit; + } + if (!Py_off_t_converter(args[2], &length)) { + goto exit; + } + if (PyFloat_Check(args[3])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + advice = _PyLong_AsInt(args[3]); + if (advice == -1 && PyErr_Occurred()) { goto exit; } return_value = os_posix_fadvise_impl(module, fd, offset, length, advice); @@ -4632,10 +4964,25 @@ os_putenv(PyObject *module, PyObject *const *args, Py_ssize_t nargs) PyObject *name; PyObject *value; - if (!_PyArg_ParseStack(args, nargs, "UU:putenv", - &name, &value)) { + if (!_PyArg_CheckPositional("putenv", nargs, 2, 2)) { + goto exit; + } + if (!PyUnicode_Check(args[0])) { + _PyArg_BadArgument("putenv", 1, "str", args[0]); + goto exit; + } + if (PyUnicode_READY(args[0]) == -1) { + goto exit; + } + name = args[0]; + if (!PyUnicode_Check(args[1])) { + _PyArg_BadArgument("putenv", 2, "str", args[1]); + goto exit; + } + if (PyUnicode_READY(args[1]) == -1) { goto exit; } + value = args[1]; return_value = os_putenv_impl(module, name, value); exit: @@ -4665,8 +5012,13 @@ os_putenv(PyObject *module, PyObject *const *args, Py_ssize_t nargs) PyObject *name = NULL; PyObject *value = NULL; - if (!_PyArg_ParseStack(args, nargs, "O&O&:putenv", - PyUnicode_FSConverter, &name, PyUnicode_FSConverter, &value)) { + if (!_PyArg_CheckPositional("putenv", nargs, 2, 2)) { + goto exit; + } + if (!PyUnicode_FSConverter(args[0], &name)) { + goto exit; + } + if (!PyUnicode_FSConverter(args[1], &value)) { goto exit; } return_value = os_putenv_impl(module, name, value); @@ -5208,8 +5560,19 @@ os_fpathconf(PyObject *module, PyObject *const *args, Py_ssize_t nargs) int name; long _return_value; - if (!_PyArg_ParseStack(args, nargs, "iO&:fpathconf", - &fd, conv_path_confname, &name)) { + if (!_PyArg_CheckPositional("fpathconf", nargs, 2, 2)) { + goto exit; + } + if (PyFloat_Check(args[0])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + fd = _PyLong_AsInt(args[0]); + if (fd == -1 && PyErr_Occurred()) { + goto exit; + } + if (!conv_path_confname(args[1], &name)) { goto exit; } _return_value = os_fpathconf_impl(module, fd, name); @@ -5496,8 +5859,16 @@ os_setresuid(PyObject *module, PyObject *const *args, Py_ssize_t nargs) uid_t euid; uid_t suid; - if (!_PyArg_ParseStack(args, nargs, "O&O&O&:setresuid", - _Py_Uid_Converter, &ruid, _Py_Uid_Converter, &euid, _Py_Uid_Converter, &suid)) { + if (!_PyArg_CheckPositional("setresuid", nargs, 3, 3)) { + goto exit; + } + if (!_Py_Uid_Converter(args[0], &ruid)) { + goto exit; + } + if (!_Py_Uid_Converter(args[1], &euid)) { + goto exit; + } + if (!_Py_Uid_Converter(args[2], &suid)) { goto exit; } return_value = os_setresuid_impl(module, ruid, euid, suid); @@ -5530,8 +5901,16 @@ os_setresgid(PyObject *module, PyObject *const *args, Py_ssize_t nargs) gid_t egid; gid_t sgid; - if (!_PyArg_ParseStack(args, nargs, "O&O&O&:setresgid", - _Py_Gid_Converter, &rgid, _Py_Gid_Converter, &egid, _Py_Gid_Converter, &sgid)) { + if (!_PyArg_CheckPositional("setresgid", nargs, 3, 3)) { + goto exit; + } + if (!_Py_Gid_Converter(args[0], &rgid)) { + goto exit; + } + if (!_Py_Gid_Converter(args[1], &egid)) { + goto exit; + } + if (!_Py_Gid_Converter(args[2], &sgid)) { goto exit; } return_value = os_setresgid_impl(module, rgid, egid, sgid); @@ -5898,8 +6277,25 @@ os_set_inheritable(PyObject *module, PyObject *const *args, Py_ssize_t nargs) int fd; int inheritable; - if (!_PyArg_ParseStack(args, nargs, "ii:set_inheritable", - &fd, &inheritable)) { + if (!_PyArg_CheckPositional("set_inheritable", nargs, 2, 2)) { + goto exit; + } + if (PyFloat_Check(args[0])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + fd = _PyLong_AsInt(args[0]); + if (fd == -1 && PyErr_Occurred()) { + goto exit; + } + if (PyFloat_Check(args[1])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + inheritable = _PyLong_AsInt(args[1]); + if (inheritable == -1 && PyErr_Occurred()) { goto exit; } return_value = os_set_inheritable_impl(module, fd, inheritable); @@ -6046,8 +6442,25 @@ os_set_blocking(PyObject *module, PyObject *const *args, Py_ssize_t nargs) int fd; int blocking; - if (!_PyArg_ParseStack(args, nargs, "ii:set_blocking", - &fd, &blocking)) { + if (!_PyArg_CheckPositional("set_blocking", nargs, 2, 2)) { + goto exit; + } + if (PyFloat_Check(args[0])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + fd = _PyLong_AsInt(args[0]); + if (fd == -1 && PyErr_Occurred()) { + goto exit; + } + if (PyFloat_Check(args[1])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + blocking = _PyLong_AsInt(args[1]); + if (blocking == -1 && PyErr_Occurred()) { goto exit; } return_value = os_set_blocking_impl(module, fd, blocking); @@ -6845,4 +7258,4 @@ exit: #ifndef OS_GETRANDOM_METHODDEF #define OS_GETRANDOM_METHODDEF #endif /* !defined(OS_GETRANDOM_METHODDEF) */ -/*[clinic end generated code: output=b02036b2a269b1db input=a9049054013a1b77]*/ +/*[clinic end generated code: output=febc1e16c9024e40 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/pwdmodule.c.h b/Modules/clinic/pwdmodule.c.h index 9270be0..cf84ec9 100644 --- a/Modules/clinic/pwdmodule.c.h +++ b/Modules/clinic/pwdmodule.c.h @@ -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]*/ diff --git a/Modules/clinic/pyexpat.c.h b/Modules/clinic/pyexpat.c.h index 1545485..3fe7b64 100644 --- a/Modules/clinic/pyexpat.c.h +++ b/Modules/clinic/pyexpat.c.h @@ -24,10 +24,23 @@ pyexpat_xmlparser_Parse(xmlparseobject *self, PyObject *const *args, Py_ssize_t PyObject *data; int isfinal = 0; - if (!_PyArg_ParseStack(args, nargs, "O|i:Parse", - &data, &isfinal)) { + if (!_PyArg_CheckPositional("Parse", nargs, 1, 2)) { goto exit; } + data = args[0]; + if (nargs < 2) { + goto skip_optional; + } + if (PyFloat_Check(args[1])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + isfinal = _PyLong_AsInt(args[1]); + if (isfinal == -1 && PyErr_Occurred()) { + goto exit; + } +skip_optional: return_value = pyexpat_xmlparser_Parse_impl(self, data, isfinal); exit: @@ -62,7 +75,7 @@ pyexpat_xmlparser_SetBase(xmlparseobject *self, PyObject *arg) const char *base; if (!PyUnicode_Check(arg)) { - _PyArg_BadArgument("SetBase", "str", arg); + _PyArg_BadArgument("SetBase", 0, "str", arg); goto exit; } Py_ssize_t base_length; @@ -140,10 +153,44 @@ pyexpat_xmlparser_ExternalEntityParserCreate(xmlparseobject *self, PyObject *con const char *context; const char *encoding = NULL; - if (!_PyArg_ParseStack(args, nargs, "z|s:ExternalEntityParserCreate", - &context, &encoding)) { + if (!_PyArg_CheckPositional("ExternalEntityParserCreate", nargs, 1, 2)) { + goto exit; + } + if (args[0] == Py_None) { + context = NULL; + } + else if (PyUnicode_Check(args[0])) { + Py_ssize_t context_length; + context = PyUnicode_AsUTF8AndSize(args[0], &context_length); + if (context == NULL) { + goto exit; + } + if (strlen(context) != (size_t)context_length) { + PyErr_SetString(PyExc_ValueError, "embedded null character"); + goto exit; + } + } + else { + _PyArg_BadArgument("ExternalEntityParserCreate", 1, "str or None", args[0]); goto exit; } + if (nargs < 2) { + goto skip_optional; + } + if (!PyUnicode_Check(args[1])) { + _PyArg_BadArgument("ExternalEntityParserCreate", 2, "str", args[1]); + goto exit; + } + Py_ssize_t encoding_length; + encoding = PyUnicode_AsUTF8AndSize(args[1], &encoding_length); + if (encoding == NULL) { + goto exit; + } + if (strlen(encoding) != (size_t)encoding_length) { + PyErr_SetString(PyExc_ValueError, "embedded null character"); + goto exit; + } +skip_optional: return_value = pyexpat_xmlparser_ExternalEntityParserCreate_impl(self, context, encoding); exit: @@ -212,10 +259,17 @@ pyexpat_xmlparser_UseForeignDTD(xmlparseobject *self, PyObject *const *args, Py_ PyObject *return_value = NULL; int flag = 1; - if (!_PyArg_ParseStack(args, nargs, "|p:UseForeignDTD", - &flag)) { + if (!_PyArg_CheckPositional("UseForeignDTD", nargs, 0, 1)) { + goto exit; + } + if (nargs < 1) { + goto skip_optional; + } + flag = PyObject_IsTrue(args[0]); + if (flag < 0) { goto exit; } +skip_optional: return_value = pyexpat_xmlparser_UseForeignDTD_impl(self, flag); exit: @@ -294,4 +348,4 @@ exit: #ifndef PYEXPAT_XMLPARSER_USEFOREIGNDTD_METHODDEF #define PYEXPAT_XMLPARSER_USEFOREIGNDTD_METHODDEF #endif /* !defined(PYEXPAT_XMLPARSER_USEFOREIGNDTD_METHODDEF) */ -/*[clinic end generated code: output=d3750256eb0da1cb input=a9049054013a1b77]*/ +/*[clinic end generated code: output=0f18b756d82b78a5 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/resource.c.h b/Modules/clinic/resource.c.h index 0a66f8f..80efb71 100644 --- a/Modules/clinic/resource.c.h +++ b/Modules/clinic/resource.c.h @@ -84,10 +84,19 @@ resource_setrlimit(PyObject *module, PyObject *const *args, Py_ssize_t nargs) int resource; PyObject *limits; - if (!_PyArg_ParseStack(args, nargs, "iO:setrlimit", - &resource, &limits)) { + if (!_PyArg_CheckPositional("setrlimit", nargs, 2, 2)) { goto exit; } + if (PyFloat_Check(args[0])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + resource = _PyLong_AsInt(args[0]); + if (resource == -1 && PyErr_Occurred()) { + goto exit; + } + limits = args[1]; return_value = resource_setrlimit_impl(module, resource, limits); exit: @@ -169,4 +178,4 @@ exit: #ifndef RESOURCE_PRLIMIT_METHODDEF #define RESOURCE_PRLIMIT_METHODDEF #endif /* !defined(RESOURCE_PRLIMIT_METHODDEF) */ -/*[clinic end generated code: output=b16a9149639081fd input=a9049054013a1b77]*/ +/*[clinic end generated code: output=ef3034f291156a34 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/selectmodule.c.h b/Modules/clinic/selectmodule.c.h index bb69d95..655e24c 100644 --- a/Modules/clinic/selectmodule.c.h +++ b/Modules/clinic/selectmodule.c.h @@ -82,10 +82,19 @@ select_poll_register(pollObject *self, PyObject *const *args, Py_ssize_t nargs) int fd; unsigned short eventmask = POLLIN | POLLPRI | POLLOUT; - if (!_PyArg_ParseStack(args, nargs, "O&|O&:register", - fildes_converter, &fd, _PyLong_UnsignedShort_Converter, &eventmask)) { + if (!_PyArg_CheckPositional("register", nargs, 1, 2)) { goto exit; } + if (!fildes_converter(args[0], &fd)) { + goto exit; + } + if (nargs < 2) { + goto skip_optional; + } + if (!_PyLong_UnsignedShort_Converter(args[1], &eventmask)) { + goto exit; + } +skip_optional: return_value = select_poll_register_impl(self, fd, eventmask); exit: @@ -121,8 +130,13 @@ select_poll_modify(pollObject *self, PyObject *const *args, Py_ssize_t nargs) int fd; unsigned short eventmask; - if (!_PyArg_ParseStack(args, nargs, "O&O&:modify", - fildes_converter, &fd, _PyLong_UnsignedShort_Converter, &eventmask)) { + if (!_PyArg_CheckPositional("modify", nargs, 2, 2)) { + goto exit; + } + if (!fildes_converter(args[0], &fd)) { + goto exit; + } + if (!_PyLong_UnsignedShort_Converter(args[1], &eventmask)) { goto exit; } return_value = select_poll_modify_impl(self, fd, eventmask); @@ -228,10 +242,19 @@ select_devpoll_register(devpollObject *self, PyObject *const *args, Py_ssize_t n int fd; unsigned short eventmask = POLLIN | POLLPRI | POLLOUT; - if (!_PyArg_ParseStack(args, nargs, "O&|O&:register", - fildes_converter, &fd, _PyLong_UnsignedShort_Converter, &eventmask)) { + if (!_PyArg_CheckPositional("register", nargs, 1, 2)) { + goto exit; + } + if (!fildes_converter(args[0], &fd)) { + goto exit; + } + if (nargs < 2) { + goto skip_optional; + } + if (!_PyLong_UnsignedShort_Converter(args[1], &eventmask)) { goto exit; } +skip_optional: return_value = select_devpoll_register_impl(self, fd, eventmask); exit: @@ -268,10 +291,19 @@ select_devpoll_modify(devpollObject *self, PyObject *const *args, Py_ssize_t nar int fd; unsigned short eventmask = POLLIN | POLLPRI | POLLOUT; - if (!_PyArg_ParseStack(args, nargs, "O&|O&:modify", - fildes_converter, &fd, _PyLong_UnsignedShort_Converter, &eventmask)) { + if (!_PyArg_CheckPositional("modify", nargs, 1, 2)) { + goto exit; + } + if (!fildes_converter(args[0], &fd)) { goto exit; } + if (nargs < 2) { + goto skip_optional; + } + if (!_PyLong_UnsignedShort_Converter(args[1], &eventmask)) { + goto exit; + } +skip_optional: return_value = select_devpoll_modify_impl(self, fd, eventmask); exit: @@ -948,10 +980,24 @@ select_kqueue_control(kqueue_queue_Object *self, PyObject *const *args, Py_ssize int maxevents; PyObject *otimeout = Py_None; - if (!_PyArg_ParseStack(args, nargs, "Oi|O:control", - &changelist, &maxevents, &otimeout)) { + if (!_PyArg_CheckPositional("control", nargs, 2, 3)) { goto exit; } + changelist = args[0]; + if (PyFloat_Check(args[1])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + maxevents = _PyLong_AsInt(args[1]); + if (maxevents == -1 && PyErr_Occurred()) { + goto exit; + } + if (nargs < 3) { + goto skip_optional; + } + otimeout = args[2]; +skip_optional: return_value = select_kqueue_control_impl(self, changelist, maxevents, otimeout); exit: @@ -1059,4 +1105,4 @@ exit: #ifndef SELECT_KQUEUE_CONTROL_METHODDEF #define SELECT_KQUEUE_CONTROL_METHODDEF #endif /* !defined(SELECT_KQUEUE_CONTROL_METHODDEF) */ -/*[clinic end generated code: output=122a49f131cdd9d9 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=20da8f9c050e1b65 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/signalmodule.c.h b/Modules/clinic/signalmodule.c.h index f374226..bc46515 100644 --- a/Modules/clinic/signalmodule.c.h +++ b/Modules/clinic/signalmodule.c.h @@ -125,10 +125,19 @@ signal_signal(PyObject *module, PyObject *const *args, Py_ssize_t nargs) int signalnum; PyObject *handler; - if (!_PyArg_ParseStack(args, nargs, "iO:signal", - &signalnum, &handler)) { + if (!_PyArg_CheckPositional("signal", nargs, 2, 2)) { goto exit; } + if (PyFloat_Check(args[0])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + signalnum = _PyLong_AsInt(args[0]); + if (signalnum == -1 && PyErr_Occurred()) { + goto exit; + } + handler = args[1]; return_value = signal_signal_impl(module, signalnum, handler); exit: @@ -234,8 +243,25 @@ signal_siginterrupt(PyObject *module, PyObject *const *args, Py_ssize_t nargs) int signalnum; int flag; - if (!_PyArg_ParseStack(args, nargs, "ii:siginterrupt", - &signalnum, &flag)) { + if (!_PyArg_CheckPositional("siginterrupt", nargs, 2, 2)) { + goto exit; + } + if (PyFloat_Check(args[0])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + signalnum = _PyLong_AsInt(args[0]); + if (signalnum == -1 && PyErr_Occurred()) { + goto exit; + } + if (PyFloat_Check(args[1])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + flag = _PyLong_AsInt(args[1]); + if (flag == -1 && PyErr_Occurred()) { goto exit; } return_value = signal_siginterrupt_impl(module, signalnum, flag); @@ -274,10 +300,24 @@ signal_setitimer(PyObject *module, PyObject *const *args, Py_ssize_t nargs) PyObject *seconds; PyObject *interval = NULL; - if (!_PyArg_ParseStack(args, nargs, "iO|O:setitimer", - &which, &seconds, &interval)) { + if (!_PyArg_CheckPositional("setitimer", nargs, 2, 3)) { + goto exit; + } + if (PyFloat_Check(args[0])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); goto exit; } + which = _PyLong_AsInt(args[0]); + if (which == -1 && PyErr_Occurred()) { + goto exit; + } + seconds = args[1]; + if (nargs < 3) { + goto skip_optional; + } + interval = args[2]; +skip_optional: return_value = signal_setitimer_impl(module, which, seconds, interval); exit: @@ -344,8 +384,19 @@ signal_pthread_sigmask(PyObject *module, PyObject *const *args, Py_ssize_t nargs int how; sigset_t mask; - if (!_PyArg_ParseStack(args, nargs, "iO&:pthread_sigmask", - &how, _Py_Sigset_Converter, &mask)) { + if (!_PyArg_CheckPositional("pthread_sigmask", nargs, 2, 2)) { + goto exit; + } + if (PyFloat_Check(args[0])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + how = _PyLong_AsInt(args[0]); + if (how == -1 && PyErr_Occurred()) { + goto exit; + } + if (!_Py_Sigset_Converter(args[1], &mask)) { goto exit; } return_value = signal_pthread_sigmask_impl(module, how, mask); @@ -498,10 +549,13 @@ signal_sigtimedwait(PyObject *module, PyObject *const *args, Py_ssize_t nargs) sigset_t sigset; PyObject *timeout_obj; - if (!_PyArg_ParseStack(args, nargs, "O&O:sigtimedwait", - _Py_Sigset_Converter, &sigset, &timeout_obj)) { + if (!_PyArg_CheckPositional("sigtimedwait", nargs, 2, 2)) { goto exit; } + if (!_Py_Sigset_Converter(args[0], &sigset)) { + goto exit; + } + timeout_obj = args[1]; return_value = signal_sigtimedwait_impl(module, sigset, timeout_obj); exit: @@ -532,8 +586,21 @@ signal_pthread_kill(PyObject *module, PyObject *const *args, Py_ssize_t nargs) unsigned long thread_id; int signalnum; - if (!_PyArg_ParseStack(args, nargs, "ki:pthread_kill", - &thread_id, &signalnum)) { + if (!_PyArg_CheckPositional("pthread_kill", nargs, 2, 2)) { + goto exit; + } + if (!PyLong_Check(args[0])) { + _PyArg_BadArgument("pthread_kill", 1, "int", args[0]); + goto exit; + } + thread_id = PyLong_AsUnsignedLongMask(args[0]); + if (PyFloat_Check(args[1])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + signalnum = _PyLong_AsInt(args[1]); + if (signalnum == -1 && PyErr_Occurred()) { goto exit; } return_value = signal_pthread_kill_impl(module, thread_id, signalnum); @@ -591,4 +658,4 @@ exit: #ifndef SIGNAL_PTHREAD_KILL_METHODDEF #define SIGNAL_PTHREAD_KILL_METHODDEF #endif /* !defined(SIGNAL_PTHREAD_KILL_METHODDEF) */ -/*[clinic end generated code: output=365db4e807c26d4e input=a9049054013a1b77]*/ +/*[clinic end generated code: output=f0d3a5703581da76 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/spwdmodule.c.h b/Modules/clinic/spwdmodule.c.h index a0a3e2e..e051e6e 100644 --- a/Modules/clinic/spwdmodule.c.h +++ b/Modules/clinic/spwdmodule.c.h @@ -25,7 +25,7 @@ spwd_getspnam(PyObject *module, PyObject *arg_) PyObject *arg; if (!PyUnicode_Check(arg_)) { - _PyArg_BadArgument("getspnam", "str", arg_); + _PyArg_BadArgument("getspnam", 0, "str", arg_); goto exit; } if (PyUnicode_READY(arg_) == -1) { @@ -71,4 +71,4 @@ spwd_getspall(PyObject *module, PyObject *Py_UNUSED(ignored)) #ifndef SPWD_GETSPALL_METHODDEF #define SPWD_GETSPALL_METHODDEF #endif /* !defined(SPWD_GETSPALL_METHODDEF) */ -/*[clinic end generated code: output=44a7c196d4b48f4e input=a9049054013a1b77]*/ +/*[clinic end generated code: output=2bbaa6bab1d9116e input=a9049054013a1b77]*/ diff --git a/Modules/clinic/symtablemodule.c.h b/Modules/clinic/symtablemodule.c.h index b5e64e0..73e340b 100644 --- a/Modules/clinic/symtablemodule.c.h +++ b/Modules/clinic/symtablemodule.c.h @@ -23,8 +23,36 @@ _symtable_symtable(PyObject *module, PyObject *const *args, Py_ssize_t nargs) PyObject *filename; const char *startstr; - if (!_PyArg_ParseStack(args, nargs, "sO&s:symtable", - &str, PyUnicode_FSDecoder, &filename, &startstr)) { + if (!_PyArg_CheckPositional("symtable", nargs, 3, 3)) { + goto exit; + } + if (!PyUnicode_Check(args[0])) { + _PyArg_BadArgument("symtable", 1, "str", args[0]); + goto exit; + } + Py_ssize_t str_length; + str = PyUnicode_AsUTF8AndSize(args[0], &str_length); + if (str == NULL) { + goto exit; + } + if (strlen(str) != (size_t)str_length) { + PyErr_SetString(PyExc_ValueError, "embedded null character"); + goto exit; + } + if (!PyUnicode_FSDecoder(args[1], &filename)) { + goto exit; + } + if (!PyUnicode_Check(args[2])) { + _PyArg_BadArgument("symtable", 3, "str", args[2]); + goto exit; + } + Py_ssize_t startstr_length; + startstr = PyUnicode_AsUTF8AndSize(args[2], &startstr_length); + if (startstr == NULL) { + goto exit; + } + if (strlen(startstr) != (size_t)startstr_length) { + PyErr_SetString(PyExc_ValueError, "embedded null character"); goto exit; } return_value = _symtable_symtable_impl(module, str, filename, startstr); @@ -32,4 +60,4 @@ _symtable_symtable(PyObject *module, PyObject *const *args, Py_ssize_t nargs) exit: return return_value; } -/*[clinic end generated code: output=52ece07dd0e7a113 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=be1cca59de019984 input=a9049054013a1b77]*/ diff --git a/Modules/clinic/unicodedata.c.h b/Modules/clinic/unicodedata.c.h index 9e8d261..8ca0881 100644 --- a/Modules/clinic/unicodedata.c.h +++ b/Modules/clinic/unicodedata.c.h @@ -26,10 +26,26 @@ unicodedata_UCD_decimal(PyObject *self, PyObject *const *args, Py_ssize_t nargs) int chr; PyObject *default_value = NULL; - if (!_PyArg_ParseStack(args, nargs, "C|O:decimal", - &chr, &default_value)) { + if (!_PyArg_CheckPositional("decimal", nargs, 1, 2)) { goto exit; } + if (!PyUnicode_Check(args[0])) { + _PyArg_BadArgument("decimal", 1, "a unicode character", args[0]); + goto exit; + } + if (PyUnicode_READY(args[0])) { + goto exit; + } + if (PyUnicode_GET_LENGTH(args[0]) != 1) { + _PyArg_BadArgument("decimal", 1, "a unicode character", args[0]); + goto exit; + } + chr = PyUnicode_READ_CHAR(args[0], 0); + if (nargs < 2) { + goto skip_optional; + } + default_value = args[1]; +skip_optional: return_value = unicodedata_UCD_decimal_impl(self, chr, default_value); exit: @@ -59,10 +75,26 @@ unicodedata_UCD_digit(PyObject *self, PyObject *const *args, Py_ssize_t nargs) int chr; PyObject *default_value = NULL; - if (!_PyArg_ParseStack(args, nargs, "C|O:digit", - &chr, &default_value)) { + if (!_PyArg_CheckPositional("digit", nargs, 1, 2)) { + goto exit; + } + if (!PyUnicode_Check(args[0])) { + _PyArg_BadArgument("digit", 1, "a unicode character", args[0]); + goto exit; + } + if (PyUnicode_READY(args[0])) { goto exit; } + if (PyUnicode_GET_LENGTH(args[0]) != 1) { + _PyArg_BadArgument("digit", 1, "a unicode character", args[0]); + goto exit; + } + chr = PyUnicode_READ_CHAR(args[0], 0); + if (nargs < 2) { + goto skip_optional; + } + default_value = args[1]; +skip_optional: return_value = unicodedata_UCD_digit_impl(self, chr, default_value); exit: @@ -93,10 +125,26 @@ unicodedata_UCD_numeric(PyObject *self, PyObject *const *args, Py_ssize_t nargs) int chr; PyObject *default_value = NULL; - if (!_PyArg_ParseStack(args, nargs, "C|O:numeric", - &chr, &default_value)) { + if (!_PyArg_CheckPositional("numeric", nargs, 1, 2)) { goto exit; } + if (!PyUnicode_Check(args[0])) { + _PyArg_BadArgument("numeric", 1, "a unicode character", args[0]); + goto exit; + } + if (PyUnicode_READY(args[0])) { + goto exit; + } + if (PyUnicode_GET_LENGTH(args[0]) != 1) { + _PyArg_BadArgument("numeric", 1, "a unicode character", args[0]); + goto exit; + } + chr = PyUnicode_READ_CHAR(args[0], 0); + if (nargs < 2) { + goto skip_optional; + } + default_value = args[1]; +skip_optional: return_value = unicodedata_UCD_numeric_impl(self, chr, default_value); exit: @@ -122,14 +170,14 @@ unicodedata_UCD_category(PyObject *self, PyObject *arg) int chr; if (!PyUnicode_Check(arg)) { - _PyArg_BadArgument("category", "a unicode character", arg); + _PyArg_BadArgument("category", 0, "a unicode character", arg); goto exit; } if (PyUnicode_READY(arg)) { goto exit; } if (PyUnicode_GET_LENGTH(arg) != 1) { - _PyArg_BadArgument("category", "a unicode character", arg); + _PyArg_BadArgument("category", 0, "a unicode character", arg); goto exit; } chr = PyUnicode_READ_CHAR(arg, 0); @@ -160,14 +208,14 @@ unicodedata_UCD_bidirectional(PyObject *self, PyObject *arg) int chr; if (!PyUnicode_Check(arg)) { - _PyArg_BadArgument("bidirectional", "a unicode character", arg); + _PyArg_BadArgument("bidirectional", 0, "a unicode character", arg); goto exit; } if (PyUnicode_READY(arg)) { goto exit; } if (PyUnicode_GET_LENGTH(arg) != 1) { - _PyArg_BadArgument("bidirectional", "a unicode character", arg); + _PyArg_BadArgument("bidirectional", 0, "a unicode character", arg); goto exit; } chr = PyUnicode_READ_CHAR(arg, 0); @@ -199,14 +247,14 @@ unicodedata_UCD_combining(PyObject *self, PyObject *arg) int _return_value; if (!PyUnicode_Check(arg)) { - _PyArg_BadArgument("combining", "a unicode character", arg); + _PyArg_BadArgument("combining", 0, "a unicode character", arg); goto exit; } if (PyUnicode_READY(arg)) { goto exit; } if (PyUnicode_GET_LENGTH(arg) != 1) { - _PyArg_BadArgument("combining", "a unicode character", arg); + _PyArg_BadArgument("combining", 0, "a unicode character", arg); goto exit; } chr = PyUnicode_READ_CHAR(arg, 0); @@ -243,14 +291,14 @@ unicodedata_UCD_mirrored(PyObject *self, PyObject *arg) int _return_value; if (!PyUnicode_Check(arg)) { - _PyArg_BadArgument("mirrored", "a unicode character", arg); + _PyArg_BadArgument("mirrored", 0, "a unicode character", arg); goto exit; } if (PyUnicode_READY(arg)) { goto exit; } if (PyUnicode_GET_LENGTH(arg) != 1) { - _PyArg_BadArgument("mirrored", "a unicode character", arg); + _PyArg_BadArgument("mirrored", 0, "a unicode character", arg); goto exit; } chr = PyUnicode_READ_CHAR(arg, 0); @@ -283,14 +331,14 @@ unicodedata_UCD_east_asian_width(PyObject *self, PyObject *arg) int chr; if (!PyUnicode_Check(arg)) { - _PyArg_BadArgument("east_asian_width", "a unicode character", arg); + _PyArg_BadArgument("east_asian_width", 0, "a unicode character", arg); goto exit; } if (PyUnicode_READY(arg)) { goto exit; } if (PyUnicode_GET_LENGTH(arg) != 1) { - _PyArg_BadArgument("east_asian_width", "a unicode character", arg); + _PyArg_BadArgument("east_asian_width", 0, "a unicode character", arg); goto exit; } chr = PyUnicode_READ_CHAR(arg, 0); @@ -321,14 +369,14 @@ unicodedata_UCD_decomposition(PyObject *self, PyObject *arg) int chr; if (!PyUnicode_Check(arg)) { - _PyArg_BadArgument("decomposition", "a unicode character", arg); + _PyArg_BadArgument("decomposition", 0, "a unicode character", arg); goto exit; } if (PyUnicode_READY(arg)) { goto exit; } if (PyUnicode_GET_LENGTH(arg) != 1) { - _PyArg_BadArgument("decomposition", "a unicode character", arg); + _PyArg_BadArgument("decomposition", 0, "a unicode character", arg); goto exit; } chr = PyUnicode_READ_CHAR(arg, 0); @@ -360,10 +408,25 @@ unicodedata_UCD_is_normalized(PyObject *self, PyObject *const *args, Py_ssize_t PyObject *form; PyObject *input; - if (!_PyArg_ParseStack(args, nargs, "UU:is_normalized", - &form, &input)) { + if (!_PyArg_CheckPositional("is_normalized", nargs, 2, 2)) { + goto exit; + } + if (!PyUnicode_Check(args[0])) { + _PyArg_BadArgument("is_normalized", 1, "str", args[0]); + goto exit; + } + if (PyUnicode_READY(args[0]) == -1) { goto exit; } + form = args[0]; + if (!PyUnicode_Check(args[1])) { + _PyArg_BadArgument("is_normalized", 2, "str", args[1]); + goto exit; + } + if (PyUnicode_READY(args[1]) == -1) { + goto exit; + } + input = args[1]; return_value = unicodedata_UCD_is_normalized_impl(self, form, input); exit: @@ -392,10 +455,25 @@ unicodedata_UCD_normalize(PyObject *self, PyObject *const *args, Py_ssize_t narg PyObject *form; PyObject *input; - if (!_PyArg_ParseStack(args, nargs, "UU:normalize", - &form, &input)) { + if (!_PyArg_CheckPositional("normalize", nargs, 2, 2)) { + goto exit; + } + if (!PyUnicode_Check(args[0])) { + _PyArg_BadArgument("normalize", 1, "str", args[0]); + goto exit; + } + if (PyUnicode_READY(args[0]) == -1) { goto exit; } + form = args[0]; + if (!PyUnicode_Check(args[1])) { + _PyArg_BadArgument("normalize", 2, "str", args[1]); + goto exit; + } + if (PyUnicode_READY(args[1]) == -1) { + goto exit; + } + input = args[1]; return_value = unicodedata_UCD_normalize_impl(self, form, input); exit: @@ -424,10 +502,26 @@ unicodedata_UCD_name(PyObject *self, PyObject *const *args, Py_ssize_t nargs) int chr; PyObject *default_value = NULL; - if (!_PyArg_ParseStack(args, nargs, "C|O:name", - &chr, &default_value)) { + if (!_PyArg_CheckPositional("name", nargs, 1, 2)) { + goto exit; + } + if (!PyUnicode_Check(args[0])) { + _PyArg_BadArgument("name", 1, "a unicode character", args[0]); goto exit; } + if (PyUnicode_READY(args[0])) { + goto exit; + } + if (PyUnicode_GET_LENGTH(args[0]) != 1) { + _PyArg_BadArgument("name", 1, "a unicode character", args[0]); + goto exit; + } + chr = PyUnicode_READ_CHAR(args[0], 0); + if (nargs < 2) { + goto skip_optional; + } + default_value = args[1]; +skip_optional: return_value = unicodedata_UCD_name_impl(self, chr, default_value); exit: @@ -465,4 +559,4 @@ unicodedata_UCD_lookup(PyObject *self, PyObject *arg) exit: return return_value; } -/*[clinic end generated code: output=709241b99d010896 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=0fc850fe5b6b312c input=a9049054013a1b77]*/ diff --git a/Modules/clinic/zlibmodule.c.h b/Modules/clinic/zlibmodule.c.h index 87ad1ea..8e5f96a 100644 --- a/Modules/clinic/zlibmodule.c.h +++ b/Modules/clinic/zlibmodule.c.h @@ -219,7 +219,7 @@ zlib_Compress_compress(compobject *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 = zlib_Compress_compress_impl(self, &data); @@ -305,10 +305,22 @@ zlib_Compress_flush(compobject *self, PyObject *const *args, Py_ssize_t nargs) PyObject *return_value = NULL; int mode = Z_FINISH; - if (!_PyArg_ParseStack(args, nargs, "|i:flush", - &mode)) { + if (!_PyArg_CheckPositional("flush", 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; + } + mode = _PyLong_AsInt(args[0]); + if (mode == -1 && PyErr_Occurred()) { + goto exit; + } +skip_optional: return_value = zlib_Compress_flush_impl(self, mode); exit: @@ -446,10 +458,16 @@ zlib_Decompress_flush(compobject *self, PyObject *const *args, Py_ssize_t nargs) PyObject *return_value = NULL; Py_ssize_t length = DEF_BUF_SIZE; - if (!_PyArg_ParseStack(args, nargs, "|O&:flush", - ssize_t_converter, &length)) { + if (!_PyArg_CheckPositional("flush", nargs, 0, 1)) { + goto exit; + } + if (nargs < 1) { + goto skip_optional; + } + if (!ssize_t_converter(args[0], &length)) { goto exit; } +skip_optional: return_value = zlib_Decompress_flush_impl(self, length); exit: @@ -480,10 +498,29 @@ zlib_adler32(PyObject *module, PyObject *const *args, Py_ssize_t nargs) Py_buffer data = {NULL, NULL}; unsigned int value = 1; - if (!_PyArg_ParseStack(args, nargs, "y*|I:adler32", - &data, &value)) { + if (!_PyArg_CheckPositional("adler32", nargs, 1, 2)) { + goto exit; + } + if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) { + goto exit; + } + if (!PyBuffer_IsContiguous(&data, 'C')) { + _PyArg_BadArgument("adler32", 1, "contiguous buffer", args[0]); + goto exit; + } + if (nargs < 2) { + goto skip_optional; + } + if (PyFloat_Check(args[1])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + value = (unsigned int)PyLong_AsUnsignedLongMask(args[1]); + if (value == (unsigned int)-1 && PyErr_Occurred()) { goto exit; } +skip_optional: return_value = zlib_adler32_impl(module, &data, value); exit: @@ -519,10 +556,29 @@ zlib_crc32(PyObject *module, PyObject *const *args, Py_ssize_t nargs) Py_buffer data = {NULL, NULL}; unsigned int value = 0; - if (!_PyArg_ParseStack(args, nargs, "y*|I:crc32", - &data, &value)) { + if (!_PyArg_CheckPositional("crc32", nargs, 1, 2)) { + goto exit; + } + if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) { + goto exit; + } + if (!PyBuffer_IsContiguous(&data, 'C')) { + _PyArg_BadArgument("crc32", 1, "contiguous buffer", args[0]); + goto exit; + } + if (nargs < 2) { + goto skip_optional; + } + if (PyFloat_Check(args[1])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + value = (unsigned int)PyLong_AsUnsignedLongMask(args[1]); + if (value == (unsigned int)-1 && PyErr_Occurred()) { goto exit; } +skip_optional: return_value = zlib_crc32_impl(module, &data, value); exit: @@ -557,4 +613,4 @@ exit: #ifndef ZLIB_DECOMPRESS___DEEPCOPY___METHODDEF #define ZLIB_DECOMPRESS___DEEPCOPY___METHODDEF #endif /* !defined(ZLIB_DECOMPRESS___DEEPCOPY___METHODDEF) */ -/*[clinic end generated code: output=bea1e3c64573d9fd input=a9049054013a1b77]*/ +/*[clinic end generated code: output=b3acec2384f18782 input=a9049054013a1b77]*/ diff --git a/Objects/clinic/bytearrayobject.c.h b/Objects/clinic/bytearrayobject.c.h index ec35eef..2d7c742 100644 --- a/Objects/clinic/bytearrayobject.c.h +++ b/Objects/clinic/bytearrayobject.c.h @@ -100,8 +100,21 @@ bytearray_maketrans(void *null, PyObject *const *args, Py_ssize_t nargs) Py_buffer frm = {NULL, NULL}; Py_buffer to = {NULL, NULL}; - if (!_PyArg_ParseStack(args, nargs, "y*y*:maketrans", - &frm, &to)) { + if (!_PyArg_CheckPositional("maketrans", nargs, 2, 2)) { + goto exit; + } + if (PyObject_GetBuffer(args[0], &frm, PyBUF_SIMPLE) != 0) { + goto exit; + } + if (!PyBuffer_IsContiguous(&frm, 'C')) { + _PyArg_BadArgument("maketrans", 1, "contiguous buffer", args[0]); + goto exit; + } + if (PyObject_GetBuffer(args[1], &to, PyBUF_SIMPLE) != 0) { + goto exit; + } + if (!PyBuffer_IsContiguous(&to, 'C')) { + _PyArg_BadArgument("maketrans", 2, "contiguous buffer", args[1]); goto exit; } return_value = bytearray_maketrans_impl(&frm, &to); @@ -147,10 +160,44 @@ bytearray_replace(PyByteArrayObject *self, PyObject *const *args, Py_ssize_t nar Py_buffer new = {NULL, NULL}; Py_ssize_t count = -1; - if (!_PyArg_ParseStack(args, nargs, "y*y*|n:replace", - &old, &new, &count)) { + if (!_PyArg_CheckPositional("replace", nargs, 2, 3)) { + goto exit; + } + if (PyObject_GetBuffer(args[0], &old, PyBUF_SIMPLE) != 0) { + goto exit; + } + if (!PyBuffer_IsContiguous(&old, 'C')) { + _PyArg_BadArgument("replace", 1, "contiguous buffer", args[0]); + goto exit; + } + if (PyObject_GetBuffer(args[1], &new, PyBUF_SIMPLE) != 0) { + goto exit; + } + if (!PyBuffer_IsContiguous(&new, 'C')) { + _PyArg_BadArgument("replace", 2, "contiguous buffer", args[1]); + goto exit; + } + if (nargs < 3) { + goto skip_optional; + } + if (PyFloat_Check(args[2])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); goto exit; } + { + Py_ssize_t ival = -1; + PyObject *iobj = PyNumber_Index(args[2]); + if (iobj != NULL) { + ival = PyLong_AsSsize_t(iobj); + Py_DECREF(iobj); + } + if (ival == -1 && PyErr_Occurred()) { + goto exit; + } + count = ival; + } +skip_optional: return_value = bytearray_replace_impl(self, &old, &new, count); exit: @@ -323,8 +370,27 @@ bytearray_insert(PyByteArrayObject *self, PyObject *const *args, Py_ssize_t narg Py_ssize_t index; int item; - if (!_PyArg_ParseStack(args, nargs, "nO&:insert", - &index, _getbytevalue, &item)) { + 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 (!_getbytevalue(args[1], &item)) { goto exit; } return_value = bytearray_insert_impl(self, index, item); @@ -399,10 +465,30 @@ bytearray_pop(PyByteArrayObject *self, PyObject *const *args, Py_ssize_t nargs) PyObject *return_value = NULL; Py_ssize_t index = -1; - if (!_PyArg_ParseStack(args, nargs, "|n:pop", - &index)) { + if (!_PyArg_CheckPositional("pop", 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; + } + index = ival; + } +skip_optional: return_value = bytearray_pop_impl(self, index); exit: @@ -641,7 +727,7 @@ bytearray_fromhex(PyTypeObject *type, PyObject *arg) PyObject *string; if (!PyUnicode_Check(arg)) { - _PyArg_BadArgument("fromhex", "str", arg); + _PyArg_BadArgument("fromhex", 0, "str", arg); goto exit; } if (PyUnicode_READY(arg) == -1) { @@ -690,10 +776,22 @@ bytearray_reduce_ex(PyByteArrayObject *self, PyObject *const *args, Py_ssize_t n PyObject *return_value = NULL; int proto = 0; - if (!_PyArg_ParseStack(args, nargs, "|i:__reduce_ex__", - &proto)) { + if (!_PyArg_CheckPositional("__reduce_ex__", 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; + } + proto = _PyLong_AsInt(args[0]); + if (proto == -1 && PyErr_Occurred()) { goto exit; } +skip_optional: return_value = bytearray_reduce_ex_impl(self, proto); exit: @@ -717,4 +815,4 @@ bytearray_sizeof(PyByteArrayObject *self, PyObject *Py_UNUSED(ignored)) { return bytearray_sizeof_impl(self); } -/*[clinic end generated code: output=cd3e13a1905a473c input=a9049054013a1b77]*/ +/*[clinic end generated code: output=010e281b823d7df1 input=a9049054013a1b77]*/ diff --git a/Objects/clinic/bytesobject.c.h b/Objects/clinic/bytesobject.c.h index 1345b64..4e754d9 100644 --- a/Objects/clinic/bytesobject.c.h +++ b/Objects/clinic/bytesobject.c.h @@ -70,7 +70,7 @@ bytes_partition(PyBytesObject *self, PyObject *arg) goto exit; } if (!PyBuffer_IsContiguous(&sep, 'C')) { - _PyArg_BadArgument("partition", "contiguous buffer", arg); + _PyArg_BadArgument("partition", 0, "contiguous buffer", arg); goto exit; } return_value = bytes_partition_impl(self, &sep); @@ -113,7 +113,7 @@ bytes_rpartition(PyBytesObject *self, PyObject *arg) goto exit; } if (!PyBuffer_IsContiguous(&sep, 'C')) { - _PyArg_BadArgument("rpartition", "contiguous buffer", arg); + _PyArg_BadArgument("rpartition", 0, "contiguous buffer", arg); goto exit; } return_value = bytes_rpartition_impl(self, &sep); @@ -338,8 +338,21 @@ bytes_maketrans(void *null, PyObject *const *args, Py_ssize_t nargs) Py_buffer frm = {NULL, NULL}; Py_buffer to = {NULL, NULL}; - if (!_PyArg_ParseStack(args, nargs, "y*y*:maketrans", - &frm, &to)) { + if (!_PyArg_CheckPositional("maketrans", nargs, 2, 2)) { + goto exit; + } + if (PyObject_GetBuffer(args[0], &frm, PyBUF_SIMPLE) != 0) { + goto exit; + } + if (!PyBuffer_IsContiguous(&frm, 'C')) { + _PyArg_BadArgument("maketrans", 1, "contiguous buffer", args[0]); + goto exit; + } + if (PyObject_GetBuffer(args[1], &to, PyBUF_SIMPLE) != 0) { + goto exit; + } + if (!PyBuffer_IsContiguous(&to, 'C')) { + _PyArg_BadArgument("maketrans", 2, "contiguous buffer", args[1]); goto exit; } return_value = bytes_maketrans_impl(&frm, &to); @@ -385,10 +398,44 @@ bytes_replace(PyBytesObject *self, PyObject *const *args, Py_ssize_t nargs) Py_buffer new = {NULL, NULL}; Py_ssize_t count = -1; - if (!_PyArg_ParseStack(args, nargs, "y*y*|n:replace", - &old, &new, &count)) { + if (!_PyArg_CheckPositional("replace", nargs, 2, 3)) { + goto exit; + } + if (PyObject_GetBuffer(args[0], &old, PyBUF_SIMPLE) != 0) { goto exit; } + if (!PyBuffer_IsContiguous(&old, 'C')) { + _PyArg_BadArgument("replace", 1, "contiguous buffer", args[0]); + goto exit; + } + if (PyObject_GetBuffer(args[1], &new, PyBUF_SIMPLE) != 0) { + goto exit; + } + if (!PyBuffer_IsContiguous(&new, 'C')) { + _PyArg_BadArgument("replace", 2, "contiguous buffer", args[1]); + goto exit; + } + if (nargs < 3) { + goto skip_optional; + } + if (PyFloat_Check(args[2])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + { + Py_ssize_t ival = -1; + PyObject *iobj = PyNumber_Index(args[2]); + if (iobj != NULL) { + ival = PyLong_AsSsize_t(iobj); + Py_DECREF(iobj); + } + if (ival == -1 && PyErr_Occurred()) { + goto exit; + } + count = ival; + } +skip_optional: return_value = bytes_replace_impl(self, &old, &new, count); exit: @@ -500,7 +547,7 @@ bytes_fromhex(PyTypeObject *type, PyObject *arg) PyObject *string; if (!PyUnicode_Check(arg)) { - _PyArg_BadArgument("fromhex", "str", arg); + _PyArg_BadArgument("fromhex", 0, "str", arg); goto exit; } if (PyUnicode_READY(arg) == -1) { @@ -512,4 +559,4 @@ bytes_fromhex(PyTypeObject *type, PyObject *arg) exit: return return_value; } -/*[clinic end generated code: output=dc9aa04f0007ab11 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=810c8dfc72520ca4 input=a9049054013a1b77]*/ diff --git a/Objects/clinic/floatobject.c.h b/Objects/clinic/floatobject.c.h index 28b24d0..741ca3b 100644 --- a/Objects/clinic/floatobject.c.h +++ b/Objects/clinic/floatobject.c.h @@ -229,7 +229,7 @@ float___getformat__(PyTypeObject *type, PyObject *arg) const char *typestr; if (!PyUnicode_Check(arg)) { - _PyArg_BadArgument("__getformat__", "str", arg); + _PyArg_BadArgument("__getformat__", 0, "str", arg); goto exit; } Py_ssize_t typestr_length; @@ -279,8 +279,33 @@ float___set_format__(PyTypeObject *type, PyObject *const *args, Py_ssize_t nargs const char *typestr; const char *fmt; - if (!_PyArg_ParseStack(args, nargs, "ss:__set_format__", - &typestr, &fmt)) { + if (!_PyArg_CheckPositional("__set_format__", nargs, 2, 2)) { + goto exit; + } + if (!PyUnicode_Check(args[0])) { + _PyArg_BadArgument("__set_format__", 1, "str", args[0]); + goto exit; + } + Py_ssize_t typestr_length; + typestr = PyUnicode_AsUTF8AndSize(args[0], &typestr_length); + if (typestr == NULL) { + goto exit; + } + if (strlen(typestr) != (size_t)typestr_length) { + PyErr_SetString(PyExc_ValueError, "embedded null character"); + goto exit; + } + if (!PyUnicode_Check(args[1])) { + _PyArg_BadArgument("__set_format__", 2, "str", args[1]); + goto exit; + } + Py_ssize_t fmt_length; + fmt = PyUnicode_AsUTF8AndSize(args[1], &fmt_length); + if (fmt == NULL) { + goto exit; + } + if (strlen(fmt) != (size_t)fmt_length) { + PyErr_SetString(PyExc_ValueError, "embedded null character"); goto exit; } return_value = float___set_format___impl(type, typestr, fmt); @@ -308,7 +333,7 @@ float___format__(PyObject *self, PyObject *arg) PyObject *format_spec; if (!PyUnicode_Check(arg)) { - _PyArg_BadArgument("__format__", "str", arg); + _PyArg_BadArgument("__format__", 0, "str", arg); goto exit; } if (PyUnicode_READY(arg) == -1) { @@ -320,4 +345,4 @@ float___format__(PyObject *self, PyObject *arg) exit: return return_value; } -/*[clinic end generated code: output=e8f8be828462d58b input=a9049054013a1b77]*/ +/*[clinic end generated code: output=2631a60701a8f7d4 input=a9049054013a1b77]*/ diff --git a/Objects/clinic/listobject.c.h b/Objects/clinic/listobject.c.h index 0097481..3617458 100644 --- a/Objects/clinic/listobject.c.h +++ b/Objects/clinic/listobject.c.h @@ -21,10 +21,27 @@ list_insert(PyListObject *self, PyObject *const *args, Py_ssize_t nargs) Py_ssize_t index; PyObject *object; - if (!_PyArg_ParseStack(args, nargs, "nO:insert", - &index, &object)) { + 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; + } + object = args[1]; return_value = list_insert_impl(self, index, object); exit: @@ -105,10 +122,30 @@ list_pop(PyListObject *self, PyObject *const *args, Py_ssize_t nargs) PyObject *return_value = NULL; Py_ssize_t index = -1; - if (!_PyArg_ParseStack(args, nargs, "|n:pop", - &index)) { + if (!_PyArg_CheckPositional("pop", 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; + } + index = ival; + } +skip_optional: return_value = list_pop_impl(self, index); exit: @@ -187,10 +224,23 @@ list_index(PyListObject *self, PyObject *const *args, Py_ssize_t nargs) Py_ssize_t start = 0; Py_ssize_t stop = PY_SSIZE_T_MAX; - if (!_PyArg_ParseStack(args, nargs, "O|O&O&:index", - &value, _PyEval_SliceIndexNotNone, &start, _PyEval_SliceIndexNotNone, &stop)) { + if (!_PyArg_CheckPositional("index", nargs, 1, 3)) { + goto exit; + } + value = args[0]; + if (nargs < 2) { + goto skip_optional; + } + if (!_PyEval_SliceIndexNotNone(args[1], &start)) { + goto exit; + } + if (nargs < 3) { + goto skip_optional; + } + if (!_PyEval_SliceIndexNotNone(args[2], &stop)) { goto exit; } +skip_optional: return_value = list_index_impl(self, value, start, stop); exit: @@ -285,4 +335,4 @@ list___reversed__(PyListObject *self, PyObject *Py_UNUSED(ignored)) { return list___reversed___impl(self); } -/*[clinic end generated code: output=652ae4ee63a9de71 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=1f641f5aef3f886f input=a9049054013a1b77]*/ diff --git a/Objects/clinic/longobject.c.h b/Objects/clinic/longobject.c.h index 27cdf9e..6770023 100644 --- a/Objects/clinic/longobject.c.h +++ b/Objects/clinic/longobject.c.h @@ -59,7 +59,7 @@ int___format__(PyObject *self, PyObject *arg) PyObject *format_spec; if (!PyUnicode_Check(arg)) { - _PyArg_BadArgument("__format__", "str", arg); + _PyArg_BadArgument("__format__", 0, "str", arg); goto exit; } if (PyUnicode_READY(arg) == -1) { @@ -244,4 +244,4 @@ int_from_bytes(PyTypeObject *type, PyObject *const *args, Py_ssize_t nargs, PyOb exit: return return_value; } -/*[clinic end generated code: output=7436b5f4decdcf9d input=a9049054013a1b77]*/ +/*[clinic end generated code: output=3b91cda9d83abaa2 input=a9049054013a1b77]*/ diff --git a/Objects/clinic/tupleobject.c.h b/Objects/clinic/tupleobject.c.h index 67d9f34..0096f0c 100644 --- a/Objects/clinic/tupleobject.c.h +++ b/Objects/clinic/tupleobject.c.h @@ -25,10 +25,23 @@ tuple_index(PyTupleObject *self, PyObject *const *args, Py_ssize_t nargs) Py_ssize_t start = 0; Py_ssize_t stop = PY_SSIZE_T_MAX; - if (!_PyArg_ParseStack(args, nargs, "O|O&O&:index", - &value, _PyEval_SliceIndexNotNone, &start, _PyEval_SliceIndexNotNone, &stop)) { + if (!_PyArg_CheckPositional("index", nargs, 1, 3)) { goto exit; } + value = args[0]; + if (nargs < 2) { + goto skip_optional; + } + if (!_PyEval_SliceIndexNotNone(args[1], &start)) { + goto exit; + } + if (nargs < 3) { + goto skip_optional; + } + if (!_PyEval_SliceIndexNotNone(args[2], &stop)) { + goto exit; + } +skip_optional: return_value = tuple_index_impl(self, value, start, stop); exit: @@ -95,4 +108,4 @@ tuple___getnewargs__(PyTupleObject *self, PyObject *Py_UNUSED(ignored)) { return tuple___getnewargs___impl(self); } -/*[clinic end generated code: output=0a6ebd2d16b09c5d input=a9049054013a1b77]*/ +/*[clinic end generated code: output=5312868473a41cfe input=a9049054013a1b77]*/ diff --git a/Objects/clinic/typeobject.c.h b/Objects/clinic/typeobject.c.h index 115a218..fbe1261 100644 --- a/Objects/clinic/typeobject.c.h +++ b/Objects/clinic/typeobject.c.h @@ -200,7 +200,7 @@ object___format__(PyObject *self, PyObject *arg) PyObject *format_spec; if (!PyUnicode_Check(arg)) { - _PyArg_BadArgument("__format__", "str", arg); + _PyArg_BadArgument("__format__", 0, "str", arg); goto exit; } if (PyUnicode_READY(arg) == -1) { @@ -248,4 +248,4 @@ object___dir__(PyObject *self, PyObject *Py_UNUSED(ignored)) { return object___dir___impl(self); } -/*[clinic end generated code: output=09f3453839e60136 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=ea5734413064fa7e input=a9049054013a1b77]*/ diff --git a/Objects/clinic/unicodeobject.c.h b/Objects/clinic/unicodeobject.c.h index 744a6eb..21e54f1 100644 --- a/Objects/clinic/unicodeobject.c.h +++ b/Objects/clinic/unicodeobject.c.h @@ -83,10 +83,33 @@ unicode_center(PyObject *self, PyObject *const *args, Py_ssize_t nargs) Py_ssize_t width; Py_UCS4 fillchar = ' '; - if (!_PyArg_ParseStack(args, nargs, "n|O&:center", - &width, convert_uc, &fillchar)) { + if (!_PyArg_CheckPositional("center", 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; + } + width = ival; + } + if (nargs < 2) { + goto skip_optional; + } + if (!convert_uc(args[1], &fillchar)) { + goto exit; + } +skip_optional: return_value = unicode_center_impl(self, width, fillchar); exit: @@ -452,10 +475,33 @@ unicode_ljust(PyObject *self, PyObject *const *args, Py_ssize_t nargs) Py_ssize_t width; Py_UCS4 fillchar = ' '; - if (!_PyArg_ParseStack(args, nargs, "n|O&:ljust", - &width, convert_uc, &fillchar)) { + if (!_PyArg_CheckPositional("ljust", 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; + } + width = ival; + } + if (nargs < 2) { + goto skip_optional; + } + if (!convert_uc(args[1], &fillchar)) { + goto exit; + } +skip_optional: return_value = unicode_ljust_impl(self, width, fillchar); exit: @@ -601,10 +647,46 @@ unicode_replace(PyObject *self, PyObject *const *args, Py_ssize_t nargs) PyObject *new; Py_ssize_t count = -1; - if (!_PyArg_ParseStack(args, nargs, "UU|n:replace", - &old, &new, &count)) { + if (!_PyArg_CheckPositional("replace", nargs, 2, 3)) { + goto exit; + } + if (!PyUnicode_Check(args[0])) { + _PyArg_BadArgument("replace", 1, "str", args[0]); + goto exit; + } + if (PyUnicode_READY(args[0]) == -1) { + goto exit; + } + old = args[0]; + if (!PyUnicode_Check(args[1])) { + _PyArg_BadArgument("replace", 2, "str", args[1]); + goto exit; + } + if (PyUnicode_READY(args[1]) == -1) { goto exit; } + new = args[1]; + if (nargs < 3) { + goto skip_optional; + } + if (PyFloat_Check(args[2])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + { + Py_ssize_t ival = -1; + PyObject *iobj = PyNumber_Index(args[2]); + if (iobj != NULL) { + ival = PyLong_AsSsize_t(iobj); + Py_DECREF(iobj); + } + if (ival == -1 && PyErr_Occurred()) { + goto exit; + } + count = ival; + } +skip_optional: return_value = unicode_replace_impl(self, old, new, count); exit: @@ -632,10 +714,33 @@ unicode_rjust(PyObject *self, PyObject *const *args, Py_ssize_t nargs) Py_ssize_t width; Py_UCS4 fillchar = ' '; - if (!_PyArg_ParseStack(args, nargs, "n|O&:rjust", - &width, convert_uc, &fillchar)) { + if (!_PyArg_CheckPositional("rjust", 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; + } + width = ival; + } + if (nargs < 2) { + goto skip_optional; + } + if (!convert_uc(args[1], &fillchar)) { + goto exit; + } +skip_optional: return_value = unicode_rjust_impl(self, width, fillchar); exit: @@ -833,10 +938,33 @@ unicode_maketrans(void *null, PyObject *const *args, Py_ssize_t nargs) PyObject *y = NULL; PyObject *z = NULL; - if (!_PyArg_ParseStack(args, nargs, "O|UU:maketrans", - &x, &y, &z)) { + if (!_PyArg_CheckPositional("maketrans", nargs, 1, 3)) { + goto exit; + } + x = args[0]; + if (nargs < 2) { + goto skip_optional; + } + if (!PyUnicode_Check(args[1])) { + _PyArg_BadArgument("maketrans", 2, "str", args[1]); + goto exit; + } + if (PyUnicode_READY(args[1]) == -1) { + goto exit; + } + y = args[1]; + if (nargs < 3) { + goto skip_optional; + } + if (!PyUnicode_Check(args[2])) { + _PyArg_BadArgument("maketrans", 3, "str", args[2]); + goto exit; + } + if (PyUnicode_READY(args[2]) == -1) { goto exit; } + z = args[2]; +skip_optional: return_value = unicode_maketrans_impl(x, y, z); exit: @@ -940,7 +1068,7 @@ unicode___format__(PyObject *self, PyObject *arg) PyObject *format_spec; if (!PyUnicode_Check(arg)) { - _PyArg_BadArgument("__format__", "str", arg); + _PyArg_BadArgument("__format__", 0, "str", arg); goto exit; } if (PyUnicode_READY(arg) == -1) { @@ -970,4 +1098,4 @@ unicode_sizeof(PyObject *self, PyObject *Py_UNUSED(ignored)) { return unicode_sizeof_impl(self); } -/*[clinic end generated code: output=ff6acd5abd1998eb input=a9049054013a1b77]*/ +/*[clinic end generated code: output=73ad9670e00a2490 input=a9049054013a1b77]*/ diff --git a/Objects/stringlib/clinic/transmogrify.h.h b/Objects/stringlib/clinic/transmogrify.h.h index 7b7fd58..15c43af 100644 --- a/Objects/stringlib/clinic/transmogrify.h.h +++ b/Objects/stringlib/clinic/transmogrify.h.h @@ -55,10 +55,40 @@ stringlib_ljust(PyObject *self, PyObject *const *args, Py_ssize_t nargs) Py_ssize_t width; char fillchar = ' '; - if (!_PyArg_ParseStack(args, nargs, "n|c:ljust", - &width, &fillchar)) { + if (!_PyArg_CheckPositional("ljust", 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; + } + width = ival; + } + if (nargs < 2) { + goto skip_optional; + } + if (PyBytes_Check(args[1]) && PyBytes_GET_SIZE(args[1]) == 1) { + fillchar = PyBytes_AS_STRING(args[1])[0]; + } + else if (PyByteArray_Check(args[1]) && PyByteArray_GET_SIZE(args[1]) == 1) { + fillchar = PyByteArray_AS_STRING(args[1])[0]; + } + else { + _PyArg_BadArgument("ljust", 2, "a byte string of length 1", args[1]); + goto exit; + } +skip_optional: return_value = stringlib_ljust_impl(self, width, fillchar); exit: @@ -86,10 +116,40 @@ stringlib_rjust(PyObject *self, PyObject *const *args, Py_ssize_t nargs) Py_ssize_t width; char fillchar = ' '; - if (!_PyArg_ParseStack(args, nargs, "n|c:rjust", - &width, &fillchar)) { + if (!_PyArg_CheckPositional("rjust", 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; + } + width = ival; + } + if (nargs < 2) { + goto skip_optional; + } + if (PyBytes_Check(args[1]) && PyBytes_GET_SIZE(args[1]) == 1) { + fillchar = PyBytes_AS_STRING(args[1])[0]; + } + else if (PyByteArray_Check(args[1]) && PyByteArray_GET_SIZE(args[1]) == 1) { + fillchar = PyByteArray_AS_STRING(args[1])[0]; + } + else { + _PyArg_BadArgument("rjust", 2, "a byte string of length 1", args[1]); goto exit; } +skip_optional: return_value = stringlib_rjust_impl(self, width, fillchar); exit: @@ -117,10 +177,40 @@ stringlib_center(PyObject *self, PyObject *const *args, Py_ssize_t nargs) Py_ssize_t width; char fillchar = ' '; - if (!_PyArg_ParseStack(args, nargs, "n|c:center", - &width, &fillchar)) { + if (!_PyArg_CheckPositional("center", 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; + } + width = ival; + } + if (nargs < 2) { + goto skip_optional; + } + if (PyBytes_Check(args[1]) && PyBytes_GET_SIZE(args[1]) == 1) { + fillchar = PyBytes_AS_STRING(args[1])[0]; + } + else if (PyByteArray_Check(args[1]) && PyByteArray_GET_SIZE(args[1]) == 1) { + fillchar = PyByteArray_AS_STRING(args[1])[0]; + } + else { + _PyArg_BadArgument("center", 2, "a byte string of length 1", args[1]); goto exit; } +skip_optional: return_value = stringlib_center_impl(self, width, fillchar); exit: @@ -169,4 +259,4 @@ stringlib_zfill(PyObject *self, PyObject *arg) exit: return return_value; } -/*[clinic end generated code: output=bf2ef501639e1190 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=787248a980f6a00e input=a9049054013a1b77]*/ diff --git a/PC/clinic/msvcrtmodule.c.h b/PC/clinic/msvcrtmodule.c.h index b1c588b..d8e77d5 100644 --- a/PC/clinic/msvcrtmodule.c.h +++ b/PC/clinic/msvcrtmodule.c.h @@ -50,8 +50,34 @@ msvcrt_locking(PyObject *module, PyObject *const *args, Py_ssize_t nargs) int mode; long nbytes; - if (!_PyArg_ParseStack(args, nargs, "iil:locking", - &fd, &mode, &nbytes)) { + if (!_PyArg_CheckPositional("locking", nargs, 3, 3)) { + goto exit; + } + if (PyFloat_Check(args[0])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + fd = _PyLong_AsInt(args[0]); + if (fd == -1 && PyErr_Occurred()) { + goto exit; + } + if (PyFloat_Check(args[1])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + mode = _PyLong_AsInt(args[1]); + if (mode == -1 && PyErr_Occurred()) { + goto exit; + } + if (PyFloat_Check(args[2])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + nbytes = PyLong_AsLong(args[2]); + if (nbytes == -1 && PyErr_Occurred()) { goto exit; } return_value = msvcrt_locking_impl(module, fd, mode, nbytes); @@ -85,8 +111,25 @@ msvcrt_setmode(PyObject *module, PyObject *const *args, Py_ssize_t nargs) int flags; long _return_value; - if (!_PyArg_ParseStack(args, nargs, "ii:setmode", - &fd, &flags)) { + if (!_PyArg_CheckPositional("setmode", nargs, 2, 2)) { + goto exit; + } + if (PyFloat_Check(args[0])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + fd = _PyLong_AsInt(args[0]); + if (fd == -1 && PyErr_Occurred()) { + goto exit; + } + if (PyFloat_Check(args[1])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + flags = _PyLong_AsInt(args[1]); + if (flags == -1 && PyErr_Occurred()) { goto exit; } _return_value = msvcrt_setmode_impl(module, fd, flags); @@ -332,7 +375,7 @@ msvcrt_putch(PyObject *module, PyObject *arg) char_value = PyByteArray_AS_STRING(arg)[0]; } else { - _PyArg_BadArgument("putch", "a byte string of length 1", arg); + _PyArg_BadArgument("putch", 0, "a byte string of length 1", arg); goto exit; } return_value = msvcrt_putch_impl(module, char_value); @@ -360,14 +403,14 @@ msvcrt_putwch(PyObject *module, PyObject *arg) int unicode_char; if (!PyUnicode_Check(arg)) { - _PyArg_BadArgument("putwch", "a unicode character", arg); + _PyArg_BadArgument("putwch", 0, "a unicode character", arg); goto exit; } if (PyUnicode_READY(arg)) { goto exit; } if (PyUnicode_GET_LENGTH(arg) != 1) { - _PyArg_BadArgument("putwch", "a unicode character", arg); + _PyArg_BadArgument("putwch", 0, "a unicode character", arg); goto exit; } unicode_char = PyUnicode_READ_CHAR(arg, 0); @@ -406,7 +449,7 @@ msvcrt_ungetch(PyObject *module, PyObject *arg) char_value = PyByteArray_AS_STRING(arg)[0]; } else { - _PyArg_BadArgument("ungetch", "a byte string of length 1", arg); + _PyArg_BadArgument("ungetch", 0, "a byte string of length 1", arg); goto exit; } return_value = msvcrt_ungetch_impl(module, char_value); @@ -434,14 +477,14 @@ msvcrt_ungetwch(PyObject *module, PyObject *arg) int unicode_char; if (!PyUnicode_Check(arg)) { - _PyArg_BadArgument("ungetwch", "a unicode character", arg); + _PyArg_BadArgument("ungetwch", 0, "a unicode character", arg); goto exit; } if (PyUnicode_READY(arg)) { goto exit; } if (PyUnicode_GET_LENGTH(arg) != 1) { - _PyArg_BadArgument("ungetwch", "a unicode character", arg); + _PyArg_BadArgument("ungetwch", 0, "a unicode character", arg); goto exit; } unicode_char = PyUnicode_READ_CHAR(arg, 0); @@ -515,8 +558,25 @@ msvcrt_CrtSetReportMode(PyObject *module, PyObject *const *args, Py_ssize_t narg int mode; long _return_value; - if (!_PyArg_ParseStack(args, nargs, "ii:CrtSetReportMode", - &type, &mode)) { + if (!_PyArg_CheckPositional("CrtSetReportMode", nargs, 2, 2)) { + goto exit; + } + if (PyFloat_Check(args[0])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + type = _PyLong_AsInt(args[0]); + if (type == -1 && PyErr_Occurred()) { + goto exit; + } + if (PyFloat_Check(args[1])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + mode = _PyLong_AsInt(args[1]); + if (mode == -1 && PyErr_Occurred()) { goto exit; } _return_value = msvcrt_CrtSetReportMode_impl(module, type, mode); @@ -619,4 +679,4 @@ exit: #ifndef MSVCRT_SET_ERROR_MODE_METHODDEF #define MSVCRT_SET_ERROR_MODE_METHODDEF #endif /* !defined(MSVCRT_SET_ERROR_MODE_METHODDEF) */ -/*[clinic end generated code: output=2530b4ff248563b4 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=816bc4f993893cea input=a9049054013a1b77]*/ diff --git a/PC/clinic/winreg.c.h b/PC/clinic/winreg.c.h index 3b100f9..21a9302 100644 --- a/PC/clinic/winreg.c.h +++ b/PC/clinic/winreg.c.h @@ -425,8 +425,19 @@ winreg_EnumKey(PyObject *module, PyObject *const *args, Py_ssize_t nargs) HKEY key; int index; - if (!_PyArg_ParseStack(args, nargs, "O&i:EnumKey", - clinic_HKEY_converter, &key, &index)) { + if (!_PyArg_CheckPositional("EnumKey", nargs, 2, 2)) { + goto exit; + } + if (!clinic_HKEY_converter(args[0], &key)) { + goto exit; + } + if (PyFloat_Check(args[1])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + index = _PyLong_AsInt(args[1]); + if (index == -1 && PyErr_Occurred()) { goto exit; } return_value = winreg_EnumKey_impl(module, key, index); @@ -472,8 +483,19 @@ winreg_EnumValue(PyObject *module, PyObject *const *args, Py_ssize_t nargs) HKEY key; int index; - if (!_PyArg_ParseStack(args, nargs, "O&i:EnumValue", - clinic_HKEY_converter, &key, &index)) { + if (!_PyArg_CheckPositional("EnumValue", nargs, 2, 2)) { + goto exit; + } + if (!clinic_HKEY_converter(args[0], &key)) { + goto exit; + } + if (PyFloat_Check(args[1])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + index = _PyLong_AsInt(args[1]); + if (index == -1 && PyErr_Occurred()) { goto exit; } return_value = winreg_EnumValue_impl(module, key, index); @@ -1095,4 +1117,4 @@ winreg_QueryReflectionKey(PyObject *module, PyObject *arg) exit: return return_value; } -/*[clinic end generated code: output=82bd56c524c6c3dd input=a9049054013a1b77]*/ +/*[clinic end generated code: output=bd491131d343ae7a input=a9049054013a1b77]*/ diff --git a/Python/clinic/bltinmodule.c.h b/Python/clinic/bltinmodule.c.h index 7f043da..68d8dcc 100644 --- a/Python/clinic/bltinmodule.c.h +++ b/Python/clinic/bltinmodule.c.h @@ -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]*/ diff --git a/Python/clinic/import.c.h b/Python/clinic/import.c.h index d34d68f..783ed4e 100644 --- a/Python/clinic/import.c.h +++ b/Python/clinic/import.c.h @@ -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]*/ diff --git a/Python/clinic/marshal.c.h b/Python/clinic/marshal.c.h index 516a315..ab45753 100644 --- a/Python/clinic/marshal.c.h +++ b/Python/clinic/marshal.c.h @@ -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]*/ diff --git a/Python/clinic/sysmodule.c.h b/Python/clinic/sysmodule.c.h index 2d9c6e2..7370ab5 100644 --- a/Python/clinic/sysmodule.c.h +++ b/Python/clinic/sysmodule.c.h @@ -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]*/ diff --git a/Python/getargs.c b/Python/getargs.c index 550d0df..c491169 100644 --- a/Python/getargs.c +++ b/Python/getargs.c @@ -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]; diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py index 3627725..4087d3f 100755 --- a/Tools/clinic/clinic.py +++ b/Tools/clinic/clinic.py @@ -807,8 +807,13 @@ class CLanguage(Language): {c_basename}({self_type}{self_name}, PyObject *%s) """ % argname) - parsearg = converters[0].parse_arg(argname) - assert parsearg is not None + parsearg = converters[0].parse_arg(argname, 0) + if parsearg is None: + parsearg = """ + if (!PyArg_Parse(%s, "{format_units}:{name}", {parse_arguments})) {{ + goto exit; + }} + """ % argname parser_definition = parser_body(parser_prototype, normalize_snippet(parsearg, indent=4)) @@ -857,26 +862,58 @@ class CLanguage(Language): flags = "METH_FASTCALL" parser_prototype = parser_prototype_fastcall - - parser_definition = parser_body(parser_prototype, normalize_snippet(""" - if (!_PyArg_ParseStack(args, nargs, "{format_units}:{name}", - {parse_arguments})) {{ - goto exit; - }} - """, indent=4)) + nargs = 'nargs' + argname_fmt = 'args[%d]' else: # positional-only, but no option groups # we only need one call to PyArg_ParseTuple flags = "METH_VARARGS" parser_prototype = parser_prototype_varargs + nargs = 'PyTuple_GET_SIZE(args)' + argname_fmt = 'PyTuple_GET_ITEM(args, %d)' + + parser_code = [] + has_optional = False + for i, converter in enumerate(converters): + parsearg = converter.parse_arg(argname_fmt % i, i + 1) + if parsearg is None: + #print('Cannot convert %s %r for %s' % (converter.__class__.__name__, converter.format_unit, converter.name), file=sys.stderr) + parser_code = None + break + if has_optional or converter.default is not unspecified: + has_optional = True + parser_code.append(normalize_snippet(""" + if (%s < %d) {{ + goto skip_optional; + }} + """, indent=4) % (nargs, i + 1)) + parser_code.append(normalize_snippet(parsearg, indent=4)) - parser_definition = parser_body(parser_prototype, normalize_snippet(""" - if (!PyArg_ParseTuple(args, "{format_units}:{name}", - {parse_arguments})) {{ + if parser_code is not None: + parser_code.insert(0, normalize_snippet(""" + if (!_PyArg_CheckPositional("{name}", %s, {unpack_min}, {unpack_max})) {{ goto exit; }} - """, indent=4)) + """ % nargs, indent=4)) + if has_optional: + parser_code.append("skip_optional:") + else: + if not new_or_init: + parser_code = [normalize_snippet(""" + if (!_PyArg_ParseStack(args, nargs, "{format_units}:{name}", + {parse_arguments})) {{ + goto exit; + }} + """, indent=4)] + else: + parser_code = [normalize_snippet(""" + if (!PyArg_ParseTuple(args, "{format_units}:{name}", + {parse_arguments})) {{ + goto exit; + }} + """, indent=4)] + parser_definition = parser_body(parser_prototype, *parser_code) elif not new_or_init: flags = "METH_FASTCALL|METH_KEYWORDS" @@ -2536,7 +2573,7 @@ class CConverter(metaclass=CConverterAutoRegister): """ pass - def parse_arg(self, argname): + def parse_arg(self, argname, argnum): if self.format_unit == 'O&': return """ if (!{converter}({argname}, &{paramname})) {{{{ @@ -2550,25 +2587,27 @@ class CConverter(metaclass=CConverterAutoRegister): typecheck, typename = type_checks[self.subclass_of] return """ if (!{typecheck}({argname})) {{{{ - _PyArg_BadArgument("{{name}}", "{typename}", {argname}); + _PyArg_BadArgument("{{name}}", {argnum}, "{typename}", {argname}); goto exit; }}}} {paramname} = {cast}{argname}; """.format(argname=argname, paramname=self.name, + argnum=argnum, typecheck=typecheck, typename=typename, cast=cast) return """ if (!PyObject_TypeCheck({argname}, {subclass_of})) {{{{ - _PyArg_BadArgument("{{name}}", ({subclass_of})->tp_name, {argname}); + _PyArg_BadArgument("{{name}}", {argnum}, ({subclass_of})->tp_name, {argname}); goto exit; }}}} {paramname} = {cast}{argname}; - """.format(argname=argname, paramname=self.name, + """.format(argname=argname, paramname=self.name, argnum=argnum, subclass_of=self.subclass_of, cast=cast) - return """ - if (!PyArg_Parse(%s, "{format_units}:{name}", {parse_arguments})) {{ - goto exit; - }} - """ % argname + if self.format_unit == 'O': + cast = '(%s)' % self.type if self.type != 'PyObject *' else '' + return """ + {paramname} = {cast}{argname}; + """.format(argname=argname, paramname=self.name, cast=cast) + return None type_checks = { '&PyLong_Type': ('PyLong_Check', 'int'), @@ -2598,7 +2637,7 @@ class bool_converter(CConverter): self.default = bool(self.default) self.c_default = str(int(self.default)) - def parse_arg(self, argname): + def parse_arg(self, argname, argnum): if self.format_unit == 'i': return """ if (PyFloat_Check({argname})) {{{{ @@ -2618,7 +2657,7 @@ class bool_converter(CConverter): goto exit; }}}} """.format(argname=argname, paramname=self.name) - return super().parse_arg(argname) + return super().parse_arg(argname, argnum) class char_converter(CConverter): type = 'char' @@ -2635,7 +2674,7 @@ class char_converter(CConverter): if self.c_default == '"\'"': self.c_default = r"'\''" - def parse_arg(self, argname): + def parse_arg(self, argname, argnum): if self.format_unit == 'c': return """ if (PyBytes_Check({argname}) && PyBytes_GET_SIZE({argname}) == 1) {{{{ @@ -2645,11 +2684,11 @@ class char_converter(CConverter): {paramname} = PyByteArray_AS_STRING({argname})[0]; }}}} else {{{{ - _PyArg_BadArgument("{{name}}", "a byte string of length 1", {argname}); + _PyArg_BadArgument("{{name}}", {argnum}, "a byte string of length 1", {argname}); goto exit; }}}} - """.format(argname=argname, paramname=self.name) - return super().parse_arg(argname) + """.format(argname=argname, paramname=self.name, argnum=argnum) + return super().parse_arg(argname, argnum) @add_legacy_c_converter('B', bitwise=True) @@ -2663,7 +2702,7 @@ class unsigned_char_converter(CConverter): if bitwise: self.format_unit = 'B' - def parse_arg(self, argname): + def parse_arg(self, argname, argnum): if self.format_unit == 'b': return """ if (PyFloat_Check({argname})) {{{{ @@ -2708,7 +2747,7 @@ class unsigned_char_converter(CConverter): }}}} }}}} """.format(argname=argname, paramname=self.name) - return super().parse_arg(argname) + return super().parse_arg(argname, argnum) class byte_converter(unsigned_char_converter): pass @@ -2718,7 +2757,7 @@ class short_converter(CConverter): format_unit = 'h' c_ignored_default = "0" - def parse_arg(self, argname): + def parse_arg(self, argname, argnum): if self.format_unit == 'h': return """ if (PyFloat_Check({argname})) {{{{ @@ -2746,7 +2785,7 @@ class short_converter(CConverter): }}}} }}}} """.format(argname=argname, paramname=self.name) - return super().parse_arg(argname) + return super().parse_arg(argname, argnum) class unsigned_short_converter(CConverter): type = 'unsigned short' @@ -2759,6 +2798,21 @@ class unsigned_short_converter(CConverter): else: self.converter = '_PyLong_UnsignedShort_Converter' + def parse_arg(self, argname, argnum): + if self.format_unit == 'H': + return """ + if (PyFloat_Check({argname})) {{{{ + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + }}}} + {paramname} = (unsigned short)PyLong_AsUnsignedLongMask({argname}); + if ({paramname} == (unsigned short)-1 && PyErr_Occurred()) {{{{ + goto exit; + }}}} + """.format(argname=argname, paramname=self.name) + return super().parse_arg(argname, argnum) + @add_legacy_c_converter('C', accept={str}) class int_converter(CConverter): type = 'int' @@ -2774,7 +2828,7 @@ class int_converter(CConverter): if type != None: self.type = type - def parse_arg(self, argname): + def parse_arg(self, argname, argnum): if self.format_unit == 'i': return """ if (PyFloat_Check({argname})) {{{{ @@ -2790,19 +2844,19 @@ class int_converter(CConverter): elif self.format_unit == 'C': return """ if (!PyUnicode_Check({argname})) {{{{ - _PyArg_BadArgument("{{name}}", "a unicode character", {argname}); + _PyArg_BadArgument("{{name}}", {argnum}, "a unicode character", {argname}); goto exit; }}}} if (PyUnicode_READY({argname})) {{{{ goto exit; }}}} if (PyUnicode_GET_LENGTH({argname}) != 1) {{{{ - _PyArg_BadArgument("{{name}}", "a unicode character", {argname}); + _PyArg_BadArgument("{{name}}", {argnum}, "a unicode character", {argname}); goto exit; }}}} {paramname} = PyUnicode_READ_CHAR({argname}, 0); - """.format(argname=argname, paramname=self.name) - return super().parse_arg(argname) + """.format(argname=argname, paramname=self.name, argnum=argnum) + return super().parse_arg(argname, argnum) class unsigned_int_converter(CConverter): type = 'unsigned int' @@ -2815,7 +2869,7 @@ class unsigned_int_converter(CConverter): else: self.converter = '_PyLong_UnsignedInt_Converter' - def parse_arg(self, argname): + def parse_arg(self, argname, argnum): if self.format_unit == 'I': return """ if (PyFloat_Check({argname})) {{{{ @@ -2828,7 +2882,7 @@ class unsigned_int_converter(CConverter): goto exit; }}}} """.format(argname=argname, paramname=self.name) - return super().parse_arg(argname) + return super().parse_arg(argname, argnum) class long_converter(CConverter): type = 'long' @@ -2836,7 +2890,7 @@ class long_converter(CConverter): format_unit = 'l' c_ignored_default = "0" - def parse_arg(self, argname): + def parse_arg(self, argname, argnum): if self.format_unit == 'l': return """ if (PyFloat_Check({argname})) {{{{ @@ -2849,7 +2903,7 @@ class long_converter(CConverter): goto exit; }}}} """.format(argname=argname, paramname=self.name) - return super().parse_arg(argname) + return super().parse_arg(argname, argnum) class unsigned_long_converter(CConverter): type = 'unsigned long' @@ -2862,16 +2916,16 @@ class unsigned_long_converter(CConverter): else: self.converter = '_PyLong_UnsignedLong_Converter' - def parse_arg(self, argname): + def parse_arg(self, argname, argnum): if self.format_unit == 'k': return """ if (!PyLong_Check({argname})) {{{{ - _PyArg_BadArgument("{{name}}", "int", {argname}); + _PyArg_BadArgument("{{name}}", {argnum}, "int", {argname}); goto exit; }}}} {paramname} = PyLong_AsUnsignedLongMask({argname}); - """.format(argname=argname, paramname=self.name) - return super().parse_arg(argname) + """.format(argname=argname, paramname=self.name, argnum=argnum) + return super().parse_arg(argname, argnum) class long_long_converter(CConverter): type = 'long long' @@ -2879,7 +2933,7 @@ class long_long_converter(CConverter): format_unit = 'L' c_ignored_default = "0" - def parse_arg(self, argname): + def parse_arg(self, argname, argnum): if self.format_unit == 'L': return """ if (PyFloat_Check({argname})) {{{{ @@ -2892,7 +2946,7 @@ class long_long_converter(CConverter): goto exit; }}}} """.format(argname=argname, paramname=self.name) - return super().parse_arg(argname) + return super().parse_arg(argname, argnum) class unsigned_long_long_converter(CConverter): type = 'unsigned long long' @@ -2905,16 +2959,16 @@ class unsigned_long_long_converter(CConverter): else: self.converter = '_PyLong_UnsignedLongLong_Converter' - def parse_arg(self, argname): + def parse_arg(self, argname, argnum): if self.format_unit == 'K': return """ if (!PyLong_Check({argname})) {{{{ - _PyArg_BadArgument("{{name}}", "int", {argname}); + _PyArg_BadArgument("{{name}}", {argnum}, "int", {argname}); goto exit; }}}} {paramname} = PyLong_AsUnsignedLongLongMask({argname}); - """.format(argname=argname, paramname=self.name) - return super().parse_arg(argname) + """.format(argname=argname, paramname=self.name, argnum=argnum) + return super().parse_arg(argname, argnum) class Py_ssize_t_converter(CConverter): type = 'Py_ssize_t' @@ -2929,7 +2983,7 @@ class Py_ssize_t_converter(CConverter): else: fail("Py_ssize_t_converter: illegal 'accept' argument " + repr(accept)) - def parse_arg(self, argname): + def parse_arg(self, argname, argnum): if self.format_unit == 'n': return """ if (PyFloat_Check({argname})) {{{{ @@ -2950,7 +3004,7 @@ class Py_ssize_t_converter(CConverter): {paramname} = ival; }}}} """.format(argname=argname, paramname=self.name) - return super().parse_arg(argname) + return super().parse_arg(argname, argnum) class slice_index_converter(CConverter): @@ -2969,7 +3023,7 @@ class size_t_converter(CConverter): converter = '_PyLong_Size_t_Converter' c_ignored_default = "0" - def parse_arg(self, argname): + def parse_arg(self, argname, argnum): if self.format_unit == 'n': return """ {paramname} = PyNumber_AsSsize_t({argname}, PyExc_OverflowError); @@ -2977,7 +3031,7 @@ class size_t_converter(CConverter): goto exit; }}}} """.format(argname=argname, paramname=self.name) - return super().parse_arg(argname) + return super().parse_arg(argname, argnum) class float_converter(CConverter): @@ -2986,7 +3040,7 @@ class float_converter(CConverter): format_unit = 'f' c_ignored_default = "0.0" - def parse_arg(self, argname): + def parse_arg(self, argname, argnum): if self.format_unit == 'f': return """ {paramname} = (float) PyFloat_AsDouble({argname}); @@ -2994,7 +3048,7 @@ class float_converter(CConverter): goto exit; }}}} """.format(argname=argname, paramname=self.name) - return super().parse_arg(argname) + return super().parse_arg(argname, argnum) class double_converter(CConverter): type = 'double' @@ -3002,7 +3056,7 @@ class double_converter(CConverter): format_unit = 'd' c_ignored_default = "0.0" - def parse_arg(self, argname): + def parse_arg(self, argname, argnum): if self.format_unit == 'd': return """ {paramname} = PyFloat_AsDouble({argname}); @@ -3010,7 +3064,7 @@ class double_converter(CConverter): goto exit; }}}} """.format(argname=argname, paramname=self.name) - return super().parse_arg(argname) + return super().parse_arg(argname, argnum) class Py_complex_converter(CConverter): @@ -3019,7 +3073,7 @@ class Py_complex_converter(CConverter): format_unit = 'D' c_ignored_default = "{0.0, 0.0}" - def parse_arg(self, argname): + def parse_arg(self, argname, argnum): if self.format_unit == 'D': return """ {paramname} = PyComplex_AsCComplex({argname}); @@ -3027,7 +3081,7 @@ class Py_complex_converter(CConverter): goto exit; }}}} """.format(argname=argname, paramname=self.name) - return super().parse_arg(argname) + return super().parse_arg(argname, argnum) class object_converter(CConverter): @@ -3093,11 +3147,11 @@ class str_converter(CConverter): name = self.name return "".join(["if (", name, ") {\n PyMem_FREE(", name, ");\n}\n"]) - def parse_arg(self, argname): + def parse_arg(self, argname, argnum): if self.format_unit == 's': return """ if (!PyUnicode_Check({argname})) {{{{ - _PyArg_BadArgument("{{name}}", "str", {argname}); + _PyArg_BadArgument("{{name}}", {argnum}, "str", {argname}); goto exit; }}}} Py_ssize_t {paramname}_length; @@ -3109,8 +3163,29 @@ class str_converter(CConverter): PyErr_SetString(PyExc_ValueError, "embedded null character"); goto exit; }}}} - """.format(argname=argname, paramname=self.name) - return super().parse_arg(argname) + """.format(argname=argname, paramname=self.name, argnum=argnum) + if self.format_unit == 'z': + return """ + if ({argname} == Py_None) {{{{ + {paramname} = NULL; + }}}} + else if (PyUnicode_Check({argname})) {{{{ + Py_ssize_t {paramname}_length; + {paramname} = PyUnicode_AsUTF8AndSize({argname}, &{paramname}_length); + if ({paramname} == NULL) {{{{ + goto exit; + }}}} + if (strlen({paramname}) != (size_t){paramname}_length) {{{{ + PyErr_SetString(PyExc_ValueError, "embedded null character"); + goto exit; + }}}} + }}}} + else {{{{ + _PyArg_BadArgument("{{name}}", {argnum}, "str or None", {argname}); + goto exit; + }}}} + """.format(argname=argname, paramname=self.name, argnum=argnum) + return super().parse_arg(argname, argnum) # # This is the fourth or fifth rewrite of registering all the @@ -3165,51 +3240,53 @@ class PyBytesObject_converter(CConverter): format_unit = 'S' # accept = {bytes} - def parse_arg(self, argname): + def parse_arg(self, argname, argnum): if self.format_unit == 'S': return """ if (!PyBytes_Check({argname})) {{{{ - _PyArg_BadArgument("{{name}}", "bytes", {argname}); + _PyArg_BadArgument("{{name}}", {argnum}, "bytes", {argname}); goto exit; }}}} {paramname} = ({type}){argname}; - """.format(argname=argname, paramname=self.name, type=self.type) - return super().parse_arg(argname) + """.format(argname=argname, paramname=self.name, argnum=argnum, + type=self.type) + return super().parse_arg(argname, argnum) class PyByteArrayObject_converter(CConverter): type = 'PyByteArrayObject *' format_unit = 'Y' # accept = {bytearray} - def parse_arg(self, argname): + def parse_arg(self, argname, argnum): if self.format_unit == 'Y': return """ if (!PyByteArray_Check({argname})) {{{{ - _PyArg_BadArgument("{{name}}", "bytearray", {argname}); + _PyArg_BadArgument("{{name}}", {argnum}, "bytearray", {argname}); goto exit; }}}} {paramname} = ({type}){argname}; - """.format(argname=argname, paramname=self.name, type=self.type) - return super().parse_arg(argname) + """.format(argname=argname, paramname=self.name, argnum=argnum, + type=self.type) + return super().parse_arg(argname, argnum) class unicode_converter(CConverter): type = 'PyObject *' default_type = (str, Null, NoneType) format_unit = 'U' - def parse_arg(self, argname): + def parse_arg(self, argname, argnum): if self.format_unit == 'U': return """ if (!PyUnicode_Check({argname})) {{{{ - _PyArg_BadArgument("{{name}}", "str", {argname}); + _PyArg_BadArgument("{{name}}", {argnum}, "str", {argname}); goto exit; }}}} if (PyUnicode_READY({argname}) == -1) {{{{ goto exit; }}}} {paramname} = {argname}; - """.format(argname=argname, paramname=self.name) - return super().parse_arg(argname) + """.format(argname=argname, paramname=self.name, argnum=argnum) + return super().parse_arg(argname, argnum) @add_legacy_c_converter('u#', zeroes=True) @add_legacy_c_converter('Z', accept={str, NoneType}) @@ -3258,17 +3335,17 @@ class Py_buffer_converter(CConverter): name = self.name return "".join(["if (", name, ".obj) {\n PyBuffer_Release(&", name, ");\n}\n"]) - def parse_arg(self, argname): + def parse_arg(self, argname, argnum): if self.format_unit == 'y*': return """ if (PyObject_GetBuffer({argname}, &{paramname}, PyBUF_SIMPLE) != 0) {{{{ goto exit; }}}} if (!PyBuffer_IsContiguous(&{paramname}, 'C')) {{{{ - _PyArg_BadArgument("{{name}}", "contiguous buffer", {argname}); + _PyArg_BadArgument("{{name}}", {argnum}, "contiguous buffer", {argname}); goto exit; }}}} - """.format(argname=argname, paramname=self.name) + """.format(argname=argname, paramname=self.name, argnum=argnum) elif self.format_unit == 's*': return """ if (PyUnicode_Check({argname})) {{{{ @@ -3284,24 +3361,24 @@ class Py_buffer_converter(CConverter): goto exit; }}}} if (!PyBuffer_IsContiguous(&{paramname}, 'C')) {{{{ - _PyArg_BadArgument("{{name}}", "contiguous buffer", {argname}); + _PyArg_BadArgument("{{name}}", {argnum}, "contiguous buffer", {argname}); goto exit; }}}} }}}} - """.format(argname=argname, paramname=self.name) + """.format(argname=argname, paramname=self.name, argnum=argnum) elif self.format_unit == 'w*': return """ if (PyObject_GetBuffer({argname}, &{paramname}, PyBUF_WRITABLE) < 0) {{{{ PyErr_Clear(); - _PyArg_BadArgument("{{name}}", "read-write bytes-like object", {argname}); + _PyArg_BadArgument("{{name}}", {argnum}, "read-write bytes-like object", {argname}); goto exit; }}}} if (!PyBuffer_IsContiguous(&{paramname}, 'C')) {{{{ - _PyArg_BadArgument("{{name}}", "contiguous buffer", {argname}); + _PyArg_BadArgument("{{name}}", {argnum}, "contiguous buffer", {argname}); goto exit; }}}} - """.format(argname=argname, paramname=self.name) - return super().parse_arg(argname) + """.format(argname=argname, paramname=self.name, argnum=argnum) + return super().parse_arg(argname, argnum) def correct_name_for_self(f): -- cgit v0.12