Skip to content

Commit a6045ea

Browse files
committed
Set Py_DEBUG flag in sysconfig
1 parent 04cbb1c commit a6045ea

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

Lib/sysconfig/__init__.py

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

404-
# Add EXT_SUFFIX, SOABI, ABIFLAGS, and Py_GIL_DISABLED
404+
# Add EXT_SUFFIX, SOABI, ABIFLAGS, Py_DEBUG, and Py_GIL_DISABLED
405405
# NOTE: ABIFLAGS is only an emulated value. It is not present during build
406406
# on Windows. sys.abiflags is absent on Windows and `vars['abiflags']
407407
# is already widely used to calculate paths. vars['abiflags'] should

Modules/_sysconfig.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,15 @@ _sysconfig_config_vars_impl(PyObject *module)
6464
# ifdef Py_GIL_DISABLED
6565
"t"
6666
# endif
67-
# ifdef _DEBUG
67+
# ifdef Py_DEBUG
68+
# ifndef _DEBUG
69+
# error "_DEBUG not defined while Py_DEBUG is defined on Windows"
70+
# endif
6871
"d"
72+
# else
73+
# ifdef _DEBUG
74+
# error "_DEBUG defined while Py_DEBUG is not defined on Windows"
75+
# endif
6976
# endif
7077
"")
7178
< 0) {
@@ -84,6 +91,16 @@ _sysconfig_config_vars_impl(PyObject *module)
8491
return NULL;
8592
}
8693

94+
#ifdef Py_DEBUG
95+
PyObject *py_debug = _PyLong_GetOne();
96+
#else
97+
PyObject *py_debug = _PyLong_GetZero();
98+
#endif
99+
if (PyDict_SetItemString(config, "Py_DEBUG", py_debug) < 0) {
100+
Py_DECREF(config);
101+
return NULL;
102+
}
103+
87104
return config;
88105
}
89106

0 commit comments

Comments
 (0)