classification
Title: setup.py should set Py_BUILD_CORE_MODULE as defined macro
Type: behavior Stage:
Components: Build Versions: Python 3.11, Python 3.10
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: christian.heimes Nosy List: christian.heimes, pablogsal, vstinner
Priority: normal Keywords: patch

Created on 2021-04-29 09:02 by christian.heimes, last changed 2021-05-01 11:34 by christian.heimes.

Pull Requests
URL Status Linked Edit
PR 25713 open christian.heimes, 2021-04-29 09:04
Messages (5)
msg392293 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2021-04-29 09:02
CPython's setup.py contains lots of

  extra_compile_args = ['-DPy_BUILD_CORE_MODULE']

to mark modules as core module. Extra compiler args is the wrong option. It's also tedious and err-prone to define the macro in each and every Extension() class instance.

The compiler flag should be set automatically for all core extensions and it should use be set using the correct option define_macros.
msg392295 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2021-04-29 09:22
Related to the change:

It looks like we can also cleanup Modules/Setup and remove -DPy_BUILD_CORE_BUILTIN and -DPy_BUILD_CORE_MODULE. Modules/makesetup adds $PY_BUILTIN_MODULE_CFLAGS in the compile step. The variable is defined as

    PY_BUILTIN_MODULE_CFLAGS= $(PY_STDMODULE_CFLAGS) -DPy_BUILD_CORE_BUILTIN
msg392332 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2021-04-29 16:55
I would prefer to limit the usage of the internal C API in extension modules built as dynamic libraries. See bpo-41111: "[C API] Convert a few stdlib extensions to the limited C API (PEP 384)".

Also, this issue is motived by PR 25653 which requires to use the internal C API in many C extensions. But I proposed a different approach, PR 25710, which prevents that.
msg392333 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2021-04-29 16:55
> It looks like we can also cleanup Modules/Setup and remove -DPy_BUILD_CORE_BUILTIN and -DPy_BUILD_CORE_MODULE. Modules/makesetup adds $PY_BUILTIN_MODULE_CFLAGS in the compile step.

Oh, I didn't notice.
msg392587 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2021-05-01 11:34
> I would prefer to limit the usage of the internal C API in extension modules built as dynamic libraries. See bpo-41111: "[C API] Convert a few stdlib extensions to the limited C API (PEP 384)".

Let's make this a coordinated effort in 3.11. I suggest that we slowly remove functions from Py_BUILD_CORE_MODULE. For now I'm interested to clean up and simplify setup.py.
History
Date User Action Args
2021-05-01 11:34:54christian.heimessetmessages: + msg392587
2021-04-29 16:55:37vstinnersetmessages: + msg392333
2021-04-29 16:55:05vstinnersetmessages: + msg392332
2021-04-29 09:22:43christian.heimessetmessages: + msg392295
stage: patch review ->
2021-04-29 09:04:49christian.heimessetkeywords: + patch
stage: patch review
pull_requests: + pull_request24402
2021-04-29 09:02:26christian.heimescreate