Skip to content

Commit d9dc597

Browse files
committed
Clarify assert
1 parent 867bd10 commit d9dc597

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

Include/internal/pycore_stackref.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ PyStackRef_IsNullOrInt(_PyStackRef ref);
242242

243243
#define Py_INT_TAG 3
244244
#define Py_TAG_REFCNT 1
245+
#define Py_TAG_BITS 3
245246

246247
static inline bool
247248
PyStackRef_IsTaggedInt(_PyStackRef i)
@@ -268,7 +269,8 @@ PyStackRef_UntagInt(_PyStackRef i)
268269
static inline _PyStackRef
269270
PyStackRef_IncrementTaggedIntNoOverflow(_PyStackRef ref)
270271
{
271-
assert(ref.bits != (uintptr_t)-1); // Deosn't overflow
272+
assert((ref.bits & Py_TAG_BITS) == Py_INT_TAG); // Is tagged int
273+
assert((ref.bits & (~Py_TAG_BITS)) != (INT_MAX & (~Py_TAG_BITS))); // Isn't about to overflow
272274
return (_PyStackRef){ .bits = ref.bits + 4 };
273275
}
274276

@@ -278,7 +280,6 @@ PyStackRef_IncrementTaggedIntNoOverflow(_PyStackRef ref)
278280
#define Py_TAG_DEFERRED Py_TAG_REFCNT
279281

280282
#define Py_TAG_PTR ((uintptr_t)0)
281-
#define Py_TAG_BITS ((uintptr_t)1)
282283

283284

284285
static const _PyStackRef PyStackRef_NULL = { .bits = Py_TAG_DEFERRED};
@@ -453,7 +454,6 @@ PyStackRef_AsStrongReference(_PyStackRef stackref)
453454
/* References to immortal objects always have their tag bit set to Py_TAG_REFCNT
454455
* as they can (must) have their reclamation deferred */
455456

456-
#define Py_TAG_BITS 3
457457
#if _Py_IMMORTAL_FLAGS != Py_TAG_REFCNT
458458
# error "_Py_IMMORTAL_FLAGS != Py_TAG_REFCNT"
459459
#endif

0 commit comments

Comments
 (0)