diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2016-04-13 15:37:23 +0300 |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2016-04-13 15:37:23 +0300 |
commit | 5c655b38b844fb6e540c6db65d505d63c89fde74 (patch) | |
tree | 89da1a94635f344e8004559f2a76cf0a189b2df1 /Python | |
parent | 00da881e08fec97df5b22e3e8d7a8835e53b0bff (diff) | |
download | cpython-5c655b38b844fb6e540c6db65d505d63c89fde74.tar.gz |
Issue #26057: Got rid of nonneeded use of PyUnicode_FromObject().
Diffstat (limited to 'Python')
-rw-r--r-- | Python/bltinmodule.c | 5 | ||||
-rw-r--r-- | Python/getargs.c | 26 |
2 files changed, 10 insertions, 21 deletions
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index 31d9e0e4d1..29fcffec61 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -1931,9 +1931,8 @@ builtin_input_impl(PyModuleDef *module, PyObject *prompt) Py_CLEAR(stringpo); if (po == NULL) goto _readline_errors; - promptstr = PyBytes_AsString(po); - if (promptstr == NULL) - goto _readline_errors; + assert(PyBytes_Check(po)); + promptstr = PyBytes_AS_STRING(po); } else { po = NULL; diff --git a/Python/getargs.c b/Python/getargs.c index 05ec27bfbb..9858bd560c 100644 --- a/Python/getargs.c +++ b/Python/getargs.c @@ -1056,35 +1056,25 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags, return converterr("(AsCharBuffer failed)", arg, msgbuf, bufsize); } - else { - PyObject *u; - - /* Convert object to Unicode */ - u = PyUnicode_FromObject(arg); - if (u == NULL) - return converterr( - "string or unicode or text buffer", - arg, msgbuf, bufsize); - + else if (PyUnicode_Check(arg)) { /* Encode object; use default error handling */ - s = PyUnicode_AsEncodedString(u, + s = PyUnicode_AsEncodedString(arg, encoding, NULL); - Py_DECREF(u); if (s == NULL) return converterr("(encoding failed)", arg, msgbuf, bufsize); - if (!PyBytes_Check(s)) { - Py_DECREF(s); - return converterr( - "(encoder failed to return bytes)", - arg, msgbuf, bufsize); - } + assert(PyBytes_Check(s)); size = PyBytes_GET_SIZE(s); ptr = PyBytes_AS_STRING(s); if (ptr == NULL) ptr = ""; } + else { + return converterr( + recode_strings ? "str" : "str, bytes or bytearray", + arg, msgbuf, bufsize); + } /* Write output; output is guaranteed to be 0-terminated */ if (*format == '#') { |