@@ -695,6 +695,7 @@ config_check_consistency(const PyConfig *config)
695
695
assert (config -> pathconfig_warnings >= 0 );
696
696
assert (config -> _is_python_build >= 0 );
697
697
assert (config -> safe_path >= 0 );
698
+ assert (config -> int_max_str_digits >= 0 );
698
699
// config->use_frozen_modules is initialized later
699
700
// by _PyConfig_InitImportConfig().
700
701
return 1 ;
@@ -789,14 +790,11 @@ _PyConfig_InitCompatConfig(PyConfig *config)
789
790
config -> use_frozen_modules = 1 ;
790
791
#endif
791
792
config -> safe_path = 0 ;
793
+ config -> int_max_str_digits = -1 ;
792
794
config -> _is_python_build = 0 ;
793
795
config -> code_debug_ranges = 1 ;
794
796
}
795
797
796
- /* Excluded from public struct PyConfig for backporting reasons. */
797
- /* default to unconfigured, _PyLong_InitTypes() does the rest */
798
- int _Py_global_config_int_max_str_digits = -1 ;
799
-
800
798
801
799
static void
802
800
config_init_defaults (PyConfig * config )
@@ -849,6 +847,7 @@ PyConfig_InitIsolatedConfig(PyConfig *config)
849
847
config -> faulthandler = 0 ;
850
848
config -> tracemalloc = 0 ;
851
849
config -> perf_profiling = 0 ;
850
+ config -> int_max_str_digits = _PY_LONG_DEFAULT_MAX_STR_DIGITS ;
852
851
config -> safe_path = 1 ;
853
852
config -> pathconfig_warnings = 0 ;
854
853
#ifdef MS_WINDOWS
@@ -1021,6 +1020,7 @@ _PyConfig_Copy(PyConfig *config, const PyConfig *config2)
1021
1020
COPY_ATTR (safe_path );
1022
1021
COPY_WSTRLIST (orig_argv );
1023
1022
COPY_ATTR (_is_python_build );
1023
+ COPY_ATTR (int_max_str_digits );
1024
1024
1025
1025
#undef COPY_ATTR
1026
1026
#undef COPY_WSTR_ATTR
@@ -1128,6 +1128,7 @@ _PyConfig_AsDict(const PyConfig *config)
1128
1128
SET_ITEM_INT (use_frozen_modules );
1129
1129
SET_ITEM_INT (safe_path );
1130
1130
SET_ITEM_INT (_is_python_build );
1131
+ SET_ITEM_INT (int_max_str_digits );
1131
1132
1132
1133
return dict ;
1133
1134
@@ -1317,6 +1318,12 @@ _PyConfig_FromDict(PyConfig *config, PyObject *dict)
1317
1318
} \
1318
1319
CHECK_VALUE(#KEY, config->KEY >= 0); \
1319
1320
} while (0)
1321
+ #define GET_INT (KEY ) \
1322
+ do { \
1323
+ if (config_dict_get_int(dict, #KEY, &config->KEY) < 0) { \
1324
+ return -1; \
1325
+ } \
1326
+ } while (0)
1320
1327
#define GET_WSTR (KEY ) \
1321
1328
do { \
1322
1329
if (config_dict_get_wstr(dict, #KEY, config, &config->KEY) < 0) { \
@@ -1415,9 +1422,11 @@ _PyConfig_FromDict(PyConfig *config, PyObject *dict)
1415
1422
GET_UINT (use_frozen_modules );
1416
1423
GET_UINT (safe_path );
1417
1424
GET_UINT (_is_python_build );
1425
+ GET_INT (int_max_str_digits );
1418
1426
1419
1427
#undef CHECK_VALUE
1420
1428
#undef GET_UINT
1429
+ #undef GET_INT
1421
1430
#undef GET_WSTR
1422
1431
#undef GET_WSTR_OPT
1423
1432
return 0 ;
@@ -1782,7 +1791,7 @@ config_init_int_max_str_digits(PyConfig *config)
1782
1791
1783
1792
const char * env = config_get_env (config , "PYTHONINTMAXSTRDIGITS" );
1784
1793
if (env ) {
1785
- int valid = 0 ;
1794
+ bool valid = 0 ;
1786
1795
if (!_Py_str_to_int (env , & maxdigits )) {
1787
1796
valid = ((maxdigits == 0 ) || (maxdigits >= _PY_LONG_MAX_STR_DIGITS_THRESHOLD ));
1788
1797
}
@@ -1794,13 +1803,13 @@ config_init_int_max_str_digits(PyConfig *config)
1794
1803
STRINGIFY (_PY_LONG_MAX_STR_DIGITS_THRESHOLD )
1795
1804
" or 0 for unlimited." );
1796
1805
}
1797
- _Py_global_config_int_max_str_digits = maxdigits ;
1806
+ config -> int_max_str_digits = maxdigits ;
1798
1807
}
1799
1808
1800
1809
const wchar_t * xoption = config_get_xoption (config , L"int_max_str_digits" );
1801
1810
if (xoption ) {
1802
1811
const wchar_t * sep = wcschr (xoption , L'=' );
1803
- int valid = 0 ;
1812
+ bool valid = 0 ;
1804
1813
if (sep ) {
1805
1814
if (!config_wstr_to_int (sep + 1 , & maxdigits )) {
1806
1815
valid = ((maxdigits == 0 ) || (maxdigits >= _PY_LONG_MAX_STR_DIGITS_THRESHOLD ));
@@ -1814,7 +1823,10 @@ config_init_int_max_str_digits(PyConfig *config)
1814
1823
#undef _STRINGIFY
1815
1824
#undef STRINGIFY
1816
1825
}
1817
- _Py_global_config_int_max_str_digits = maxdigits ;
1826
+ config -> int_max_str_digits = maxdigits ;
1827
+ }
1828
+ if (config -> int_max_str_digits < 0 ) {
1829
+ config -> int_max_str_digits = _PY_LONG_DEFAULT_MAX_STR_DIGITS ;
1818
1830
}
1819
1831
return _PyStatus_OK ();
1820
1832
}
@@ -1882,7 +1894,7 @@ config_read_complex_options(PyConfig *config)
1882
1894
}
1883
1895
}
1884
1896
1885
- if (_Py_global_config_int_max_str_digits < 0 ) {
1897
+ if (config -> int_max_str_digits < 0 ) {
1886
1898
status = config_init_int_max_str_digits (config );
1887
1899
if (_PyStatus_EXCEPTION (status )) {
1888
1900
return status ;
0 commit comments