mirror of
https://github.com/python/cpython.git
synced 2025-08-24 10:45:53 +00:00
bpo-41123: Remove PyUnicode_AsUnicodeCopy (GH-21209)
This commit is contained in:
parent
2515a28230
commit
b3332660ad
6 changed files with 5 additions and 58 deletions
|
@ -15862,39 +15862,6 @@ unicode_iter(PyObject *seq)
|
|||
return (PyObject *)it;
|
||||
}
|
||||
|
||||
Py_UNICODE*
|
||||
PyUnicode_AsUnicodeCopy(PyObject *unicode)
|
||||
{
|
||||
Py_UNICODE *u, *copy;
|
||||
Py_ssize_t len, size;
|
||||
|
||||
if (!PyUnicode_Check(unicode)) {
|
||||
PyErr_BadArgument();
|
||||
return NULL;
|
||||
}
|
||||
_Py_COMP_DIAG_PUSH
|
||||
_Py_COMP_DIAG_IGNORE_DEPR_DECLS
|
||||
u = PyUnicode_AsUnicodeAndSize(unicode, &len);
|
||||
_Py_COMP_DIAG_POP
|
||||
if (u == NULL)
|
||||
return NULL;
|
||||
/* Ensure we won't overflow the size. */
|
||||
if (len > ((PY_SSIZE_T_MAX / (Py_ssize_t)sizeof(Py_UNICODE)) - 1)) {
|
||||
PyErr_NoMemory();
|
||||
return NULL;
|
||||
}
|
||||
size = len + 1; /* copy the null character */
|
||||
size *= sizeof(Py_UNICODE);
|
||||
copy = PyMem_Malloc(size);
|
||||
if (copy == NULL) {
|
||||
PyErr_NoMemory();
|
||||
return NULL;
|
||||
}
|
||||
memcpy(copy, u, size);
|
||||
return copy;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
encode_wstr_utf8(wchar_t *wstr, char **str, const char *name)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue