diff options
author | Inada Naoki <songofacandy@gmail.com> | 2020-06-30 06:26:56 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-30 06:26:56 (GMT) |
commit | 038dd0f79dc89566b01ba66a5a018266b2917a19 (patch) | |
tree | 786a85a4a6b9eafa2b768d386077a381dc6a7df1 /Objects | |
parent | 349f76c6aace5a4a2b57f6b442a532faf0027d6b (diff) | |
download | cpython-038dd0f79dc89566b01ba66a5a018266b2917a19.zip cpython-038dd0f79dc89566b01ba66a5a018266b2917a19.tar.gz cpython-038dd0f79dc89566b01ba66a5a018266b2917a19.tar.bz2 |
bpo-36346: Raise DeprecationWarning when creating legacy Unicode (GH-20933)
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/unicodeobject.c | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index db3f55e..fe46de2 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -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 * |