Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpo-39355: making Python.h compatible with C++20 compilers #31282

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Doc/whatsnew/3.11.rst
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,9 @@ Build Changes
* The :mod:`tkinter` package now requires Tcl/Tk version 8.5.12 or newer.
(Contributed by Serhiy Storchaka in :issue:`46996`.)

* Python.h is now compatible with C++20 compilers. (Contributed by by Hasan
Aliyev in :issue:`39355`.)


C API Changes
=============
Expand Down
4 changes: 2 additions & 2 deletions Include/cpython/import.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ PyMODINIT_FUNC PyInit__imp(void);
PyAPI_FUNC(int) _PyImport_IsInitialized(PyInterpreterState *);

PyAPI_FUNC(PyObject *) _PyImport_GetModuleId(_Py_Identifier *name);
PyAPI_FUNC(int) _PyImport_SetModule(PyObject *name, PyObject *module);
PyAPI_FUNC(int) _PyImport_SetModuleString(const char *name, PyObject* module);
PyAPI_FUNC(int) _PyImport_SetModule(PyObject *name, PyObject *mod);
PyAPI_FUNC(int) _PyImport_SetModuleString(const char *name, PyObject *mod);

PyAPI_FUNC(void) _PyImport_AcquireLock(void);
PyAPI_FUNC(int) _PyImport_ReleaseLock(void);
Expand Down
4 changes: 2 additions & 2 deletions Include/cpython/warnings.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ PyAPI_FUNC(int) PyErr_WarnExplicitObject(
PyObject *message,
PyObject *filename,
int lineno,
PyObject *module,
PyObject *mod,
PyObject *registry);

PyAPI_FUNC(int) PyErr_WarnExplicitFormat(
PyObject *category,
const char *filename, int lineno,
const char *module, PyObject *registry,
const char *mod, PyObject *registry,
const char *format, ...);

// DEPRECATED: Use PyErr_WarnEx() instead.
Expand Down
4 changes: 2 additions & 2 deletions Include/modsupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ PyAPI_FUNC(int) PyModule_AddIntConstant(PyObject *, const char *, long);
PyAPI_FUNC(int) PyModule_AddStringConstant(PyObject *, const char *, const char *);
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03090000
/* New in 3.9 */
PyAPI_FUNC(int) PyModule_AddType(PyObject *module, PyTypeObject *type);
PyAPI_FUNC(int) PyModule_AddType(PyObject *mod, PyTypeObject *type);
#endif /* Py_LIMITED_API */
#define PyModule_AddIntMacro(m, c) PyModule_AddIntConstant(m, #c, c)
#define PyModule_AddStringMacro(m, c) PyModule_AddStringConstant(m, #c, c)
Expand All @@ -165,7 +165,7 @@ PyAPI_FUNC(int) PyModule_AddType(PyObject *module, PyTypeObject *type);
/* New in 3.5 */
PyAPI_FUNC(int) PyModule_SetDocString(PyObject *, const char *);
PyAPI_FUNC(int) PyModule_AddFunctions(PyObject *, PyMethodDef *);
PyAPI_FUNC(int) PyModule_ExecDef(PyObject *module, PyModuleDef *def);
PyAPI_FUNC(int) PyModule_ExecDef(PyObject *mod, PyModuleDef *def);
#endif

#define Py_CLEANUP_SUPPORTED 0x20000
Expand Down
2 changes: 1 addition & 1 deletion Include/warnings.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ PyAPI_FUNC(int) PyErr_WarnExplicit(
const char *message, /* UTF-8 encoded string */
const char *filename, /* decoded from the filesystem encoding */
int lineno,
const char *module, /* UTF-8 encoded string */
const char *mod, /* UTF-8 encoded string */
PyObject *registry);

#ifndef Py_LIMITED_API
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Make Python.h compatible with C++20 compilers.
Copy link
Member

Choose a reason for hiding this comment

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

Would you mind to explain that the change is to avoid the usage of "module" which became a keyword in C++20?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes @vstinner, you are right!

I have mentioned in bugs.python.org, about this change.
After making a little research, i realized that this "module" keyword has meaning with "export"
Sorry i am not c++ expert )) If somebody have knowledge about it, share it plz :)

Copy link
Member

Choose a reason for hiding this comment

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

I don't understand your comment. Do you mean that https://bugs.python.org/issue39355 is not a bug and the Python C API is compatible with C++20?

If there is an issue, please explain the change in NEWS entry. "Make Python.h compatible with C++20 compilers." is not enough.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@vstinner I asked question ))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@vstinner it was interesting for me, if "module" keyword has meaning with "export" how gcc will treat "module" without "export" keyword ?

Copy link
Member

Choose a reason for hiding this comment

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

So far, I failed to reproduce https://bugs.python.org/issue39355 issue: using the Python C API in C++ doesn't emit any compiler warning or compiler error. See my test: https://bugs.python.org/issue39355#msg416256

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@vstinner thanks for great investigation!

Copy link
Member

Choose a reason for hiding this comment

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

You're welcome. I'm now considering serious to convert #32175 to a real unit test to make sure that the Python C API is compatible with C++.

Copy link
Member

Choose a reason for hiding this comment

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