mirror of
https://github.com/python/cpython.git
synced 2025-10-23 01:43:53 +00:00
gh-129813, PEP 782: Use Py_GetConstant(Py_CONSTANT_EMPTY_BYTES) (#138830)
Replace PyBytes_FromStringAndSize(NULL, 0) with Py_GetConstant(Py_CONSTANT_EMPTY_BYTES). Py_GetConstant() cannot fail.
This commit is contained in:
parent
8fc6ae68b0
commit
06b7891f12
6 changed files with 11 additions and 23 deletions
|
@ -4913,7 +4913,7 @@ _PyUnicode_EncodeUTF7(PyObject *str,
|
|||
len = PyUnicode_GET_LENGTH(str);
|
||||
|
||||
if (len == 0)
|
||||
return PyBytes_FromStringAndSize(NULL, 0);
|
||||
return Py_GetConstant(Py_CONSTANT_EMPTY_BYTES);
|
||||
|
||||
/* It might be possible to tighten this worst case */
|
||||
if (len > PY_SSIZE_T_MAX / 8)
|
||||
|
@ -6914,7 +6914,7 @@ PyUnicode_AsUnicodeEscapeString(PyObject *unicode)
|
|||
|
||||
len = PyUnicode_GET_LENGTH(unicode);
|
||||
if (len == 0) {
|
||||
return PyBytes_FromStringAndSize(NULL, 0);
|
||||
return Py_GetConstant(Py_CONSTANT_EMPTY_BYTES);
|
||||
}
|
||||
|
||||
kind = PyUnicode_KIND(unicode);
|
||||
|
@ -7364,7 +7364,7 @@ unicode_encode_ucs1(PyObject *unicode,
|
|||
/* allocate enough for a simple encoding without
|
||||
replacements, if we need more, we'll resize */
|
||||
if (size == 0)
|
||||
return PyBytes_FromStringAndSize(NULL, 0);
|
||||
return Py_GetConstant(Py_CONSTANT_EMPTY_BYTES);
|
||||
|
||||
_PyBytesWriter_Init(&writer);
|
||||
str = _PyBytesWriter_Alloc(&writer, size);
|
||||
|
@ -8305,7 +8305,7 @@ encode_code_page(int code_page,
|
|||
}
|
||||
|
||||
if (len == 0)
|
||||
return PyBytes_FromStringAndSize(NULL, 0);
|
||||
return Py_GetConstant(Py_CONSTANT_EMPTY_BYTES);
|
||||
|
||||
offset = 0;
|
||||
do
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue