Issue 39355: The Python library will not compile with a C++2020 compiler because the code uses the reserved “module” keyword
Created on 2020-01-16 09:25 by aCuria, last changed 2022-04-11 14:59 by admin. This issue is now closed.
| Pull Requests | |||
|---|---|---|---|
| URL | Status | Linked | Edit |
| PR 28359 | closed | AliyevH, 2021-09-15 17:02 | |
| PR 28373 | closed | AliyevH, 2021-09-15 18:54 | |
| PR 31282 | closed | AliyevH, 2022-02-11 17:28 | |
| PR 32175 | open | vstinner, 2022-03-29 13:05 | |
| Messages (19) | |||
|---|---|---|---|
| msg360103 - (view) | Author: Keith (aCuria) | Date: 2020-01-16 09:25 | |
The Python library will not compile with a C++2020 compiler because the code uses the reserved “module” keyword
For example, in warnings.h, we have the following code:
#ifndef Py_LIMITED_API
PyAPI_FUNC(int) PyErr_WarnExplicitObject(
PyObject *category,
PyObject *message,
PyObject *filename,
int lineno,
PyObject *module,
PyObject *registry);
In modsupport.h we have the following code:
PyAPI_FUNC(int) PyModule_ExecDef(PyObject *module, PyModuleDef *def);
We can fix this by using a different identifier, for example “pyModule” instead of “module”
|
|||
| msg360106 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * ![]() |
Date: 2020-01-16 09:37 | |
Names of arguments can be just removed from function declarations in header files. |
|||
| msg360110 - (view) | Author: STINNER Victor (vstinner) * ![]() |
Date: 2020-01-16 09:52 | |
Qt has a similar issue with "slots": bpo-1086854 and bpo-38007. |
|||
| msg360115 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * ![]() |
Date: 2020-01-16 10:31 | |
Qt has different issue. "slots" is not a keyword, and the issue can be avoided by including Python.h before Qt.h or undefining the "slots" macro. It could be a harder issue if "module" would be a field name of a public structure. But names of arguments are not part of the API. |
|||
| msg398915 - (view) | Author: Hasan (AliyevH) * | Date: 2021-08-04 17:05 | |
If nobody works, i would like to solve this |
|||
| msg399073 - (view) | Author: STINNER Victor (vstinner) * ![]() |
Date: 2021-08-06 11:22 | |
Please go ahead. Anyone is free to propose a fix. |
|||
| msg399975 - (view) | Author: Hasan (AliyevH) * | Date: 2021-08-20 15:27 | |
We have tested with cxx-modules that issue. module is just a specifier for export (only export is a compiler-based keyword in >= C++20) That's why we can use module as argument name and there's no need to rename or delete *module arguments from header files. What do you recommend to do? http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1103r3.pdf |
|||
| msg401109 - (view) | Author: Keith (aCuria) | Date: 2021-09-06 02:13 | |
the word "module" should be treated as a reserved keyword. Any use of "module" as an argument name should be changed to something else throughout the code base. On Fri, Aug 20, 2021 at 11:28 PM Hasan <report@bugs.python.org> wrote: > > Hasan <hasan.aleeyev@gmail.com> added the comment: > > We have tested with cxx-modules that issue. > module is just a specifier for export (only export is a compiler-based > keyword in >= C++20) > That's why we can use module as argument name and there's no need to > rename or delete *module arguments from header files. > > What do you recommend to do? > > http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1103r3.pdf > > ---------- > > _______________________________________ > Python tracker <report@bugs.python.org> > <https://bugs.python.org/issue39355> > _______________________________________ > |
|||
| msg401778 - (view) | Author: Hasan (AliyevH) * | Date: 2021-09-14 12:39 | |
Okey. There will be huge changes for this issue as this keyword has been used in a lot of places. That's why i will try to send pull requests module by module to keep it clean and simple for review. |
|||
| msg413056 - (view) | Author: Erlend E. Aasland (erlendaasland) * ![]() |
Date: 2022-02-11 10:42 | |
> There will be huge changes for this issue as this keyword has been used in a lot of places. For external extension modules, it should be sufficient to change only the exposed headers; that is Include/*.h and Include/cpython/*.h. We should also change the AC tool, since that may be used by external projects. |
|||
| msg414646 - (view) | Author: STINNER Victor (vstinner) * ![]() |
Date: 2022-03-07 09:32 | |
> The Python library will not compile with a C++2020 compiler because the code uses the reserved “module” keyword What is the error message? How can the error be reproduced? |
|||
| msg414654 - (view) | Author: Keith (aCuria) | Date: 2022-03-07 10:50 | |
Compile with a compiler supporting the C++20 core feature (Modules) https://en.cppreference.com/w/cpp/compiler_support In visual studio, use C/C++ > Language > CPP Language Standard > C++20 or higher On Mon, Mar 7, 2022 at 5:32 PM STINNER Victor <report@bugs.python.org> wrote: > > STINNER Victor <vstinner@python.org> added the comment: > > > The Python library will not compile with a C++2020 compiler because the > code uses the reserved “module” keyword > > What is the error message? How can the error be reproduced? > > ---------- > > _______________________________________ > Python tracker <report@bugs.python.org> > <https://bugs.python.org/issue39355> > _______________________________________ > |
|||
| msg416253 - (view) | Author: STINNER Victor (vstinner) * ![]() |
Date: 2022-03-29 12:07 | |
If I build a C++ extension with -std=c++20, I get a compiler error on PyModuleDef_HEAD_INIT: Modules/_testcppext.cpp:419:5: error: either all initializer clauses should be designated or none of them should be 419 | .m_name = "_testcppext", | ^ Code: --- static struct PyModuleDef module = { PyModuleDef_HEAD_INIT, .m_name = "_testcppext", .m_doc = module_doc, ... }; --- Macro defined as (simplified code): --- #define PyObject_HEAD_INIT(type) \ { 1, type }, #define PyModuleDef_HEAD_INIT { \ PyObject_HEAD_INIT(NULL) \ NULL, /* m_init */ \ 0, /* m_index */ \ NULL, /* m_copy */ \ } --- |
|||
| msg416254 - (view) | Author: STINNER Victor (vstinner) * ![]() |
Date: 2022-03-29 12:53 | |
When I wrote a PR to use the C header file pythoncapi_compat.h in the datatable C++ project, I got multiple C++ compiler warnings in static inline functions and in some macros: https://github.com/h2oai/datatable/pull/3231#issuecomment-1032864790 * Usage of NULL * Usage of "old-style cast" like (ssize_t)1 or (PyObject*)obj I solved this issue in pythoncapi_compat.h by using reinterpret_cast and nullptr: * https://github.com/python/pythoncapi_compat/commit/347746379f79fa091017e23427932c9f9980234d * https://github.com/python/pythoncapi_compat/pull/18 * https://github.com/h2oai/datatable/pull/3237 By the way, pythoncapi_compat.h no longer uses "module": https://github.com/python/pythoncapi_compat/pull/22 The Python C API has similar issues, but warnings about NULL and old-style cast depend on the C++ compiler flags: * -Wzero-as-null-pointer-constant * -Wold-style-cast |
|||
| msg416255 - (view) | Author: STINNER Victor (vstinner) * ![]() |
Date: 2022-03-29 13:01 | |
STINNER Victor: > What is the error message? How can the error be reproduced? Keith (aCuria): > Compile with a compiler supporting the C++20 core feature (Modules) > https://en.cppreference.com/w/cpp/compiler_support I built a C++ extension which calls PyModule_AddType(): I get no warning. I tested GCC and LLVM clang. Commands: clang -Wno-unused-result -g -Og -Wall -O0 -fPIC -I/home/vstinner/python/main/Include -I/home/vstinner/python/main -c Modules/_testcppext.cpp -o build/temp.linux-x86_64-3.11-pydebug/Modules/_testcppext.o -I/home/vstinner/python -Werror -Wall -Wextra -Wconversion -Wno-typedef-redefinition -std=c++20 -Wzero-as-null-pointer-constant -Wold-style-cast gcc -Wno-unused-result -g -Og -Wall -O0 -fPIC -I/home/vstinner/python/main/Include -I/home/vstinner/python/main -c Modules/_testcppext.cpp -o build/temp.linux-x86_64-3.11-pydebug/Modules/_testcppext.o -I/home/vstinner/python -Werror -Wall -Wextra -Wconversion -Wno-typedef-redefinition -std=c++20 -Wzero-as-null-pointer-constant -Wold-style-cast Reformatted commands: ['clang', '-Wno-unused-result', '-g', '-Og', '-Wall', '-O0', '-fPIC', '-I/home/vstinner/python/main/Include', '-I/home/vstinner/python/main', '-c', 'Modules/_testcppext.cpp', '-o', 'build/temp.linux-x86_64-3.11-pydebug/Modules/_testcppext.o', '-I/home/vstinner/python', '-Werror', '-Wall', '-Wextra', '-Wconversion', '-Wno-typedef-redefinition', '-std=c++20', '-Wzero-as-null-pointer-constant', '-Wold-style-cast'] ['gcc', '-Wno-unused-result', '-g', '-Og', '-Wall', '-O0', '-fPIC', '-I/home/vstinner/python/main/Include', '-I/home/vstinner/python/main', '-c', 'Modules/_testcppext.cpp', '-o', 'build/temp.linux-x86_64-3.11-pydebug/Modules/_testcppext.o', '-I/home/vstinner/python', '-Werror', '-Wall', '-Wextra', '-Wconversion', '-Wno-typedef-redefinition', '-std=c++20', '-Wzero-as-null-pointer-constant', '-Wold-style-cast'] |
|||
| msg416256 - (view) | Author: STINNER Victor (vstinner) * ![]() |
Date: 2022-03-29 13:07 | |
I wrote the draft PR GH-32175 to test https://bugs.python.org/issue39355 and GH-31282. Problem: I don't get any compiler warning or error about the "module" C++20 keyword. I tested GCC 11.2.1 and clang 13.0.0 of Fedora 35. |
|||
| msg416257 - (view) | Author: STINNER Victor (vstinner) * ![]() |
Date: 2022-03-29 13:39 | |
The C++20 "module" keyword is "contextual keyword". It's only a keyword if the first line if a file contains "module". * https://en.cppreference.com/w/cpp/language/modules#Module_declarations * https://en.cppreference.com/w/cpp/keyword/module It's not the case in any .h file of the Python C API, so Python doesn't need to be changed. I close the issue. |
|||
| msg416259 - (view) | Author: Erlend E. Aasland (erlendaasland) * ![]() |
Date: 2022-03-29 13:44 | |
> The C++20 "module" keyword is "contextual keyword". It's only a keyword if the first line if a file contains "module". Great! No changes needed. Thanks for investigating. |
|||
| msg416360 - (view) | Author: STINNER Victor (vstinner) * ![]() |
Date: 2022-03-30 14:14 | |
Follow-up issue: bpo-47165 "[C API] Test that the Python C API is compatible with C++". |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:59:25 | admin | set | github: 83536 |
| 2022-03-30 14:14:56 | vstinner | set | messages: + msg416360 |
| 2022-03-29 15:09:20 | corona10 | set | nosy:
+ corona10 |
| 2022-03-29 13:44:31 | erlendaasland | set | messages: + msg416259 |
| 2022-03-29 13:39:30 | vstinner | set | status: open -> closed resolution: not a bug messages: + msg416257 stage: patch review -> resolved |
| 2022-03-29 13:07:39 | vstinner | set | messages: + msg416256 |
| 2022-03-29 13:05:26 | vstinner | set | pull_requests: + pull_request30252 |
| 2022-03-29 13:01:51 | vstinner | set | messages:
+ msg416255 versions: + Python 3.10, Python 3.11, - Python 3.7, Python 3.8 |
| 2022-03-29 12:53:17 | vstinner | set | messages: + msg416254 |
| 2022-03-29 12:07:02 | vstinner | set | messages: + msg416253 |
| 2022-03-07 10:50:38 | aCuria | set | messages: + msg414654 |
| 2022-03-07 09:32:00 | vstinner | set | messages: + msg414646 |
| 2022-02-11 17:28:41 | AliyevH | set | pull_requests: + pull_request29442 |
| 2022-02-11 10:42:11 | erlendaasland | set | messages: + msg413056 |
| 2022-02-11 10:41:58 | erlendaasland | set | messages: - msg413055 |
| 2022-02-11 10:41:15 | erlendaasland | set | nosy:
+ erlendaasland messages: + msg413055 |
| 2021-09-15 18:54:25 | AliyevH | set | pull_requests: + pull_request26787 |
| 2021-09-15 17:02:23 | AliyevH | set | keywords:
+ patch stage: needs patch -> patch review pull_requests: + pull_request26773 |
| 2021-09-14 12:39:47 | AliyevH | set | messages: + msg401778 |
| 2021-09-06 02:13:43 | aCuria | set | messages: + msg401109 |
| 2021-08-20 15:27:05 | AliyevH | set | messages: + msg399975 |
| 2021-08-06 11:22:12 | vstinner | set | messages: + msg399073 |
| 2021-08-04 17:05:11 | AliyevH | set | nosy:
+ AliyevH messages: + msg398915 |
| 2021-06-22 14:40:32 | petr.viktorin | set | nosy:
+ petr.viktorin |
| 2020-01-16 10:31:54 | serhiy.storchaka | set | messages: + msg360115 |
| 2020-01-16 09:52:11 | vstinner | set | messages: + msg360110 |
| 2020-01-16 09:37:16 | serhiy.storchaka | set | type: enhancement versions: - Python 2.7, Python 3.5, Python 3.6 keywords: + easy (C) nosy: + serhiy.storchaka messages:
+ msg360106 |
| 2020-01-16 09:33:25 | xtreak | set | nosy:
+ vstinner |
| 2020-01-16 09:25:21 | aCuria | create | |

