Skip to content

Commit ba0301d

Browse files
committed
Revert readonly_state; fix is fully in clear_deleteme_list
Greenlet construction (green_new, green_unswitchable_new) must also trigger clear_deleteme_list because existing code and tests depend on it for cross-thread cleanup (e.g. test_dealloc_other_thread uses RawGreenlet() to trigger deleteme processing). With std::swap + exception preservation in clear_deleteme_list, the crash and exception-loss bugs are fixed at the source. The readonly_state / const borrow_current utilities are no longer needed and are removed. Made-with: Cursor
1 parent 8e57397 commit ba0301d

4 files changed

Lines changed: 2 additions & 26 deletions

File tree

src/greenlet/PyGreenlet.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ green_new(PyTypeObject* type, PyObject* UNUSED(args), PyObject* UNUSED(kwds))
6060
// C++ object assigns it to the pimpl pointer of the Python
6161
// object (o); we'll need that later.
6262
UserGreenlet* c = new UserGreenlet(o,
63-
GET_THREAD_STATE().readonly_state().borrow_current());
63+
GET_THREAD_STATE().state().borrow_current());
6464
assert(Py_REFCNT(o) == 1);
6565
assert(c == o->pimpl);
6666
}

src/greenlet/PyGreenletUnswitchable.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ green_unswitchable_new(PyTypeObject* type, PyObject* UNUSED(args), PyObject* UNU
5050
PyGreenlet* o =
5151
(PyGreenlet*)PyBaseObject_Type.tp_new(type, mod_globs->empty_tuple, mod_globs->empty_dict);
5252
if (o) {
53-
new BrokenGreenlet(o, GET_THREAD_STATE().readonly_state().borrow_current());
53+
new BrokenGreenlet(o, GET_THREAD_STATE().state().borrow_current());
5454
assert(Py_REFCNT(o) == 1);
5555
}
5656
return o;

src/greenlet/TThreadState.hpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -257,15 +257,6 @@ class ThreadState {
257257
return this->current_greenlet;
258258
}
259259

260-
/**
261-
* As for const get_current(), but returns a borrowed reference.
262-
* Does no maintenance.
263-
*/
264-
inline BorrowedGreenlet borrow_current() const
265-
{
266-
return this->current_greenlet;
267-
}
268-
269260
template<typename T, refs::TypeChecker TC>
270261
inline bool is_current(const refs::PyObjectPointer<T, TC>& obj) const
271262
{

src/greenlet/TThreadStateCreator.hpp

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -75,21 +75,6 @@ class ThreadStateCreator
7575
return *this->_state;
7676
}
7777

78-
/**
79-
* Return the ThreadState as a const reference, which restricts the
80-
* caller to read-only operations (the const overloads of
81-
* get_current() and borrow_current()).
82-
*
83-
* Those const overloads skip the clear_deleteme_list() maintenance
84-
* that the non-const versions perform. Use this when the caller
85-
* only needs the current greenlet reference and triggering
86-
* cross-thread cleanup is unnecessary (e.g. greenlet construction).
87-
*/
88-
inline const ThreadState& readonly_state()
89-
{
90-
return this->state();
91-
}
92-
9378
operator ThreadState&()
9479
{
9580
return this->state();

0 commit comments

Comments
 (0)