This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: [C API] Clean-up the Python.h header file
Type: Stage: resolved
Components: C API Versions: Python 3.11
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: corona10, twouters, vstinner
Priority: normal Keywords: patch

Created on 2021-10-11 20:08 by vstinner, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 28883 merged vstinner, 2021-10-11 20:22
PR 28888 merged vstinner, 2021-10-11 21:04
PR 28912 merged vstinner, 2021-10-13 01:13
PR 28913 merged vstinner, 2021-10-13 01:27
PR 28914 merged vstinner, 2021-10-13 01:43
PR 28922 merged vstinner, 2021-10-13 12:16
PR 28923 merged vstinner, 2021-10-13 12:48
PR 28924 merged vstinner, 2021-10-13 13:44
PR 28960 merged vstinner, 2021-10-14 22:37
PR 28963 merged vstinner, 2021-10-14 23:24
PR 28973 merged vstinner, 2021-10-15 10:07
PR 29015 merged corona10, 2021-10-18 08:27
PR 29027 merged vstinner, 2021-10-18 10:38
Messages (19)
msg403675 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2021-10-11 20:08
I would like to remove #include <stdlib.h> from Python.h, and make Python.h smaller.
msg403684 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2021-10-11 20:51
New changeset 47717d1186563695e798b40350d15b00d04a5237 by Victor Stinner in branch 'main':
bpo-45434: Cleanup Python.h header file (GH-28883)
https://github.com/python/cpython/commit/47717d1186563695e798b40350d15b00d04a5237
msg403689 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2021-10-11 21:30
New changeset 03ea862b8a8234176761240ba122254e9eb11663 by Victor Stinner in branch 'main':
bpo-45434: Python.h no longer includes <stdlib.h> (GH-28888)
https://github.com/python/cpython/commit/03ea862b8a8234176761240ba122254e9eb11663
msg403775 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2021-10-13 01:39
New changeset 489176e4285314f9ea87b8bd91fe1d55d9af2c42 by Victor Stinner in branch 'main':
bpo-45434: Convert Py_GETENV() macro to a function (GH-28912)
https://github.com/python/cpython/commit/489176e4285314f9ea87b8bd91fe1d55d9af2c42
msg403785 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2021-10-13 02:38
New changeset c63623a0a6892ce8683dbf8c769793ea897e6ba8 by Victor Stinner in branch 'main':
bpo-45434: bytearrayobject.h no longer includes <stdarg.h> (GH-28913)
https://github.com/python/cpython/commit/c63623a0a6892ce8683dbf8c769793ea897e6ba8
msg403829 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2021-10-13 13:03
New changeset 97308dfcdc0696e0b116c37386e2ff4d72e6c3f4 by Victor Stinner in branch 'main':
bpo-45434: Move _Py_BEGIN_SUPPRESS_IPH to pycore_fileutils.h (GH-28922)
https://github.com/python/cpython/commit/97308dfcdc0696e0b116c37386e2ff4d72e6c3f4
msg403831 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2021-10-13 13:22
New changeset bbe7497c5a44c2b4ec726605cf5a9086ba02daf1 by Victor Stinner in branch 'main':
bpo-45434: Remove pystrhex.h header file (GH-28923)
https://github.com/python/cpython/commit/bbe7497c5a44c2b4ec726605cf5a9086ba02daf1
msg403841 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2021-10-13 15:21
Oh, Include/errcode.h *is* used by PyRun_InteractiveOneFlags() and its variants. It's mentioned in its documentation:

   Returns ``0`` when the input was
   executed successfully, ``-1`` if there was an exception, or an error code
   from the :file:`errcode.h` include file distributed as part of Python if
   there was a parse error.  (Note that :file:`errcode.h` is not included by
   :file:`Python.h`, so must be included specifically if needed.)
msg403842 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2021-10-13 15:22
New changeset 713bb19356bce9b8f2b95461834fe1dae505f889 by Victor Stinner in branch 'main':
bpo-45434: Mark the PyTokenizer C API as private (GH-28924)
https://github.com/python/cpython/commit/713bb19356bce9b8f2b95461834fe1dae505f889
msg403843 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2021-10-13 15:24
PyRun_InteractiveOneObjectEx() returns a single error code of errcode.h: E_EOF (11):

    if (mod == NULL) {
        _PyArena_Free(arena);
        if (errcode == E_EOF) {
            PyErr_Clear();
            return E_EOF;
        }
        return -1;
    }
msg403859 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2021-10-13 17:26
New changeset aac29af6785712019d34f1a7f15b3c408a4f68ae by Victor Stinner in branch 'main':
bpo-45434: pyport.h no longer includes <stdlib.h> (GH-28914)
https://github.com/python/cpython/commit/aac29af6785712019d34f1a7f15b3c408a4f68ae
msg403940 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2021-10-14 20:05
I tried to remove the <string.h> include from Python.h:

-#include <string.h>               // memcpy()

... but it required me to modify 100+ files. I don't know the exact number, I gave up after 100 files. I was near half of C extensions built by setup.py, so the number total may be around 150 files which should include explicitly <string.h>.

"#include <errno.h>" can now be removed from Python.h, but I'm not sure if it's a good idea. I started by removing <stdlib.h> and my plan is to see if it breaks third party C extensions. Right now, Cython is broken which prevents me to use my https://github.com/vstinner/pythonci tool :-(
msg403959 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2021-10-14 23:09
New changeset 284994762d820d8e09cc019f8f7c4bc501e37dd4 by Victor Stinner in branch 'main':
bpo-45434: Limited Python.h no longer includes stdio.h (GH-28960)
https://github.com/python/cpython/commit/284994762d820d8e09cc019f8f7c4bc501e37dd4
msg403963 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2021-10-14 23:50
New changeset 7076bef8ba8836a19d5033f4ceb8eb9837de2301 by Victor Stinner in branch 'main':
bpo-45434: Remove useless space in includes (GH-28963)
https://github.com/python/cpython/commit/7076bef8ba8836a19d5033f4ceb8eb9837de2301
msg404002 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2021-10-15 11:06
New changeset 105582e74c1817bc6a9d99bcb6540b34a3367292 by Victor Stinner in branch 'main':
bpo-45434: Remove Include/eval.h header file (GH-28973)
https://github.com/python/cpython/commit/105582e74c1817bc6a9d99bcb6540b34a3367292
msg404162 - (view) Author: Dong-hee Na (corona10) * (Python committer) Date: 2021-10-18 08:31
New changeset fd03917786a9036ee87b7df604dfb260cc2420c9 by Dong-hee Na in branch 'main':
bpo-45434: Include stdlib.h for specialize stat (GH-29015)
https://github.com/python/cpython/commit/fd03917786a9036ee87b7df604dfb260cc2420c9
msg404170 - (view) Author: Thomas Wouters (twouters) * (Python committer) Date: 2021-10-18 09:47
Victor, what's the benefit of doing this work? Are there real problems this fixes? I'm worried about the churn in third-party extensions, examples, tutorials, etc, especially for audiences that upon seeing a compiler error won't immediately realise they need to include stdlib.h themselves. (Also, since Python.h sets things like _POSIX_C_SOURCE and _XOPEN_SOURCE, including them in the wrong order can produce even more confusing errors, or errors that only appear on some platforms.)
msg404172 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2021-10-18 09:58
I reopen the issue.
msg404283 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2021-10-19 10:10
New changeset 52af0756b2ffc6788e364971d05cdaf127d77d5a by Victor Stinner in branch 'main':
bpo-45434: Only exclude <stdlib.h> in Python 3.11 limited C API (GH-29027)
https://github.com/python/cpython/commit/52af0756b2ffc6788e364971d05cdaf127d77d5a
History
Date User Action Args
2022-04-11 14:59:51adminsetgithub: 89597
2021-10-19 15:01:04vstinnersetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2021-10-19 10:10:26vstinnersetmessages: + msg404283
2021-10-18 10:38:48vstinnersetstage: resolved -> patch review
pull_requests: + pull_request27298
2021-10-18 09:58:07vstinnersetstatus: closed -> open
resolution: fixed -> (no value)
messages: + msg404172
2021-10-18 09:47:47twouterssetnosy: + twouters
messages: + msg404170
2021-10-18 08:31:32corona10setmessages: + msg404162
2021-10-18 08:27:46corona10setnosy: + corona10

pull_requests: + pull_request27295
2021-10-15 11:06:09vstinnersetmessages: + msg404002
2021-10-15 10:07:13vstinnersetpull_requests: + pull_request27261
2021-10-15 06:43:20vstinnersetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2021-10-14 23:50:12vstinnersetmessages: + msg403963
2021-10-14 23:24:18vstinnersetpull_requests: + pull_request27252
2021-10-14 23:09:13vstinnersetmessages: + msg403959
2021-10-14 22:37:51vstinnersetpull_requests: + pull_request27249
2021-10-14 20:05:29vstinnersetmessages: + msg403940
2021-10-13 17:26:00vstinnersetmessages: + msg403859
2021-10-13 15:24:19vstinnersetmessages: + msg403843
2021-10-13 15:22:18vstinnersetmessages: + msg403842
2021-10-13 15:21:56vstinnersetmessages: + msg403841
2021-10-13 13:44:05vstinnersetpull_requests: + pull_request27214
2021-10-13 13:22:43vstinnersetmessages: + msg403831
2021-10-13 13:03:43vstinnersetmessages: + msg403829
2021-10-13 12:48:18vstinnersetpull_requests: + pull_request27213
2021-10-13 12:16:08vstinnersetpull_requests: + pull_request27212
2021-10-13 02:38:03vstinnersetmessages: + msg403785
2021-10-13 01:43:01vstinnersetpull_requests: + pull_request27204
2021-10-13 01:39:57vstinnersetmessages: + msg403775
2021-10-13 01:27:19vstinnersetpull_requests: + pull_request27203
2021-10-13 01:13:39vstinnersetpull_requests: + pull_request27202
2021-10-11 21:30:09vstinnersetmessages: + msg403689
2021-10-11 21:04:11vstinnersetpull_requests: + pull_request27183
2021-10-11 20:51:40vstinnersetmessages: + msg403684
2021-10-11 20:22:29vstinnersetkeywords: + patch
stage: patch review
pull_requests: + pull_request27180
2021-10-11 20:08:05vstinnercreate