Skip to content

Commit 76c85bb

Browse files
committed
Move ABIFLAGS definition to C code
1 parent 9a4586a commit 76c85bb

File tree

3 files changed

+30
-7
lines changed

3 files changed

+30
-7
lines changed

Lib/sysconfig/__init__.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,11 @@ def _init_non_posix(vars):
401401
vars['BINLIBDEST'] = get_path('platstdlib')
402402
vars['INCLUDEPY'] = get_path('include')
403403

404-
# Add EXT_SUFFIX, SOABI, and Py_GIL_DISABLED
404+
# Add EXT_SUFFIX, SOABI, ABIFLAGS, and Py_GIL_DISABLED (defined in Modules/_sysconfig.c)
405+
# NOTE: ABIFLAGS is only an emulated value. It is not present during build
406+
# on Windows. sys.abiflags is absent on Windows and `vars['abiflags']
407+
# is already widely used to calculate paths. vars['abiflags'] should
408+
# remain empty string.
405409
vars.update(_sysconfig.config_vars())
406410

407411
vars['LIBDIR'] = _safe_realpath(os.path.join(get_config_var('installed_base'), 'libs'))
@@ -414,12 +418,6 @@ def _init_non_posix(vars):
414418
vars['BINDIR'] = os.path.dirname(_safe_realpath(sys.executable))
415419
vars['TZPATH'] = ''
416420

417-
abiflags = vars['abi_thread']
418-
if vars['EXT_SUFFIX'].endswith('_d.'):
419-
abiflags += 'd'
420-
# Do not touch lower-cased `abiflags` here.
421-
# sys.abiflags is absent on Windows. So vars['abiflags'] should be empty.
422-
vars['ABIFLAGS'] = abiflags
423421

424422
#
425423
# public APIs

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1402,6 +1402,7 @@ Todd R. Palmer
14021402
Juan David Ibáñez Palomar
14031403
Nicola Palumbo
14041404
Jan Palus
1405+
Xuehai Pan
14051406
Yongzhi Pan
14061407
Martin Panter
14071408
Mathias Panzenböck

Modules/_sysconfig.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,30 @@ _sysconfig_config_vars_impl(PyObject *module)
5555
Py_DECREF(config);
5656
return NULL;
5757
}
58+
59+
// On Unix, the `ABIFLAGS` key is defined via a different logic.
60+
# ifdef Py_GIL_DISABLED
61+
# define _SYSCONFIG_ABI_THREAD "t"
62+
# else
63+
# define _SYSCONFIG_ABI_THREAD ""
64+
# endif
65+
# ifdef _DEBUG
66+
# define _SYSCONFIG_ABI_DEBUG "d"
67+
# else
68+
# define _SYSCONFIG_ABI_DEBUG ""
69+
# endif
70+
# define _SYSCONFIG_ABIFLAGS (_SYSCONFIG_ABI_THREAD _SYSCONFIG_ABI_DEBUG)
71+
72+
// Emulate `sys.abiflags` value on Unix for Windows. ABIFLAGS here is only
73+
// an emulated value. It is not present during build on Windows.
74+
if (add_string_value(config, "ABIFLAGS", SYSCONFIG_ABIFLAGS) < 0) {
75+
Py_DECREF(config);
76+
return NULL;
77+
}
78+
79+
# undef _SYSCONFIG_ABI_THREAD
80+
# undef _SYSCONFIG_ABI_DEBUG
81+
# undef _SYSCONFIG_ABIFLAGS
5882
#endif
5983

6084
#ifdef Py_GIL_DISABLED

0 commit comments

Comments
 (0)