Skip to content

gh-157695: Rename HAVE_ICONV to _Py_HAVE_ICONV - #157821

Merged
vstinner merged 3 commits into
python:mainfrom
vstinner:rename_iconv_macro
Sep 22, 2026
Merged

vstinner merged 3 commits into
python:mainfrom
vstinner:rename_iconv_macro

Conversation

@vstinner

@vstinner vstinner commented Sep 19, 2026 •

Copy link
Copy Markdown
Member
@vstinner

Copy link
Copy Markdown
Member Author

cc @serhiy-storchaka

The HAVE_ICONV macro is new in Python 3.16.

@serhiy-storchaka serhiy-storchaka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not mind, but does it make difference if most of configure macros are HAVE_* and this is standard?

@encukou

encukou commented Sep 21, 2026

Copy link
Copy Markdown
Member

does it make difference if most of configure macros are HAVE_*

Before we fix things, we should stop making them worse.

and this is standard?

Which standard is that?

@serhiy-storchaka

Copy link
Copy Markdown
Member

I do not know if this is a formal standard, but many projects use HAVE_*.

@vstinner

Copy link
Copy Markdown
Member Author

I do not mind, but does it make difference if most of configure macros are HAVE_* and this is standard?
(...)
I do not know if this is a formal standard, but many projects use HAVE_*.

It's fine to use HAVE_xxx macros to build a project. What bothers me is that Python exposes these macros in its public C API.

It's rare that a project exposes its HAVE_xxx macros in public header files. Example of a search on my Fedora 44 which has 6,130 header files in /usr/include:

$ find -name "*.h"|wc -l
6130

$ grep -l 'define HAVE_' -R /usr/include/|grep -v /python3|grep -v /pypy3
/usr/include/ncurses/etip.h
/usr/include/ncursesw/etip.h
/usr/include/etip.h
/usr/include/expat_config.h
/usr/include/freetype2/freetype/config/ftconfig-64.h
/usr/include/tcl-private/unix/tclUnixPort.h

All macros:

Details
vstinner@vstinner-thinkpadp1gen3$ grep 'define HAVE_' -R /usr/include/|grep -v /python3|grep -v /pypy3
/usr/include/ncurses/etip.h:#define HAVE_BUILTIN_H 0
/usr/include/ncurses/etip.h:#define HAVE_EXCEPTION 1
/usr/include/ncurses/etip.h:#define HAVE_GXX_BUILTIN_H 0
/usr/include/ncurses/etip.h:#define HAVE_GPP_BUILTIN_H 0
/usr/include/ncurses/etip.h:#define HAVE_IOSTREAM 1
/usr/include/ncurses/etip.h:#define HAVE_NEW 1
/usr/include/ncurses/etip.h:#define HAVE_TYPEINFO 1
/usr/include/ncurses/etip.h:#define HAVE_VALUES_H 0
/usr/include/ncursesw/etip.h:#define HAVE_BUILTIN_H 0
/usr/include/ncursesw/etip.h:#define HAVE_EXCEPTION 1
/usr/include/ncursesw/etip.h:#define HAVE_GXX_BUILTIN_H 0
/usr/include/ncursesw/etip.h:#define HAVE_GPP_BUILTIN_H 0
/usr/include/ncursesw/etip.h:#define HAVE_IOSTREAM 1
/usr/include/ncursesw/etip.h:#define HAVE_NEW 1
/usr/include/ncursesw/etip.h:#define HAVE_TYPEINFO 1
/usr/include/ncursesw/etip.h:#define HAVE_VALUES_H 0
/usr/include/etip.h:#define HAVE_BUILTIN_H 0
/usr/include/etip.h:#define HAVE_EXCEPTION 1
/usr/include/etip.h:#define HAVE_GXX_BUILTIN_H 0
/usr/include/etip.h:#define HAVE_GPP_BUILTIN_H 0
/usr/include/etip.h:#define HAVE_IOSTREAM 1
/usr/include/etip.h:#define HAVE_NEW 1
/usr/include/etip.h:#define HAVE_TYPEINFO 1
/usr/include/etip.h:#define HAVE_VALUES_H 0
/usr/include/expat_config.h:#define HAVE_ARC4RANDOM 1
/usr/include/expat_config.h:#define HAVE_ARC4RANDOM_BUF 1
/usr/include/expat_config.h:#define HAVE_CXX11 1
/usr/include/expat_config.h:#define HAVE_DLFCN_H 1
/usr/include/expat_config.h:#define HAVE_FCNTL_H 1
/usr/include/expat_config.h:#define HAVE_GETENTROPY 1
/usr/include/expat_config.h:#define HAVE_GETPAGESIZE 1
/usr/include/expat_config.h:#define HAVE_GETRANDOM 1
/usr/include/expat_config.h:#define HAVE_INTTYPES_H 1
/usr/include/expat_config.h:#define HAVE_MMAP 1
/usr/include/expat_config.h:#define HAVE_STDINT_H 1
/usr/include/expat_config.h:#define HAVE_STDIO_H 1
/usr/include/expat_config.h:#define HAVE_STDLIB_H 1
/usr/include/expat_config.h:#define HAVE_STRINGS_H 1
/usr/include/expat_config.h:#define HAVE_STRING_H 1
/usr/include/expat_config.h:#define HAVE_SYSCALL_GETRANDOM 1
/usr/include/expat_config.h:#define HAVE_SYS_PARAM_H 1
/usr/include/expat_config.h:#define HAVE_SYS_STAT_H 1
/usr/include/expat_config.h:#define HAVE_SYS_TYPES_H 1
/usr/include/expat_config.h:#define HAVE_UNISTD_H 1
/usr/include/freetype2/freetype/config/ftconfig-64.h:#define HAVE_UNISTD_H 1
/usr/include/freetype2/freetype/config/ftconfig-64.h:#define HAVE_FCNTL_H 1
/usr/include/tcl-private/unix/tclUnixPort.h:#	    define HAVE_PUTENV_THAT_COPIES	1

Projects built with <Python.h> should implement their own function and header checks, not rely on HAVE_xxx macros. For example, Python can built on a machine and installed on a different machine where HAVE_xxx macros are outdated.

@serhiy-storchaka

Copy link
Copy Markdown
Member

Then the problem is not in having HAVE_* names, but in exposing them in Python.h. What other libraries do to avoid this?

@vstinner
vstinner merged commit 315ed16 into python:main Sep 22, 2026
53 checks passed
@vstinner
vstinner deleted the rename_iconv_macro branch September 22, 2026 05:28
@vstinner

Copy link
Copy Markdown
Member Author

Then the problem is not in having HAVE_* names, but in exposing them in Python.h. What other libraries do to avoid this?

It seems like they do no include the "config.h" file in their public C API.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

3 participants