Skip to content

Commit 055fa11

Browse files
Move local _Py_IDENTIFER to global for core files.
1 parent 6902106 commit 055fa11

File tree

13 files changed

+92
-85
lines changed

13 files changed

+92
-85
lines changed

Parser/tokenizer.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
|| c == '_'\
3232
|| (c >= 128))
3333

34+
_Py_IDENTIFIER(open);
35+
_Py_IDENTIFIER(readline);
36+
3437
extern char *PyOS_Readline(FILE *, FILE *, const char *);
3538
/* Return malloc'ed string including trailing \n;
3639
empty malloc'ed string for EOF;
@@ -412,8 +415,6 @@ static int
412415
fp_setreadl(struct tok_state *tok, const char* enc)
413416
{
414417
PyObject *readline, *io, *stream;
415-
_Py_IDENTIFIER(open);
416-
_Py_IDENTIFIER(readline);
417418
int fd;
418419
long pos;
419420

Python/Python-ast.c

Lines changed: 4 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/_warnings.c

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,20 @@ PyDoc_STRVAR(warnings__doc__,
99
MODULE_NAME " provides basic warning filtering support.\n"
1010
"It is a helper module to speed up interpreter start-up.");
1111

12+
_Py_IDENTIFIER(__loader__);
13+
_Py_IDENTIFIER(__name__);
14+
_Py_IDENTIFIER(__warningregistry__);
15+
_Py_IDENTIFIER(_showwarnmsg);
16+
_Py_IDENTIFIER(_warn_unawaited_coroutine);
17+
_Py_IDENTIFIER(defaultaction);
18+
_Py_IDENTIFIER(filters);
19+
_Py_IDENTIFIER(get_source);
20+
_Py_IDENTIFIER(match);
21+
_Py_IDENTIFIER(onceregistry);
1222
_Py_IDENTIFIER(stderr);
23+
_Py_IDENTIFIER(version);
24+
_Py_IDENTIFIER(warnings);
25+
_Py_IDENTIFIER(WarningMessage);
1326
#ifndef Py_DEBUG
1427
_Py_IDENTIFIER(default);
1528
_Py_IDENTIFIER(ignore);
@@ -147,7 +160,6 @@ static int
147160
check_matched(PyObject *obj, PyObject *arg)
148161
{
149162
PyObject *result;
150-
_Py_IDENTIFIER(match);
151163
int rc;
152164

153165
/* A 'None' filter always matches */
@@ -182,7 +194,6 @@ get_warnings_attr(_Py_Identifier *attr_id, int try_import)
182194
{
183195
PyObject *warnings_str;
184196
PyObject *warnings_module, *obj;
185-
_Py_IDENTIFIER(warnings);
186197

187198
warnings_str = _PyUnicode_FromId(&PyId_warnings);
188199
if (warnings_str == NULL) {
@@ -224,7 +235,6 @@ static PyObject *
224235
get_once_registry(WarningsState *st)
225236
{
226237
PyObject *registry;
227-
_Py_IDENTIFIER(onceregistry);
228238

229239
registry = get_warnings_attr(&PyId_onceregistry, 0);
230240
if (registry == NULL) {
@@ -250,7 +260,6 @@ static PyObject *
250260
get_default_action(WarningsState *st)
251261
{
252262
PyObject *default_action;
253-
_Py_IDENTIFIER(defaultaction);
254263

255264
default_action = get_warnings_attr(&PyId_defaultaction, 0);
256265
if (default_action == NULL) {
@@ -281,7 +290,6 @@ get_filter(PyObject *category, PyObject *text, Py_ssize_t lineno,
281290
PyObject *action;
282291
Py_ssize_t i;
283292
PyObject *warnings_filters;
284-
_Py_IDENTIFIER(filters);
285293
WarningsState *st = _Warnings_GetState();
286294
if (st == NULL) {
287295
return NULL;
@@ -379,7 +387,6 @@ static int
379387
already_warned(PyObject *registry, PyObject *key, int should_set)
380388
{
381389
PyObject *version_obj, *already_warned;
382-
_Py_IDENTIFIER(version);
383390

384391
if (key == NULL)
385392
return -1;
@@ -482,7 +489,6 @@ show_warning(PyObject *filename, int lineno, PyObject *text,
482489
PyObject *f_stderr;
483490
PyObject *name;
484491
char lineno_str[128];
485-
_Py_IDENTIFIER(__name__);
486492

487493
PyOS_snprintf(lineno_str, sizeof(lineno_str), ":%d: ", lineno);
488494

@@ -554,8 +560,6 @@ call_show_warning(PyObject *category, PyObject *text, PyObject *message,
554560
PyObject *sourceline, PyObject *source)
555561
{
556562
PyObject *show_fn, *msg, *res, *warnmsg_cls = NULL;
557-
_Py_IDENTIFIER(_showwarnmsg);
558-
_Py_IDENTIFIER(WarningMessage);
559563

560564
/* If the source parameter is set, try to get the Python implementation.
561565
The Python implementation is able to log the traceback where the source
@@ -816,8 +820,6 @@ static int
816820
setup_context(Py_ssize_t stack_level, PyObject **filename, int *lineno,
817821
PyObject **module, PyObject **registry)
818822
{
819-
_Py_IDENTIFIER(__warningregistry__);
820-
_Py_IDENTIFIER(__name__);
821823
PyObject *globals;
822824

823825
/* Setup globals, filename and lineno. */
@@ -966,9 +968,6 @@ warnings_warn_impl(PyObject *module, PyObject *message, PyObject *category,
966968
static PyObject *
967969
get_source_line(PyObject *module_globals, int lineno)
968970
{
969-
_Py_IDENTIFIER(get_source);
970-
_Py_IDENTIFIER(__loader__);
971-
_Py_IDENTIFIER(__name__);
972971
PyObject *loader;
973972
PyObject *module_name;
974973
PyObject *get_source;
@@ -1280,7 +1279,6 @@ _PyErr_WarnUnawaitedCoroutine(PyObject *coro)
12801279
Since this is called from __del__ context, it's careful to never raise
12811280
an exception.
12821281
*/
1283-
_Py_IDENTIFIER(_warn_unawaited_coroutine);
12841282
int warned = 0;
12851283
PyObject *fn = get_warnings_attr(&PyId__warn_unawaited_coroutine, 1);
12861284
if (fn) {

Python/ast.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
#define MAXLEVEL 200 /* Max parentheses level */
1717

18+
_Py_IDENTIFIER(NFKC);
19+
1820
static int validate_stmts(asdl_seq *);
1921
static int validate_exprs(asdl_seq *, expr_context_ty, int);
2022
static int validate_nonempty_seq(asdl_seq *, const char *, const char *);
@@ -618,7 +620,6 @@ new_identifier(const char *n, struct compiling *c)
618620
identifier; if so, normalize to NFKC. */
619621
if (!PyUnicode_IS_ASCII(id)) {
620622
PyObject *id2;
621-
_Py_IDENTIFIER(NFKC);
622623
if (!c->c_normalize && !init_normalization(c)) {
623624
Py_DECREF(id);
624625
return NULL;

Python/ceval.c

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,22 @@
3535
# error "ceval.c must be build with Py_BUILD_CORE define for best performance"
3636
#endif
3737

38+
_Py_IDENTIFIER(__aenter__);
39+
_Py_IDENTIFIER(__aexit__);
40+
_Py_IDENTIFIER(__all__);
41+
_Py_IDENTIFIER(__annotations__);
42+
_Py_IDENTIFIER(__build_class__);
43+
_Py_IDENTIFIER(__dict__);
44+
_Py_IDENTIFIER(__enter__);
45+
_Py_IDENTIFIER(__exit__);
46+
_Py_IDENTIFIER(__import__);
47+
#ifdef LLTRACE
48+
_Py_IDENTIFIER(__ltrace__);
49+
#endif
50+
_Py_IDENTIFIER(__name__);
51+
_Py_IDENTIFIER(displayhook);
52+
_Py_IDENTIFIER(send);
53+
3854
/* Private API for the LOAD_METHOD opcode. */
3955
extern int _PyObject_GetMethod(PyObject *, PyObject *, PyObject **);
4056

@@ -716,10 +732,6 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag)
716732
PyObject *names;
717733
PyObject *consts;
718734

719-
#ifdef LLTRACE
720-
_Py_IDENTIFIER(__ltrace__);
721-
#endif
722-
723735
/* Computed GOTOs, or
724736
the-optimization-commonly-but-improperly-known-as-"threaded code"
725737
using gcc's labels-as-values extension
@@ -1757,7 +1769,6 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag)
17571769
}
17581770

17591771
case TARGET(PRINT_EXPR): {
1760-
_Py_IDENTIFIER(displayhook);
17611772
PyObject *value = POP();
17621773
PyObject *hook = _PySys_GetObjectId(&PyId_displayhook);
17631774
PyObject *res;
@@ -1945,7 +1956,6 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag)
19451956
if (PyGen_CheckExact(receiver) || PyCoro_CheckExact(receiver)) {
19461957
retval = _PyGen_Send((PyGenObject *)receiver, v);
19471958
} else {
1948-
_Py_IDENTIFIER(send);
19491959
if (v == Py_None)
19501960
retval = Py_TYPE(receiver)->tp_iternext(receiver);
19511961
else
@@ -2140,7 +2150,6 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag)
21402150
}
21412151

21422152
case TARGET(LOAD_BUILD_CLASS): {
2143-
_Py_IDENTIFIER(__build_class__);
21442153

21452154
PyObject *bc;
21462155
if (PyDict_CheckExact(f->f_builtins)) {
@@ -2656,7 +2665,6 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag)
26562665
}
26572666

26582667
case TARGET(SETUP_ANNOTATIONS): {
2659-
_Py_IDENTIFIER(__annotations__);
26602668
int err;
26612669
PyObject *ann_dict;
26622670
if (f->f_locals == NULL) {
@@ -3083,8 +3091,6 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag)
30833091
}
30843092

30853093
case TARGET(BEFORE_ASYNC_WITH): {
3086-
_Py_IDENTIFIER(__aexit__);
3087-
_Py_IDENTIFIER(__aenter__);
30883094

30893095
PyObject *mgr = TOP();
30903096
PyObject *exit = special_lookup(mgr, &PyId___aexit__),
@@ -3117,8 +3123,6 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag)
31173123
}
31183124

31193125
case TARGET(SETUP_WITH): {
3120-
_Py_IDENTIFIER(__exit__);
3121-
_Py_IDENTIFIER(__enter__);
31223126
PyObject *mgr = TOP();
31233127
PyObject *enter = special_lookup(mgr, &PyId___enter__), *exit;
31243128
PyObject *res;
@@ -5012,7 +5016,6 @@ cmp_outcome(int op, PyObject *v, PyObject *w)
50125016
static PyObject *
50135017
import_name(PyFrameObject *f, PyObject *name, PyObject *fromlist, PyObject *level)
50145018
{
5015-
_Py_IDENTIFIER(__import__);
50165019
PyObject *import_func, *res;
50175020
PyObject* stack[5];
50185021

@@ -5055,7 +5058,6 @@ static PyObject *
50555058
import_from(PyObject *v, PyObject *name)
50565059
{
50575060
PyObject *x;
5058-
_Py_IDENTIFIER(__name__);
50595061
PyObject *fullmodname, *pkgname, *pkgpath, *pkgname_or_unknown, *errmsg;
50605062

50615063
if (_PyObject_LookupAttr(v, name, &x) != 0) {
@@ -5123,9 +5125,6 @@ import_from(PyObject *v, PyObject *name)
51235125
static int
51245126
import_all_from(PyObject *locals, PyObject *v)
51255127
{
5126-
_Py_IDENTIFIER(__all__);
5127-
_Py_IDENTIFIER(__dict__);
5128-
_Py_IDENTIFIER(__name__);
51295128
PyObject *all, *dict, *name, *value;
51305129
int skip_leading_underscores = 0;
51315130
int pos, err;

Python/codecs.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ Copyright (c) Corporation for National Research Initiatives.
1313
#include "ucnhash.h"
1414
#include <ctype.h>
1515

16+
17+
_Py_IDENTIFIER(_is_text_encoding);
18+
1619
const char *Py_hexdigits = "0123456789abcdef";
1720

1821
/* --- Codec Registry ----------------------------------------------------- */
@@ -528,7 +531,6 @@ PyObject *PyCodec_Decode(PyObject *object,
528531
PyObject * _PyCodec_LookupTextEncoding(const char *encoding,
529532
const char *alternate_command)
530533
{
531-
_Py_IDENTIFIER(_is_text_encoding);
532534
PyObject *codec;
533535
PyObject *attr;
534536
int is_text_codec;

Python/compile.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
#include "opcode.h"
3232
#include "wordcode_helpers.h"
3333

34+
35+
_Py_IDENTIFIER(__class__);
36+
3437
#define DEFAULT_BLOCK_SIZE 16
3538
#define DEFAULT_BLOCKS 8
3639
#define DEFAULT_CODE_SIZE 128
@@ -572,7 +575,6 @@ compiler_enter_scope(struct compiler *c, identifier name,
572575
}
573576
if (u->u_ste->ste_needs_class_closure) {
574577
/* Cook up an implicit __class__ cell. */
575-
_Py_IDENTIFIER(__class__);
576578
PyObject *name;
577579
int res;
578580
assert(u->u_scope_type == COMPILER_SCOPE_CLASS);

Python/errors.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,15 @@ extern char *strerror(int);
2121
extern "C" {
2222
#endif
2323

24+
_Py_IDENTIFIER(__module__);
2425
_Py_IDENTIFIER(builtins);
26+
_Py_IDENTIFIER(filename);
27+
_Py_IDENTIFIER(lineno);
28+
_Py_IDENTIFIER(msg);
29+
_Py_IDENTIFIER(offset);
30+
_Py_IDENTIFIER(print_file_and_line);
2531
_Py_IDENTIFIER(stderr);
32+
_Py_IDENTIFIER(text);
2633

2734

2835
void
@@ -858,7 +865,6 @@ PyErr_Format(PyObject *exception, const char *format, ...)
858865
PyObject *
859866
PyErr_NewException(const char *name, PyObject *base, PyObject *dict)
860867
{
861-
_Py_IDENTIFIER(__module__);
862868
const char *dot;
863869
PyObject *modulename = NULL;
864870
PyObject *classname = NULL;
@@ -949,7 +955,6 @@ PyErr_NewExceptionWithDoc(const char *name, const char *doc,
949955
void
950956
PyErr_WriteUnraisable(PyObject *obj)
951957
{
952-
_Py_IDENTIFIER(__module__);
953958
PyObject *f, *t, *v, *tb;
954959
PyObject *moduleName = NULL;
955960
const char *className;
@@ -1049,12 +1054,6 @@ void
10491054
PyErr_SyntaxLocationObject(PyObject *filename, int lineno, int col_offset)
10501055
{
10511056
PyObject *exc, *v, *tb, *tmp;
1052-
_Py_IDENTIFIER(filename);
1053-
_Py_IDENTIFIER(lineno);
1054-
_Py_IDENTIFIER(msg);
1055-
_Py_IDENTIFIER(offset);
1056-
_Py_IDENTIFIER(print_file_and_line);
1057-
_Py_IDENTIFIER(text);
10581057

10591058
/* add attributes for the line number and filename for the error */
10601059
PyErr_Fetch(&exc, &v, &tb);

0 commit comments

Comments
 (0)