You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[C API] The internal C API <pycore_dict.h> cannot be used in C++ #108216
In file included from /opt/hostedtoolcache/Python/3.12.0-rc.1/x64/include/python3.12/internal/pycore_atomic.h:15,
from /opt/hostedtoolcache/Python/3.12.0-rc.1/x64/include/python3.12/internal/pycore_runtime.h:12,
from /opt/hostedtoolcache/Python/3.12.0-rc.1/x64/include/python3.12/internal/pycore_dict.h:13,
from ./echion/mirrors.h:14,
from echion/coremodule.cc:29:
/usr/lib/gcc/x86_64-linux-gnu/9/include/stdatomic.h: At global scope:
/usr/lib/gcc/x86_64-linux-gnu/9/include/stdatomic.h:40:9: error: ‘_Atomic’ does not name a type
40 | typedef _Atomic _Bool atomic_bool;
| ^~~~~~~
changed the title [-]Cannot compile C++ extensions with GCC when importing from core[/-][+]Cannot compile C++ extensions with GCC when including core headers[/+]on Aug 21, 2023
changed the title [-]Cannot compile C++ extensions with GCC when including core headers[/-][+][C API] The internal C API <pycore_dict.h> cannot be used in C++[/+]on Aug 21, 2023
Indeed it is a profiler (actually just a frame stack sample fwiw). The internal API is used to access internal fields of structures from copies of Python objects so that it can all be done without the GIL
PEP 684: A Per-Interpreter GIL modified DICT_NEXT_VERSION() to access interp->dict_state.global_version: the counter is now "per-interpreter". The problem is that accessing PyInterprepter members requires to include pycore_interp.h is a giant beast: pycore_interp.h includes the problematic pycore_atomic.h.
With that "noise" reduced, I spotted this other seemingly GCC-only issue
In file included from /opt/hostedtoolcache/Python/3.12.0-rc.1/x64/include/python3.12/objimpl.h:227,
from /opt/hostedtoolcache/Python/3.12.0-rc.1/x64/include/python3.12/Python.h:45,
from echion/coremodule.cc:6:
/opt/hostedtoolcache/Python/3.12.0-rc.1/x64/include/python3.12/internal/pycore_gc.h: At global scope:
/opt/hostedtoolcache/Python/3.12.0-rc.1/x64/include/python3.12/cpython/objimpl.h:85:30: error: ‘int PyObject_GC_IsFinalized(PyObject*)’ was declared ‘extern’ and later ‘static’ [-fpermissive]
85 | # define _PyGC_FINALIZED(o) PyObject_GC_IsFinalized(o)
| ^~~~~~~~~~~~~~~~~~~~~~~
/opt/hostedtoolcache/Python/3.12.0-rc.1/x64/include/python3.12/internal/pycore_gc.h:84:19: note: in expansion of macro ‘_PyGC_FINALIZED’
84 | static inline int _PyGC_FINALIZED(PyObject *op) {
| ^~~~~~~~~~~~~~~
In file included from /opt/hostedtoolcache/Python/3.12.0-rc.1/x64/include/python3.12/Python.h:45,
from echion/coremodule.cc:6:
/opt/hostedtoolcache/Python/3.12.0-rc.1/x64/include/python3.12/objimpl.h:209:17: note: previous declaration of ‘int PyObject_GC_IsFinalized(PyObject*)’
209 | PyAPI_FUNC(int) PyObject_GC_IsFinalized(PyObject *);
| ^~~~~~~~~~~~~~~~~~~~~~~
Activity
[-]Cannot compile C++ extensions with GCC when importing from core[/-][+]Cannot compile C++ extensions with GCC when including core headers[/+]vstinner commentedon Aug 21, 2023
This old issue was about including the public C API <Python.h>. This issue is about using the internal C API in C++.
[-]Cannot compile C++ extensions with GCC when including core headers[/-][+][C API] The internal C API <pycore_dict.h> cannot be used in C++[/+]vstinner commentedon Aug 21, 2023
What is your use case for using the internal C API?
https://github.com/P403n1x87/echion/ description:
It looks like a Python profiler.
vstinner commentedon Aug 21, 2023
In Python 3.11, I added
test_cppextto check that the Python C API is usable in C++, but only the public C API.P403n1x87 commentedon Aug 21, 2023
Indeed it is a profiler (actually just a frame stack sample fwiw). The internal API is used to access internal fields of structures from copies of Python objects so that it can all be done without the GIL
pythongh-108216: Cleanup #include in internal header files
pythongh-108216: Cleanup #include in internal header files
vstinner commentedon Aug 21, 2023
With Python 3.11, it's possible to include <pycore_dict.h> in C++? In 3.11, there is no include.
Python 3.12 added two includes:
PEP 684: A Per-Interpreter GIL modified
DICT_NEXT_VERSION()to accessinterp->dict_state.global_version: the counter is now "per-interpreter". The problem is that accessing PyInterprepter members requires to includepycore_interp.his a giant beast:pycore_interp.hincludes the problematicpycore_atomic.h.gh-108216: Cleanup #include in internal header files (#108228)
pythongh-108216: Add pycore_dict_struct.h internal header file
pythongh-108216: Add pycore_dict_struct.h internal header file
pythongh-108216: Add pycore_dict_struct.h internal header file
2 remaining items
P403n1x87 commentedon Aug 21, 2023
Yep I add the import of
pycore_dictifPY_VERSION_HEX >= 0x030b0000and it compiles finehttps://github.com/P403n1x87/echion/blob/29275a13aea67a8d008471523f38bc4477499a98/echion/mirrors.h#L12-L15
methane commentedon Aug 22, 2023
Maybe workaround:
vstinner commentedon Aug 27, 2023
@P403n1x87: Does @methane's workaround work for you? If yes, there is no need to change the header file, right?
P403n1x87 commentedon Aug 28, 2023
@vstinner will try to test today and report
P403n1x87 commentedon Aug 28, 2023
@vstinner @methane's workaround seems to work as it makes all the atomic-related errors disappear
GH job: https://github.com/P403n1x87/echion/actions/runs/5997079612/job/16262783675?pr=8
PR: P403n1x87/echion#8
With that "noise" reduced, I spotted this other seemingly GCC-only issue
but this likely a different issue.
vstinner commentedon Aug 28, 2023
I removed
# define _PyGC_FINALIZED(o)in the main branch, but my backport to 3.12 was rejected. Just undefine the macro manually.vstinner commentedon Aug 28, 2023
In that case, I propose to not add
pycore_dict_struct.hfor now. I suggest you using:Thanks for the feedback. I close the issue.
erlend-aasland commentedon Aug 29, 2023
Ops, sorry for the noise, Victor! I didn't see there was a related PR that fixed some of the issues.
vstinner commentedon Aug 29, 2023
This issue was not fixed. Only workaround is offered as a way to avoid the issue 😁
erlend-aasland commentedon Aug 29, 2023
Aha, so we close it as not planned then! :)
vstinner commentedon Aug 29, 2023
Oh. I tried but apparently failed to do that.