@@ -339,7 +339,6 @@ static int compiler_pattern_subpattern(struct compiler *, pattern_ty,
339
339
static void clean_basic_block (basicblock * bb );
340
340
341
341
static PyCodeObject * assemble (struct compiler * , int addNone );
342
- static PyObject * __doc__ , * __annotations__ ;
343
342
344
343
#define CAPSULE_NAME "compile.c compiler unit"
345
344
@@ -438,17 +437,6 @@ _PyAST_Compile(mod_ty mod, PyObject *filename, PyCompilerFlags *flags,
438
437
PyCodeObject * co = NULL ;
439
438
PyCompilerFlags local_flags = _PyCompilerFlags_INIT ;
440
439
int merged ;
441
-
442
- if (!__doc__ ) {
443
- __doc__ = PyUnicode_InternFromString ("__doc__" );
444
- if (!__doc__ )
445
- return NULL ;
446
- }
447
- if (!__annotations__ ) {
448
- __annotations__ = PyUnicode_InternFromString ("__annotations__" );
449
- if (!__annotations__ )
450
- return NULL ;
451
- }
452
440
if (!compiler_init (& c ))
453
441
return NULL ;
454
442
Py_INCREF (filename );
@@ -1938,6 +1926,11 @@ compiler_body(struct compiler *c, asdl_stmt_seq *stmts)
1938
1926
int i = 0 ;
1939
1927
stmt_ty st ;
1940
1928
PyObject * docstring ;
1929
+ _Py_IDENTIFIER (__doc__ );
1930
+ PyObject * __doc__ = _PyUnicode_FromId (& PyId___doc__ ); /* borrowed ref*/
1931
+ if (__doc__ == NULL ) {
1932
+ return 0 ;
1933
+ }
1941
1934
1942
1935
/* Set current line number to the line number of first statement.
1943
1936
This way line number for SETUP_ANNOTATIONS will always
@@ -1975,11 +1968,10 @@ compiler_mod(struct compiler *c, mod_ty mod)
1975
1968
{
1976
1969
PyCodeObject * co ;
1977
1970
int addNone = 1 ;
1978
- static PyObject * module ;
1979
- if (!module ) {
1980
- module = PyUnicode_InternFromString ("<module>" );
1981
- if (!module )
1982
- return NULL ;
1971
+ _Py_static_string (PyId__module , "<module>" );
1972
+ PyObject * module = _PyUnicode_FromId (& PyId__module ); /* borrowed ref */
1973
+ if (module == NULL ) {
1974
+ return 0 ;
1983
1975
}
1984
1976
/* Use 0 for firstlineno initially, will fixup in assemble(). */
1985
1977
if (!compiler_enter_scope (c , module , COMPILER_SCOPE_MODULE , mod , 1 ))
@@ -2232,7 +2224,7 @@ compiler_visit_annotations(struct compiler *c, arguments_ty args,
2232
2224
2233
2225
Return 0 on error, -1 if no annotations pushed, 1 if a annotations is pushed.
2234
2226
*/
2235
- static identifier return_str ;
2227
+ _Py_IDENTIFIER ( return ) ;
2236
2228
Py_ssize_t annotations_len = 0 ;
2237
2229
2238
2230
if (!compiler_visit_argannotations (c , args -> args , & annotations_len ))
@@ -2250,10 +2242,9 @@ compiler_visit_annotations(struct compiler *c, arguments_ty args,
2250
2242
args -> kwarg -> annotation , & annotations_len ))
2251
2243
return 0 ;
2252
2244
2253
- if (!return_str ) {
2254
- return_str = PyUnicode_InternFromString ("return" );
2255
- if (!return_str )
2256
- return 0 ;
2245
+ identifier return_str = _PyUnicode_FromId (& PyId_return ); /* borrowed ref */
2246
+ if (return_str == NULL ) {
2247
+ return 0 ;
2257
2248
}
2258
2249
if (!compiler_visit_argannotation (c , return_str , returns , & annotations_len )) {
2259
2250
return 0 ;
@@ -2799,18 +2790,18 @@ compiler_lambda(struct compiler *c, expr_ty e)
2799
2790
{
2800
2791
PyCodeObject * co ;
2801
2792
PyObject * qualname ;
2802
- static identifier name ;
2793
+ identifier name ;
2803
2794
Py_ssize_t funcflags ;
2804
2795
arguments_ty args = e -> v .Lambda .args ;
2805
2796
assert (e -> kind == Lambda_kind );
2806
2797
2807
2798
if (!compiler_check_debug_args (c , args ))
2808
2799
return 0 ;
2809
2800
2810
- if (! name ) {
2811
- name = PyUnicode_InternFromString ( "<lambda>" );
2812
- if (! name )
2813
- return 0 ;
2801
+ _Py_static_string ( PyId_lambda , "<lambda>" );
2802
+ name = _PyUnicode_FromId ( & PyId_lambda ); /* borrowed ref */
2803
+ if (name == NULL ) {
2804
+ return 0 ;
2814
2805
}
2815
2806
2816
2807
funcflags = compiler_default_arguments (c , args );
@@ -3421,12 +3412,11 @@ compiler_from_import(struct compiler *c, stmt_ty s)
3421
3412
{
3422
3413
Py_ssize_t i , n = asdl_seq_LEN (s -> v .ImportFrom .names );
3423
3414
PyObject * names ;
3424
- static PyObject * empty_string ;
3415
+ _Py_static_string (PyId_empty_string , "" );
3416
+ PyObject * empty_string = _PyUnicode_FromId (& PyId_empty_string ); /* borrowed ref */
3425
3417
3426
- if (!empty_string ) {
3427
- empty_string = PyUnicode_FromString ("" );
3428
- if (!empty_string )
3429
- return 0 ;
3418
+ if (empty_string == NULL ) {
3419
+ return 0 ;
3430
3420
}
3431
3421
3432
3422
ADDOP_LOAD_CONST_NEW (c , PyLong_FromLong (s -> v .ImportFrom .level ));
@@ -4972,11 +4962,10 @@ compiler_comprehension(struct compiler *c, expr_ty e, int type,
4972
4962
static int
4973
4963
compiler_genexp (struct compiler * c , expr_ty e )
4974
4964
{
4975
- static identifier name ;
4976
- if (!name ) {
4977
- name = PyUnicode_InternFromString ("<genexpr>" );
4978
- if (!name )
4979
- return 0 ;
4965
+ _Py_static_string (PyId_genexpr , "<genexpr>" );
4966
+ identifier name = _PyUnicode_FromId (& PyId_genexpr ); /* borrowed ref */
4967
+ if (name == NULL ) {
4968
+ return 0 ;
4980
4969
}
4981
4970
assert (e -> kind == GeneratorExp_kind );
4982
4971
return compiler_comprehension (c , e , COMP_GENEXP , name ,
@@ -4987,11 +4976,10 @@ compiler_genexp(struct compiler *c, expr_ty e)
4987
4976
static int
4988
4977
compiler_listcomp (struct compiler * c , expr_ty e )
4989
4978
{
4990
- static identifier name ;
4991
- if (!name ) {
4992
- name = PyUnicode_InternFromString ("<listcomp>" );
4993
- if (!name )
4994
- return 0 ;
4979
+ _Py_static_string (PyId_listcomp , "<listcomp>" );
4980
+ identifier name = _PyUnicode_FromId (& PyId_listcomp ); /* borrowed ref */
4981
+ if (name == NULL ) {
4982
+ return 0 ;
4995
4983
}
4996
4984
assert (e -> kind == ListComp_kind );
4997
4985
return compiler_comprehension (c , e , COMP_LISTCOMP , name ,
@@ -5002,11 +4990,10 @@ compiler_listcomp(struct compiler *c, expr_ty e)
5002
4990
static int
5003
4991
compiler_setcomp (struct compiler * c , expr_ty e )
5004
4992
{
5005
- static identifier name ;
5006
- if (!name ) {
5007
- name = PyUnicode_InternFromString ("<setcomp>" );
5008
- if (!name )
5009
- return 0 ;
4993
+ _Py_static_string (PyId_setcomp , "<setcomp>" );
4994
+ identifier name = _PyUnicode_FromId (& PyId_setcomp ); /* borrowed ref */
4995
+ if (name == NULL ) {
4996
+ return 0 ;
5010
4997
}
5011
4998
assert (e -> kind == SetComp_kind );
5012
4999
return compiler_comprehension (c , e , COMP_SETCOMP , name ,
@@ -5018,11 +5005,10 @@ compiler_setcomp(struct compiler *c, expr_ty e)
5018
5005
static int
5019
5006
compiler_dictcomp (struct compiler * c , expr_ty e )
5020
5007
{
5021
- static identifier name ;
5022
- if (!name ) {
5023
- name = PyUnicode_InternFromString ("<dictcomp>" );
5024
- if (!name )
5025
- return 0 ;
5008
+ _Py_static_string (PyId_dictcomp , "<dictcomp>" );
5009
+ identifier name = _PyUnicode_FromId (& PyId_dictcomp ); /* borrowed ref */
5010
+ if (name == NULL ) {
5011
+ return 0 ;
5026
5012
}
5027
5013
assert (e -> kind == DictComp_kind );
5028
5014
return compiler_comprehension (c , e , COMP_DICTCOMP , name ,
@@ -5553,6 +5539,12 @@ compiler_annassign(struct compiler *c, stmt_ty s)
5553
5539
{
5554
5540
expr_ty targ = s -> v .AnnAssign .target ;
5555
5541
PyObject * mangled ;
5542
+ _Py_IDENTIFIER (__annotations__ );
5543
+ /* borrowed ref*/
5544
+ PyObject * __annotations__ = _PyUnicode_FromId (& PyId___annotations__ );
5545
+ if (__annotations__ == NULL ) {
5546
+ return 0 ;
5547
+ }
5556
5548
5557
5549
assert (s -> kind == AnnAssign_kind );
5558
5550
0 commit comments