File tree Expand file tree Collapse file tree 1 file changed +12
-3
lines changed
Expand file tree Collapse file tree 1 file changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -206,10 +206,19 @@ test_py_set_immortal(PyObject *self, PyObject *unused)
206206{
207207 // the object is allocated on C stack as otherwise,
208208 // it would trip the refleak checker when the object
209- // is made immortal and leak memory
209+ // is made immortal and leak memory, for the same
210+ // reason we cannot call PyObject_Init() on it.
210211 PyObject object = {0 };
211- Py_SET_REFCNT (& object , 1 );
212- Py_SET_TYPE (& object , & PyBaseObject_Type );
212+ #ifdef Py_GIL_DISABLED
213+ object .ob_tid = _Py_ThreadId ();
214+ object .ob_gc_bits = 0 ;
215+ object .ob_ref_local = 1 ;
216+ object .ob_ref_shared = 0 ;
217+ #else
218+ object .ob_refcnt = 1 ;
219+ #endif
220+ object .ob_type = & PyBaseObject_Type ;
221+
213222 assert (!PyUnstable_IsImmortal (& object ));
214223 int rc = PyUnstable_SetImmortal (& object );
215224 assert (rc == 1 );
You can’t perform that action at this time.
0 commit comments