Mercurial > cpython-lru_cache-weakref
diff Modules/_csv.c @ 41684:fb705f18bf3d
Fix some miscellaneous places that incorrectly insisted on str8.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Thu, 10 May 2007 18:04:33 +0000 |
| parents | 4aee3f672f77 |
| children | e70cdce0e8b2 |
line wrap: on
line diff
--- a/Modules/_csv.c Thu May 10 17:35:11 2007 +0000 +++ b/Modules/_csv.c Thu May 10 18:04:33 2007 +0000 @@ -235,19 +235,19 @@ 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;
