@@ -1813,87 +1813,60 @@ config_get_env_dup(PyConfig *config,
18131813static void
18141814config_get_global_vars (PyConfig * config )
18151815{
1816- _Py_COMP_DIAG_PUSH
1817- _Py_COMP_DIAG_IGNORE_DEPR_DECLS
18181816 if (config -> _config_init != _PyConfig_INIT_COMPAT ) {
18191817 /* Python and Isolated configuration ignore global variables */
18201818 return ;
18211819 }
18221820
1823- #define COPY_FLAG (ATTR , VALUE ) \
1824- if (config->ATTR == -1) { \
1825- config->ATTR = VALUE; \
1821+ const PyConfigSpec * spec = PYCONFIG_SPEC ;
1822+ for (; spec -> name != NULL ; spec ++ ) {
1823+ if (spec -> global_var .ptr == NULL ) {
1824+ continue ;
18261825 }
1827- #define COPY_NOT_FLAG (ATTR , VALUE ) \
1828- if (config->ATTR == -1) { \
1829- config->ATTR = !(VALUE); \
1826+ assert (spec -> type == PyConfig_MEMBER_INT
1827+ || spec -> type == PyConfig_MEMBER_UINT
1828+ || spec -> type == PyConfig_MEMBER_BOOL );
1829+ int * member = config_get_spec_member (config , spec );
1830+ if (* member != -1 ) {
1831+ continue ;
18301832 }
1831-
1832- COPY_FLAG (isolated , Py_IsolatedFlag );
1833- COPY_NOT_FLAG (use_environment , Py_IgnoreEnvironmentFlag );
1834- COPY_FLAG (bytes_warning , Py_BytesWarningFlag );
1835- COPY_FLAG (inspect , Py_InspectFlag );
1836- COPY_FLAG (interactive , Py_InteractiveFlag );
1837- COPY_FLAG (optimization_level , Py_OptimizeFlag );
1838- COPY_FLAG (parser_debug , Py_DebugFlag );
1839- COPY_FLAG (verbose , Py_VerboseFlag );
1840- COPY_FLAG (quiet , Py_QuietFlag );
1841- #ifdef MS_WINDOWS
1842- COPY_FLAG (legacy_windows_stdio , Py_LegacyWindowsStdioFlag );
1843- #endif
1844- COPY_NOT_FLAG (pathconfig_warnings , Py_FrozenFlag );
1845-
1846- COPY_NOT_FLAG (buffered_stdio , Py_UnbufferedStdioFlag );
1847- COPY_NOT_FLAG (site_import , Py_NoSiteFlag );
1848- COPY_NOT_FLAG (write_bytecode , Py_DontWriteBytecodeFlag );
1849- COPY_NOT_FLAG (user_site_directory , Py_NoUserSiteDirectory );
1850-
1851- #undef COPY_FLAG
1852- #undef COPY_NOT_FLAG
1853- _Py_COMP_DIAG_POP
1833+ int value = * spec -> global_var .ptr ;
1834+ if (spec -> global_var .not ) {
1835+ value = !value ;
1836+ }
1837+ * member = value ;
1838+ }
18541839}
18551840
18561841
18571842/* Set Py_xxx global configuration variables from 'config' configuration. */
18581843static void
18591844config_set_global_vars (const PyConfig * config )
18601845{
1846+ const PyConfigSpec * spec = PYCONFIG_SPEC ;
1847+ for (; spec -> name != NULL ; spec ++ ) {
1848+ if (spec -> global_var .ptr == NULL ) {
1849+ continue ;
1850+ }
1851+ assert (spec -> type == PyConfig_MEMBER_INT
1852+ || spec -> type == PyConfig_MEMBER_UINT
1853+ || spec -> type == PyConfig_MEMBER_BOOL );
1854+ int * member = config_get_spec_member (config , spec );
1855+ int value = * member ;
1856+ if (value == -1 ) {
1857+ continue ;
1858+ }
1859+ if (spec -> global_var .not ) {
1860+ value = !value ;
1861+ }
1862+ * spec -> global_var .ptr = value ;
1863+ }
1864+
18611865_Py_COMP_DIAG_PUSH
18621866_Py_COMP_DIAG_IGNORE_DEPR_DECLS
1863- #define COPY_FLAG (ATTR , VAR ) \
1864- if (config->ATTR != -1) { \
1865- VAR = config->ATTR; \
1866- }
1867- #define COPY_NOT_FLAG (ATTR , VAR ) \
1868- if (config->ATTR != -1) { \
1869- VAR = !config->ATTR; \
1870- }
1871-
1872- COPY_FLAG (isolated , Py_IsolatedFlag );
1873- COPY_NOT_FLAG (use_environment , Py_IgnoreEnvironmentFlag );
1874- COPY_FLAG (bytes_warning , Py_BytesWarningFlag );
1875- COPY_FLAG (inspect , Py_InspectFlag );
1876- COPY_FLAG (interactive , Py_InteractiveFlag );
1877- COPY_FLAG (optimization_level , Py_OptimizeFlag );
1878- COPY_FLAG (parser_debug , Py_DebugFlag );
1879- COPY_FLAG (verbose , Py_VerboseFlag );
1880- COPY_FLAG (quiet , Py_QuietFlag );
1881- #ifdef MS_WINDOWS
1882- COPY_FLAG (legacy_windows_stdio , Py_LegacyWindowsStdioFlag );
1883- #endif
1884- COPY_NOT_FLAG (pathconfig_warnings , Py_FrozenFlag );
1885-
1886- COPY_NOT_FLAG (buffered_stdio , Py_UnbufferedStdioFlag );
1887- COPY_NOT_FLAG (site_import , Py_NoSiteFlag );
1888- COPY_NOT_FLAG (write_bytecode , Py_DontWriteBytecodeFlag );
1889- COPY_NOT_FLAG (user_site_directory , Py_NoUserSiteDirectory );
1890-
18911867 /* Random or non-zero hash seed */
18921868 Py_HashRandomizationFlag = (config -> use_hash_seed == 0 ||
18931869 config -> hash_seed != 0 );
1894-
1895- #undef COPY_FLAG
1896- #undef COPY_NOT_FLAG
18971870_Py_COMP_DIAG_POP
18981871}
18991872
0 commit comments