summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorHai Shi <shihai1992@gmail.com>2020-01-30 23:20:25 (GMT)
committerGitHub <noreply@github.com>2020-01-30 23:20:25 (GMT)
commit46874c26ee1fc752e2e6930efa1d223b2351edb8 (patch)
treeb4c85470214ac73ec6e4fa9981bb1f0e7b46472e /Python
parentc232c9110cfefa0935cbf158e35e91746a8a9361 (diff)
downloadcpython-46874c26ee1fc752e2e6930efa1d223b2351edb8.zip
cpython-46874c26ee1fc752e2e6930efa1d223b2351edb8.tar.gz
cpython-46874c26ee1fc752e2e6930efa1d223b2351edb8.tar.bz2
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.
Diffstat (limited to 'Python')
-rw-r--r--Python/_warnings.c5
-rw-r--r--Python/ceval.c3
-rw-r--r--Python/errors.c4
-rw-r--r--Python/import.c7
4 files changed, 7 insertions, 12 deletions
diff --git a/Python/_warnings.c b/Python/_warnings.c
index b8585d2..602211c 100644
--- a/Python/_warnings.c
+++ b/Python/_warnings.c
@@ -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;
diff --git a/Python/ceval.c b/Python/ceval.c
index 2bf64ed..892d668 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -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;
diff --git a/Python/errors.c b/Python/errors.c
index 18ea9c5..652f4c9 100644
--- a/Python/errors.c
+++ b/Python/errors.c
@@ -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);
diff --git a/Python/import.c b/Python/import.c
index 2e5f783..9838c3f 100644
--- a/Python/import.c
+++ b/Python/import.c
@@ -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;