bpo-39487: Merge duplicated _Py_IDENTIFIER identifiers in C code (GH-18254)

Moving repetitive `_Py_IDENTIFIER` instances to a global location helps identify them more easily in regards to sub-interpreter support.
This commit is contained in:
Hai Shi 2020-01-30 17:20:25 -06:00 committed by GitHub
parent c232c9110c
commit 46874c26ee
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 24 additions and 34 deletions

View file

@ -24,6 +24,8 @@ typedef struct _warnings_runtime_state WarningsState;
/* Forward declaration of the _warnings module definition. */
static struct PyModuleDef warningsmodule;
_Py_IDENTIFIER(__name__);
/* Given a module object, get its per-module state. */
static WarningsState *
_Warnings_GetState()
@ -484,7 +486,6 @@ show_warning(PyObject *filename, int lineno, PyObject *text,
PyObject *f_stderr;
PyObject *name;
char lineno_str[128];
_Py_IDENTIFIER(__name__);
PyOS_snprintf(lineno_str, sizeof(lineno_str), ":%d: ", lineno);
@ -818,7 +819,6 @@ setup_context(Py_ssize_t stack_level, PyObject **filename, int *lineno,
PyObject **module, PyObject **registry)
{
_Py_IDENTIFIER(__warningregistry__);
_Py_IDENTIFIER(__name__);
PyObject *globals;
/* Setup globals, filename and lineno. */
@ -969,7 +969,6 @@ get_source_line(PyObject *module_globals, int lineno)
{
_Py_IDENTIFIER(get_source);
_Py_IDENTIFIER(__loader__);
_Py_IDENTIFIER(__name__);
PyObject *loader;
PyObject *module_name;
PyObject *get_source;

View file

@ -39,6 +39,7 @@
# error "ceval.c must be build with Py_BUILD_CORE define for best performance"
#endif
_Py_IDENTIFIER(__name__);
/* Forward declarations */
Py_LOCAL_INLINE(PyObject *) call_function(
@ -5032,7 +5033,6 @@ static PyObject *
import_from(PyThreadState *tstate, PyObject *v, PyObject *name)
{
PyObject *x;
_Py_IDENTIFIER(__name__);
PyObject *fullmodname, *pkgname, *pkgpath, *pkgname_or_unknown, *errmsg;
if (_PyObject_LookupAttr(v, name, &x) != 0) {
@ -5108,7 +5108,6 @@ import_all_from(PyThreadState *tstate, PyObject *locals, PyObject *v)
{
_Py_IDENTIFIER(__all__);
_Py_IDENTIFIER(__dict__);
_Py_IDENTIFIER(__name__);
PyObject *all, *dict, *name, *value;
int skip_leading_underscores = 0;
int pos, err;

View file

@ -24,11 +24,11 @@ extern char *strerror(int);
extern "C" {
#endif
_Py_IDENTIFIER(__module__);
_Py_IDENTIFIER(builtins);
_Py_IDENTIFIER(stderr);
_Py_IDENTIFIER(flush);
/* Forward declarations */
static PyObject *
_PyErr_FormatV(PyThreadState *tstate, PyObject *exception,
@ -1009,7 +1009,6 @@ PyObject *
PyErr_NewException(const char *name, PyObject *base, PyObject *dict)
{
PyThreadState *tstate = _PyThreadState_GET();
_Py_IDENTIFIER(__module__);
PyObject *modulename = NULL;
PyObject *classname = NULL;
PyObject *mydict = NULL;
@ -1235,7 +1234,6 @@ write_unraisable_exc_file(PyThreadState *tstate, PyObject *exc_type,
}
}
_Py_IDENTIFIER(__module__);
PyObject *moduleName = _PyObject_GetAttrId(exc_type, &PyId___module__);
if (moduleName == NULL || !PyUnicode_Check(moduleName)) {
Py_XDECREF(moduleName);

View file

@ -39,6 +39,9 @@ extern struct _inittab _PyImport_Inittab[];
struct _inittab *PyImport_Inittab = _PyImport_Inittab;
static struct _inittab *inittab_copy = NULL;
_Py_IDENTIFIER(__path__);
_Py_IDENTIFIER(__spec__);
/*[clinic input]
module _imp
[clinic start generated code]*/
@ -383,7 +386,6 @@ import_ensure_initialized(PyThreadState *tstate, PyObject *mod, PyObject *name)
PyInterpreterState *interp = tstate->interp;
PyObject *spec;
_Py_IDENTIFIER(__spec__);
_Py_IDENTIFIER(_lock_unlock_module);
/* Optimization: only call _bootstrap._lock_unlock_module() if
@ -1566,9 +1568,7 @@ done:
static PyObject *
resolve_name(PyThreadState *tstate, PyObject *name, PyObject *globals, int level)
{
_Py_IDENTIFIER(__spec__);
_Py_IDENTIFIER(__package__);
_Py_IDENTIFIER(__path__);
_Py_IDENTIFIER(__name__);
_Py_IDENTIFIER(parent);
PyObject *abs_name;
@ -1930,7 +1930,6 @@ PyImport_ImportModuleLevelObject(PyObject *name, PyObject *globals,
}
}
else {
_Py_IDENTIFIER(__path__);
PyObject *path;
if (_PyObject_LookupAttrId(mod, &PyId___path__, &path) < 0) {
goto error;