diff options
author | Guido van Rossum <guido@python.org> | 2007-08-29 13:53:23 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2007-08-29 13:53:23 (GMT) |
commit | 7d1df6c9b1a7e075c03c4790f47bc83e0104579f (patch) | |
tree | 6dceba59593ca682c88dd1a699fec2fc51f78129 /Objects | |
parent | 9befa93b04ee0c485615d87e4b34dcfe5e811194 (diff) | |
download | cpython-7d1df6c9b1a7e075c03c4790f47bc83e0104579f.zip cpython-7d1df6c9b1a7e075c03c4790f47bc83e0104579f.tar.gz cpython-7d1df6c9b1a7e075c03c4790f47bc83e0104579f.tar.bz2 |
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).
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/unicodeobject.c | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 4e8b2ed..9de1e53 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -1184,16 +1184,25 @@ PyObject *_PyUnicode_AsDefaultEncodedString(PyObject *unicode, } char* -PyUnicode_AsString(PyObject *unicode) +PyUnicode_AsStringAndSize(PyObject *unicode, Py_ssize_t *psize) { + PyObject *str8; if (!PyUnicode_Check(unicode)) { PyErr_BadArgument(); return NULL; } - unicode = _PyUnicode_AsDefaultEncodedString(unicode, NULL); - if (!unicode) + str8 = _PyUnicode_AsDefaultEncodedString(unicode, NULL); + if (str8 == NULL) return NULL; - return PyString_AsString(unicode); + if (psize != NULL) + *psize = PyString_GET_SIZE(str8); + return PyString_AS_STRING(str8); +} + +char* +PyUnicode_AsString(PyObject *unicode) +{ + return PyUnicode_AsStringAndSize(unicode, NULL); } Py_UNICODE *PyUnicode_AsUnicode(PyObject *unicode) @@ -8098,6 +8107,7 @@ unicode_buffer_getbuffer(PyUnicodeObject *self, PyBuffer *view, int flags) if (flags & PyBUF_CHARACTER) { PyErr_SetString(PyExc_SystemError, "can't use str as char buffer"); + abort(); return -1; } return PyBuffer_FillInfo(view, (void *)self->str, |