@@ -9,12 +9,11 @@ extern "C" {
9
9
#endif
10
10
11
11
#include <stdbool.h>
12
- #include "pycore_gc.h" // _PyObject_GC_IS_TRACKED()
13
12
#include "pycore_emscripten_trampoline.h" // _PyCFunction_TrampolineCall()
14
- #include "pycore_interp .h" // PyInterpreterState.gc
13
+ #include "pycore_object_deferred .h" // _PyObject_HasDeferredRefcount
15
14
#include "pycore_pyatomic_ft_wrappers.h" // FT_ATOMIC_STORE_PTR_RELAXED
16
15
#include "pycore_pystate.h" // _PyInterpreterState_GET()
17
- #include "pycore_stackref .h"
16
+ #include "pycore_typeobject .h" // _PyStaticType_GetState()
18
17
#include "pycore_uniqueid.h" // _PyObject_ThreadIncrefSlow()
19
18
20
19
// 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)
455
454
Py_SET_SIZE (op , size );
456
455
}
457
456
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
-
536
457
// Macros to accept any type for the parameter, and to automatically pass
537
458
// the filename and the filename (if NDEBUG is not defined) where the macro
538
459
// is called.
@@ -618,20 +539,6 @@ _Py_TryIncrefCompare(PyObject **src, PyObject *op)
618
539
return 1 ;
619
540
}
620
541
621
- static inline int
622
- _Py_TryIncrefCompareStackRef (PyObject * * src , PyObject * op , _PyStackRef * out )
623
- {
624
- if (_PyObject_HasDeferredRefcount (op )) {
625
- * out = (_PyStackRef ){ .bits = (intptr_t )op | Py_TAG_DEFERRED };
626
- return 1 ;
627
- }
628
- if (_Py_TryIncrefCompare (src , op )) {
629
- * out = PyStackRef_FromPyObjectSteal (op );
630
- return 1 ;
631
- }
632
- return 0 ;
633
- }
634
-
635
542
/* Loads and increfs an object from ptr, which may contain a NULL value.
636
543
Safe with concurrent (atomic) updates to ptr.
637
544
NOTE: The writer must set maybe-weakref on the stored object! */
0 commit comments