Skip to content

Commit d48616e

Browse files
authored
GH-133261: Make sure trashcan pointers look mortal -- 32 bit (GH-133450)
Make sure trashcan pointer look mortal -- 32 bit
1 parent 9434709 commit d48616e

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

Objects/object.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2940,20 +2940,29 @@ pointer_to_safe_refcount(void *ptr)
29402940
{
29412941
uintptr_t full = (uintptr_t)ptr;
29422942
assert((full & 3) == 0);
2943+
#if SIZEOF_VOID_P > 4
29432944
uint32_t refcnt = (uint32_t)full;
29442945
if (refcnt >= (uint32_t)_Py_IMMORTAL_MINIMUM_REFCNT) {
29452946
full = full - ((uintptr_t)_Py_IMMORTAL_MINIMUM_REFCNT) + 1;
29462947
}
29472948
return full + 2;
2949+
#else
2950+
// Make the top two bits 0, so it appears mortal.
2951+
return (full >> 2) + 1;
2952+
#endif
29482953
}
29492954

29502955
static void *
29512956
safe_refcount_to_pointer(uintptr_t refcnt)
29522957
{
2958+
#if SIZEOF_VOID_P > 4
29532959
if (refcnt & 1) {
29542960
refcnt += _Py_IMMORTAL_MINIMUM_REFCNT - 1;
29552961
}
29562962
return (void *)(refcnt - 2);
2963+
#else
2964+
return (void *)((refcnt -1) << 2);
2965+
#endif
29572966
}
29582967
#endif
29592968

0 commit comments

Comments
 (0)