[Python-3000-checkins] r55211 - python/branches/py3k-struni/Python/getargs.c
guido.van.rossum
python-3000-checkins at python.org
Thu May 10 01:35:13 CEST 2007
Author: guido.van.rossum
Date: Thu May 10 01:35:09 2007
New Revision: 55211
Modified:
python/branches/py3k-struni/Python/getargs.c
Log:
Be more robust around bytes for e[st]#? formats.
Modified: python/branches/py3k-struni/Python/getargs.c
==============================================================================
--- python/branches/py3k-struni/Python/getargs.c (original)
+++ python/branches/py3k-struni/Python/getargs.c Thu May 10 01:35:09 2007
@@ -915,7 +915,7 @@
PyObject *s;
int recode_strings;
Py_ssize_t size;
- char *ptr;
+ const char *ptr;
/* Get 'e' parameter: the encoding name */
encoding = (const char *)va_arg(*p_va, const char *);
@@ -941,11 +941,13 @@
arg, msgbuf, bufsize);
/* Encode object */
- if (!recode_strings && PyString_Check(arg)) {
+ if (!recode_strings &&
+ (PyString_Check(arg) || PyBytes_Check(arg))) {
s = arg;
Py_INCREF(s);
- size = PyString_GET_SIZE(s);
- ptr = PyString_AS_STRING(s);
+ if (PyObject_AsCharBuffer(s, &ptr, &size) < 0)
+ return converterr("(AsCharBuffer failed)",
+ arg, msgbuf, bufsize);
}
else {
PyObject *u;
@@ -973,6 +975,8 @@
}
size = PyBytes_GET_SIZE(s);
ptr = PyBytes_AS_STRING(s);
+ if (ptr == NULL)
+ ptr = "";
}
/* Write output; output is guaranteed to be 0-terminated */
More information about the Python-3000-checkins
mailing list