mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
bpo-36346: Raise DeprecationWarning when creating legacy Unicode (GH-20933)
This commit is contained in:
parent
349f76c6aa
commit
038dd0f79d
4 changed files with 30 additions and 4 deletions
|
@ -2179,8 +2179,16 @@ unicode_char(Py_UCS4 ch)
|
|||
PyObject *
|
||||
PyUnicode_FromUnicode(const Py_UNICODE *u, Py_ssize_t size)
|
||||
{
|
||||
if (u == NULL)
|
||||
if (u == NULL) {
|
||||
if (size > 0) {
|
||||
if (PyErr_WarnEx(PyExc_DeprecationWarning,
|
||||
"PyUnicode_FromUnicode(NULL, size) is deprecated; "
|
||||
"use PyUnicode_New() instead", 1) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
return (PyObject*)_PyUnicode_New(size);
|
||||
}
|
||||
|
||||
if (size < 0) {
|
||||
PyErr_BadInternalCall();
|
||||
|
@ -2266,10 +2274,19 @@ PyUnicode_FromStringAndSize(const char *u, Py_ssize_t size)
|
|||
"Negative size passed to PyUnicode_FromStringAndSize");
|
||||
return NULL;
|
||||
}
|
||||
if (u != NULL)
|
||||
if (u != NULL) {
|
||||
return PyUnicode_DecodeUTF8Stateful(u, size, NULL, NULL);
|
||||
else
|
||||
}
|
||||
else {
|
||||
if (size > 0) {
|
||||
if (PyErr_WarnEx(PyExc_DeprecationWarning,
|
||||
"PyUnicode_FromStringAndSize(NULL, size) is deprecated; "
|
||||
"use PyUnicode_New() instead", 1) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
return (PyObject *)_PyUnicode_New(size);
|
||||
}
|
||||
}
|
||||
|
||||
PyObject *
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue