diff -r dbdd5bc4df99 Modules/_io/clinic/bufferedio.c.h --- a/Modules/_io/clinic/bufferedio.c.h Sun May 01 13:36:42 2016 +0300 +++ b/Modules/_io/clinic/bufferedio.c.h Sun May 01 16:52:27 2016 +0300 @@ -150,7 +150,8 @@ static PyObject * PyObject *return_value = NULL; Py_ssize_t n; - if (!PyArg_Parse(arg, "n:read1", &n)) + size = PyNumber_AsSsize_t(arg, PyExc_OverflowError); + if (size == -1 && PyErr_Occurred()) goto exit; return_value = _io__Buffered_read1_impl(self, n); @@ -371,7 +372,7 @@ static PyObject * PyObject *return_value = NULL; Py_buffer buffer = {NULL, NULL}; - if (!PyArg_Parse(arg, "y*:write", &buffer)) + if (PyObject_GetBuffer(arg, &buffer, PyBUF_SIMPLE) != 0) goto exit; return_value = _io_BufferedWriter_write_impl(self, &buffer); @@ -451,4 +452,4 @@ static int exit: return return_value; } -/*[clinic end generated code: output=2bbb5e239b4ffe6f input=a9049054013a1b77]*/ +/*[clinic end generated code: output=7071667169bc4a38 input=a9049054013a1b77]*/ diff -r dbdd5bc4df99 Modules/_io/clinic/fileio.c.h --- a/Modules/_io/clinic/fileio.c.h Sun May 01 13:36:42 2016 +0300 +++ b/Modules/_io/clinic/fileio.c.h Sun May 01 16:52:27 2016 +0300 @@ -240,7 +240,7 @@ static PyObject * PyObject *return_value = NULL; Py_buffer b = {NULL, NULL}; - if (!PyArg_Parse(arg, "y*:write", &b)) + if (PyObject_GetBuffer(arg, &b, PyBUF_SIMPLE) != 0) goto exit; return_value = _io_FileIO_write_impl(self, &b); @@ -364,4 +364,4 @@ static PyObject * #ifndef _IO_FILEIO_TRUNCATE_METHODDEF #define _IO_FILEIO_TRUNCATE_METHODDEF #endif /* !defined(_IO_FILEIO_TRUNCATE_METHODDEF) */ -/*[clinic end generated code: output=b1a20b10c81add64 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=9d3f8e303d1f1ac2 input=a9049054013a1b77]*/ diff -r dbdd5bc4df99 Modules/_io/clinic/textio.c.h --- a/Modules/_io/clinic/textio.c.h Sun May 01 13:36:42 2016 +0300 +++ b/Modules/_io/clinic/textio.c.h Sun May 01 16:52:27 2016 +0300 @@ -204,8 +204,14 @@ static PyObject * PyObject *return_value = NULL; PyObject *text; - if (!PyArg_Parse(arg, "U:write", &text)) + if (!PyUnicode_Check(arg)) { + PyErr_Format(PyExc_TypeError, "must be str, not %.50s", + arg == Py_None ? "None" : arg->ob_type->tp_name); goto exit; + } + if (PyUnicode_READY(arg) == -1) + goto exit; + text = arg; return_value = _io_TextIOWrapper_write_impl(self, text); exit: @@ -453,4 +459,4 @@ static PyObject * { return _io_TextIOWrapper_close_impl(self); } -/*[clinic end generated code: output=690608f85aab8ba5 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=142c7a8442559182 input=a9049054013a1b77]*/ diff -r dbdd5bc4df99 Modules/clinic/_bz2module.c.h --- a/Modules/clinic/_bz2module.c.h Sun May 01 13:36:42 2016 +0300 +++ b/Modules/clinic/_bz2module.c.h Sun May 01 16:52:27 2016 +0300 @@ -25,7 +25,7 @@ static PyObject * PyObject *return_value = NULL; Py_buffer data = {NULL, NULL}; - if (!PyArg_Parse(arg, "y*:compress", &data)) + if (PyObject_GetBuffer(arg, &data, PyBUF_SIMPLE) != 0) goto exit; return_value = _bz2_BZ2Compressor_compress_impl(self, &data); @@ -165,4 +165,4 @@ static int exit: return return_value; } -/*[clinic end generated code: output=fef29b76b3314fc7 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=1ccd9e869a439d86 input=a9049054013a1b77]*/ diff -r dbdd5bc4df99 Modules/clinic/_codecsmodule.c.h --- a/Modules/clinic/_codecsmodule.c.h Sun May 01 13:36:42 2016 +0300 +++ b/Modules/clinic/_codecsmodule.c.h Sun May 01 16:52:27 2016 +0300 @@ -33,8 +33,18 @@ static PyObject * PyObject *return_value = NULL; const char *encoding; - if (!PyArg_Parse(arg, "s:lookup", &encoding)) + if (!PyUnicode_Check(arg)) { + PyErr_Format(PyExc_TypeError, "must be str, not %.50s", + arg == Py_None ? "None" : arg->ob_type->tp_name); goto exit; + } + encoding = PyUnicode_AsUTF8(arg); + if (encoding == NULL) + goto exit; + if (strlen(encoding) != (size_t)PyUnicode_GET_LENGTH(arg)) { + PyErr_SetString(PyExc_ValueError, "embedded null character"); + goto exit; + } return_value = _codecs_lookup_impl(module, encoding); exit: @@ -133,8 +143,18 @@ static PyObject * PyObject *return_value = NULL; const char *encoding; - if (!PyArg_Parse(arg, "s:_forget_codec", &encoding)) + if (!PyUnicode_Check(arg)) { + PyErr_Format(PyExc_TypeError, "must be str, not %.50s", + arg == Py_None ? "None" : arg->ob_type->tp_name); goto exit; + } + encoding = PyUnicode_AsUTF8(arg); + if (encoding == NULL) + goto exit; + if (strlen(encoding) != (size_t)PyUnicode_GET_LENGTH(arg)) { + PyErr_SetString(PyExc_ValueError, "embedded null character"); + goto exit; + } return_value = _codecs__forget_codec_impl(module, encoding); exit: @@ -1243,8 +1263,14 @@ static PyObject * PyObject *return_value = NULL; PyObject *map; - if (!PyArg_Parse(arg, "U:charmap_build", &map)) + if (!PyUnicode_Check(arg)) { + PyErr_Format(PyExc_TypeError, "must be str, not %.50s", + arg == Py_None ? "None" : arg->ob_type->tp_name); goto exit; + } + if (PyUnicode_READY(arg) == -1) + goto exit; + map = arg; return_value = _codecs_charmap_build_impl(module, map); exit: @@ -1370,8 +1396,18 @@ static PyObject * PyObject *return_value = NULL; const char *name; - if (!PyArg_Parse(arg, "s:lookup_error", &name)) + if (!PyUnicode_Check(arg)) { + PyErr_Format(PyExc_TypeError, "must be str, not %.50s", + arg == Py_None ? "None" : arg->ob_type->tp_name); goto exit; + } + name = PyUnicode_AsUTF8(arg); + if (name == NULL) + goto exit; + if (strlen(name) != (size_t)PyUnicode_GET_LENGTH(arg)) { + PyErr_SetString(PyExc_ValueError, "embedded null character"); + goto exit; + } return_value = _codecs_lookup_error_impl(module, name); exit: @@ -1393,4 +1429,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=04007a13c8387689 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=90a104682a7bde23 input=a9049054013a1b77]*/ diff -r dbdd5bc4df99 Modules/clinic/_lzmamodule.c.h --- a/Modules/clinic/_lzmamodule.c.h Sun May 01 13:36:42 2016 +0300 +++ b/Modules/clinic/_lzmamodule.c.h Sun May 01 16:52:27 2016 +0300 @@ -25,7 +25,7 @@ static PyObject * PyObject *return_value = NULL; Py_buffer data = {NULL, NULL}; - if (!PyArg_Parse(arg, "y*:compress", &data)) + if (PyObject_GetBuffer(arg, &data, PyBUF_SIMPLE) != 0) goto exit; return_value = _lzma_LZMACompressor_compress_impl(self, &data); @@ -171,7 +171,13 @@ static PyObject * PyObject *return_value = NULL; int check_id; - if (!PyArg_Parse(arg, "i:is_check_supported", &check_id)) + if (PyFloat_Check(arg)) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + check_id = _PyLong_AsInt(arg); + if (check_id == -1 && PyErr_Occurred()) goto exit; return_value = _lzma_is_check_supported_impl(module, check_id); @@ -199,7 +205,7 @@ static PyObject * PyObject *return_value = NULL; lzma_filter filter = {LZMA_VLI_UNKNOWN, NULL}; - if (!PyArg_Parse(arg, "O&:_encode_filter_properties", lzma_filter_converter, &filter)) + if (!lzma_filter_converter(arg, &filter)) goto exit; return_value = _lzma__encode_filter_properties_impl(module, filter); @@ -245,4 +251,4 @@ exit: return return_value; } -/*[clinic end generated code: output=2d3e0842be3d3fe1 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=1b5fdbc636b0ecd3 input=a9049054013a1b77]*/ diff -r dbdd5bc4df99 Modules/clinic/_ssl.c.h --- a/Modules/clinic/_ssl.c.h Sun May 01 13:36:42 2016 +0300 +++ b/Modules/clinic/_ssl.c.h Sun May 01 16:52:27 2016 +0300 @@ -36,7 +36,7 @@ static PyObject * PyObject *return_value = NULL; PyObject *path; - if (!PyArg_Parse(arg, "O&:_test_decode_cert", PyUnicode_FSConverter, &path)) + if (!PyUnicode_FSConverter(arg, &path)) goto exit; return_value = _ssl__test_decode_cert_impl(module, path); @@ -209,7 +209,7 @@ static PyObject * PyObject *return_value = NULL; Py_buffer b = {NULL, NULL}; - if (!PyArg_Parse(arg, "y*:write", &b)) + if (PyObject_GetBuffer(arg, &b, PyBUF_SIMPLE) != 0) goto exit; return_value = _ssl__SSLSocket_write_impl(self, &b); @@ -360,8 +360,18 @@ static PyObject * PyObject *return_value = NULL; const char *cipherlist; - if (!PyArg_Parse(arg, "s:set_ciphers", &cipherlist)) + if (!PyUnicode_Check(arg)) { + PyErr_Format(PyExc_TypeError, "must be str, not %.50s", + arg == Py_None ? "None" : arg->ob_type->tp_name); goto exit; + } + cipherlist = PyUnicode_AsUTF8(arg); + if (cipherlist == NULL) + goto exit; + if (strlen(cipherlist) != (size_t)PyUnicode_GET_LENGTH(arg)) { + PyErr_SetString(PyExc_ValueError, "embedded null character"); + goto exit; + } return_value = _ssl__SSLContext_set_ciphers_impl(self, cipherlist); exit: @@ -386,7 +396,7 @@ static PyObject * PyObject *return_value = NULL; Py_buffer protos = {NULL, NULL}; - if (!PyArg_Parse(arg, "y*:_set_npn_protocols", &protos)) + if (PyObject_GetBuffer(arg, &protos, PyBUF_SIMPLE) != 0) goto exit; return_value = _ssl__SSLContext__set_npn_protocols_impl(self, &protos); @@ -416,7 +426,7 @@ static PyObject * PyObject *return_value = NULL; Py_buffer protos = {NULL, NULL}; - if (!PyArg_Parse(arg, "y*:_set_alpn_protocols", &protos)) + if (PyObject_GetBuffer(arg, &protos, PyBUF_SIMPLE) != 0) goto exit; return_value = _ssl__SSLContext__set_alpn_protocols_impl(self, &protos); @@ -750,7 +760,7 @@ static PyObject * PyObject *return_value = NULL; Py_buffer b = {NULL, NULL}; - if (!PyArg_Parse(arg, "y*:write", &b)) + if (PyObject_GetBuffer(arg, &b, PyBUF_SIMPLE) != 0) goto exit; return_value = _ssl_MemoryBIO_write_impl(self, &b); @@ -835,7 +845,13 @@ static PyObject * PyObject *return_value = NULL; int n; - if (!PyArg_Parse(arg, "i:RAND_bytes", &n)) + if (PyFloat_Check(arg)) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + n = _PyLong_AsInt(arg); + if (n == -1 && PyErr_Occurred()) goto exit; return_value = _ssl_RAND_bytes_impl(module, n); @@ -864,7 +880,13 @@ static PyObject * PyObject *return_value = NULL; int n; - if (!PyArg_Parse(arg, "i:RAND_pseudo_bytes", &n)) + if (PyFloat_Check(arg)) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + n = _PyLong_AsInt(arg); + if (n == -1 && PyErr_Occurred()) goto exit; return_value = _ssl_RAND_pseudo_bytes_impl(module, n); @@ -916,7 +938,7 @@ static PyObject * PyObject *return_value = NULL; PyObject *path; - if (!PyArg_Parse(arg, "O&:RAND_egd", PyUnicode_FSConverter, &path)) + if (!PyUnicode_FSConverter(arg, &path)) goto exit; return_value = _ssl_RAND_egd_impl(module, path); @@ -996,7 +1018,13 @@ static PyObject * PyObject *return_value = NULL; int nid; - if (!PyArg_Parse(arg, "i:nid2obj", &nid)) + if (PyFloat_Check(arg)) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + nid = _PyLong_AsInt(arg); + if (nid == -1 && PyErr_Occurred()) goto exit; return_value = _ssl_nid2obj_impl(module, nid); @@ -1102,4 +1130,4 @@ exit: #ifndef _SSL_ENUM_CRLS_METHODDEF #define _SSL_ENUM_CRLS_METHODDEF #endif /* !defined(_SSL_ENUM_CRLS_METHODDEF) */ -/*[clinic end generated code: output=a14999cb565a69a2 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=c5a70a7e88d831f1 input=a9049054013a1b77]*/ diff -r dbdd5bc4df99 Modules/clinic/_tkinter.c.h --- a/Modules/clinic/_tkinter.c.h Sun May 01 13:36:42 2016 +0300 +++ b/Modules/clinic/_tkinter.c.h Sun May 01 16:52:27 2016 +0300 @@ -19,8 +19,18 @@ static PyObject * PyObject *return_value = NULL; const char *script; - if (!PyArg_Parse(arg, "s:eval", &script)) + if (!PyUnicode_Check(arg)) { + PyErr_Format(PyExc_TypeError, "must be str, not %.50s", + arg == Py_None ? "None" : arg->ob_type->tp_name); goto exit; + } + script = PyUnicode_AsUTF8(arg); + if (script == NULL) + goto exit; + if (strlen(script) != (size_t)PyUnicode_GET_LENGTH(arg)) { + PyErr_SetString(PyExc_ValueError, "embedded null character"); + goto exit; + } return_value = _tkinter_tkapp_eval_impl(self, script); exit: @@ -44,8 +54,18 @@ static PyObject * PyObject *return_value = NULL; const char *fileName; - if (!PyArg_Parse(arg, "s:evalfile", &fileName)) + if (!PyUnicode_Check(arg)) { + PyErr_Format(PyExc_TypeError, "must be str, not %.50s", + arg == Py_None ? "None" : arg->ob_type->tp_name); goto exit; + } + fileName = PyUnicode_AsUTF8(arg); + if (fileName == NULL) + goto exit; + if (strlen(fileName) != (size_t)PyUnicode_GET_LENGTH(arg)) { + PyErr_SetString(PyExc_ValueError, "embedded null character"); + goto exit; + } return_value = _tkinter_tkapp_evalfile_impl(self, fileName); exit: @@ -69,8 +89,18 @@ static PyObject * PyObject *return_value = NULL; const char *script; - if (!PyArg_Parse(arg, "s:record", &script)) + if (!PyUnicode_Check(arg)) { + PyErr_Format(PyExc_TypeError, "must be str, not %.50s", + arg == Py_None ? "None" : arg->ob_type->tp_name); goto exit; + } + script = PyUnicode_AsUTF8(arg); + if (script == NULL) + goto exit; + if (strlen(script) != (size_t)PyUnicode_GET_LENGTH(arg)) { + PyErr_SetString(PyExc_ValueError, "embedded null character"); + goto exit; + } return_value = _tkinter_tkapp_record_impl(self, script); exit: @@ -94,8 +124,18 @@ static PyObject * PyObject *return_value = NULL; const char *msg; - if (!PyArg_Parse(arg, "s:adderrinfo", &msg)) + if (!PyUnicode_Check(arg)) { + PyErr_Format(PyExc_TypeError, "must be str, not %.50s", + arg == Py_None ? "None" : arg->ob_type->tp_name); goto exit; + } + msg = PyUnicode_AsUTF8(arg); + if (msg == NULL) + goto exit; + if (strlen(msg) != (size_t)PyUnicode_GET_LENGTH(arg)) { + PyErr_SetString(PyExc_ValueError, "embedded null character"); + goto exit; + } return_value = _tkinter_tkapp_adderrinfo_impl(self, msg); exit: @@ -143,8 +183,18 @@ static PyObject * PyObject *return_value = NULL; const char *s; - if (!PyArg_Parse(arg, "s:exprstring", &s)) + if (!PyUnicode_Check(arg)) { + PyErr_Format(PyExc_TypeError, "must be str, not %.50s", + arg == Py_None ? "None" : arg->ob_type->tp_name); goto exit; + } + s = PyUnicode_AsUTF8(arg); + if (s == NULL) + goto exit; + if (strlen(s) != (size_t)PyUnicode_GET_LENGTH(arg)) { + PyErr_SetString(PyExc_ValueError, "embedded null character"); + goto exit; + } return_value = _tkinter_tkapp_exprstring_impl(self, s); exit: @@ -168,8 +218,18 @@ static PyObject * PyObject *return_value = NULL; const char *s; - if (!PyArg_Parse(arg, "s:exprlong", &s)) + if (!PyUnicode_Check(arg)) { + PyErr_Format(PyExc_TypeError, "must be str, not %.50s", + arg == Py_None ? "None" : arg->ob_type->tp_name); goto exit; + } + s = PyUnicode_AsUTF8(arg); + if (s == NULL) + goto exit; + if (strlen(s) != (size_t)PyUnicode_GET_LENGTH(arg)) { + PyErr_SetString(PyExc_ValueError, "embedded null character"); + goto exit; + } return_value = _tkinter_tkapp_exprlong_impl(self, s); exit: @@ -193,8 +253,18 @@ static PyObject * PyObject *return_value = NULL; const char *s; - if (!PyArg_Parse(arg, "s:exprdouble", &s)) + if (!PyUnicode_Check(arg)) { + PyErr_Format(PyExc_TypeError, "must be str, not %.50s", + arg == Py_None ? "None" : arg->ob_type->tp_name); goto exit; + } + s = PyUnicode_AsUTF8(arg); + if (s == NULL) + goto exit; + if (strlen(s) != (size_t)PyUnicode_GET_LENGTH(arg)) { + PyErr_SetString(PyExc_ValueError, "embedded null character"); + goto exit; + } return_value = _tkinter_tkapp_exprdouble_impl(self, s); exit: @@ -218,8 +288,18 @@ static PyObject * PyObject *return_value = NULL; const char *s; - if (!PyArg_Parse(arg, "s:exprboolean", &s)) + if (!PyUnicode_Check(arg)) { + PyErr_Format(PyExc_TypeError, "must be str, not %.50s", + arg == Py_None ? "None" : arg->ob_type->tp_name); goto exit; + } + s = PyUnicode_AsUTF8(arg); + if (s == NULL) + goto exit; + if (strlen(s) != (size_t)PyUnicode_GET_LENGTH(arg)) { + PyErr_SetString(PyExc_ValueError, "embedded null character"); + goto exit; + } return_value = _tkinter_tkapp_exprboolean_impl(self, s); exit: @@ -287,8 +367,18 @@ static PyObject * PyObject *return_value = NULL; const char *name; - if (!PyArg_Parse(arg, "s:deletecommand", &name)) + if (!PyUnicode_Check(arg)) { + PyErr_Format(PyExc_TypeError, "must be str, not %.50s", + arg == Py_None ? "None" : arg->ob_type->tp_name); goto exit; + } + name = PyUnicode_AsUTF8(arg); + if (name == NULL) + goto exit; + if (strlen(name) != (size_t)PyUnicode_GET_LENGTH(arg)) { + PyErr_SetString(PyExc_ValueError, "embedded null character"); + goto exit; + } return_value = _tkinter_tkapp_deletecommand_impl(self, name); exit: @@ -579,7 +669,13 @@ static PyObject * PyObject *return_value = NULL; int new_val; - if (!PyArg_Parse(arg, "i:setbusywaitinterval", &new_val)) + if (PyFloat_Check(arg)) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + new_val = _PyLong_AsInt(arg); + if (new_val == -1 && PyErr_Occurred()) goto exit; return_value = _tkinter_setbusywaitinterval_impl(module, new_val); @@ -621,4 +717,4 @@ exit: #ifndef _TKINTER_TKAPP_DELETEFILEHANDLER_METHODDEF #define _TKINTER_TKAPP_DELETEFILEHANDLER_METHODDEF #endif /* !defined(_TKINTER_TKAPP_DELETEFILEHANDLER_METHODDEF) */ -/*[clinic end generated code: output=6dd667b91cf8addd input=a9049054013a1b77]*/ +/*[clinic end generated code: output=f97f7c4f2b35e3b7 input=a9049054013a1b77]*/ diff -r dbdd5bc4df99 Modules/clinic/arraymodule.c.h --- a/Modules/clinic/arraymodule.c.h Sun May 01 13:36:42 2016 +0300 +++ b/Modules/clinic/arraymodule.c.h Sun May 01 16:52:27 2016 +0300 @@ -275,8 +275,17 @@ array_array_fromstring(arrayobject *self PyObject *return_value = NULL; Py_buffer buffer = {NULL, NULL}; - if (!PyArg_Parse(arg, "s*:fromstring", &buffer)) - goto exit; + if (PyUnicode_Check(arg)) { + Py_ssize_t len; + char *ptr = PyUnicode_AsUTF8AndSize(arg, &len); + if (ptr == NULL) + goto exit; + PyBuffer_FillInfo(&buffer, arg, ptr, len, 1, 0); + } + else { /* any bytes-like object */ + if (PyObject_GetBuffer(arg, &buffer, PyBUF_SIMPLE) != 0) + goto exit; + } return_value = array_array_fromstring_impl(self, &buffer); exit: @@ -305,7 +314,7 @@ array_array_frombytes(arrayobject *self, PyObject *return_value = NULL; Py_buffer buffer = {NULL, NULL}; - if (!PyArg_Parse(arg, "y*:frombytes", &buffer)) + if (PyObject_GetBuffer(arg, &buffer, PyBUF_SIMPLE) != 0) goto exit; return_value = array_array_frombytes_impl(self, &buffer); @@ -496,4 +505,4 @@ PyDoc_STRVAR(array_arrayiterator___setst #define ARRAY_ARRAYITERATOR___SETSTATE___METHODDEF \ {"__setstate__", (PyCFunction)array_arrayiterator___setstate__, METH_O, array_arrayiterator___setstate____doc__}, -/*[clinic end generated code: output=d2e82c65ea841cfc input=a9049054013a1b77]*/ +/*[clinic end generated code: output=f4e6969f0939c773 input=a9049054013a1b77]*/ diff -r dbdd5bc4df99 Modules/clinic/binascii.c.h --- a/Modules/clinic/binascii.c.h Sun May 01 13:36:42 2016 +0300 +++ b/Modules/clinic/binascii.c.h Sun May 01 16:52:27 2016 +0300 @@ -20,7 +20,7 @@ binascii_a2b_uu(PyModuleDef *module, PyO PyObject *return_value = NULL; Py_buffer data = {NULL, NULL}; - if (!PyArg_Parse(arg, "O&:a2b_uu", ascii_buffer_converter, &data)) + if (!ascii_buffer_converter(arg, &data)) goto exit; return_value = binascii_a2b_uu_impl(module, &data); @@ -50,7 +50,7 @@ binascii_b2a_uu(PyModuleDef *module, PyO PyObject *return_value = NULL; Py_buffer data = {NULL, NULL}; - if (!PyArg_Parse(arg, "y*:b2a_uu", &data)) + if (PyObject_GetBuffer(arg, &data, PyBUF_SIMPLE) != 0) goto exit; return_value = binascii_b2a_uu_impl(module, &data); @@ -80,7 +80,7 @@ binascii_a2b_base64(PyModuleDef *module, PyObject *return_value = NULL; Py_buffer data = {NULL, NULL}; - if (!PyArg_Parse(arg, "O&:a2b_base64", ascii_buffer_converter, &data)) + if (!ascii_buffer_converter(arg, &data)) goto exit; return_value = binascii_a2b_base64_impl(module, &data); @@ -143,7 +143,7 @@ binascii_a2b_hqx(PyModuleDef *module, Py PyObject *return_value = NULL; Py_buffer data = {NULL, NULL}; - if (!PyArg_Parse(arg, "O&:a2b_hqx", ascii_buffer_converter, &data)) + if (!ascii_buffer_converter(arg, &data)) goto exit; return_value = binascii_a2b_hqx_impl(module, &data); @@ -173,7 +173,7 @@ binascii_rlecode_hqx(PyModuleDef *module PyObject *return_value = NULL; Py_buffer data = {NULL, NULL}; - if (!PyArg_Parse(arg, "y*:rlecode_hqx", &data)) + if (PyObject_GetBuffer(arg, &data, PyBUF_SIMPLE) != 0) goto exit; return_value = binascii_rlecode_hqx_impl(module, &data); @@ -203,7 +203,7 @@ binascii_b2a_hqx(PyModuleDef *module, Py PyObject *return_value = NULL; Py_buffer data = {NULL, NULL}; - if (!PyArg_Parse(arg, "y*:b2a_hqx", &data)) + if (PyObject_GetBuffer(arg, &data, PyBUF_SIMPLE) != 0) goto exit; return_value = binascii_b2a_hqx_impl(module, &data); @@ -233,7 +233,7 @@ binascii_rledecode_hqx(PyModuleDef *modu PyObject *return_value = NULL; Py_buffer data = {NULL, NULL}; - if (!PyArg_Parse(arg, "y*:rledecode_hqx", &data)) + if (PyObject_GetBuffer(arg, &data, PyBUF_SIMPLE) != 0) goto exit; return_value = binascii_rledecode_hqx_impl(module, &data); @@ -338,7 +338,7 @@ binascii_b2a_hex(PyModuleDef *module, Py PyObject *return_value = NULL; Py_buffer data = {NULL, NULL}; - if (!PyArg_Parse(arg, "y*:b2a_hex", &data)) + if (PyObject_GetBuffer(arg, &data, PyBUF_SIMPLE) != 0) goto exit; return_value = binascii_b2a_hex_impl(module, &data); @@ -370,7 +370,7 @@ binascii_hexlify(PyModuleDef *module, Py PyObject *return_value = NULL; Py_buffer data = {NULL, NULL}; - if (!PyArg_Parse(arg, "y*:hexlify", &data)) + if (PyObject_GetBuffer(arg, &data, PyBUF_SIMPLE) != 0) goto exit; return_value = binascii_hexlify_impl(module, &data); @@ -403,7 +403,7 @@ binascii_a2b_hex(PyModuleDef *module, Py PyObject *return_value = NULL; Py_buffer hexstr = {NULL, NULL}; - if (!PyArg_Parse(arg, "O&:a2b_hex", ascii_buffer_converter, &hexstr)) + if (!ascii_buffer_converter(arg, &hexstr)) goto exit; return_value = binascii_a2b_hex_impl(module, &hexstr); @@ -435,7 +435,7 @@ binascii_unhexlify(PyModuleDef *module, PyObject *return_value = NULL; Py_buffer hexstr = {NULL, NULL}; - if (!PyArg_Parse(arg, "O&:unhexlify", ascii_buffer_converter, &hexstr)) + if (!ascii_buffer_converter(arg, &hexstr)) goto exit; return_value = binascii_unhexlify_impl(module, &hexstr); @@ -519,4 +519,4 @@ exit: return return_value; } -/*[clinic end generated code: output=b15a24350d105251 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=f7f5e0fdf65c02f8 input=a9049054013a1b77]*/ diff -r dbdd5bc4df99 Modules/clinic/cmathmodule.c.h --- a/Modules/clinic/cmathmodule.c.h Sun May 01 13:36:42 2016 +0300 +++ b/Modules/clinic/cmathmodule.c.h Sun May 01 16:52:27 2016 +0300 @@ -21,7 +21,8 @@ cmath_acos(PyModuleDef *module, PyObject Py_complex z; Py_complex _return_value; - if (!PyArg_Parse(arg, "D:acos", &z)) + z = PyComplex_AsCComplex(arg); + if (PyErr_Occurred()) goto exit; /* modifications for z */ errno = 0; PyFPE_START_PROTECT("complex function", goto exit); @@ -62,7 +63,8 @@ cmath_acosh(PyModuleDef *module, PyObjec Py_complex z; Py_complex _return_value; - if (!PyArg_Parse(arg, "D:acosh", &z)) + z = PyComplex_AsCComplex(arg); + if (PyErr_Occurred()) goto exit; /* modifications for z */ errno = 0; PyFPE_START_PROTECT("complex function", goto exit); @@ -103,7 +105,8 @@ cmath_asin(PyModuleDef *module, PyObject Py_complex z; Py_complex _return_value; - if (!PyArg_Parse(arg, "D:asin", &z)) + z = PyComplex_AsCComplex(arg); + if (PyErr_Occurred()) goto exit; /* modifications for z */ errno = 0; PyFPE_START_PROTECT("complex function", goto exit); @@ -144,7 +147,8 @@ cmath_asinh(PyModuleDef *module, PyObjec Py_complex z; Py_complex _return_value; - if (!PyArg_Parse(arg, "D:asinh", &z)) + z = PyComplex_AsCComplex(arg); + if (PyErr_Occurred()) goto exit; /* modifications for z */ errno = 0; PyFPE_START_PROTECT("complex function", goto exit); @@ -185,7 +189,8 @@ cmath_atan(PyModuleDef *module, PyObject Py_complex z; Py_complex _return_value; - if (!PyArg_Parse(arg, "D:atan", &z)) + z = PyComplex_AsCComplex(arg); + if (PyErr_Occurred()) goto exit; /* modifications for z */ errno = 0; PyFPE_START_PROTECT("complex function", goto exit); @@ -226,7 +231,8 @@ cmath_atanh(PyModuleDef *module, PyObjec Py_complex z; Py_complex _return_value; - if (!PyArg_Parse(arg, "D:atanh", &z)) + z = PyComplex_AsCComplex(arg); + if (PyErr_Occurred()) goto exit; /* modifications for z */ errno = 0; PyFPE_START_PROTECT("complex function", goto exit); @@ -267,7 +273,8 @@ cmath_cos(PyModuleDef *module, PyObject Py_complex z; Py_complex _return_value; - if (!PyArg_Parse(arg, "D:cos", &z)) + z = PyComplex_AsCComplex(arg); + if (PyErr_Occurred()) goto exit; /* modifications for z */ errno = 0; PyFPE_START_PROTECT("complex function", goto exit); @@ -308,7 +315,8 @@ cmath_cosh(PyModuleDef *module, PyObject Py_complex z; Py_complex _return_value; - if (!PyArg_Parse(arg, "D:cosh", &z)) + z = PyComplex_AsCComplex(arg); + if (PyErr_Occurred()) goto exit; /* modifications for z */ errno = 0; PyFPE_START_PROTECT("complex function", goto exit); @@ -349,7 +357,8 @@ cmath_exp(PyModuleDef *module, PyObject Py_complex z; Py_complex _return_value; - if (!PyArg_Parse(arg, "D:exp", &z)) + z = PyComplex_AsCComplex(arg); + if (PyErr_Occurred()) goto exit; /* modifications for z */ errno = 0; PyFPE_START_PROTECT("complex function", goto exit); @@ -390,7 +399,8 @@ cmath_log10(PyModuleDef *module, PyObjec Py_complex z; Py_complex _return_value; - if (!PyArg_Parse(arg, "D:log10", &z)) + z = PyComplex_AsCComplex(arg); + if (PyErr_Occurred()) goto exit; /* modifications for z */ errno = 0; PyFPE_START_PROTECT("complex function", goto exit); @@ -431,7 +441,8 @@ cmath_sin(PyModuleDef *module, PyObject Py_complex z; Py_complex _return_value; - if (!PyArg_Parse(arg, "D:sin", &z)) + z = PyComplex_AsCComplex(arg); + if (PyErr_Occurred()) goto exit; /* modifications for z */ errno = 0; PyFPE_START_PROTECT("complex function", goto exit); @@ -472,7 +483,8 @@ cmath_sinh(PyModuleDef *module, PyObject Py_complex z; Py_complex _return_value; - if (!PyArg_Parse(arg, "D:sinh", &z)) + z = PyComplex_AsCComplex(arg); + if (PyErr_Occurred()) goto exit; /* modifications for z */ errno = 0; PyFPE_START_PROTECT("complex function", goto exit); @@ -513,7 +525,8 @@ cmath_sqrt(PyModuleDef *module, PyObject Py_complex z; Py_complex _return_value; - if (!PyArg_Parse(arg, "D:sqrt", &z)) + z = PyComplex_AsCComplex(arg); + if (PyErr_Occurred()) goto exit; /* modifications for z */ errno = 0; PyFPE_START_PROTECT("complex function", goto exit); @@ -554,7 +567,8 @@ cmath_tan(PyModuleDef *module, PyObject Py_complex z; Py_complex _return_value; - if (!PyArg_Parse(arg, "D:tan", &z)) + z = PyComplex_AsCComplex(arg); + if (PyErr_Occurred()) goto exit; /* modifications for z */ errno = 0; PyFPE_START_PROTECT("complex function", goto exit); @@ -595,7 +609,8 @@ cmath_tanh(PyModuleDef *module, PyObject Py_complex z; Py_complex _return_value; - if (!PyArg_Parse(arg, "D:tanh", &z)) + z = PyComplex_AsCComplex(arg); + if (PyErr_Occurred()) goto exit; /* modifications for z */ errno = 0; PyFPE_START_PROTECT("complex function", goto exit); @@ -665,7 +680,8 @@ cmath_phase(PyModuleDef *module, PyObjec PyObject *return_value = NULL; Py_complex z; - if (!PyArg_Parse(arg, "D:phase", &z)) + z = PyComplex_AsCComplex(arg); + if (PyErr_Occurred()) goto exit; return_value = cmath_phase_impl(module, z); @@ -693,7 +709,8 @@ cmath_polar(PyModuleDef *module, PyObjec PyObject *return_value = NULL; Py_complex z; - if (!PyArg_Parse(arg, "D:polar", &z)) + z = PyComplex_AsCComplex(arg); + if (PyErr_Occurred()) goto exit; return_value = cmath_polar_impl(module, z); @@ -747,7 +764,8 @@ cmath_isfinite(PyModuleDef *module, PyOb PyObject *return_value = NULL; Py_complex z; - if (!PyArg_Parse(arg, "D:isfinite", &z)) + z = PyComplex_AsCComplex(arg); + if (PyErr_Occurred()) goto exit; return_value = cmath_isfinite_impl(module, z); @@ -773,7 +791,8 @@ cmath_isnan(PyModuleDef *module, PyObjec PyObject *return_value = NULL; Py_complex z; - if (!PyArg_Parse(arg, "D:isnan", &z)) + z = PyComplex_AsCComplex(arg); + if (PyErr_Occurred()) goto exit; return_value = cmath_isnan_impl(module, z); @@ -799,7 +818,8 @@ cmath_isinf(PyModuleDef *module, PyObjec PyObject *return_value = NULL; Py_complex z; - if (!PyArg_Parse(arg, "D:isinf", &z)) + z = PyComplex_AsCComplex(arg); + if (PyErr_Occurred()) goto exit; return_value = cmath_isinf_impl(module, z); @@ -857,4 +877,4 @@ cmath_isclose(PyModuleDef *module, PyObj exit: return return_value; } -/*[clinic end generated code: output=229e9c48c9d27362 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=a7309bb6ddc72e7c input=a9049054013a1b77]*/ diff -r dbdd5bc4df99 Modules/clinic/posixmodule.c.h --- a/Modules/clinic/posixmodule.c.h Sun May 01 13:36:42 2016 +0300 +++ b/Modules/clinic/posixmodule.c.h Sun May 01 16:52:27 2016 +0300 @@ -179,7 +179,13 @@ os_ttyname(PyModuleDef *module, PyObject int fd; char *_return_value; - if (!PyArg_Parse(arg, "i:ttyname", &fd)) + if (PyFloat_Check(arg)) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + fd = _PyLong_AsInt(arg); + if (fd == -1 && PyErr_Occurred()) goto exit; _return_value = os_ttyname_impl(module, fd); if (_return_value == NULL) @@ -907,7 +913,7 @@ os__getfullpathname(PyModuleDef *module, PyObject *return_value = NULL; path_t path = PATH_T_INITIALIZE("_getfullpathname", "path", 0, 0); - if (!PyArg_Parse(arg, "O&:_getfullpathname", path_converter, &path)) + if (!path_converter(arg, &path)) goto exit; return_value = os__getfullpathname_impl(module, &path); @@ -940,8 +946,14 @@ os__getfinalpathname(PyModuleDef *module PyObject *return_value = NULL; PyObject *path; - if (!PyArg_Parse(arg, "U:_getfinalpathname", &path)) + if (!PyUnicode_Check(arg)) { + PyErr_Format(PyExc_TypeError, "must be str, not %.50s", + arg == Py_None ? "None" : arg->ob_type->tp_name); goto exit; + } + if (PyUnicode_READY(arg) == -1) + goto exit; + path = arg; return_value = os__getfinalpathname_impl(module, path); exit: @@ -969,7 +981,7 @@ os__isdir(PyModuleDef *module, PyObject PyObject *return_value = NULL; path_t path = PATH_T_INITIALIZE("_isdir", "path", 0, 0); - if (!PyArg_Parse(arg, "O&:_isdir", path_converter, &path)) + if (!path_converter(arg, &path)) goto exit; return_value = os__isdir_impl(module, &path); @@ -1074,7 +1086,13 @@ os_nice(PyModuleDef *module, PyObject *a PyObject *return_value = NULL; int increment; - if (!PyArg_Parse(arg, "i:nice", &increment)) + if (PyFloat_Check(arg)) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + increment = _PyLong_AsInt(arg); + if (increment == -1 && PyErr_Occurred()) goto exit; return_value = os_nice_impl(module, increment); @@ -1367,7 +1385,13 @@ os_umask(PyModuleDef *module, PyObject * PyObject *return_value = NULL; int mask; - if (!PyArg_Parse(arg, "i:umask", &mask)) + if (PyFloat_Check(arg)) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + mask = _PyLong_AsInt(arg); + if (mask == -1 && PyErr_Occurred()) goto exit; return_value = os_umask_impl(module, mask); @@ -2529,7 +2553,13 @@ os_plock(PyModuleDef *module, PyObject * PyObject *return_value = NULL; int op; - if (!PyArg_Parse(arg, "i:plock", &op)) + if (PyFloat_Check(arg)) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + op = _PyLong_AsInt(arg); + if (op == -1 && PyErr_Occurred()) goto exit; return_value = os_plock_impl(module, op); @@ -2559,7 +2589,7 @@ os_setuid(PyModuleDef *module, PyObject PyObject *return_value = NULL; uid_t uid; - if (!PyArg_Parse(arg, "O&:setuid", _Py_Uid_Converter, &uid)) + if (!_Py_Uid_Converter(arg, &uid)) goto exit; return_value = os_setuid_impl(module, uid); @@ -2589,7 +2619,7 @@ os_seteuid(PyModuleDef *module, PyObject PyObject *return_value = NULL; uid_t euid; - if (!PyArg_Parse(arg, "O&:seteuid", _Py_Uid_Converter, &euid)) + if (!_Py_Uid_Converter(arg, &euid)) goto exit; return_value = os_seteuid_impl(module, euid); @@ -2619,7 +2649,7 @@ os_setegid(PyModuleDef *module, PyObject PyObject *return_value = NULL; gid_t egid; - if (!PyArg_Parse(arg, "O&:setegid", _Py_Gid_Converter, &egid)) + if (!_Py_Gid_Converter(arg, &egid)) goto exit; return_value = os_setegid_impl(module, egid); @@ -2713,7 +2743,7 @@ os_setgid(PyModuleDef *module, PyObject PyObject *return_value = NULL; gid_t gid; - if (!PyArg_Parse(arg, "O&:setgid", _Py_Gid_Converter, &gid)) + if (!_Py_Gid_Converter(arg, &gid)) goto exit; return_value = os_setgid_impl(module, gid); @@ -3131,7 +3161,13 @@ os_tcgetpgrp(PyModuleDef *module, PyObje PyObject *return_value = NULL; int fd; - if (!PyArg_Parse(arg, "i:tcgetpgrp", &fd)) + if (PyFloat_Check(arg)) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + fd = _PyLong_AsInt(arg); + if (fd == -1 && PyErr_Occurred()) goto exit; return_value = os_tcgetpgrp_impl(module, fd); @@ -3292,7 +3328,13 @@ os_dup(PyModuleDef *module, PyObject *ar int fd; int _return_value; - if (!PyArg_Parse(arg, "i:dup", &fd)) + if (PyFloat_Check(arg)) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + fd = _PyLong_AsInt(arg); + if (fd == -1 && PyErr_Occurred()) goto exit; _return_value = os_dup_impl(module, fd); if ((_return_value == -1) && PyErr_Occurred()) @@ -3606,7 +3648,13 @@ os_isatty(PyModuleDef *module, PyObject int fd; int _return_value; - if (!PyArg_Parse(arg, "i:isatty", &fd)) + if (PyFloat_Check(arg)) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + fd = _PyLong_AsInt(arg); + if (fd == -1 && PyErr_Occurred()) goto exit; _return_value = os_isatty_impl(module, fd); if ((_return_value == -1) && PyErr_Occurred()) @@ -3668,7 +3716,13 @@ os_pipe2(PyModuleDef *module, PyObject * PyObject *return_value = NULL; int flags; - if (!PyArg_Parse(arg, "i:pipe2", &flags)) + if (PyFloat_Check(arg)) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + flags = _PyLong_AsInt(arg); + if (flags == -1 && PyErr_Occurred()) goto exit; return_value = os_pipe2_impl(module, flags); @@ -3877,7 +3931,7 @@ os_major(PyModuleDef *module, PyObject * dev_t device; unsigned int _return_value; - if (!PyArg_Parse(arg, "O&:major", _Py_Dev_Converter, &device)) + if (!_Py_Dev_Converter(arg, &device)) goto exit; _return_value = os_major_impl(module, device); if ((_return_value == (unsigned int)-1) && PyErr_Occurred()) @@ -3911,7 +3965,7 @@ os_minor(PyModuleDef *module, PyObject * dev_t device; unsigned int _return_value; - if (!PyArg_Parse(arg, "O&:minor", _Py_Dev_Converter, &device)) + if (!_Py_Dev_Converter(arg, &device)) goto exit; _return_value = os_minor_impl(module, device); if ((_return_value == (unsigned int)-1) && PyErr_Occurred()) @@ -4200,7 +4254,7 @@ os_unsetenv(PyModuleDef *module, PyObjec PyObject *return_value = NULL; PyObject *name = NULL; - if (!PyArg_Parse(arg, "O&:unsetenv", PyUnicode_FSConverter, &name)) + if (!PyUnicode_FSConverter(arg, &name)) goto exit; return_value = os_unsetenv_impl(module, name); @@ -4231,7 +4285,13 @@ os_strerror(PyModuleDef *module, PyObjec PyObject *return_value = NULL; int code; - if (!PyArg_Parse(arg, "i:strerror", &code)) + if (PyFloat_Check(arg)) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + code = _PyLong_AsInt(arg); + if (code == -1 && PyErr_Occurred()) goto exit; return_value = os_strerror_impl(module, code); @@ -4260,7 +4320,13 @@ os_WCOREDUMP(PyModuleDef *module, PyObje int status; int _return_value; - if (!PyArg_Parse(arg, "i:WCOREDUMP", &status)) + if (PyFloat_Check(arg)) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + status = _PyLong_AsInt(arg); + if (status == -1 && PyErr_Occurred()) goto exit; _return_value = os_WCOREDUMP_impl(module, status); if ((_return_value == -1) && PyErr_Occurred()) @@ -4550,7 +4616,13 @@ os_fstatvfs(PyModuleDef *module, PyObjec PyObject *return_value = NULL; int fd; - if (!PyArg_Parse(arg, "i:fstatvfs", &fd)) + if (PyFloat_Check(arg)) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + fd = _PyLong_AsInt(arg); + if (fd == -1 && PyErr_Occurred()) goto exit; return_value = os_fstatvfs_impl(module, fd); @@ -4733,7 +4805,7 @@ os_confstr(PyModuleDef *module, PyObject PyObject *return_value = NULL; int name; - if (!PyArg_Parse(arg, "O&:confstr", conv_confstr_confname, &name)) + if (!conv_confstr_confname(arg, &name)) goto exit; return_value = os_confstr_impl(module, name); @@ -4764,7 +4836,7 @@ os_sysconf(PyModuleDef *module, PyObject int name; long _return_value; - if (!PyArg_Parse(arg, "O&:sysconf", conv_sysconf_confname, &name)) + if (!conv_sysconf_confname(arg, &name)) goto exit; _return_value = os_sysconf_impl(module, name); if ((_return_value == -1) && PyErr_Occurred()) @@ -5166,7 +5238,8 @@ os_urandom(PyModuleDef *module, PyObject PyObject *return_value = NULL; Py_ssize_t size; - if (!PyArg_Parse(arg, "n:urandom", &size)) + size = PyNumber_AsSsize_t(arg, PyExc_OverflowError); + if (size == -1 && PyErr_Occurred()) goto exit; return_value = os_urandom_impl(module, size); @@ -5215,7 +5288,13 @@ os_get_inheritable(PyModuleDef *module, int fd; int _return_value; - if (!PyArg_Parse(arg, "i:get_inheritable", &fd)) + if (PyFloat_Check(arg)) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + fd = _PyLong_AsInt(arg); + if (fd == -1 && PyErr_Occurred()) goto exit; _return_value = os_get_inheritable_impl(module, fd); if ((_return_value == -1) && PyErr_Occurred()) @@ -5792,4 +5871,4 @@ exit: #ifndef OS_SET_HANDLE_INHERITABLE_METHODDEF #define OS_SET_HANDLE_INHERITABLE_METHODDEF #endif /* !defined(OS_SET_HANDLE_INHERITABLE_METHODDEF) */ -/*[clinic end generated code: output=a5c9bef9ad11a20b input=a9049054013a1b77]*/ +/*[clinic end generated code: output=4c57841683330f9c input=a9049054013a1b77]*/ diff -r dbdd5bc4df99 Modules/clinic/pwdmodule.c.h --- a/Modules/clinic/pwdmodule.c.h Sun May 01 13:36:42 2016 +0300 +++ b/Modules/clinic/pwdmodule.c.h Sun May 01 16:52:27 2016 +0300 @@ -33,8 +33,14 @@ pwd_getpwnam(PyModuleDef *module, PyObje PyObject *return_value = NULL; PyObject *arg; - if (!PyArg_Parse(arg_, "U:getpwnam", &arg)) + if (!PyUnicode_Check(arg_)) { + PyErr_Format(PyExc_TypeError, "must be str, not %.50s", + arg_ == Py_None ? "None" : arg_->ob_type->tp_name); goto exit; + } + if (PyUnicode_READY(arg_) == -1) + goto exit; + arg = arg_; return_value = pwd_getpwnam_impl(module, arg); exit: @@ -68,4 +74,4 @@ pwd_getpwall(PyModuleDef *module, PyObje #ifndef PWD_GETPWALL_METHODDEF #define PWD_GETPWALL_METHODDEF #endif /* !defined(PWD_GETPWALL_METHODDEF) */ -/*[clinic end generated code: output=2ed0ecf34fd3f98f input=a9049054013a1b77]*/ +/*[clinic end generated code: output=16fedf83e3357d7c input=a9049054013a1b77]*/ diff -r dbdd5bc4df99 Modules/clinic/pyexpat.c.h --- a/Modules/clinic/pyexpat.c.h Sun May 01 13:36:42 2016 +0300 +++ b/Modules/clinic/pyexpat.c.h Sun May 01 16:52:27 2016 +0300 @@ -60,8 +60,18 @@ pyexpat_xmlparser_SetBase(xmlparseobject PyObject *return_value = NULL; const char *base; - if (!PyArg_Parse(arg, "s:SetBase", &base)) + if (!PyUnicode_Check(arg)) { + PyErr_Format(PyExc_TypeError, "must be str, not %.50s", + arg == Py_None ? "None" : arg->ob_type->tp_name); goto exit; + } + base = PyUnicode_AsUTF8(arg); + if (base == NULL) + goto exit; + if (strlen(base) != (size_t)PyUnicode_GET_LENGTH(arg)) { + PyErr_SetString(PyExc_ValueError, "embedded null character"); + goto exit; + } return_value = pyexpat_xmlparser_SetBase_impl(self, base); exit: @@ -160,7 +170,13 @@ pyexpat_xmlparser_SetParamEntityParsing( PyObject *return_value = NULL; int flag; - if (!PyArg_Parse(arg, "i:SetParamEntityParsing", &flag)) + if (PyFloat_Check(arg)) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + flag = _PyLong_AsInt(arg); + if (flag == -1 && PyErr_Occurred()) goto exit; return_value = pyexpat_xmlparser_SetParamEntityParsing_impl(self, flag); @@ -270,7 +286,13 @@ pyexpat_ErrorString(PyModuleDef *module, PyObject *return_value = NULL; long code; - if (!PyArg_Parse(arg, "l:ErrorString", &code)) + if (PyFloat_Check(arg)) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + code = PyLong_AsLong(arg); + if (code == -1 && PyErr_Occurred()) goto exit; return_value = pyexpat_ErrorString_impl(module, code); @@ -281,4 +303,4 @@ exit: #ifndef PYEXPAT_XMLPARSER_USEFOREIGNDTD_METHODDEF #define PYEXPAT_XMLPARSER_USEFOREIGNDTD_METHODDEF #endif /* !defined(PYEXPAT_XMLPARSER_USEFOREIGNDTD_METHODDEF) */ -/*[clinic end generated code: output=bf4d99c9702d8a6c input=a9049054013a1b77]*/ +/*[clinic end generated code: output=34181e29f3ad63c9 input=a9049054013a1b77]*/ diff -r dbdd5bc4df99 Modules/clinic/signalmodule.c.h --- a/Modules/clinic/signalmodule.c.h Sun May 01 13:36:42 2016 +0300 +++ b/Modules/clinic/signalmodule.c.h Sun May 01 16:52:27 2016 +0300 @@ -23,7 +23,13 @@ signal_alarm(PyModuleDef *module, PyObje int seconds; long _return_value; - if (!PyArg_Parse(arg, "i:alarm", &seconds)) + if (PyFloat_Check(arg)) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + seconds = _PyLong_AsInt(arg); + if (seconds == -1 && PyErr_Occurred()) goto exit; _return_value = signal_alarm_impl(module, seconds); if ((_return_value == -1) && PyErr_Occurred()) @@ -117,7 +123,13 @@ signal_getsignal(PyModuleDef *module, Py PyObject *return_value = NULL; int signalnum; - if (!PyArg_Parse(arg, "i:getsignal", &signalnum)) + if (PyFloat_Check(arg)) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + signalnum = _PyLong_AsInt(arg); + if (signalnum == -1 && PyErr_Occurred()) goto exit; return_value = signal_getsignal_impl(module, signalnum); @@ -219,7 +231,13 @@ signal_getitimer(PyModuleDef *module, Py PyObject *return_value = NULL; int which; - if (!PyArg_Parse(arg, "i:getitimer", &which)) + if (PyFloat_Check(arg)) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + which = _PyLong_AsInt(arg); + if (which == -1 && PyErr_Occurred()) goto exit; return_value = signal_getitimer_impl(module, which); @@ -429,4 +447,4 @@ exit: #ifndef SIGNAL_PTHREAD_KILL_METHODDEF #define SIGNAL_PTHREAD_KILL_METHODDEF #endif /* !defined(SIGNAL_PTHREAD_KILL_METHODDEF) */ -/*[clinic end generated code: output=b99278c16c40ea43 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=2e8f0dc7e12aa577 input=a9049054013a1b77]*/ diff -r dbdd5bc4df99 Modules/clinic/spwdmodule.c.h --- a/Modules/clinic/spwdmodule.c.h Sun May 01 13:36:42 2016 +0300 +++ b/Modules/clinic/spwdmodule.c.h Sun May 01 16:52:27 2016 +0300 @@ -24,8 +24,14 @@ spwd_getspnam(PyModuleDef *module, PyObj PyObject *return_value = NULL; PyObject *arg; - if (!PyArg_Parse(arg_, "U:getspnam", &arg)) + if (!PyUnicode_Check(arg_)) { + PyErr_Format(PyExc_TypeError, "must be str, not %.50s", + arg_ == Py_None ? "None" : arg_->ob_type->tp_name); goto exit; + } + if (PyUnicode_READY(arg_) == -1) + goto exit; + arg = arg_; return_value = spwd_getspnam_impl(module, arg); exit: @@ -65,4 +71,4 @@ spwd_getspall(PyModuleDef *module, PyObj #ifndef SPWD_GETSPALL_METHODDEF #define SPWD_GETSPALL_METHODDEF #endif /* !defined(SPWD_GETSPALL_METHODDEF) */ -/*[clinic end generated code: output=6c178830413f7763 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=a15e904122a183bd input=a9049054013a1b77]*/ diff -r dbdd5bc4df99 Modules/clinic/unicodedata.c.h --- a/Modules/clinic/unicodedata.c.h Sun May 01 13:36:42 2016 +0300 +++ b/Modules/clinic/unicodedata.c.h Sun May 01 16:52:27 2016 +0300 @@ -118,8 +118,21 @@ unicodedata_UCD_category(PyObject *self, PyObject *return_value = NULL; int chr; - if (!PyArg_Parse(arg, "C:category", &chr)) + if (!PyUnicode_Check(arg)) { + PyErr_Format(PyExc_TypeError, + "must be a unicode character, not %.50s", + arg == Py_None ? "None" : arg->ob_type->tp_name); goto exit; + } + if (PyUnicode_READY(arg)) + goto exit; + if (PyUnicode_GET_LENGTH(arg) != 1) { + PyErr_Format(PyExc_TypeError, + "must be a unicode character, not %.50s", + arg->ob_type->tp_name); + goto exit; + } + chr = PyUnicode_READ_CHAR(arg, 0); return_value = unicodedata_UCD_category_impl(self, chr); exit: @@ -146,8 +159,21 @@ unicodedata_UCD_bidirectional(PyObject * PyObject *return_value = NULL; int chr; - if (!PyArg_Parse(arg, "C:bidirectional", &chr)) + if (!PyUnicode_Check(arg)) { + PyErr_Format(PyExc_TypeError, + "must be a unicode character, not %.50s", + arg == Py_None ? "None" : arg->ob_type->tp_name); goto exit; + } + if (PyUnicode_READY(arg)) + goto exit; + if (PyUnicode_GET_LENGTH(arg) != 1) { + PyErr_Format(PyExc_TypeError, + "must be a unicode character, not %.50s", + arg->ob_type->tp_name); + goto exit; + } + chr = PyUnicode_READ_CHAR(arg, 0); return_value = unicodedata_UCD_bidirectional_impl(self, chr); exit: @@ -175,8 +201,21 @@ unicodedata_UCD_combining(PyObject *self int chr; int _return_value; - if (!PyArg_Parse(arg, "C:combining", &chr)) + if (!PyUnicode_Check(arg)) { + PyErr_Format(PyExc_TypeError, + "must be a unicode character, not %.50s", + arg == Py_None ? "None" : arg->ob_type->tp_name); goto exit; + } + if (PyUnicode_READY(arg)) + goto exit; + if (PyUnicode_GET_LENGTH(arg) != 1) { + PyErr_Format(PyExc_TypeError, + "must be a unicode character, not %.50s", + arg->ob_type->tp_name); + goto exit; + } + chr = PyUnicode_READ_CHAR(arg, 0); _return_value = unicodedata_UCD_combining_impl(self, chr); if ((_return_value == -1) && PyErr_Occurred()) goto exit; @@ -208,8 +247,21 @@ unicodedata_UCD_mirrored(PyObject *self, int chr; int _return_value; - if (!PyArg_Parse(arg, "C:mirrored", &chr)) + if (!PyUnicode_Check(arg)) { + PyErr_Format(PyExc_TypeError, + "must be a unicode character, not %.50s", + arg == Py_None ? "None" : arg->ob_type->tp_name); goto exit; + } + if (PyUnicode_READY(arg)) + goto exit; + if (PyUnicode_GET_LENGTH(arg) != 1) { + PyErr_Format(PyExc_TypeError, + "must be a unicode character, not %.50s", + arg->ob_type->tp_name); + goto exit; + } + chr = PyUnicode_READ_CHAR(arg, 0); _return_value = unicodedata_UCD_mirrored_impl(self, chr); if ((_return_value == -1) && PyErr_Occurred()) goto exit; @@ -237,8 +289,21 @@ unicodedata_UCD_east_asian_width(PyObjec PyObject *return_value = NULL; int chr; - if (!PyArg_Parse(arg, "C:east_asian_width", &chr)) + if (!PyUnicode_Check(arg)) { + PyErr_Format(PyExc_TypeError, + "must be a unicode character, not %.50s", + arg == Py_None ? "None" : arg->ob_type->tp_name); goto exit; + } + if (PyUnicode_READY(arg)) + goto exit; + if (PyUnicode_GET_LENGTH(arg) != 1) { + PyErr_Format(PyExc_TypeError, + "must be a unicode character, not %.50s", + arg->ob_type->tp_name); + goto exit; + } + chr = PyUnicode_READ_CHAR(arg, 0); return_value = unicodedata_UCD_east_asian_width_impl(self, chr); exit: @@ -265,8 +330,21 @@ unicodedata_UCD_decomposition(PyObject * PyObject *return_value = NULL; int chr; - if (!PyArg_Parse(arg, "C:decomposition", &chr)) + if (!PyUnicode_Check(arg)) { + PyErr_Format(PyExc_TypeError, + "must be a unicode character, not %.50s", + arg == Py_None ? "None" : arg->ob_type->tp_name); goto exit; + } + if (PyUnicode_READY(arg)) + goto exit; + if (PyUnicode_GET_LENGTH(arg) != 1) { + PyErr_Format(PyExc_TypeError, + "must be a unicode character, not %.50s", + arg->ob_type->tp_name); + goto exit; + } + chr = PyUnicode_READ_CHAR(arg, 0); return_value = unicodedata_UCD_decomposition_impl(self, chr); exit: @@ -365,4 +443,4 @@ unicodedata_UCD_lookup(PyObject *self, P exit: return return_value; } -/*[clinic end generated code: output=4f8da33c6bc6efc9 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=9264fd4d534f00cc input=a9049054013a1b77]*/ diff -r dbdd5bc4df99 Modules/clinic/zlibmodule.c.h --- a/Modules/clinic/zlibmodule.c.h Sun May 01 13:36:42 2016 +0300 +++ b/Modules/clinic/zlibmodule.c.h Sun May 01 16:52:27 2016 +0300 @@ -200,7 +200,7 @@ zlib_Compress_compress(compobject *self, PyObject *return_value = NULL; Py_buffer data = {NULL, NULL}; - if (!PyArg_Parse(arg, "y*:compress", &data)) + if (PyObject_GetBuffer(arg, &data, PyBUF_SIMPLE) != 0) goto exit; return_value = zlib_Compress_compress_impl(self, &data); @@ -440,4 +440,4 @@ exit: #ifndef ZLIB_COMPRESS_COPY_METHODDEF #define ZLIB_COMPRESS_COPY_METHODDEF #endif /* !defined(ZLIB_COMPRESS_COPY_METHODDEF) */ -/*[clinic end generated code: output=e6f3b79e051ecc35 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=fee6f8bbc7a6576d input=a9049054013a1b77]*/ diff -r dbdd5bc4df99 Objects/clinic/bytearrayobject.c.h --- a/Objects/clinic/bytearrayobject.c.h Sun May 01 13:36:42 2016 +0300 +++ b/Objects/clinic/bytearrayobject.c.h Sun May 01 16:52:27 2016 +0300 @@ -349,7 +349,7 @@ bytearray_append(PyByteArrayObject *self PyObject *return_value = NULL; int item; - if (!PyArg_Parse(arg, "O&:append", _getbytevalue, &item)) + if (!_getbytevalue(arg, &item)) goto exit; return_value = bytearray_append_impl(self, item); @@ -423,7 +423,7 @@ bytearray_remove(PyByteArrayObject *self PyObject *return_value = NULL; int value; - if (!PyArg_Parse(arg, "O&:remove", _getbytevalue, &value)) + if (!_getbytevalue(arg, &value)) goto exit; return_value = bytearray_remove_impl(self, value); @@ -625,8 +625,14 @@ bytearray_fromhex(PyTypeObject *cls, PyO PyObject *return_value = NULL; PyObject *string; - if (!PyArg_Parse(arg, "U:fromhex", &string)) + if (!PyUnicode_Check(arg)) { + PyErr_Format(PyExc_TypeError, "must be str, not %.50s", + arg == Py_None ? "None" : arg->ob_type->tp_name); goto exit; + } + if (PyUnicode_READY(arg) == -1) + goto exit; + string = arg; return_value = bytearray_fromhex_impl((PyObject*)cls, string); exit: @@ -695,4 +701,4 @@ bytearray_sizeof(PyByteArrayObject *self { return bytearray_sizeof_impl(self); } -/*[clinic end generated code: output=966c15ff22c5e243 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=b500c64e244d69e6 input=a9049054013a1b77]*/ diff -r dbdd5bc4df99 Objects/clinic/bytesobject.c.h --- a/Objects/clinic/bytesobject.c.h Sun May 01 13:36:42 2016 +0300 +++ b/Objects/clinic/bytesobject.c.h Sun May 01 16:52:27 2016 +0300 @@ -64,7 +64,7 @@ bytes_partition(PyBytesObject *self, PyO PyObject *return_value = NULL; Py_buffer sep = {NULL, NULL}; - if (!PyArg_Parse(arg, "y*:partition", &sep)) + if (PyObject_GetBuffer(arg, &sep, PyBUF_SIMPLE) != 0) goto exit; return_value = bytes_partition_impl(self, &sep); @@ -101,7 +101,7 @@ bytes_rpartition(PyBytesObject *self, Py PyObject *return_value = NULL; Py_buffer sep = {NULL, NULL}; - if (!PyArg_Parse(arg, "y*:rpartition", &sep)) + if (PyObject_GetBuffer(arg, &sep, PyBUF_SIMPLE) != 0) goto exit; return_value = bytes_rpartition_impl(self, &sep); @@ -477,11 +477,17 @@ bytes_fromhex(PyTypeObject *type, PyObje PyObject *return_value = NULL; PyObject *string; - if (!PyArg_Parse(arg, "U:fromhex", &string)) + if (!PyUnicode_Check(arg)) { + PyErr_Format(PyExc_TypeError, "must be str, not %.50s", + arg == Py_None ? "None" : arg->ob_type->tp_name); goto exit; + } + if (PyUnicode_READY(arg) == -1) + goto exit; + string = arg; return_value = bytes_fromhex_impl(type, string); exit: return return_value; } -/*[clinic end generated code: output=bd0ce8f25d7e18f4 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=7634a29c182b114b input=a9049054013a1b77]*/ diff -r dbdd5bc4df99 PC/clinic/msvcrtmodule.c.h --- a/PC/clinic/msvcrtmodule.c.h Sun May 01 13:36:42 2016 +0300 +++ b/PC/clinic/msvcrtmodule.c.h Sun May 01 16:52:27 2016 +0300 @@ -154,7 +154,13 @@ msvcrt_get_osfhandle(PyModuleDef *module int fd; Py_intptr_t _return_value; - if (!PyArg_Parse(arg, "i:get_osfhandle", &fd)) + if (PyFloat_Check(arg)) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + fd = _PyLong_AsInt(arg); + if (fd == -1 && PyErr_Occurred()) goto exit; _return_value = msvcrt_get_osfhandle_impl(module, fd); if ((_return_value == -1) && PyErr_Occurred()) @@ -338,8 +344,21 @@ msvcrt_putwch(PyModuleDef *module, PyObj PyObject *return_value = NULL; int unicode_char; - if (!PyArg_Parse(arg, "C:putwch", &unicode_char)) + if (!PyUnicode_Check(arg)) { + PyErr_Format(PyExc_TypeError, + "must be a unicode character, not %.50s", + arg == Py_None ? "None" : arg->ob_type->tp_name); goto exit; + } + if (PyUnicode_READY(arg)) + goto exit; + if (PyUnicode_GET_LENGTH(arg) != 1) { + PyErr_Format(PyExc_TypeError, + "must be a unicode character, not %.50s", + arg->ob_type->tp_name); + goto exit; + } + unicode_char = PyUnicode_READ_CHAR(arg, 0); return_value = msvcrt_putwch_impl(module, unicode_char); exit: @@ -394,8 +413,21 @@ msvcrt_ungetwch(PyModuleDef *module, PyO PyObject *return_value = NULL; int unicode_char; - if (!PyArg_Parse(arg, "C:ungetwch", &unicode_char)) + if (!PyUnicode_Check(arg)) { + PyErr_Format(PyExc_TypeError, + "must be a unicode character, not %.50s", + arg == Py_None ? "None" : arg->ob_type->tp_name); goto exit; + } + if (PyUnicode_READY(arg)) + goto exit; + if (PyUnicode_GET_LENGTH(arg) != 1) { + PyErr_Format(PyExc_TypeError, + "must be a unicode character, not %.50s", + arg->ob_type->tp_name); + goto exit; + } + unicode_char = PyUnicode_READ_CHAR(arg, 0); return_value = msvcrt_ungetwch_impl(module, unicode_char); exit: @@ -501,7 +533,13 @@ msvcrt_set_error_mode(PyModuleDef *modul int mode; long _return_value; - if (!PyArg_Parse(arg, "i:set_error_mode", &mode)) + if (PyFloat_Check(arg)) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + mode = _PyLong_AsInt(arg); + if (mode == -1 && PyErr_Occurred()) goto exit; _return_value = msvcrt_set_error_mode_impl(module, mode); if ((_return_value == -1) && PyErr_Occurred()) @@ -551,4 +589,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=16613d3119a1fd44 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=58e1fd193073444f input=a9049054013a1b77]*/ diff -r dbdd5bc4df99 PC/clinic/winreg.c.h --- a/PC/clinic/winreg.c.h Sun May 01 13:36:42 2016 +0300 +++ b/PC/clinic/winreg.c.h Sun May 01 16:52:27 2016 +0300 @@ -522,7 +522,7 @@ winreg_FlushKey(PyModuleDef *module, PyO PyObject *return_value = NULL; HKEY key; - if (!PyArg_Parse(arg, "O&:FlushKey", clinic_HKEY_converter, &key)) + if (!clinic_HKEY_converter(arg, &key)) goto exit; return_value = winreg_FlushKey_impl(module, key); @@ -707,7 +707,7 @@ winreg_QueryInfoKey(PyModuleDef *module, PyObject *return_value = NULL; HKEY key; - if (!PyArg_Parse(arg, "O&:QueryInfoKey", clinic_HKEY_converter, &key)) + if (!clinic_HKEY_converter(arg, &key)) goto exit; return_value = winreg_QueryInfoKey_impl(module, key); @@ -985,7 +985,7 @@ winreg_DisableReflectionKey(PyModuleDef PyObject *return_value = NULL; HKEY key; - if (!PyArg_Parse(arg, "O&:DisableReflectionKey", clinic_HKEY_converter, &key)) + if (!clinic_HKEY_converter(arg, &key)) goto exit; return_value = winreg_DisableReflectionKey_impl(module, key); @@ -1018,7 +1018,7 @@ winreg_EnableReflectionKey(PyModuleDef * PyObject *return_value = NULL; HKEY key; - if (!PyArg_Parse(arg, "O&:EnableReflectionKey", clinic_HKEY_converter, &key)) + if (!clinic_HKEY_converter(arg, &key)) goto exit; return_value = winreg_EnableReflectionKey_impl(module, key); @@ -1049,11 +1049,11 @@ winreg_QueryReflectionKey(PyModuleDef *m PyObject *return_value = NULL; HKEY key; - if (!PyArg_Parse(arg, "O&:QueryReflectionKey", clinic_HKEY_converter, &key)) + if (!clinic_HKEY_converter(arg, &key)) goto exit; return_value = winreg_QueryReflectionKey_impl(module, key); exit: return return_value; } -/*[clinic end generated code: output=5e346dccc296f9f1 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=6818d200e0c3a4bb input=a9049054013a1b77]*/ diff -r dbdd5bc4df99 Python/bltinmodule.c --- a/Python/bltinmodule.c Sun May 01 13:36:42 2016 +0300 +++ b/Python/bltinmodule.c Sun May 01 16:52:27 2016 +0300 @@ -801,7 +801,7 @@ Return the tuple (x//y, x%y). Invariant static PyObject * builtin_divmod_impl(PyModuleDef *module, PyObject *x, PyObject *y) -/*[clinic end generated code: output=9ad0076120ebf9ac input=7fdb15f8a97a5fe7]*/ +/*[clinic end generated code: output=9ad0076120ebf9ac input=175ad9c84ff41a85]*/ { return PyNumber_Divmod(x, y); } diff -r dbdd5bc4df99 Python/clinic/bltinmodule.c.h --- a/Python/clinic/bltinmodule.c.h Sun May 01 13:36:42 2016 +0300 +++ b/Python/clinic/bltinmodule.c.h Sun May 01 16:52:27 2016 +0300 @@ -120,7 +120,13 @@ builtin_chr(PyModuleDef *module, PyObjec PyObject *return_value = NULL; int i; - if (!PyArg_Parse(arg, "i:chr", &i)) + if (PyFloat_Check(arg)) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + i = _PyLong_AsInt(arg); + if (i == -1 && PyErr_Occurred()) goto exit; return_value = builtin_chr_impl(module, i); @@ -179,7 +185,7 @@ PyDoc_STRVAR(builtin_divmod__doc__, "divmod($module, x, y, /)\n" "--\n" "\n" -"Return the tuple ((x-x%y)/y, x%y). Invariant: div*y + mod == x."); +"Return the tuple (x//y, x%y). Invariant: div*y + mod == x."); #define BUILTIN_DIVMOD_METHODDEF \ {"divmod", (PyCFunction)builtin_divmod, METH_VARARGS, builtin_divmod__doc__}, @@ -660,4 +666,4 @@ builtin_issubclass(PyModuleDef *module, exit: return return_value; } -/*[clinic end generated code: output=bec3399c0aee98d7 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=b56943487d91a5c9 input=a9049054013a1b77]*/ diff -r dbdd5bc4df99 Python/clinic/import.c.h --- a/Python/clinic/import.c.h Sun May 01 13:36:42 2016 +0300 +++ b/Python/clinic/import.c.h Sun May 01 16:52:27 2016 +0300 @@ -142,8 +142,14 @@ static PyObject * PyObject *return_value = NULL; PyObject *name; - if (!PyArg_Parse(arg, "U:init_frozen", &name)) + if (!PyUnicode_Check(arg)) { + PyErr_Format(PyExc_TypeError, "must be str, not %.50s", + arg == Py_None ? "None" : arg->ob_type->tp_name); goto exit; + } + if (PyUnicode_READY(arg) == -1) + goto exit; + name = arg; return_value = _imp_init_frozen_impl(module, name); exit: @@ -168,8 +174,14 @@ static PyObject * PyObject *return_value = NULL; PyObject *name; - if (!PyArg_Parse(arg, "U:get_frozen_object", &name)) + if (!PyUnicode_Check(arg)) { + PyErr_Format(PyExc_TypeError, "must be str, not %.50s", + arg == Py_None ? "None" : arg->ob_type->tp_name); goto exit; + } + if (PyUnicode_READY(arg) == -1) + goto exit; + name = arg; return_value = _imp_get_frozen_object_impl(module, name); exit: @@ -194,8 +206,14 @@ static PyObject * PyObject *return_value = NULL; PyObject *name; - if (!PyArg_Parse(arg, "U:is_frozen_package", &name)) + if (!PyUnicode_Check(arg)) { + PyErr_Format(PyExc_TypeError, "must be str, not %.50s", + arg == Py_None ? "None" : arg->ob_type->tp_name); goto exit; + } + if (PyUnicode_READY(arg) == -1) + goto exit; + name = arg; return_value = _imp_is_frozen_package_impl(module, name); exit: @@ -220,8 +238,14 @@ static PyObject * PyObject *return_value = NULL; PyObject *name; - if (!PyArg_Parse(arg, "U:is_builtin", &name)) + if (!PyUnicode_Check(arg)) { + PyErr_Format(PyExc_TypeError, "must be str, not %.50s", + arg == Py_None ? "None" : arg->ob_type->tp_name); goto exit; + } + if (PyUnicode_READY(arg) == -1) + goto exit; + name = arg; return_value = _imp_is_builtin_impl(module, name); exit: @@ -246,8 +270,14 @@ static PyObject * PyObject *return_value = NULL; PyObject *name; - if (!PyArg_Parse(arg, "U:is_frozen", &name)) + if (!PyUnicode_Check(arg)) { + PyErr_Format(PyExc_TypeError, "must be str, not %.50s", + arg == Py_None ? "None" : arg->ob_type->tp_name); goto exit; + } + if (PyUnicode_READY(arg) == -1) + goto exit; + name = arg; return_value = _imp_is_frozen_impl(module, name); exit: @@ -352,4 +382,4 @@ exit: #ifndef _IMP_EXEC_DYNAMIC_METHODDEF #define _IMP_EXEC_DYNAMIC_METHODDEF #endif /* !defined(_IMP_EXEC_DYNAMIC_METHODDEF) */ -/*[clinic end generated code: output=32324a5e46cdfc4b input=a9049054013a1b77]*/ +/*[clinic end generated code: output=3cb23ec72cb965bc input=a9049054013a1b77]*/ diff -r dbdd5bc4df99 Tools/clinic/clinic.py --- a/Tools/clinic/clinic.py Sun May 01 13:36:42 2016 +0300 +++ b/Tools/clinic/clinic.py Sun May 01 16:52:27 2016 +0300 @@ -789,10 +789,26 @@ class CLanguage(Language): {c_basename}({self_type}{self_name}, PyObject *%s) """ % argname) - parser_definition = parser_body(parser_prototype, normalize_snippet(""" - if (!PyArg_Parse(%s, "{format_units}:{name}", {parse_arguments})) - goto exit; - """ % argname, indent=4)) + if (isinstance(converters[0], CConverter) and + converters[0].format_unit == 'O&'): + parsearg = """ + if (!{converter}({argname}, &{paramname})) + goto exit; + """.format(argname=argname, + paramname=parameters[0].name, + converter=converters[0].converter) + else: + parsearg = converters[0].parse_arg() + if parsearg is not None: + parsearg = parsearg.format(argname=argname, + paramname=parameters[0].name) + else: + parsearg = """ + if (!PyArg_Parse(%s, "{format_units}:{name}", {parse_arguments})) + goto exit; + """ % argname + parser_definition = parser_body(parser_prototype, + normalize_snippet(parsearg, indent=4)) elif has_option_groups: # positional parameters with option groups @@ -2314,6 +2330,9 @@ class CConverter(metaclass=CConverterAut def converter_init(self): pass + def parse_arg(self): + return None + def is_optional(self): return (self.default is not unspecified) @@ -2545,6 +2564,37 @@ class int_converter(CConverter): if type != None: self.type = type + def parse_arg(self): + if self.format_unit == 'i': + return """ + if (PyFloat_Check({argname})) {{{{ + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + }}}} + {paramname} = _PyLong_AsInt({argname}); + if ({paramname} == -1 && PyErr_Occurred()) + goto exit; + """ + elif self.format_unit == 'C': + return """ + if (!PyUnicode_Check({argname})) {{{{ + PyErr_Format(PyExc_TypeError, + "must be a unicode character, not %.50s", + {argname} == Py_None ? "None" : {argname}->ob_type->tp_name); + goto exit; + }}}} + if (PyUnicode_READY({argname})) + goto exit; + if (PyUnicode_GET_LENGTH({argname}) != 1) {{{{ + PyErr_Format(PyExc_TypeError, + "must be a unicode character, not %.50s", + {argname}->ob_type->tp_name); + goto exit; + }}}} + {paramname} = PyUnicode_READ_CHAR({argname}, 0); + """ + class unsigned_int_converter(CConverter): type = 'unsigned int' default_type = int @@ -2561,6 +2611,19 @@ class long_converter(CConverter): format_unit = 'l' c_ignored_default = "0" + def parse_arg(self): + if self.format_unit == 'l': + return """ + if (PyFloat_Check({argname})) {{{{ + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + }}}} + {paramname} = PyLong_AsLong({argname}); + if ({paramname} == -1 && PyErr_Occurred()) + goto exit; + """ + class unsigned_long_converter(CConverter): type = 'unsigned long' default_type = int @@ -2577,6 +2640,19 @@ class PY_LONG_LONG_converter(CConverter) format_unit = 'L' c_ignored_default = "0" + def parse_arg(self): + if self.format_unit == 'L': + return """ + if (PyFloat_Check({argname})) {{{{ + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + }}}} + {paramname} = PyLong_AsLongLong({argname}); + if ({paramname} == (PY_LONG_LONG)-1 && PyErr_Occurred()) + goto exit; + """ + class unsigned_PY_LONG_LONG_converter(CConverter): type = 'unsigned PY_LONG_LONG' default_type = int @@ -2593,6 +2669,13 @@ class Py_ssize_t_converter(CConverter): format_unit = 'n' c_ignored_default = "0" + def parse_arg(self): + if self.format_unit == 'n': + return """ + {paramname} = PyNumber_AsSsize_t({argname}, PyExc_OverflowError); + if ({paramname} == -1 && PyErr_Occurred()) + goto exit; + """ class float_converter(CConverter): type = 'float' @@ -2600,12 +2683,27 @@ class float_converter(CConverter): format_unit = 'f' c_ignored_default = "0.0" + def parse_arg(self): + if self.format_unit == 'D': + return """ + {paramname} = (float) PyFloat_AsDouble({argname}); + if (PyErr_Occurred()) + goto exit; + """ + class double_converter(CConverter): type = 'double' default_type = float format_unit = 'd' c_ignored_default = "0.0" + def parse_arg(self): + if self.format_unit == 'D': + return """ + {paramname} = PyFloat_AsDouble({argname}); + if (PyErr_Occurred()) + goto exit; + """ class Py_complex_converter(CConverter): type = 'Py_complex' @@ -2613,6 +2711,13 @@ class Py_complex_converter(CConverter): format_unit = 'D' c_ignored_default = "{0.0, 0.0}" + def parse_arg(self): + if self.format_unit == 'D': + return """ + {paramname} = PyComplex_AsCComplex({argname}); + if (PyErr_Occurred()) + goto exit; + """ class object_converter(CConverter): type = 'PyObject *' @@ -2677,6 +2782,23 @@ class str_converter(CConverter): name = ensure_legal_c_identifier(self.name) return "".join(["if (", name, ")\n PyMem_FREE(", name, ");\n"]) + def parse_arg(self): + if self.format_unit == 's': + return """ + if (!PyUnicode_Check({argname})) {{{{ + PyErr_Format(PyExc_TypeError, "must be str, not %.50s", + {argname} == Py_None ? "None" : {argname}->ob_type->tp_name); + goto exit; + }}}} + {paramname} = PyUnicode_AsUTF8({argname}); + if ({paramname} == NULL) + goto exit; + if (strlen({paramname}) != (size_t)PyUnicode_GET_LENGTH({argname})) {{{{ + PyErr_SetString(PyExc_ValueError, "embedded null character"); + goto exit; + }}}} + """ + # # This is the fourth or fifth rewrite of registering all the # crazy string converter format units. Previous approaches hid @@ -2724,7 +2846,6 @@ r('z', acc r('z#', zeroes=True, accept={robuffer, str, NoneType}) del r - class PyBytesObject_converter(CConverter): type = 'PyBytesObject *' format_unit = 'S' @@ -2740,6 +2861,19 @@ class unicode_converter(CConverter): default_type = (str, Null, NoneType) format_unit = 'U' + def parse_arg(self): + if self.format_unit == 'U': + return """ + if (!PyUnicode_Check({argname})) {{{{ + PyErr_Format(PyExc_TypeError, "must be str, not %.50s", + {argname} == Py_None ? "None" : {argname}->ob_type->tp_name); + goto exit; + }}}} + if (PyUnicode_READY({argname}) == -1) + goto exit; + {paramname} = {argname}; + """ + @add_legacy_c_converter('u#', zeroes=True) @add_legacy_c_converter('Z', accept={str, NoneType}) @add_legacy_c_converter('Z#', accept={str, NoneType}, zeroes=True) @@ -2787,6 +2921,26 @@ class Py_buffer_converter(CConverter): name = ensure_legal_c_identifier(self.name) return "".join(["if (", name, ".obj)\n PyBuffer_Release(&", name, ");\n"]) + def parse_arg(self): + if self.format_unit == 'y*': + return """ + if (PyObject_GetBuffer({argname}, &{paramname}, PyBUF_SIMPLE) != 0) + goto exit; + """ + elif self.format_unit == 's*': + return """ + if (PyUnicode_Check({argname})) {{{{ + Py_ssize_t len; + char *ptr = PyUnicode_AsUTF8AndSize({argname}, &len); + if (ptr == NULL) + goto exit; + PyBuffer_FillInfo(&{paramname}, {argname}, ptr, len, 1, 0); + }}}} + else {{{{ /* any bytes-like object */ + if (PyObject_GetBuffer({argname}, &{paramname}, PyBUF_SIMPLE) != 0) + goto exit; + }}}} + """ def correct_name_for_self(f): if f.kind in (CALLABLE, METHOD_INIT):