Skip to content

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

Description

@mitya57

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

Activity

  1. added a commit that references this issue on Dec 13, 2024
  2. eendebakpt commented on Dec 13, 2024

    @eendebakpt
    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

  3. vstinner commented on Dec 13, 2024

    @vstinner
    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.

  4. added a commit that references this issue on Dec 13, 2024
  5. vstinner commented on Dec 13, 2024

    @vstinner
    Member

    Fixed by change b184f48.

  6. vstinner commented on Dec 13, 2024

    @vstinner
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.12only security fixestype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions