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

[3.12] extern "C" not closed in tracemalloc.h when using Py_LIMITED_API #127902

Closed
mitya57 opened this issue Dec 13, 2024 · 4 comments
Closed

[3.12] extern "C" not closed in tracemalloc.h when using Py_LIMITED_API #127902

mitya57 opened this issue Dec 13, 2024 · 4 comments
Labels
3.12 bugs and security fixes type-bug An unexpected behavior, bug, or error

Comments

@mitya57
Copy link
Contributor

mitya57 commented Dec 13, 2024

Bug report

Bug description:

When building PyQt6 with the latest 3.12 branch, I get the following error:

g++ -c -pipe -g -O2 -ffile-prefix-map=/pyqt6=. -fstack-protector-strong -fstack-clash-protection -Wformat -Werror=format-security -fcf-protection -Wdate-time -D_FORTIFY_SOURCE=2 -O2 -fno-exceptions -Wall -Wextra -D_REENTRANT -fPIC -DPy_LIMITED_API=0x03090000 -DQT_NO_EXCEPTIONS -DQT_NO_DEBUG -DQT_PLUGIN -DQT_CORE_LIB -I. -I/usr/include/dbus-1.0 -I/usr/lib/x86_64-linux-gnu/dbus-1.0/include -I/usr/include/python3.12 -I/usr/include/x86_64-linux-gnu/qt6 -I/usr/include/x86_64-linux-gnu/qt6/QtCore -I. -I/usr/lib/x86_64-linux-gnu/qt6/mkspecs/linux-g++ -o dbus.o ../../../../dbus/dbus.cpp
In file included from /usr/include/c++/14/utility:68,
                 from /usr/include/x86_64-linux-gnu/qt6/QtCore/qglobal.h:15,
                 from /usr/include/x86_64-linux-gnu/qt6/QtCore/qcoreapplication.h:7,
                 from /usr/include/x86_64-linux-gnu/qt6/QtCore/QCoreApplication:1,
                 from ../../../../dbus/dbus.cpp:29:
/usr/include/c++/14/bits/stl_relops.h:86:5: error: template with C linkage
   86 |     template <class _Tp>
      |     ^~~~~~~~
In file included from /usr/include/python3.12/Python.h:107,
                 from /usr/include/dbus-1.0/dbus/dbus-python.h:34,
                 from ../../../../dbus/dbus.cpp:27:
/usr/include/python3.12/tracemalloc.h:4:1: note: ‘extern "C"’ linkage started here
    4 | extern "C" {
      | ^~~~~~~~~~

This happened because of the commit 65bca19, which changed the structure of tracemalloc.h to the following:

#ifndef Py_TRACEMALLOC_H
#define Py_TRACEMALLOC_H
#ifdef __cplusplus
extern "C" {
#endif

#ifndef Py_LIMITED_API
/* ... */

#ifdef __cplusplus
}
#endif
#endif /* !Py_LIMITED_API */
#endif /* !Py_TRACEMALLOC_H */

Here, if Py_LIMITED_API is defined, the extern "C" block is opened but never closed.

This problem does not affect 3.13 and newer versions, because the order is different there. I am going to submit a trivial pull request to fix this.

CPython versions tested on:

3.12

Operating systems tested on:

Linux

Linked PRs

@mitya57 mitya57 added the type-bug An unexpected behavior, bug, or error label Dec 13, 2024
mitya57 added a commit to mitya57/cpython that referenced this issue Dec 13, 2024
@eendebakpt
Copy link
Contributor

@mitya57 Thanks for reporting. Making a PR would nice!

@vstinner Is there a reason why this was not noticed by the CI? I checked the CI on your PR #127817 and it was all green

@vstinner
Copy link
Member

Oops, thanks for catching this regression!

Is there a reason why this was not noticed by the CI?

The limited C API is not well tested in Python 3.12.

vstinner pushed a commit that referenced this issue Dec 13, 2024
@vstinner
Copy link
Member

Fixed by change b184f48.

@vstinner
Copy link
Member

The limited C API is not well tested in Python 3.12.

I created #127906 to add more tests to 3.12.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.12 bugs and security fixes type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

3 participants