diff options
author | Guido van Rossum <guido@python.org> | 2007-05-10 18:04:33 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2007-05-10 18:04:33 (GMT) |
commit | bce56a6c5ba368c3cb84da315266ce975005f82c (patch) | |
tree | a49e74e73df59770d7822791977331149ea84444 /Modules/_csv.c | |
parent | 3b116a3187705fd04bb16bf5028d21ca14284249 (diff) | |
download | cpython-bce56a6c5ba368c3cb84da315266ce975005f82c.zip cpython-bce56a6c5ba368c3cb84da315266ce975005f82c.tar.gz cpython-bce56a6c5ba368c3cb84da315266ce975005f82c.tar.bz2 |
Fix some miscellaneous places that incorrectly insisted on str8.
Diffstat (limited to 'Modules/_csv.c')
-rw-r--r-- | Modules/_csv.c | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/Modules/_csv.c b/Modules/_csv.c index e99acf9..e3dca2c 100644 --- a/Modules/_csv.c +++ b/Modules/_csv.c @@ -235,19 +235,19 @@ _set_char(const char *name, char *target, PyObject *src, char dflt) if (src == NULL) *target = dflt; else { - if (src == Py_None || PyString_Size(src) == 0) - *target = '\0'; - else if (!PyString_Check(src) || PyString_Size(src) != 1) { - PyErr_Format(PyExc_TypeError, - "\"%s\" must be an 1-character string", - name); - return -1; - } - else { - char *s = PyString_AsString(src); - if (s == NULL) + *target = '\0'; + if (src != Py_None) { + const char *buf; + Py_ssize_t len; + if (PyObject_AsCharBuffer(src, &buf, &len) < 0 || + len > 1) { + PyErr_Format(PyExc_TypeError, + "\"%s\" must be an 1-character string", + name); return -1; - *target = s[0]; + } + if (len > 0) + *target = buf[0]; } } return 0; |