@@ -11,10 +11,9 @@ extern "C" {
1111#include <stdbool.h>
1212#include "pycore_gc.h" // _PyObject_GC_IS_TRACKED()
1313#include "pycore_emscripten_trampoline.h" // _PyCFunction_TrampolineCall()
14- #include "pycore_interp.h" // PyInterpreterState.gc
1514#include "pycore_pyatomic_ft_wrappers.h" // FT_ATOMIC_STORE_PTR_RELAXED
1615#include "pycore_pystate.h" // _PyInterpreterState_GET()
17- #include "pycore_stackref .h"
16+ #include "pycore_typeobject .h" // _PyStaticType_GetState()
1817#include "pycore_uniqueid.h" // _PyObject_ThreadIncrefSlow()
1918
2019// This value is added to `ob_ref_shared` for objects that use deferred
@@ -455,84 +454,6 @@ _PyObject_InitVar(PyVarObject *op, PyTypeObject *typeobj, Py_ssize_t size)
455454 Py_SET_SIZE (op , size );
456455}
457456
458-
459- /* Tell the GC to track this object.
460- *
461- * The object must not be tracked by the GC.
462- *
463- * NB: While the object is tracked by the collector, it must be safe to call the
464- * ob_traverse method.
465- *
466- * Internal note: interp->gc.generation0->_gc_prev doesn't have any bit flags
467- * because it's not object header. So we don't use _PyGCHead_PREV() and
468- * _PyGCHead_SET_PREV() for it to avoid unnecessary bitwise operations.
469- *
470- * See also the public PyObject_GC_Track() function.
471- */
472- static inline void _PyObject_GC_TRACK (
473- // The preprocessor removes _PyObject_ASSERT_FROM() calls if NDEBUG is defined
474- #ifndef NDEBUG
475- const char * filename , int lineno ,
476- #endif
477- PyObject * op )
478- {
479- _PyObject_ASSERT_FROM (op , !_PyObject_GC_IS_TRACKED (op ),
480- "object already tracked by the garbage collector" ,
481- filename , lineno , __func__ );
482- #ifdef Py_GIL_DISABLED
483- _PyObject_SET_GC_BITS (op , _PyGC_BITS_TRACKED );
484- #else
485- PyGC_Head * gc = _Py_AS_GC (op );
486- _PyObject_ASSERT_FROM (op ,
487- (gc -> _gc_prev & _PyGC_PREV_MASK_COLLECTING ) == 0 ,
488- "object is in generation which is garbage collected" ,
489- filename , lineno , __func__ );
490-
491- PyInterpreterState * interp = _PyInterpreterState_GET ();
492- PyGC_Head * generation0 = & interp -> gc .young .head ;
493- PyGC_Head * last = (PyGC_Head * )(generation0 -> _gc_prev );
494- _PyGCHead_SET_NEXT (last , gc );
495- _PyGCHead_SET_PREV (gc , last );
496- uintptr_t not_visited = 1 ^ interp -> gc .visited_space ;
497- gc -> _gc_next = ((uintptr_t )generation0 ) | not_visited ;
498- generation0 -> _gc_prev = (uintptr_t )gc ;
499- #endif
500- }
501-
502- /* Tell the GC to stop tracking this object.
503- *
504- * Internal note: This may be called while GC. So _PyGC_PREV_MASK_COLLECTING
505- * must be cleared. But _PyGC_PREV_MASK_FINALIZED bit is kept.
506- *
507- * The object must be tracked by the GC.
508- *
509- * See also the public PyObject_GC_UnTrack() which accept an object which is
510- * not tracked.
511- */
512- static inline void _PyObject_GC_UNTRACK (
513- // The preprocessor removes _PyObject_ASSERT_FROM() calls if NDEBUG is defined
514- #ifndef NDEBUG
515- const char * filename , int lineno ,
516- #endif
517- PyObject * op )
518- {
519- _PyObject_ASSERT_FROM (op , _PyObject_GC_IS_TRACKED (op ),
520- "object not tracked by the garbage collector" ,
521- filename , lineno , __func__ );
522-
523- #ifdef Py_GIL_DISABLED
524- _PyObject_CLEAR_GC_BITS (op , _PyGC_BITS_TRACKED );
525- #else
526- PyGC_Head * gc = _Py_AS_GC (op );
527- PyGC_Head * prev = _PyGCHead_PREV (gc );
528- PyGC_Head * next = _PyGCHead_NEXT (gc );
529- _PyGCHead_SET_NEXT (prev , next );
530- _PyGCHead_SET_PREV (next , prev );
531- gc -> _gc_next = 0 ;
532- gc -> _gc_prev &= _PyGC_PREV_MASK_FINALIZED ;
533- #endif
534- }
535-
536457// Macros to accept any type for the parameter, and to automatically pass
537458// the filename and the filename (if NDEBUG is not defined) where the macro
538459// is called.
0 commit comments