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
3.12.0b1: static declaration follows non-static when importing internal/pycore_dict.h #105268
I have a change within a project that includes a native extension which fails to compile with 3.12.0b1:
In file included from echion/coremodule.cc:22:
In file included from ./echion/dict.h:7:
In file included from /Users/gabriele/.pyenv/versions/3.12.0b1/include/python3.12/internal/pycore_dict.h:13:
In file included from /Users/gabriele/.pyenv/versions/3.12.0b1/include/python3.12/internal/pycore_runtime.h:16:
In file included from /Users/gabriele/.pyenv/versions/3.12.0b1/include/python3.12/internal/pycore_global_objects.h:11:
/Users/gabriele/.pyenv/versions/3.12.0b1/include/python3.12/internal/pycore_gc.h:84:19: error: static declaration of 'PyObject_GC_IsFinalized' follows non-static declaration
static inline int _PyGC_FINALIZED(PyObject *op) {
^
/Users/gabriele/.pyenv/versions/3.12.0b1/include/python3.12/cpython/objimpl.h:85:30: note: expanded from macro '_PyGC_FINALIZED'
# define _PyGC_FINALIZED(o) PyObject_GC_IsFinalized(o)
^
/Users/gabriele/.pyenv/versions/3.12.0b1/include/python3.12/objimpl.h:209:17: note: previous declaration is here
PyAPI_FUNC(int) PyObject_GC_IsFinalized(PyObject *);
I didn't look too deep into what changed here, but my guess would be that the macro should drop the _ prefix, i.e.
You are including internal headers which is not allowed. You should never define Py_BUILD_CORE.
/* Defines to build Python and its standard library:
*
* - Py_BUILD_CORE: Build Python core. Give access to Python internals, but
* should not be used by third-party modules.
* - Py_BUILD_CORE_BUILTIN: Build a Python stdlib module as a built-in module.
* - Py_BUILD_CORE_MODULE: Build a Python stdlib module as a dynamic library.
*
* Py_BUILD_CORE_BUILTIN and Py_BUILD_CORE_MODULE imply Py_BUILD_CORE.
*
* On Windows, Py_BUILD_CORE_MODULE exports "PyInit_xxx" symbol, whereas
* Py_BUILD_CORE_BUILTIN does not.
*/
Thus, you will never see this function:
staticinlineint_PyGC_FINALIZED(PyObject*op) {
Say if you are really relying on some internal things, make sure you have defined Py_BUILD_CORE for all headers.
Say if you are really relying on some internal things, make sure you have defined Py_BUILD_CORE for all headers.
I really do need these internal structures. So this means that the fact it used to work for older versions of Python is just a mere accident. Correct? I'll try defining Py_BUILD_CORE in all my headers and see what happens 🤞 . Just wanted to call this out in case it was the symptom of an actual issue, since this worked with previous minor releases.
P.S. I have found no dict.h in your repo.
The change with the #include <internal/pycore_dict.h> lives in a local branch that I haven't pushed yet.
include/python3.12/cpython/objimpl.h:85:30: note: expanded from macro '_PyGC_FINALIZED'
# define _PyGC_FINALIZED(o) PyObject_GC_IsFinalized(o)
It seems like the Python.h header was included before the Py_BUILD_CORE macro was defined, and the internal/pycore_gc.h header was included after the Py_BUILD_CORE macro was defined.
Well, this old macro is causing the trouble here. It should just be removed: I wrote PR #105350 for that.
You should be able to work around the issue by defining the Py_BUILD_CORE macro earlier.
I would add to this issue that the PyTorch project is also heavily using partial Py_BUILD_CORE import.
It is actually required to have access to the _PyInterpreterFrame object required for the frame hook API
Maybe you should open an issue to ask for a way to avoid Py_BUILD_CORE in PyTorch :-)
The removal of the macro fixes our build as well but wanted to add one more data point.
Hum, I didn't backport this change to Python 3.12. Maybe I should? Are you using Python 3.12 or the future 3.13? Can you patch Python?
Maybe I should? Are you using Python 3.12 or the future 3.13? Can you patch Python?
Ho I assumed it would make it to the rc even though it wasn't on b4. Backporting it would be amazing as other we will have to build the whole of PyTorch with Py_BUILD_CORE for 3.12 :/
Maybe you should open an issue to ask for a way to avoid Py_BUILD_CORE in PyTorch
Very happy to do that! Is the best place here on github or on the discuss forum?
The change is not going to be backported to Python 3.12: #107348
The workaround is to first include <Python.h>, undefine _PyGC_FINALIZED macro (#undef _PyGC_FINALIZED), and only then include the internal pycore header files.
Thanks for the bug report.
Reacted by albanD, Dmitry Gomzyakov, gouzil and Dian Sheng
Activity
sunmy2019 commentedon Jun 3, 2023
You are including internal headers which is not allowed. You should never define
Py_BUILD_CORE.Thus, you will never see this function:
Say if you are really relying on some internal things, make sure you have defined
Py_BUILD_COREfor all headers.Then you will never see this definition:
P.S. I have found no
dict.hin your repo.P403n1x87 commentedon Jun 3, 2023
I really do need these internal structures. So this means that the fact it used to work for older versions of Python is just a mere accident. Correct? I'll try defining
Py_BUILD_COREin all my headers and see what happens 🤞 . Just wanted to call this out in case it was the symptom of an actual issue, since this worked with previous minor releases.The change with the
#include <internal/pycore_dict.h>lives in a local branch that I haven't pushed yet.iritkatriel commentedon Jun 4, 2023
CC @vstinner .
pythongh-105268: Remove _PyGC_FINALIZED() macro
vstinner commentedon Jun 6, 2023
It seems like the
Python.hheader was included before thePy_BUILD_COREmacro was defined, and theinternal/pycore_gc.hheader was included after thePy_BUILD_COREmacro was defined.Well, this old macro is causing the trouble here. It should just be removed: I wrote PR #105350 for that.
You should be able to work around the issue by defining the
Py_BUILD_COREmacro earlier.gh-105268: Remove _PyGC_FINALIZED() macro (#105350)
vstinner commentedon Jun 6, 2023
I removed the macro. Thanks for your reminder :-) I close the issue.
pythongh-105268: Add _Py_FROM_GC() function to pycore_gc.h
pythongh-105268: Add _Py_FROM_GC() function to pycore_gc.h
gh-105268: Add _Py_FROM_GC() function to pycore_gc.h (#105362)
albanD commentedon Jul 26, 2023
I would add to this issue that the PyTorch project is also heavily using partial Py_BUILD_CORE import.
It is actually required to have access to the _PyInterpreterFrame object required for the frame hook API https://docs.python.org/3/c-api/init.html#c._PyFrameEvalFunction from https://peps.python.org/pep-0523/
The removal of the macro fixes our build as well but wanted to add one more data point.
vstinner commentedon Jul 26, 2023
Maybe you should open an issue to ask for a way to avoid Py_BUILD_CORE in PyTorch :-)
Hum, I didn't backport this change to Python 3.12. Maybe I should? Are you using Python 3.12 or the future 3.13? Can you patch Python?
albanD commentedon Jul 27, 2023
Ho I assumed it would make it to the rc even though it wasn't on b4. Backporting it would be amazing as other we will have to build the whole of PyTorch with Py_BUILD_CORE for 3.12 :/
Very happy to do that! Is the best place here on github or on the discuss forum?
pythongh-105268: Remove _PyGC_FINALIZED() macro (python#105350)
pythongh-105268: _PyGC_FINALIZED() removal is already documented in 3.12
vstinner commentedon Jul 27, 2023
I created PR #107348 and PR #107350 for the backport to 3.12.
An issue on GitHub sounds like a good idea.
gh-105268: _PyGC_FINALIZED() removal is already documented in 3.12 (#…
pythongh-105268: Remove _PyGC_FINALIZED() macro (python#105350)
vstinner commentedon Aug 15, 2023
The change is not going to be backported to Python 3.12: #107348
The workaround is to first include <Python.h>, undefine _PyGC_FINALIZED macro (
#undef _PyGC_FINALIZED), and only then include the internal pycore header files.Thanks for the bug report.