Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork34k
Description
Description
Tripped up by--with-readline in our configure file while debuggingGH-142353, I was curious if we have any other unused build flags.
Removing them could slightly shorten preprocessing work, reduce cognitive load when debugging platform‑specific issues, and reduce the risk of accidentally relying on dead configuration paths.
After runningmake regen-configure, I put together this script withripgrep:
# t.shFLAGS="$(rg'#\s*define\s+(\w+)' -g pyconfig.h -g pyconfig.h.in -or'$1' --no-line-number --no-filename)"forflagin$FLAGSdo rg"\b$flag\b" -g!pyconfig.h -g!pyconfig.h.in. --stats| rg'\b0 matches' -r"$flag"done
Then I ran this command:
bash t.sh| sort| uniq
I got the following results:
Expand results
DIRENTDONT_HAVE_SIG_ALARMDONT_HAVE_SIG_PAUSEHAVE_ACOSHHAVE_ASINHHAVE_ATANHHAVE_ERFHAVE_ERFCHAVE_EXPM1HAVE_INTPTR_THAVE_LIBSOCKETHAVE_LOG1PHAVE_LOG2HAVE_PUTENVHAVE_STRERRORHAVE_UINTPTR_THAVE_X509_VERIFY_PARAM_SET1_HOSTPy_CONFIG_HPy_NTDDI_Py_PASTE_VERSIONPy_SOCKET_FD_CAN_BE_GE_FD_SETSIZE_Py_STRINGIZE_Py_STRINGIZE1SIZEOF_HKEYUSE_SOCKET_W64WITH_READLINEWORD_BITThese macros are not referenced by any CPython source files outside configuration headers (pyconfig.h,PC/pyconfig.h andpyconfig.h.in files) and are not part of the documented public API.
A few of them are actually used and cannot be removed. Most of them, however, weren't used in years (or decades) and appear to be safely removable, because they no longer affect the behavior of Python.
Here's what I found about every single one of them.
PC/pyconfig.h and pyconfig.h
HAVE_ERF,HAVE_ERFCUnused since5839575.
PC/pyconfig.h
DIRENT(gh-144228: RemoveDIRENTbuild flag comment #144229)This is commented out:
Lines 444 to 445 ine66597d
/* Define if you have dirent.h. */ /* #define DIRENT 1 */ But we already have
HAVE_DIRENT_H 1for that:Lines 290 to 292 ine66597d
/* Define to 1 if you have the <dirent.h> header file, and it defines 'DIR'. */ #undef HAVE_DIRENT_H which is used. Let's remove the
DIRENTcomment.DONT_HAVE_SIG_ALARM,DONT_HAVE_SIG_PAUSE(gh-144228: RemoveDONT_HAVE_SIG_ALARMandDONT_HAVE_SIG_PAUSEbuild flags #144230)Superseded by
HAVE_ALARMandHAVE_PAUSEsince 1997, see1171ee6.
Removed fromPC/os2vacpp/pyconfig.hinab70e2a (when OS/2 support was dropped).USE_SOCKET(gh-144228: RemoveUSE_SOCKETbuild flag #144231)Unused sinceab70e2a (when OS/2 support was dropped).
HAVE_STRERROR(gh-144228: RemoveHAVE_STRERRORbuild flag #144232)Last occurences removed inab70e2a as well.
This was meant to be removed in 2008 according to the description ofada8c3b:r61523 | brett.cannon | 2008-03-18 16:35:58 +0100 (Di, 18 Mär 2008) | 5 lines Remove all traces of HAVE_STRERROR. The removal of strerror.c led to the function check being removed from configure.in.HAVE_LIBSOCKETI'm not sure if it was or was not ever used, because I haven't bisected this.
Seems unused at the moment.
First added in61fe861.HAVE_PUTENV(gh-144228: RemoveHAVE_PUTENVbuild flag #144236)Unused sinceb8d1262 (when
putenv()andunsetenv()became universally available).HAVE_X509_VERIFY_PARAM_SET1_HOST(gh-144228: RemoveHAVE_X509_VERIFY_PARAM_SET1_HOSTbuild flag #144235)Unused since39258d3 (when OpenSSL was bumped to 1.1.1).
SIZEOF_HKEYNo longer used since11fc411.
WITH_READLINEObsolete since 1997, seeb06df27.
The presence of this flag was very confusing to me when I was debuggingReadline-reliant tests are not isolated from personal init files #142353.
pyconfig.h
HAVE_ACOSH,HAVE_ASINH,HAVE_ATANH,HAVE_EXPM1,HAVE_LOG1PUnused sincefa26245.
HAVE_LOG2Unused since5839575.
Ambiguous
Not touching these before I get additional feedback.
Consider them out of the scope of my proposal for now!
HAVE_INTPTR_T,HAVE_UINTPTR_T(PC/pyconfig.h)Added infe393f4, never used since. Maybe it's intentionally reserved for future use?
Py_SOCKET_FD_CAN_BE_GE_FD_SETSIZE(PC/pyconfig.h)Allowing this seems to have caused a stack corruption fixed inaa26b27. Since the fix, the flag has not been used.
cc:@zooba,@cf-natali, can this be removed?
WORD_BIT(PC/pyconfig.h)Standardized by POSIX.1 (IEEE Std 1003.1).
Not sure if it should be in PC/.
Maybe it is used downstream?
Still used or won't fix
(PC/pyconfig.h)Py_CONFIG_HThis was identified by the script, but it's an include guard.
(PC/pyconfig.h)_W64Used in PC/pyconfig.h to define
Py_ssize_t.(PC/pyconfig)Py_NTDDIUsed for defining
NTDDI_VERSION.(PC/pyconfig.h)_Py_PASTE_VERSIONUsed for defining
_Py_COMPILER.(PC/pyconfig.h)_Py_STRINGIZE,_Py_STRINGIZE1I'd not touch these, as they are used for defining
_Py_COMPILER.
These correspond toPy_STRINGIFYand_Py_XSTRINGIFYfrom the pymacro.h header.
MakingPC/pyconfig.hinclude pymacro.h just forPy_STRINGIFYdoesn't seem like a sensible option.
Conclusion
I'm going to start from PRs one per every item (grouping one or more related macros) in the bullet lists of flags certainly removable.
Going forward, I'll appreciate feedback about the ambiguous flags or any things that I've overlooked.
Are there any flags listed for removal that still have known downstream or platform‑specific uses? I pinged some changeset authors to help decide the most ambiguous cases.
Finally, I considered adding automated checks for unused configuration macros, but given the amount of variables involved, this seems non-trivial and not worth it.
Thanks for reading through all of this!
cc@vstinner@encukou I think you will have useful insights into this one.
Linked PRs
- gh-144228: Remove
DIRENTbuild flag comment #144229 - gh-144228: Remove
DONT_HAVE_SIG_ALARMandDONT_HAVE_SIG_PAUSEbuild flags #144230 - gh-144228: Remove
USE_SOCKETbuild flag #144231 - gh-144228: Remove
HAVE_STRERRORbuild flag #144232 - gh-144228: Remove
HAVE_X509_VERIFY_PARAM_SET1_HOSTbuild flag #144235 - gh-144228: Remove
HAVE_PUTENVbuild flag #144236