Bug 2245874

Summary: python-greenlet fails to build with Python 3.13: error: #error "this header requires Py_BUILD_CORE define"
Product: [Fedora] Fedora Reporter: Karolina Surma <ksurma>
Component: python-greenletAssignee: Kevin Fenzi <kevin>
Status: CLOSED RAWHIDE QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 40CC: apevec, code, hiwkby, igor.raits, kevin, ksurma, mhroncok, michel, shamardin, terjeros, terje.rosten, vstinner
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2024-07-01 18:50:50 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 2244836    

Description Karolina Surma 2023-10-24 12:18:29 UTC
python-greenlet fails to build with Python 3.13.0a1.

The fragment of the build log:

  In file included from src/greenlet/greenlet_greenlet.hpp:26,
                   from src/greenlet/greenlet_internal.hpp:20,
                   from src/greenlet/greenlet.cpp:19:
  /usr/include/python3.13/internal/pycore_frame.h:8:4: error: #error "this header requires Py_BUILD_CORE define"
      8 | #  error "this header requires Py_BUILD_CORE define"
        |    ^~~~~
  In file included from /usr/include/python3.13/internal/pycore_frame.h:13:
  /usr/include/python3.13/internal/pycore_code.h:8:4: error: #error "this header requires Py_BUILD_CORE define"
      8 | #  error "this header requires Py_BUILD_CORE define"
        |    ^~~~~
  src/greenlet/greenlet_greenlet.hpp:104:9: error: ‘_PyCFrame’ does not name a type; did you mean ‘_frame’?
    104 |         _PyCFrame* cframe;
        |         ^~~~~~~~~
        |         _frame
  src/greenlet/greenlet_greenlet.hpp:138:29: error: ‘_PyCFrame’ has not been declared
    138 |         void set_new_cframe(_PyCFrame& frame) noexcept;
        |                             ^~~~~~~~~
  In file included from src/greenlet/greenlet.cpp:33:
  src/greenlet/TUserGreenlet.cpp: In member function ‘virtual greenlet::Greenlet::switchstack_result_t greenlet::UserGreenlet::g_initialstub(void*)’:
  src/greenlet/TUserGreenlet.cpp:280:5: error: ‘_PyCFrame’ was not declared in this scope; did you mean ‘_frame’?
    280 |     _PyCFrame trace_info;
        |     ^~~~~~~~~
        |     _frame
  src/greenlet/TUserGreenlet.cpp:282:39: error: ‘trace_info’ was not declared in this scope
    282 |     this->python_state.set_new_cframe(trace_info);
        |                                       ^~~~~~~~~~
  In file included from src/greenlet/greenlet.cpp:36:
  src/greenlet/TPythonState.cpp: In constructor ‘greenlet::PythonState::PythonState()’:
  src/greenlet/TPythonState.cpp:12:6: error: class ‘greenlet::PythonState’ does not have any field named ‘cframe’
     12 |     ,cframe(nullptr)
        |      ^~~~~~
  src/greenlet/TPythonState.cpp:82:11: error: ‘class greenlet::PythonState’ has no member named ‘cframe’
     82 |     this->cframe = &PyThreadState_GET()->root_cframe;
        |           ^~~~~~
  src/greenlet/TPythonState.cpp:82:42: error: ‘PyThreadState’ {aka ‘struct _ts’} has no member named ‘root_cframe’
     82 |     this->cframe = &PyThreadState_GET()->root_cframe;
        |                                          ^~~~~~~~~~~
  src/greenlet/TPythonState.cpp: In member function ‘void greenlet::PythonState::operator<<(const PyThreadState*)’:
  src/greenlet/TPythonState.cpp:128:11: error: ‘class greenlet::PythonState’ has no member named ‘cframe’
    128 |     this->cframe = tstate->cframe;
        |           ^~~~~~
  src/greenlet/TPythonState.cpp:128:28: error: ‘const PyThreadState’ {aka ‘const struct _ts’} has no member named ‘cframe’
    128 |     this->cframe = tstate->cframe;
        |                            ^~~~~~
  src/greenlet/TPythonState.cpp:136:31: error: ‘C_RECURSION_LIMIT’ was not declared in this scope; did you mean ‘Py_C_RECURSION_LIMIT’?
    136 |     this->c_recursion_depth = C_RECURSION_LIMIT - tstate->c_recursion_remaining;
        |                               ^~~~~~~~~~~~~~~~~
        |                               Py_C_RECURSION_LIMIT
  src/greenlet/TPythonState.cpp:140:35: error: ‘const PyThreadState’ {aka ‘const struct _ts’} has no member named ‘cframe’
    140 |     this->current_frame = tstate->cframe->current_frame;
        |                                   ^~~~~~
  src/greenlet/TPythonState.cpp: In member function ‘void greenlet::PythonState::operator>>(PyThreadState*)’:
  src/greenlet/TPythonState.cpp:175:13: error: ‘PyThreadState’ {aka ‘struct _ts’} has no member named ‘cframe’
    175 |     tstate->cframe = this->cframe;
        |             ^~~~~~
  src/greenlet/TPythonState.cpp:175:28: error: ‘class greenlet::PythonState’ has no member named ‘cframe’
    175 |     tstate->cframe = this->cframe;
        |                            ^~~~~~
  src/greenlet/TPythonState.cpp:189:37: error: ‘C_RECURSION_LIMIT’ was not declared in this scope; did you mean ‘Py_C_RECURSION_LIMIT’?
    189 |     tstate->c_recursion_remaining = C_RECURSION_LIMIT - this->c_recursion_depth;
        |                                     ^~~~~~~~~~~~~~~~~
        |                                     Py_C_RECURSION_LIMIT
  src/greenlet/TPythonState.cpp:200:13: error: ‘PyThreadState’ {aka ‘struct _ts’} has no member named ‘cframe’
    200 |     tstate->cframe->current_frame = this->current_frame;
        |             ^~~~~~
  src/greenlet/TPythonState.cpp: At global scope:
  src/greenlet/TPythonState.cpp:266:6: error: variable or field ‘set_new_cframe’ declared void
    266 | void PythonState::set_new_cframe(_PyCFrame& frame) noexcept
        |      ^~~~~~~~~~~
  src/greenlet/TPythonState.cpp:266:34: error: ‘_PyCFrame’ was not declared in this scope; did you mean ‘_frame’?
    266 | void PythonState::set_new_cframe(_PyCFrame& frame) noexcept
        |                                  ^~~~~~~~~
        |                                  _frame
  src/greenlet/TPythonState.cpp:266:45: error: ‘frame’ was not declared in this scope; did you mean ‘_frame’?
    266 | void PythonState::set_new_cframe(_PyCFrame& frame) noexcept
        |                                             ^~~~~
        |                                             _frame


https://docs.python.org/3.13/whatsnew/3.13.html

For the build logs, see:
https://copr-be.cloud.fedoraproject.org/results/@python/python3.13/fedora-rawhide-x86_64/06559210-python-greenlet/

For all our attempts to build python-greenlet with Python 3.13, see:
https://copr.fedorainfracloud.org/coprs/g/python/python3.13/package/python-greenlet/

Testing and mass rebuild of packages is happening in copr.
You can follow these instructions to test locally in mock if your package builds with Python 3.13:
https://copr.fedorainfracloud.org/coprs/g/python/python3.13/

Let us know here if you have any questions.

Python 3.13 is planned to be included in Fedora 41.
To make that update smoother, we're building Fedora packages with all pre-releases of Python 3.13.
A build failure prevents us from testing all dependent packages (transitive [Build]Requires),
so if this package is required a lot, it's important for us to get it fixed soon.

We'd appreciate help from the people who know this package best,
but if you don't want to work on this now, let us know so we can try to work around it on our side.

Comment 1 Victor Stinner 2023-12-20 10:01:18 UTC
  /usr/include/python3.13/internal/pycore_frame.h:8:4: error: #error "this header requires Py_BUILD_CORE define"
      8 | #  error "this header requires Py_BUILD_CORE define"

greenlet_greenlet.hpp includes Python internal/pycore_frame.h header. In Python 3.13, Py_BUILD_CORE macro must be defined to access this internal C API.

I suppose that something like "#define Py_BUILD_CORE" should be added before this include:
https://github.com/python-greenlet/greenlet/blob/edbdda27ab1983ac157b588dd0c04816cb31b0ea/src/greenlet/greenlet_greenlet.hpp#L26

Comment 2 Victor Stinner 2024-02-14 15:48:01 UTC
I wrote https://github.com/python-greenlet/greenlet/pull/396 to port greenlet to Python 3.13.

The issue was reported upstream: https://github.com/python-greenlet/greenlet/issues/392

Comment 3 Aoife Moloney 2024-02-15 23:01:30 UTC
This bug appears to have been reported against 'rawhide' during the Fedora Linux 40 development cycle.
Changing version to 40.

Comment 4 Ben Beasley 2024-06-05 11:57:41 UTC
Could you please take a look at this PR to backport https://github.com/python-greenlet/greenlet/pull/396 and consider merging it ASAP, since Python 3.13 rebuilds will soon begin in Rawhide? Thanks!

https://src.fedoraproject.org/rpms/python-greenlet/pull-request/13

Comment 5 Kevin Fenzi 2024-06-05 16:15:40 UTC
Looks good to me. 

Let me know if you would like me to merge and build, just merge, or leave everything for python mass rebuild...

Comment 7 Victor Stinner 2024-07-02 06:29:20 UTC
Great! That one was not tricky to solve, I'm happy that it works as expected :-)