Skip to content

Commit 6902106

Browse files
Move local _Py_IDENTIFER to global for objects.
1 parent b1afab1 commit 6902106

22 files changed

+142
-116
lines changed

Objects/abstract.c

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,18 @@
77
#include "longintrepr.h"
88

99

10+
_Py_IDENTIFIER(__bases__);
11+
_Py_IDENTIFIER(__class__);
12+
_Py_IDENTIFIER(__class_getitem__);
13+
_Py_IDENTIFIER(__format__);
14+
_Py_IDENTIFIER(__instancecheck__);
15+
_Py_IDENTIFIER(__length_hint__);
16+
_Py_IDENTIFIER(__subclasscheck__);
17+
_Py_IDENTIFIER(__trunc__);
18+
_Py_IDENTIFIER(items);
19+
_Py_IDENTIFIER(keys);
20+
_Py_IDENTIFIER(values);
21+
1022

1123
/* Shorthands to return certain errors */
1224

@@ -87,7 +99,6 @@ PyObject_LengthHint(PyObject *o, Py_ssize_t defaultvalue)
8799
{
88100
PyObject *hint, *result;
89101
Py_ssize_t res;
90-
_Py_IDENTIFIER(__length_hint__);
91102
if (_PyObject_HasLen(o)) {
92103
res = PyObject_Length(o);
93104
if (res < 0) {
@@ -173,7 +184,6 @@ PyObject_GetItem(PyObject *o, PyObject *key)
173184

174185
if (PyType_Check(o)) {
175186
PyObject *meth, *result, *stack[1] = {key};
176-
_Py_IDENTIFIER(__class_getitem__);
177187
if (_PyObject_LookupAttrId(o, &PyId___class_getitem__, &meth) < 0) {
178188
return NULL;
179189
}
@@ -700,7 +710,6 @@ PyObject_Format(PyObject *obj, PyObject *format_spec)
700710
PyObject *meth;
701711
PyObject *empty = NULL;
702712
PyObject *result = NULL;
703-
_Py_IDENTIFIER(__format__);
704713

705714
if (format_spec != NULL && !PyUnicode_Check(format_spec)) {
706715
PyErr_Format(PyExc_SystemError,
@@ -1355,7 +1364,6 @@ PyNumber_Long(PyObject *o)
13551364
PyNumberMethods *m;
13561365
PyObject *trunc_func;
13571366
Py_buffer view;
1358-
_Py_IDENTIFIER(__trunc__);
13591367

13601368
if (o == NULL) {
13611369
return null_error();
@@ -2227,7 +2235,6 @@ method_output_as_list(PyObject *o, _Py_Identifier *meth_id)
22272235
PyObject *
22282236
PyMapping_Keys(PyObject *o)
22292237
{
2230-
_Py_IDENTIFIER(keys);
22312238

22322239
if (o == NULL) {
22332240
return null_error();
@@ -2241,7 +2248,6 @@ PyMapping_Keys(PyObject *o)
22412248
PyObject *
22422249
PyMapping_Items(PyObject *o)
22432250
{
2244-
_Py_IDENTIFIER(items);
22452251

22462252
if (o == NULL) {
22472253
return null_error();
@@ -2255,7 +2261,6 @@ PyMapping_Items(PyObject *o)
22552261
PyObject *
22562262
PyMapping_Values(PyObject *o)
22572263
{
2258-
_Py_IDENTIFIER(values);
22592264

22602265
if (o == NULL) {
22612266
return null_error();
@@ -2295,7 +2300,6 @@ PyMapping_Values(PyObject *o)
22952300
static PyObject *
22962301
abstract_get_bases(PyObject *cls)
22972302
{
2298-
_Py_IDENTIFIER(__bases__);
22992303
PyObject *bases;
23002304

23012305
Py_ALLOW_RECURSION
@@ -2365,7 +2369,6 @@ recursive_isinstance(PyObject *inst, PyObject *cls)
23652369
{
23662370
PyObject *icls;
23672371
int retval;
2368-
_Py_IDENTIFIER(__class__);
23692372

23702373
if (PyType_Check(cls)) {
23712374
retval = PyObject_TypeCheck(inst, (PyTypeObject *)cls);
@@ -2401,7 +2404,6 @@ recursive_isinstance(PyObject *inst, PyObject *cls)
24012404
int
24022405
PyObject_IsInstance(PyObject *inst, PyObject *cls)
24032406
{
2404-
_Py_IDENTIFIER(__instancecheck__);
24052407
PyObject *checker;
24062408

24072409
/* Quick test for an exact match */
@@ -2476,7 +2478,6 @@ recursive_issubclass(PyObject *derived, PyObject *cls)
24762478
int
24772479
PyObject_IsSubclass(PyObject *derived, PyObject *cls)
24782480
{
2479-
_Py_IDENTIFIER(__subclasscheck__);
24802481
PyObject *checker;
24812482

24822483
/* We know what type's __subclasscheck__ does. */

Objects/bytearrayobject.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
#include "bytesobject.h"
1111
#include "pystrhex.h"
1212

13+
14+
_Py_IDENTIFIER(__dict__);
15+
_Py_IDENTIFIER(iter);
16+
1317
/*[clinic input]
1418
class bytearray "PyByteArrayObject *" "&PyByteArray_Type"
1519
[clinic start generated code]*/
@@ -2037,7 +2041,6 @@ static PyObject *
20372041
_common_reduce(PyByteArrayObject *self, int proto)
20382042
{
20392043
PyObject *dict;
2040-
_Py_IDENTIFIER(__dict__);
20412044
char *buf;
20422045

20432046
dict = _PyObject_GetAttrId((PyObject *)self, &PyId___dict__);
@@ -2349,7 +2352,6 @@ PyDoc_STRVAR(length_hint_doc,
23492352
static PyObject *
23502353
bytearrayiter_reduce(bytesiterobject *it, PyObject *Py_UNUSED(ignored))
23512354
{
2352-
_Py_IDENTIFIER(iter);
23532355
if (it->it_seq != NULL) {
23542356
return Py_BuildValue("N(O)n", _PyEval_GetBuiltinId(&PyId_iter),
23552357
it->it_seq, it->it_index);

Objects/bytesobject.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
#include "pystrhex.h"
1212
#include <stddef.h>
1313

14+
15+
_Py_IDENTIFIER(__bytes__);
16+
_Py_IDENTIFIER(iter);
17+
1418
/*[clinic input]
1519
class bytes "PyBytesObject *" "&PyBytes_Type"
1620
[clinic start generated code]*/
@@ -543,7 +547,6 @@ static PyObject *
543547
format_obj(PyObject *v, const char **pbuf, Py_ssize_t *plen)
544548
{
545549
PyObject *func, *result;
546-
_Py_IDENTIFIER(__bytes__);
547550
/* is it a bytes object? */
548551
if (PyBytes_Check(v)) {
549552
*pbuf = PyBytes_AS_STRING(v);
@@ -2536,7 +2539,6 @@ bytes_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
25362539
PyObject *func;
25372540
Py_ssize_t size;
25382541
static char *kwlist[] = {"source", "encoding", "errors", 0};
2539-
_Py_IDENTIFIER(__bytes__);
25402542

25412543
if (type != &PyBytes_Type)
25422544
return bytes_subtype_new(type, args, kwds);
@@ -3110,7 +3112,6 @@ PyDoc_STRVAR(length_hint_doc,
31103112
static PyObject *
31113113
striter_reduce(striterobject *it, PyObject *Py_UNUSED(ignored))
31123114
{
3113-
_Py_IDENTIFIER(iter);
31143115
if (it->it_seq != NULL) {
31153116
return Py_BuildValue("N(O)n", _PyEval_GetBuiltinId(&PyId_iter),
31163117
it->it_seq, it->it_index);

Objects/classobject.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
#include "pycore_pystate.h"
77
#include "structmember.h"
88

9+
10+
_Py_IDENTIFIER(getattr);
11+
912
#define TP_DESCR_GET(t) ((t)->tp_descr_get)
1013

1114
/* Free list for method objects to safe malloc/free overhead
@@ -80,7 +83,6 @@ method_reduce(PyMethodObject *im, PyObject *Py_UNUSED(ignored))
8083
PyObject *self = PyMethod_GET_SELF(im);
8184
PyObject *func = PyMethod_GET_FUNCTION(im);
8285
PyObject *funcname;
83-
_Py_IDENTIFIER(getattr);
8486

8587
funcname = _PyObject_GetAttrId(func, &PyId___name__);
8688
if (funcname == NULL) {

Objects/complexobject.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
#include "Python.h"
99
#include "structmember.h"
1010

11+
12+
_Py_IDENTIFIER(__complex__);
13+
1114
/*[clinic input]
1215
class complex "PyComplexObject *" "&PyComplex_Type"
1316
[clinic start generated code]*/
@@ -277,7 +280,6 @@ static PyObject *
277280
try_complex_special_method(PyObject *op)
278281
{
279282
PyObject *f;
280-
_Py_IDENTIFIER(__complex__);
281283

282284
f = _PyObject_LookupSpecial(op, &PyId___complex__);
283285
if (f) {

Objects/descrobject.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@
66
#include "pycore_tupleobject.h"
77
#include "structmember.h" /* Why is this not included in Python.h? */
88

9+
10+
_Py_IDENTIFIER(__doc__);
11+
_Py_IDENTIFIER(__qualname__);
12+
_Py_IDENTIFIER(copy);
13+
_Py_IDENTIFIER(get);
14+
_Py_IDENTIFIER(getattr);
15+
_Py_IDENTIFIER(items);
16+
_Py_IDENTIFIER(keys);
17+
_Py_IDENTIFIER(values);
18+
919
/*[clinic input]
1020
class mappingproxy "mappingproxyobject *" "&PyDictProxy_Type"
1121
class property "propertyobject *" "&PyProperty_Type"
@@ -411,7 +421,6 @@ static PyObject *
411421
calculate_qualname(PyDescrObject *descr)
412422
{
413423
PyObject *type_qualname, *res;
414-
_Py_IDENTIFIER(__qualname__);
415424

416425
if (descr->d_name == NULL || !PyUnicode_Check(descr->d_name)) {
417426
PyErr_SetString(PyExc_TypeError,
@@ -448,7 +457,6 @@ descr_get_qualname(PyDescrObject *descr, void *Py_UNUSED(ignored))
448457
static PyObject *
449458
descr_reduce(PyDescrObject *descr, PyObject *Py_UNUSED(ignored))
450459
{
451-
_Py_IDENTIFIER(getattr);
452460
return Py_BuildValue("N(OO)", _PyEval_GetBuiltinId(&PyId_getattr),
453461
PyDescr_TYPE(descr), PyDescr_NAME(descr));
454462
}
@@ -852,7 +860,6 @@ static PyObject *
852860
mappingproxy_get(mappingproxyobject *pp, PyObject *args)
853861
{
854862
PyObject *key, *def = Py_None;
855-
_Py_IDENTIFIER(get);
856863

857864
if (!PyArg_UnpackTuple(args, "get", 1, 2, &key, &def))
858865
return NULL;
@@ -863,28 +870,24 @@ mappingproxy_get(mappingproxyobject *pp, PyObject *args)
863870
static PyObject *
864871
mappingproxy_keys(mappingproxyobject *pp, PyObject *Py_UNUSED(ignored))
865872
{
866-
_Py_IDENTIFIER(keys);
867873
return _PyObject_CallMethodId(pp->mapping, &PyId_keys, NULL);
868874
}
869875

870876
static PyObject *
871877
mappingproxy_values(mappingproxyobject *pp, PyObject *Py_UNUSED(ignored))
872878
{
873-
_Py_IDENTIFIER(values);
874879
return _PyObject_CallMethodId(pp->mapping, &PyId_values, NULL);
875880
}
876881

877882
static PyObject *
878883
mappingproxy_items(mappingproxyobject *pp, PyObject *Py_UNUSED(ignored))
879884
{
880-
_Py_IDENTIFIER(items);
881885
return _PyObject_CallMethodId(pp->mapping, &PyId_items, NULL);
882886
}
883887

884888
static PyObject *
885889
mappingproxy_copy(mappingproxyobject *pp, PyObject *Py_UNUSED(ignored))
886890
{
887-
_Py_IDENTIFIER(copy);
888891
return _PyObject_CallMethodId(pp->mapping, &PyId_copy, NULL);
889892
}
890893

@@ -1078,7 +1081,6 @@ wrapper_repr(wrapperobject *wp)
10781081
static PyObject *
10791082
wrapper_reduce(wrapperobject *wp, PyObject *Py_UNUSED(ignored))
10801083
{
1081-
_Py_IDENTIFIER(getattr);
10821084
return Py_BuildValue("N(OO)", _PyEval_GetBuiltinId(&PyId_getattr),
10831085
wp->self, PyDescr_NAME(wp->descr));
10841086
}
@@ -1461,7 +1463,6 @@ property_init_impl(propertyobject *self, PyObject *fget, PyObject *fset,
14611463

14621464
/* if no docstring given and the getter has one, use that one */
14631465
if ((doc == NULL || doc == Py_None) && fget != NULL) {
1464-
_Py_IDENTIFIER(__doc__);
14651466
PyObject *get_doc = _PyObject_GetAttrId(fget, &PyId___doc__);
14661467
if (get_doc) {
14671468
if (Py_TYPE(self) == &PyProperty_Type) {

Objects/dictobject.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,15 @@ converting the dict to the combined table.
116116
#include "dict-common.h"
117117
#include "stringlib/eq.h" /* to get unicode_eq() */
118118

119+
120+
_Py_IDENTIFIER(__missing__);
121+
_Py_IDENTIFIER(difference_update);
122+
_Py_IDENTIFIER(intersection_update);
123+
_Py_IDENTIFIER(iter);
124+
_Py_IDENTIFIER(keys);
125+
_Py_IDENTIFIER(symmetric_difference_update);
126+
_Py_IDENTIFIER(update);
127+
119128
/*[clinic input]
120129
class dict "PyDictObject *" "&PyDict_Type"
121130
[clinic start generated code]*/
@@ -2109,7 +2118,6 @@ dict_subscript(PyDictObject *mp, PyObject *key)
21092118
if (!PyDict_CheckExact(mp)) {
21102119
/* Look up __missing__ method if we're a subclass. */
21112120
PyObject *missing, *res;
2112-
_Py_IDENTIFIER(__missing__);
21132121
missing = _PyObject_LookupSpecial((PyObject *)mp, &PyId___missing__);
21142122
if (missing != NULL) {
21152123
res = PyObject_CallFunctionObjArgs(missing,
@@ -2317,7 +2325,6 @@ dict_update_common(PyObject *self, PyObject *args, PyObject *kwds,
23172325
result = -1;
23182326
}
23192327
else if (arg != NULL) {
2320-
_Py_IDENTIFIER(keys);
23212328
PyObject *func;
23222329
if (_PyObject_LookupAttrId(arg, &PyId_keys, &func) < 0) {
23232330
result = -1;
@@ -3910,7 +3917,6 @@ dict___reversed___impl(PyDictObject *self)
39103917
static PyObject *
39113918
dictiter_reduce(dictiterobject *di, PyObject *Py_UNUSED(ignored))
39123919
{
3913-
_Py_IDENTIFIER(iter);
39143920
/* copy the iterator state */
39153921
dictiterobject tmp = *di;
39163922
Py_XINCREF(tmp.di_dict);
@@ -4154,7 +4160,6 @@ dictviews_sub(PyObject* self, PyObject *other)
41544160
{
41554161
PyObject *result = PySet_New(self);
41564162
PyObject *tmp;
4157-
_Py_IDENTIFIER(difference_update);
41584163

41594164
if (result == NULL)
41604165
return NULL;
@@ -4174,7 +4179,6 @@ _PyDictView_Intersect(PyObject* self, PyObject *other)
41744179
{
41754180
PyObject *result = PySet_New(self);
41764181
PyObject *tmp;
4177-
_Py_IDENTIFIER(intersection_update);
41784182

41794183
if (result == NULL)
41804184
return NULL;
@@ -4194,7 +4198,6 @@ dictviews_or(PyObject* self, PyObject *other)
41944198
{
41954199
PyObject *result = PySet_New(self);
41964200
PyObject *tmp;
4197-
_Py_IDENTIFIER(update);
41984201

41994202
if (result == NULL)
42004203
return NULL;
@@ -4214,7 +4217,6 @@ dictviews_xor(PyObject* self, PyObject *other)
42144217
{
42154218
PyObject *result = PySet_New(self);
42164219
PyObject *tmp;
4217-
_Py_IDENTIFIER(symmetric_difference_update);
42184220

42194221
if (result == NULL)
42204222
return NULL;

Objects/enumobject.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
#include "clinic/enumobject.c.h"
66

7+
8+
_Py_IDENTIFIER(__reversed__);
9+
710
/*[clinic input]
811
class enumerate "enumobject *" "&PyEnum_Type"
912
class reversed "reversedobject *" "&PyReversed_Type"
@@ -273,7 +276,6 @@ reversed_new_impl(PyTypeObject *type, PyObject *seq)
273276
Py_ssize_t n;
274277
PyObject *reversed_meth;
275278
reversedobject *ro;
276-
_Py_IDENTIFIER(__reversed__);
277279

278280
reversed_meth = _PyObject_LookupSpecial(seq, &PyId___reversed__);
279281
if (reversed_meth == Py_None) {

Objects/exceptions.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
#include "osdefs.h"
1414

1515

16+
_Py_IDENTIFIER(name);
17+
_Py_IDENTIFIER(path);
18+
1619
/* Compatibility aliases */
1720
PyObject *PyExc_EnvironmentError = NULL;
1821
PyObject *PyExc_IOError = NULL;
@@ -699,8 +702,6 @@ ImportError_getstate(PyImportErrorObject *self)
699702
{
700703
PyObject *dict = ((PyBaseExceptionObject *)self)->dict;
701704
if (self->name || self->path) {
702-
_Py_IDENTIFIER(name);
703-
_Py_IDENTIFIER(path);
704705
dict = dict ? PyDict_Copy(dict) : PyDict_New();
705706
if (dict == NULL)
706707
return NULL;

0 commit comments

Comments
 (0)