Skip to content

Commit 0f9c865

Browse files
committed
Drop 'immortal' bit. Only use 'counted' bit.
1 parent 36f6034 commit 0f9c865

File tree

3 files changed

+10
-34
lines changed

3 files changed

+10
-34
lines changed

Include/internal/pycore_stackref.h

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -187,16 +187,6 @@ _PyStackRef_FromPyObjectStealMortal(PyObject *obj, const char *filename, int lin
187187
}
188188
#define PyStackRef_FromPyObjectStealMortal(obj) _PyStackRef_FromPyObjectStealMortal(_PyObject_CAST(obj), __FILE__, __LINE__)
189189

190-
static inline bool
191-
PyStackRef_IsMortal(_PyStackRef ref)
192-
{
193-
PyObject *obj = _Py_stackref_get_object(ref);
194-
if (obj == NULL) {
195-
return false;
196-
}
197-
return _Py_IsImmortal(obj);
198-
}
199-
200190
static inline bool
201191
PyStackRef_IsHeapSafe(_PyStackRef ref)
202192
{
@@ -377,8 +367,12 @@ PyStackRef_AsStrongReference(_PyStackRef stackref)
377367
// With GIL
378368

379369
#define Py_TAG_BITS 3
380-
#define Py_TAG_IMMORTAL _Py_IMMORTAL_FLAGS
381370
#define Py_TAG_REFCNT 1
371+
#if _Py_IMMORTAL_FLAGS != Py_TAG_REFCNT
372+
# error "_Py_IMMORTAL_FLAGS != Py_TAG_REFCNT"
373+
#endif
374+
#define Py_TAG_IMMORTAL _Py_IMMORTAL_FLAGS
375+
382376
#define BITS_TO_PTR(REF) ((PyObject *)((REF).bits))
383377
#define BITS_TO_PTR_MASKED(REF) ((PyObject *)(((REF).bits) & (~Py_TAG_BITS)))
384378

@@ -402,7 +396,6 @@ static inline void PyStackRef_CheckValid(_PyStackRef ref) {
402396
PyObject *obj = BITS_TO_PTR_MASKED(ref);
403397
switch (tag) {
404398
case 0:
405-
case Py_TAG_REFCNT:
406399
/* Can be immortal if object was made immortal after reference came into existence */
407400
assert(!_Py_IsStaticImmortal(obj));
408401
break;
@@ -422,8 +415,6 @@ static inline void PyStackRef_CheckValid(_PyStackRef ref) {
422415

423416
#ifdef _WIN32
424417
#define PyStackRef_IsUncountedMortal(REF) (((REF).bits & Py_TAG_BITS) == 0)
425-
#define PyStackRef_IsCountedMortal(REF) (((REF).bits & Py_TAG_BITS) == Py_TAG_REFCNT)
426-
#define PyStackRef_IsMortal(REF) (((REF).bits & Py_TAG_BITS) != Py_TAG_IMMORTAL)
427418
#define PyStackRef_AsPyObjectBorrow BITS_TO_PTR_MASKED
428419
#else
429420
/* Does this ref not have an embedded refcount and refer to a mortal object? */
@@ -433,20 +424,6 @@ PyStackRef_IsUncountedMortal(_PyStackRef ref)
433424
return (ref.bits & Py_TAG_BITS) == 0;
434425
}
435426

436-
/* Does this ref have an embedded refcount and refer to a mortal object (NULL is not mortal)? */
437-
static inline bool
438-
PyStackRef_IsCountedMortal(_PyStackRef ref)
439-
{
440-
return (ref.bits & Py_TAG_BITS) == Py_TAG_REFCNT;
441-
}
442-
443-
/* Does this ref refer to a mortal object (NULL is not mortal) */
444-
static inline bool
445-
PyStackRef_IsMortal(_PyStackRef ref)
446-
{
447-
return (ref.bits & Py_TAG_BITS) != Py_TAG_IMMORTAL;
448-
}
449-
450427
static inline PyObject *
451428
PyStackRef_AsPyObjectBorrow(_PyStackRef ref)
452429
{
@@ -547,13 +524,13 @@ PyStackRef_DUP(_PyStackRef ref)
547524
static inline bool
548525
PyStackRef_IsHeapSafe(_PyStackRef ref)
549526
{
550-
return !PyStackRef_IsCountedMortal(ref);
527+
return (ref.bits & Py_TAG_BITS) == 0 || ref.bits == PyStackRef_NULL_BITS || _Py_IsImmortal(BITS_TO_PTR_MASKED(ref));
551528
}
552529

553530
static inline _PyStackRef
554531
PyStackRef_MakeHeapSafe(_PyStackRef ref)
555532
{
556-
if (!PyStackRef_IsCountedMortal(ref)) {
533+
if (PyStackRef_IsHeapSafe(ref)) {
557534
return ref;
558535
}
559536
PyObject *obj = BITS_TO_PTR_MASKED(ref);

Include/refcount.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@ immortal. The latter should be the only instances that require
1919
cleanup during runtime finalization.
2020
*/
2121

22-
/* Leave the low bits for refcount overflow for old stable ABI code */
2322
#define _Py_STATICALLY_ALLOCATED_FLAG 4
24-
#define _Py_IMMORTAL_FLAGS 3
23+
#define _Py_IMMORTAL_FLAGS 1
2524

2625
#if SIZEOF_VOID_P > 4
2726
/*

Python/gc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1488,10 +1488,10 @@ mark_stacks(PyInterpreterState *interp, PyGC_Head *visited, int visited_space, b
14881488
objects_marked += move_to_reachable(func, &reachable, visited_space);
14891489
while (sp > locals) {
14901490
sp--;
1491-
if (!PyStackRef_IsMortal(*sp)) {
1491+
PyObject *op = PyStackRef_AsPyObjectBorrow(*sp);
1492+
if (op == NULL || _Py_IsImmortal(op)) {
14921493
continue;
14931494
}
1494-
PyObject *op = PyStackRef_AsPyObjectBorrow(*sp);
14951495
if (_PyObject_IS_GC(op)) {
14961496
PyGC_Head *gc = AS_GC(op);
14971497
if (_PyObject_GC_IS_TRACKED(op) &&

0 commit comments

Comments
 (0)