diff -r 973c9ec53bbb Modules/clinic/_bz2module.c.h --- a/Modules/clinic/_bz2module.c.h Sat Apr 04 17:06:55 2015 +0300 +++ b/Modules/clinic/_bz2module.c.h Sat Apr 04 17:16:29 2015 +0300 @@ -25,9 +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); @@ -168,4 +166,4 @@ static int exit: return return_value; } -/*[clinic end generated code: output=3565d163a360af01 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=e8431bc08257a5a7 input=a9049054013a1b77]*/ diff -r 973c9ec53bbb Modules/clinic/_codecsmodule.c.h --- a/Modules/clinic/_codecsmodule.c.h Sat Apr 04 17:06:55 2015 +0300 +++ b/Modules/clinic/_codecsmodule.c.h Sat Apr 04 17:16:29 2015 +0300 @@ -20,13 +20,21 @@ 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: return return_value; } -/*[clinic end generated code: output=fc5ce4d3166f7d96 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=858b45971045a058 input=a9049054013a1b77]*/ diff -r 973c9ec53bbb Modules/clinic/_lzmamodule.c.h --- a/Modules/clinic/_lzmamodule.c.h Sat Apr 04 17:06:55 2015 +0300 +++ b/Modules/clinic/_lzmamodule.c.h Sat Apr 04 17:16:29 2015 +0300 @@ -25,9 +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); @@ -173,9 +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); @@ -203,9 +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); @@ -251,4 +251,4 @@ exit: return return_value; } -/*[clinic end generated code: output=ea7f2b2c4019fe86 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=b011233fb12e58fb input=a9049054013a1b77]*/ diff -r 973c9ec53bbb Modules/clinic/arraymodule.c.h --- a/Modules/clinic/arraymodule.c.h Sat Apr 04 17:06:55 2015 +0300 +++ b/Modules/clinic/arraymodule.c.h Sat Apr 04 17:16:29 2015 +0300 @@ -278,10 +278,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: @@ -310,9 +317,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); @@ -502,4 +507,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=a8fbe83c2026fa83 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=77650cfc0bec96e6 input=a9049054013a1b77]*/ diff -r 973c9ec53bbb Modules/clinic/binascii.c.h --- a/Modules/clinic/binascii.c.h Sat Apr 04 17:06:55 2015 +0300 +++ b/Modules/clinic/binascii.c.h Sat Apr 04 17:16:29 2015 +0300 @@ -20,9 +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); @@ -52,9 +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); @@ -84,9 +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); @@ -116,9 +110,7 @@ binascii_b2a_base64(PyModuleDef *module, PyObject *return_value = NULL; Py_buffer data = {NULL, NULL}; - if (!PyArg_Parse(arg, - "y*:b2a_base64", - &data)) + if (PyObject_GetBuffer(arg, &data, PyBUF_SIMPLE) != 0) goto exit; return_value = binascii_b2a_base64_impl(module, &data); @@ -148,9 +140,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); @@ -180,9 +170,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); @@ -212,9 +200,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); @@ -244,9 +230,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); @@ -353,9 +337,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); @@ -387,9 +369,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); @@ -422,9 +402,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); @@ -456,9 +434,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); @@ -543,4 +519,4 @@ exit: return return_value; } -/*[clinic end generated code: output=31ccbd5fddc8fd75 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=05ad95da79287b26 input=a9049054013a1b77]*/ diff -r 973c9ec53bbb Modules/clinic/cmathmodule.c.h --- a/Modules/clinic/cmathmodule.c.h Sat Apr 04 17:06:55 2015 +0300 +++ b/Modules/clinic/cmathmodule.c.h Sat Apr 04 17:16:29 2015 +0300 @@ -21,9 +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); @@ -64,9 +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); @@ -107,9 +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); @@ -150,9 +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); @@ -193,9 +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); @@ -236,9 +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); @@ -279,9 +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); @@ -322,9 +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); @@ -365,9 +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); @@ -408,9 +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); @@ -451,9 +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); @@ -494,9 +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); @@ -537,9 +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); @@ -580,9 +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); @@ -623,9 +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); @@ -696,9 +681,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); @@ -726,9 +710,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); @@ -783,9 +766,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); @@ -811,9 +793,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); @@ -839,13 +820,12 @@ 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); exit: return return_value; } -/*[clinic end generated code: output=9143b8dcc8069024 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=c36ef3d43caf5d2d input=a9049054013a1b77]*/ diff -r 973c9ec53bbb Modules/clinic/posixmodule.c.h --- a/Modules/clinic/posixmodule.c.h Sat Apr 04 17:06:55 2015 +0300 +++ b/Modules/clinic/posixmodule.c.h Sat Apr 04 17:16:29 2015 +0300 @@ -180,9 +180,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) @@ -922,10 +926,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: @@ -1028,9 +1036,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); @@ -1328,9 +1340,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); @@ -2512,9 +2528,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); @@ -2544,9 +2564,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); @@ -2576,9 +2594,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); @@ -2608,9 +2624,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); @@ -2706,9 +2720,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); @@ -3134,9 +3146,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); @@ -3300,9 +3316,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()) @@ -3624,9 +3644,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()) @@ -3688,9 +3712,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); @@ -3901,9 +3929,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()) @@ -3937,9 +3963,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()) @@ -4233,9 +4257,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); @@ -4266,9 +4288,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); @@ -4297,9 +4323,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()) @@ -4596,9 +4626,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); @@ -4785,9 +4819,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); @@ -4818,9 +4850,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()) @@ -5226,9 +5256,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); @@ -5273,9 +5302,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()) @@ -5847,4 +5880,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=b15ceac3a8ff0eae input=a9049054013a1b77]*/ +/*[clinic end generated code: output=3354137902812644 input=a9049054013a1b77]*/ diff -r 973c9ec53bbb Modules/clinic/pwdmodule.c.h --- a/Modules/clinic/pwdmodule.c.h Sat Apr 04 17:06:55 2015 +0300 +++ b/Modules/clinic/pwdmodule.c.h Sat Apr 04 17:16:29 2015 +0300 @@ -33,10 +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: @@ -70,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=e7d5ac24b20e91ae input=a9049054013a1b77]*/ +/*[clinic end generated code: output=16fedf83e3357d7c input=a9049054013a1b77]*/ diff -r 973c9ec53bbb Modules/clinic/pyexpat.c.h --- a/Modules/clinic/pyexpat.c.h Sat Apr 04 17:06:55 2015 +0300 +++ b/Modules/clinic/pyexpat.c.h Sat Apr 04 17:16:29 2015 +0300 @@ -60,10 +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: @@ -161,9 +169,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); @@ -273,9 +285,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); @@ -286,4 +302,4 @@ exit: #ifndef PYEXPAT_XMLPARSER_USEFOREIGNDTD_METHODDEF #define PYEXPAT_XMLPARSER_USEFOREIGNDTD_METHODDEF #endif /* !defined(PYEXPAT_XMLPARSER_USEFOREIGNDTD_METHODDEF) */ -/*[clinic end generated code: output=9715b916f2d618fa input=a9049054013a1b77]*/ +/*[clinic end generated code: output=ac7dd63afd32b0bc input=a9049054013a1b77]*/ diff -r 973c9ec53bbb Modules/clinic/spwdmodule.c.h --- a/Modules/clinic/spwdmodule.c.h Sat Apr 04 17:06:55 2015 +0300 +++ b/Modules/clinic/spwdmodule.c.h Sat Apr 04 17:16:29 2015 +0300 @@ -24,10 +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: @@ -67,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=67a4f8c47008f28f input=a9049054013a1b77]*/ +/*[clinic end generated code: output=a15e904122a183bd input=a9049054013a1b77]*/ diff -r 973c9ec53bbb Modules/clinic/zlibmodule.c.h --- a/Modules/clinic/zlibmodule.c.h Sat Apr 04 17:06:55 2015 +0300 +++ b/Modules/clinic/zlibmodule.c.h Sat Apr 04 17:16:29 2015 +0300 @@ -200,9 +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); @@ -446,4 +444,4 @@ exit: #ifndef ZLIB_COMPRESS_COPY_METHODDEF #define ZLIB_COMPRESS_COPY_METHODDEF #endif /* !defined(ZLIB_COMPRESS_COPY_METHODDEF) */ -/*[clinic end generated code: output=0743b1aa908f0b68 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=1d36e744d5f997ec input=a9049054013a1b77]*/ diff -r 973c9ec53bbb Objects/clinic/bytearrayobject.c.h --- a/Objects/clinic/bytearrayobject.c.h Sat Apr 04 17:06:55 2015 +0300 +++ b/Objects/clinic/bytearrayobject.c.h Sat Apr 04 17:16:29 2015 +0300 @@ -350,9 +350,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); @@ -427,9 +425,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); @@ -632,10 +628,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: @@ -705,4 +705,4 @@ bytearray_sizeof(PyByteArrayObject *self { return bytearray_sizeof_impl(self); } -/*[clinic end generated code: output=d763876718a66fc3 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=2a28124f61d71c47 input=a9049054013a1b77]*/ diff -r 973c9ec53bbb Objects/clinic/bytesobject.c.h --- a/Objects/clinic/bytesobject.c.h Sat Apr 04 17:06:55 2015 +0300 +++ b/Objects/clinic/bytesobject.c.h Sat Apr 04 17:16:29 2015 +0300 @@ -65,9 +65,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); @@ -104,9 +102,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); @@ -484,13 +480,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=b9e69e1f7c8ccd14 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=5ac2c2fd3c4d5d4d input=a9049054013a1b77]*/ diff -r 973c9ec53bbb Python/clinic/bltinmodule.c.h --- a/Python/clinic/bltinmodule.c.h Sat Apr 04 17:06:55 2015 +0300 +++ b/Python/clinic/bltinmodule.c.h Sat Apr 04 17:16:29 2015 +0300 @@ -120,9 +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); @@ -656,4 +660,4 @@ builtin_issubclass(PyModuleDef *module, exit: return return_value; } -/*[clinic end generated code: output=12db4cde92eb11b3 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=bf2d5fe59cf5a287 input=a9049054013a1b77]*/ diff -r 973c9ec53bbb Python/clinic/import.c.h --- a/Python/clinic/import.c.h Sat Apr 04 17:06:55 2015 +0300 +++ b/Python/clinic/import.c.h Sat Apr 04 17:16:29 2015 +0300 @@ -133,10 +133,14 @@ static PyObject * PyObject *return_value = NULL; PyObject *name; - if (!PyArg_Parse(arg, - "U:init_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_init_builtin_impl(module, name); exit: @@ -161,10 +165,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: @@ -189,10 +197,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: @@ -217,10 +229,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: @@ -245,10 +261,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: @@ -273,10 +293,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: @@ -320,4 +344,4 @@ exit: #ifndef _IMP_LOAD_DYNAMIC_METHODDEF #define _IMP_LOAD_DYNAMIC_METHODDEF #endif /* !defined(_IMP_LOAD_DYNAMIC_METHODDEF) */ -/*[clinic end generated code: output=d41c392510815c5b input=a9049054013a1b77]*/ +/*[clinic end generated code: output=ae562064b18ba780 input=a9049054013a1b77]*/ diff -r 973c9ec53bbb Tools/clinic/clinic.py --- a/Tools/clinic/clinic.py Sat Apr 04 17:06:55 2015 +0300 +++ b/Tools/clinic/clinic.py Sat Apr 04 17:16:29 2015 +0300 @@ -726,12 +726,28 @@ 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 @@ -2251,6 +2267,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) @@ -2482,6 +2501,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 @@ -2498,6 +2548,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 @@ -2514,6 +2577,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 @@ -2530,6 +2606,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' @@ -2537,12 +2620,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' @@ -2550,6 +2648,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 *' @@ -2632,6 +2737,22 @@ class str_converter(CConverter): fail("str_converter: illegal combination of arguments") self.format_unit = format_unit + 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; + }}}} + """ class PyBytesObject_converter(CConverter): type = 'PyBytesObject *' @@ -2646,6 +2767,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#', length=True) @add_legacy_c_converter('Z', nullable=True) @add_legacy_c_converter('Z#', nullable=True, length=True) @@ -2708,6 +2842,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):