Add PyUnicode_AsStringAndSize(), which is like PyUnicode_AsString() but

has an extra (optional) output parameter through which it returns the size.
Use this in a few places where I used PyUnicode_AsString() + strlen(),
and in one new place (which fixes test_pep263).
This commit is contained in:
Guido van Rossum 2007-08-29 13:53:23 +00:00
parent 9befa93b04
commit 7d1df6c9b1
4 changed files with 31 additions and 17 deletions

View file

@ -383,7 +383,8 @@ fp_readl(char *s, int size, struct tok_state *tok)
goto error;
allocated = 1;
}
if (PyObject_AsCharBuffer(bufobj, &buf, &buflen) < 0) {
buf = PyUnicode_AsStringAndSize(bufobj, &buflen);
if (buf == NULL) {
goto error;
}
if (buflen > size) {