summaryrefslogtreecommitdiffstats
path: root/Python/getargs.c
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2016-04-13 12:37:23 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2016-04-13 12:37:23 (GMT)
commit21a663ea2829b6808dd6981904c393332d271f8e (patch)
treede7302e8c98b9b075236c6e52f006835d01562e2 /Python/getargs.c
parent131b8f8eee3498d5d334bde9671825bdfe0cf222 (diff)
downloadcpython-21a663ea2829b6808dd6981904c393332d271f8e.zip
cpython-21a663ea2829b6808dd6981904c393332d271f8e.tar.gz
cpython-21a663ea2829b6808dd6981904c393332d271f8e.tar.bz2
Issue #26057: Got rid of nonneeded use of PyUnicode_FromObject().
Diffstat (limited to 'Python/getargs.c')
-rw-r--r--Python/getargs.c26
1 files changed, 8 insertions, 18 deletions
diff --git a/Python/getargs.c b/Python/getargs.c
index 05ec27b..9858bd5 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 == '#') {