@@ -1138,7 +1138,8 @@ class GlobalState(object):
1138
1138
'pystring_table' ,
1139
1139
'cached_builtins' ,
1140
1140
'cached_constants' ,
1141
- 'init_globals' ,
1141
+ 'init_constants' ,
1142
+ 'init_globals' , # (utility code called at init-time)
1142
1143
'init_module' ,
1143
1144
'cleanup_globals' ,
1144
1145
'cleanup_module' ,
@@ -1209,6 +1210,11 @@ def initialize_main_c_code(self):
1209
1210
w .putln ("" )
1210
1211
w .putln ("static CYTHON_SMALL_CODE int __Pyx_InitGlobals(void) {" )
1211
1212
1213
+ w = self .parts ['init_constants' ]
1214
+ w .enter_cfunc_scope ()
1215
+ w .putln ("" )
1216
+ w .putln ("static CYTHON_SMALL_CODE int __Pyx_InitConstants(void) {" )
1217
+
1212
1218
if not Options .generate_cleanup_code :
1213
1219
del self .parts ['cleanup_globals' ]
1214
1220
else :
@@ -1284,13 +1290,14 @@ def close_global_decls(self):
1284
1290
w .putln ("}" )
1285
1291
w .exit_cfunc_scope ()
1286
1292
1287
- w = self .parts ['init_globals' ]
1288
- w .putln ("return 0;" )
1289
- if w .label_used (w .error_label ):
1290
- w .put_label (w .error_label )
1291
- w .putln ("return -1;" )
1292
- w .putln ("}" )
1293
- w .exit_cfunc_scope ()
1293
+ for part in ['init_globals' , 'init_constants' ]:
1294
+ w = self .parts [part ]
1295
+ w .putln ("return 0;" )
1296
+ if w .label_used (w .error_label ):
1297
+ w .put_label (w .error_label )
1298
+ w .putln ("return -1;" )
1299
+ w .putln ("}" )
1300
+ w .exit_cfunc_scope ()
1294
1301
1295
1302
if Options .generate_cleanup_code :
1296
1303
w = self .parts ['cleanup_globals' ]
@@ -1510,7 +1517,7 @@ def generate_cached_methods_decls(self):
1510
1517
return
1511
1518
1512
1519
decl = self .parts ['decls' ]
1513
- init = self .parts ['init_globals ' ]
1520
+ init = self .parts ['init_constants ' ]
1514
1521
cnames = []
1515
1522
for (type_cname , method_name ), cname in sorted (self .cached_cmethods .items ()):
1516
1523
cnames .append (cname )
@@ -1560,7 +1567,7 @@ def generate_string_constants(self):
1560
1567
decls_writer .putln ("static Py_UNICODE %s[] = { %s };" % (cname , utf16_array ))
1561
1568
decls_writer .putln ("#endif" )
1562
1569
1563
- init_globals = self .parts ['init_globals ' ]
1570
+ init_constants = self .parts ['init_constants ' ]
1564
1571
if py_strings :
1565
1572
self .use_utility_code (UtilityCode .load_cached ("InitStrings" , "StringTools.c" ))
1566
1573
py_strings .sort ()
@@ -1575,9 +1582,9 @@ def generate_string_constants(self):
1575
1582
decls_writer .putln ("#if !CYTHON_USE_MODULE_STATE" )
1576
1583
not_limited_api_decls_writer = decls_writer .insertion_point ()
1577
1584
decls_writer .putln ("#endif" )
1578
- init_globals .putln ("#if CYTHON_USE_MODULE_STATE" )
1579
- init_globals_in_module_state = init_globals .insertion_point ()
1580
- init_globals .putln ("#endif" )
1585
+ init_constants .putln ("#if CYTHON_USE_MODULE_STATE" )
1586
+ init_constants_in_module_state = init_constants .insertion_point ()
1587
+ init_constants .putln ("#endif" )
1581
1588
for idx , py_string_args in enumerate (py_strings ):
1582
1589
c_cname , _ , py_string = py_string_args
1583
1590
if not py_string .is_str or not py_string .encoding or \
@@ -1627,28 +1634,28 @@ def generate_string_constants(self):
1627
1634
py_string .is_str ,
1628
1635
py_string .intern
1629
1636
))
1630
- init_globals_in_module_state .putln ("if (__Pyx_InitString(%s[%d], &%s) < 0) %s;" % (
1637
+ init_constants_in_module_state .putln ("if (__Pyx_InitString(%s[%d], &%s) < 0) %s;" % (
1631
1638
Naming .stringtab_cname ,
1632
1639
idx ,
1633
1640
py_string .cname ,
1634
- init_globals .error_goto (self .module_pos )))
1641
+ init_constants .error_goto (self .module_pos )))
1635
1642
w .putln ("{0, 0, 0, 0, 0, 0, 0}" )
1636
1643
w .putln ("};" )
1637
1644
1638
- init_globals .putln ("#if !CYTHON_USE_MODULE_STATE" )
1639
- init_globals .putln (
1645
+ init_constants .putln ("#if !CYTHON_USE_MODULE_STATE" )
1646
+ init_constants .putln (
1640
1647
"if (__Pyx_InitStrings(%s) < 0) %s;" % (
1641
1648
Naming .stringtab_cname ,
1642
- init_globals .error_goto (self .module_pos )))
1643
- init_globals .putln ("#endif" )
1649
+ init_constants .error_goto (self .module_pos )))
1650
+ init_constants .putln ("#endif" )
1644
1651
1645
1652
def generate_num_constants (self ):
1646
1653
consts = [(c .py_type , c .value [0 ] == '-' , len (c .value ), c .value , c .value_code , c )
1647
1654
for c in self .num_const_index .values ()]
1648
1655
consts .sort ()
1649
1656
decls_writer = self .parts ['decls' ]
1650
1657
decls_writer .putln ("#if !CYTHON_USE_MODULE_STATE" )
1651
- init_globals = self .parts ['init_globals ' ]
1658
+ init_constants = self .parts ['init_constants ' ]
1652
1659
for py_type , _ , _ , value , value_code , c in consts :
1653
1660
cname = c .cname
1654
1661
self .parts ['module_state' ].putln ("PyObject *%s;" % cname )
@@ -1669,9 +1676,9 @@ def generate_num_constants(self):
1669
1676
function = "PyInt_FromLong(%sL)"
1670
1677
else :
1671
1678
function = "PyInt_FromLong(%s)"
1672
- init_globals .putln ('%s = %s; %s' % (
1679
+ init_constants .putln ('%s = %s; %s' % (
1673
1680
cname , function % value_code ,
1674
- init_globals .error_goto_if_null (cname , self .module_pos )))
1681
+ init_constants .error_goto_if_null (cname , self .module_pos )))
1675
1682
decls_writer .putln ("#endif" )
1676
1683
1677
1684
# The functions below are there in a transition phase only
0 commit comments