On error, PyUnicode_AsUTF8AndSize() now sets the size argument to -1,
to avoid undefined value.
returned buffer always has an extra null byte appended (not included in
*size*), regardless of whether there are any other null code points.
- In the case of an error, ``NULL`` is returned with an exception set and no
- *size* is stored.
+ On error, set an exception, set *size* to ``-1`` (if it's not NULL) and
+ return ``NULL``.
This caches the UTF-8 representation of the string in the Unicode object, and
subsequent calls will return a pointer to the same buffer. The caller is not
NULLABLE(unicode);
s = PyUnicode_AsUTF8AndSize(unicode, &size);
if (s == NULL) {
- assert(size == UNINITIALIZED_SIZE);
+ assert(size == -1);
return NULL;
}
{
if (!PyUnicode_Check(unicode)) {
PyErr_BadArgument();
+ if (psize) {
+ *psize = -1;
+ }
return NULL;
}
if (PyUnicode_UTF8(unicode) == NULL) {
if (unicode_fill_utf8(unicode) == -1) {
+ if (psize) {
+ *psize = -1;
+ }
return NULL;
}
}
- if (psize)
+ if (psize) {
*psize = PyUnicode_UTF8_LENGTH(unicode);
+ }
return PyUnicode_UTF8(unicode);
}