https://github.com/python/cpython/commit/d48616e08cbf069847026a2ee35017ad5cbe12a8 commit: d48616e08cbf069847026a2ee35017ad5cbe12a8 branch: main author: Mark Shannon <m...@hotpy.org> committer: ambv <luk...@langa.pl> date: 2025-05-05T21:51:32+02:00 summary:
GH-133261: Make sure trashcan pointers look mortal -- 32 bit (GH-133450) Make sure trashcan pointer look mortal -- 32 bit files: M Objects/object.c diff --git a/Objects/object.c b/Objects/object.c index e9a93f87be4cf7..723b0427e69251 100644 --- a/Objects/object.c +++ b/Objects/object.c @@ -2940,20 +2940,29 @@ pointer_to_safe_refcount(void *ptr) { uintptr_t full = (uintptr_t)ptr; assert((full & 3) == 0); +#if SIZEOF_VOID_P > 4 uint32_t refcnt = (uint32_t)full; if (refcnt >= (uint32_t)_Py_IMMORTAL_MINIMUM_REFCNT) { full = full - ((uintptr_t)_Py_IMMORTAL_MINIMUM_REFCNT) + 1; } return full + 2; +#else + // Make the top two bits 0, so it appears mortal. + return (full >> 2) + 1; +#endif } static void * safe_refcount_to_pointer(uintptr_t refcnt) { +#if SIZEOF_VOID_P > 4 if (refcnt & 1) { refcnt += _Py_IMMORTAL_MINIMUM_REFCNT - 1; } return (void *)(refcnt - 2); +#else + return (void *)((refcnt -1) << 2); +#endif } #endif _______________________________________________ Python-checkins mailing list -- python-checkins@python.org To unsubscribe send an email to python-checkins-le...@python.org https://mail.python.org/mailman3/lists/python-checkins.python.org/ Member address: arch...@mail-archive.com