summaryrefslogtreecommitdiffstats
path: root/Python/getargs.c
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2009-04-02 00:33:55 (GMT)
committerBenjamin Peterson <benjamin@python.org>2009-04-02 00:33:55 (GMT)
commit7fe9853596189cb250f895800edfa19147bbb0f1 (patch)
tree5907e37a8dba72265b68f0dd59f9d4368927ac90 /Python/getargs.c
parent605b9d9fe8509f9da305b2ef7a7774419e47094d (diff)
downloadcpython-7fe9853596189cb250f895800edfa19147bbb0f1.zip
cpython-7fe9853596189cb250f895800edfa19147bbb0f1.tar.gz
cpython-7fe9853596189cb250f895800edfa19147bbb0f1.tar.bz2
make 'c' only accept bytes and 'C' only unicode #5499
Diffstat (limited to 'Python/getargs.c')
-rw-r--r--Python/getargs.c14
1 files changed, 4 insertions, 10 deletions
diff --git a/Python/getargs.c b/Python/getargs.c
index 3ab59b3..a89ee6f 100644
--- a/Python/getargs.c
+++ b/Python/getargs.c
@@ -776,24 +776,18 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
char *p = va_arg(*p_va, char *);
if (PyBytes_Check(arg) && PyBytes_Size(arg) == 1)
*p = PyBytes_AS_STRING(arg)[0];
- else if (PyUnicode_Check(arg) &&
- PyUnicode_GET_SIZE(arg) == 1 &&
- PyUnicode_AS_UNICODE(arg)[0] < 256)
- *p = (char)PyUnicode_AS_UNICODE(arg)[0];
else
- return converterr("char < 256", arg, msgbuf, bufsize);
+ return converterr("a byte string of length 1", arg, msgbuf, bufsize);
break;
}
case 'C': {/* unicode char */
int *p = va_arg(*p_va, int *);
- if (PyBytes_Check(arg) && PyBytes_Size(arg) == 1)
- *p = PyBytes_AS_STRING(arg)[0];
- else if (PyUnicode_Check(arg) &&
- PyUnicode_GET_SIZE(arg) == 1)
+ if (PyUnicode_Check(arg) &&
+ PyUnicode_GET_SIZE(arg) == 1)
*p = PyUnicode_AS_UNICODE(arg)[0];
else
- return converterr("char", arg, msgbuf, bufsize);
+ return converterr("a unicode character", arg, msgbuf, bufsize);
break;
}