Skip to content

Commit 9a4003c

Browse files
fix test on ft
1 parent 9987a92 commit 9a4003c

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

Modules/_testcapi/object.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff 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);

0 commit comments

Comments
 (0)