mirror of
https://github.com/python/cpython.git
synced 2025-07-23 03:05:38 +00:00
gh-115754: Use Py_GetConstant(Py_CONSTANT_EMPTY_STR) (#125194)
Replace PyUnicode_New(0, 0), PyUnicode_FromString("") and PyUnicode_FromStringAndSize("", 0) with Py_GetConstant(Py_CONSTANT_EMPTY_STR).
This commit is contained in:
parent
6a39e96ab8
commit
b9a8ca0a6a
22 changed files with 35 additions and 35 deletions
|
@ -263,7 +263,7 @@ tokenizeriter_next(tokenizeriterobject *it)
|
|||
}
|
||||
PyObject *str = NULL;
|
||||
if (token.start == NULL || token.end == NULL) {
|
||||
str = PyUnicode_FromString("");
|
||||
str = Py_GetConstant(Py_CONSTANT_EMPTY_STR);
|
||||
}
|
||||
else {
|
||||
str = PyUnicode_FromStringAndSize(token.start, token.end - token.start);
|
||||
|
@ -281,7 +281,7 @@ tokenizeriter_next(tokenizeriterobject *it)
|
|||
PyObject* line = NULL;
|
||||
int line_changed = 1;
|
||||
if (it->tok->tok_extra_tokens && is_trailing_token) {
|
||||
line = PyUnicode_FromString("");
|
||||
line = Py_GetConstant(Py_CONSTANT_EMPTY_STR);
|
||||
} else {
|
||||
Py_ssize_t size = it->tok->inp - line_start;
|
||||
if (size >= 1 && it->tok->implicit_newline) {
|
||||
|
@ -326,7 +326,7 @@ tokenizeriter_next(tokenizeriterobject *it)
|
|||
else if (type == NL) {
|
||||
if (it->tok->implicit_newline) {
|
||||
Py_DECREF(str);
|
||||
str = PyUnicode_FromString("");
|
||||
str = Py_GetConstant(Py_CONSTANT_EMPTY_STR);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1287,7 +1287,7 @@ too_many_positional(PyThreadState *tstate, PyCodeObject *co,
|
|||
}
|
||||
else {
|
||||
/* This will not fail. */
|
||||
kwonly_sig = PyUnicode_FromString("");
|
||||
kwonly_sig = Py_GetConstant(Py_CONSTANT_EMPTY_STR);
|
||||
assert(kwonly_sig != NULL);
|
||||
}
|
||||
_PyErr_Format(tstate, PyExc_TypeError,
|
||||
|
|
|
@ -696,7 +696,7 @@ PyObject *PyCodec_IgnoreErrors(PyObject *exc)
|
|||
wrong_exception_type(exc);
|
||||
return NULL;
|
||||
}
|
||||
return Py_BuildValue("(Nn)", PyUnicode_New(0, 0), end);
|
||||
return Py_BuildValue("(Nn)", Py_GetConstant(Py_CONSTANT_EMPTY_STR), end);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -740,7 +740,7 @@ get_locale_info(enum LocaleType type, LocaleInfo *locale_info)
|
|||
break;
|
||||
case LT_NO_LOCALE:
|
||||
locale_info->decimal_point = PyUnicode_FromOrdinal('.');
|
||||
locale_info->thousands_sep = PyUnicode_New(0, 0);
|
||||
locale_info->thousands_sep = Py_GetConstant(Py_CONSTANT_EMPTY_STR);
|
||||
if (!locale_info->decimal_point || !locale_info->thousands_sep)
|
||||
return -1;
|
||||
locale_info->grouping = no_grouping;
|
||||
|
|
|
@ -1226,7 +1226,7 @@ r_object(RFILE *p)
|
|||
v = PyUnicode_DecodeUTF8(buffer, n, "surrogatepass");
|
||||
}
|
||||
else {
|
||||
v = PyUnicode_New(0, 0);
|
||||
v = Py_GetConstant(Py_CONSTANT_EMPTY_STR);
|
||||
}
|
||||
if (v == NULL)
|
||||
break;
|
||||
|
|
|
@ -354,7 +354,7 @@ static void _dump_symtable(PySTEntryObject* ste, PyObject* prefix)
|
|||
|
||||
static void dump_symtable(PySTEntryObject* ste)
|
||||
{
|
||||
PyObject *empty = PyUnicode_FromString("");
|
||||
PyObject *empty = Py_GetConstant(Py_CONSTANT_EMPTY_STR);
|
||||
assert(empty != NULL);
|
||||
_dump_symtable(ste, empty);
|
||||
Py_DECREF(empty);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue