summaryrefslogtreecommitdiff
path: root/Objects
diff options
context:
space:
mode:
authorHai Shi <shihai1992@gmail.com>2020-01-30 17:20:25 -0600
committerGitHub <noreply@github.com>2020-01-30 15:20:25 -0800
commit46874c26ee1fc752e2e6930efa1d223b2351edb8 (patch)
treeb4c85470214ac73ec6e4fa9981bb1f0e7b46472e /Objects
parentc232c9110cfefa0935cbf158e35e91746a8a9361 (diff)
downloadcpython-git-46874c26ee1fc752e2e6930efa1d223b2351edb8.tar.gz
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 'Objects')
-rw-r--r--Objects/bytesobject.c4
-rw-r--r--Objects/descrobject.c4
-rw-r--r--Objects/fileobject.c4
-rw-r--r--Objects/iterobject.c4
-rw-r--r--Objects/moduleobject.c11
-rw-r--r--Objects/odictobject.c5
-rw-r--r--Objects/rangeobject.c4
-rw-r--r--Objects/typeobject.c3
8 files changed, 17 insertions, 22 deletions
diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c
index f9823f18e8..5fd92f72a5 100644
--- a/Objects/bytesobject.c
+++ b/Objects/bytesobject.c
@@ -25,6 +25,8 @@ Py_ssize_t _Py_null_strings, _Py_one_strings;
static PyBytesObject *characters[UCHAR_MAX + 1];
static PyBytesObject *nullstring;
+_Py_IDENTIFIER(__bytes__);
+
/* PyBytesObject_SIZE gives the basic size of a string; any memory allocation
for a string of length n should request PyBytesObject_SIZE + n bytes.
@@ -543,7 +545,6 @@ static PyObject *
format_obj(PyObject *v, const char **pbuf, Py_ssize_t *plen)
{
PyObject *func, *result;
- _Py_IDENTIFIER(__bytes__);
/* is it a bytes object? */
if (PyBytes_Check(v)) {
*pbuf = PyBytes_AS_STRING(v);
@@ -2485,7 +2486,6 @@ bytes_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
PyObject *func;
Py_ssize_t size;
static char *kwlist[] = {"source", "encoding", "errors", 0};
- _Py_IDENTIFIER(__bytes__);
if (type != &PyBytes_Type)
return bytes_subtype_new(type, args, kwds);
diff --git a/Objects/descrobject.c b/Objects/descrobject.c
index 342b993e09..b9b16d6d0a 100644
--- a/Objects/descrobject.c
+++ b/Objects/descrobject.c
@@ -6,6 +6,8 @@
#include "pycore_tupleobject.h"
#include "structmember.h" /* Why is this not included in Python.h? */
+_Py_IDENTIFIER(getattr);
+
/*[clinic input]
class mappingproxy "mappingproxyobject *" "&PyDictProxy_Type"
class property "propertyobject *" "&PyProperty_Type"
@@ -571,7 +573,6 @@ descr_get_qualname(PyDescrObject *descr, void *Py_UNUSED(ignored))
static PyObject *
descr_reduce(PyDescrObject *descr, PyObject *Py_UNUSED(ignored))
{
- _Py_IDENTIFIER(getattr);
return Py_BuildValue("N(OO)", _PyEval_GetBuiltinId(&PyId_getattr),
PyDescr_TYPE(descr), PyDescr_NAME(descr));
}
@@ -1240,7 +1241,6 @@ wrapper_repr(wrapperobject *wp)
static PyObject *
wrapper_reduce(wrapperobject *wp, PyObject *Py_UNUSED(ignored))
{
- _Py_IDENTIFIER(getattr);
return Py_BuildValue("N(OO)", _PyEval_GetBuiltinId(&PyId_getattr),
wp->self, PyDescr_NAME(wp->descr));
}
diff --git a/Objects/fileobject.c b/Objects/fileobject.c
index 3ec5a00f30..527693c809 100644
--- a/Objects/fileobject.c
+++ b/Objects/fileobject.c
@@ -25,6 +25,8 @@
extern "C" {
#endif
+_Py_IDENTIFIER(open);
+
/* External C interface */
PyObject *
@@ -32,7 +34,6 @@ PyFile_FromFd(int fd, const char *name, const char *mode, int buffering, const c
const char *errors, const char *newline, int closefd)
{
PyObject *io, *stream;
- _Py_IDENTIFIER(open);
/* import _io in case we are being used to open io.py */
io = PyImport_ImportModule("_io");
@@ -547,7 +548,6 @@ PyObject *
PyFile_OpenCodeObject(PyObject *path)
{
PyObject *iomod, *f = NULL;
- _Py_IDENTIFIER(open);
if (!PyUnicode_Check(path)) {
PyErr_Format(PyExc_TypeError, "'path' must be 'str', not '%.200s'",
diff --git a/Objects/iterobject.c b/Objects/iterobject.c
index da89298edc..fe1de7e211 100644
--- a/Objects/iterobject.c
+++ b/Objects/iterobject.c
@@ -11,6 +11,8 @@ typedef struct {
PyObject *it_seq; /* Set to NULL when iterator is exhausted */
} seqiterobject;
+_Py_IDENTIFIER(iter);
+
PyObject *
PySeqIter_New(PyObject *seq)
{
@@ -104,7 +106,6 @@ PyDoc_STRVAR(length_hint_doc, "Private method returning an estimate of len(list(
static PyObject *
iter_reduce(seqiterobject *it, PyObject *Py_UNUSED(ignored))
{
- _Py_IDENTIFIER(iter);
if (it->it_seq != NULL)
return Py_BuildValue("N(O)n", _PyEval_GetBuiltinId(&PyId_iter),
it->it_seq, it->it_index);
@@ -244,7 +245,6 @@ calliter_iternext(calliterobject *it)
static PyObject *
calliter_reduce(calliterobject *it, PyObject *Py_UNUSED(ignored))
{
- _Py_IDENTIFIER(iter);
if (it->it_callable != NULL && it->it_sentinel != NULL)
return Py_BuildValue("N(OO)", _PyEval_GetBuiltinId(&PyId_iter),
it->it_callable, it->it_sentinel);
diff --git a/Objects/moduleobject.c b/Objects/moduleobject.c
index 912c258401..49cfd574d5 100644
--- a/Objects/moduleobject.c
+++ b/Objects/moduleobject.c
@@ -7,6 +7,10 @@
static Py_ssize_t max_module_number;
+_Py_IDENTIFIER(__doc__);
+_Py_IDENTIFIER(__name__);
+_Py_IDENTIFIER(__spec__);
+
typedef struct {
PyObject_HEAD
PyObject *md_dict;
@@ -58,11 +62,8 @@ static int
module_init_dict(PyModuleObject *mod, PyObject *md_dict,
PyObject *name, PyObject *doc)
{
- _Py_IDENTIFIER(__name__);
- _Py_IDENTIFIER(__doc__);
_Py_IDENTIFIER(__package__);
_Py_IDENTIFIER(__loader__);
- _Py_IDENTIFIER(__spec__);
if (md_dict == NULL)
return -1;
@@ -461,7 +462,6 @@ int
PyModule_SetDocString(PyObject *m, const char *doc)
{
PyObject *v;
- _Py_IDENTIFIER(__doc__);
v = PyUnicode_FromString(doc);
if (v == NULL || _PyObject_SetAttrId(m, &PyId___doc__, v) != 0) {
@@ -488,7 +488,6 @@ PyModule_GetDict(PyObject *m)
PyObject*
PyModule_GetNameObject(PyObject *m)
{
- _Py_IDENTIFIER(__name__);
PyObject *d;
PyObject *name;
if (!PyModule_Check(m)) {
@@ -741,10 +740,8 @@ module_getattro(PyModuleObject *m, PyObject *name)
if (getattr) {
return _PyObject_CallOneArg(getattr, name);
}
- _Py_IDENTIFIER(__name__);
mod_name = _PyDict_GetItemId(m->md_dict, &PyId___name__);
if (mod_name && PyUnicode_Check(mod_name)) {
- _Py_IDENTIFIER(__spec__);
Py_INCREF(mod_name);
PyObject *spec = _PyDict_GetItemId(m->md_dict, &PyId___spec__);
Py_XINCREF(spec);
diff --git a/Objects/odictobject.c b/Objects/odictobject.c
index dfbd30a976..45e089be28 100644
--- a/Objects/odictobject.c
+++ b/Objects/odictobject.c
@@ -526,6 +526,8 @@ struct _odictnode {
#define _odict_FOREACH(od, node) \
for (node = _odict_FIRST(od); node != NULL; node = _odictnode_NEXT(node))
+_Py_IDENTIFIER(items);
+
/* Return the index into the hash table, regardless of a valid node. */
static Py_ssize_t
_odict_get_index_raw(PyODictObject *od, PyObject *key, Py_hash_t hash)
@@ -896,7 +898,6 @@ static PyObject *
odict_reduce(register PyODictObject *od, PyObject *Py_UNUSED(ignored))
{
_Py_IDENTIFIER(__dict__);
- _Py_IDENTIFIER(items);
PyObject *dict = NULL, *result = NULL;
PyObject *items_iter, *items, *args = NULL;
@@ -1375,7 +1376,6 @@ static PyObject *
odict_repr(PyODictObject *self)
{
int i;
- _Py_IDENTIFIER(items);
PyObject *pieces = NULL, *result = NULL;
if (PyODict_SIZE(self) == 0)
@@ -2195,7 +2195,6 @@ mutablemapping_update(PyObject *self, PyObject *args, PyObject *kwargs)
{
int res = 0;
Py_ssize_t len;
- _Py_IDENTIFIER(items);
_Py_IDENTIFIER(keys);
/* first handle args, if any */
diff --git a/Objects/rangeobject.c b/Objects/rangeobject.c
index 9311f8b1f1..e716820932 100644
--- a/Objects/rangeobject.c
+++ b/Objects/rangeobject.c
@@ -18,6 +18,8 @@ typedef struct {
PyObject *length;
} rangeobject;
+_Py_IDENTIFIER(iter);
+
/* Helper function for validating step. Always returns a new reference or
NULL on error.
*/
@@ -757,7 +759,6 @@ PyDoc_STRVAR(length_hint_doc,
static PyObject *
rangeiter_reduce(rangeiterobject *r, PyObject *Py_UNUSED(ignored))
{
- _Py_IDENTIFIER(iter);
PyObject *start=NULL, *stop=NULL, *step=NULL;
PyObject *range;
@@ -915,7 +916,6 @@ longrangeiter_len(longrangeiterobject *r, PyObject *no_args)
static PyObject *
longrangeiter_reduce(longrangeiterobject *r, PyObject *Py_UNUSED(ignored))
{
- _Py_IDENTIFIER(iter);
PyObject *product, *stop=NULL;
PyObject *range;
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index 8422a3c5a3..01def83780 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -74,6 +74,7 @@ _Py_IDENTIFIER(__new__);
_Py_IDENTIFIER(__set_name__);
_Py_IDENTIFIER(__setitem__);
_Py_IDENTIFIER(builtins);
+_Py_IDENTIFIER(mro);
static PyObject *
slot_tp_new(PyTypeObject *type, PyObject *args, PyObject *kwds);
@@ -310,7 +311,6 @@ type_mro_modified(PyTypeObject *type, PyObject *bases) {
return;
if (custom) {
- _Py_IDENTIFIER(mro);
mro_meth = lookup_maybe_method(
(PyObject *)type, &PyId_mro, &unbound);
if (mro_meth == NULL)
@@ -1891,7 +1891,6 @@ mro_invoke(PyTypeObject *type)
int custom = (Py_TYPE(type) != &PyType_Type);
if (custom) {
- _Py_IDENTIFIER(mro);
int unbound;
PyObject *mro_meth = lookup_method((PyObject *)type, &PyId_mro,
&unbound);