bpo-46765: Replace Locally Cached Strings with Statically Initialized Objects (gh-31366)

https://bugs.python.org/issue46765
This commit is contained in:
Eric Snow 2022-02-22 17:23:51 -07:00 committed by GitHub
parent cff4d5c5d2
commit 1f455361ec
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
22 changed files with 192 additions and 526 deletions

View file

@ -553,16 +553,11 @@ PyCode_New(int argcount, int kwonlyargcount,
PyCodeObject *
PyCode_NewEmpty(const char *filename, const char *funcname, int firstlineno)
{
PyObject *emptystring = NULL;
PyObject *nulltuple = NULL;
PyObject *filename_ob = NULL;
PyObject *funcname_ob = NULL;
PyCodeObject *result = NULL;
emptystring = PyBytes_FromString("");
if (emptystring == NULL) {
goto failed;
}
nulltuple = PyTuple_New(0);
if (nulltuple == NULL) {
goto failed;
@ -576,6 +571,7 @@ PyCode_NewEmpty(const char *filename, const char *funcname, int firstlineno)
goto failed;
}
#define emptystring (PyObject *)&_Py_SINGLETON(bytes_empty)
struct _PyCodeConstructor con = {
.filename = filename_ob,
.name = funcname_ob,
@ -594,7 +590,6 @@ PyCode_NewEmpty(const char *filename, const char *funcname, int firstlineno)
result = _PyCode_New(&con);
failed:
Py_XDECREF(emptystring);
Py_XDECREF(nulltuple);
Py_XDECREF(funcname_ob);
Py_XDECREF(filename_ob);