mirror of
https://github.com/python/cpython.git
synced 2025-10-17 20:28:43 +00:00
Use PyUnicode_AsUnicodeAndSize() instead of PyUnicode_GET_SIZE()
This commit is contained in:
parent
e459a0877e
commit
beac78bb24
3 changed files with 15 additions and 9 deletions
|
@ -982,10 +982,11 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
|
|||
STORE_SIZE(0);
|
||||
}
|
||||
else if (PyUnicode_Check(arg)) {
|
||||
*p = PyUnicode_AS_UNICODE(arg);
|
||||
Py_ssize_t len;
|
||||
*p = PyUnicode_AsUnicodeAndSize(arg, &len);
|
||||
if (*p == NULL)
|
||||
RETURN_ERR_OCCURRED;
|
||||
STORE_SIZE(PyUnicode_GET_SIZE(arg));
|
||||
STORE_SIZE(len);
|
||||
}
|
||||
else
|
||||
return converterr("str or None", arg, msgbuf, bufsize);
|
||||
|
@ -995,10 +996,11 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
|
|||
if (c == 'Z' && arg == Py_None)
|
||||
*p = NULL;
|
||||
else if (PyUnicode_Check(arg)) {
|
||||
*p = PyUnicode_AS_UNICODE(arg);
|
||||
Py_ssize_t len;
|
||||
*p = PyUnicode_AsUnicodeAndSize(arg, &len);
|
||||
if (*p == NULL)
|
||||
RETURN_ERR_OCCURRED;
|
||||
if (Py_UNICODE_strlen(*p) != PyUnicode_GET_SIZE(arg))
|
||||
if (Py_UNICODE_strlen(*p) != len)
|
||||
return converterr(
|
||||
"str without null character or None",
|
||||
arg, msgbuf, bufsize);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue