Skip to content

Commit f5dec96

Browse files
committed
Avoid masking when comparing to True and False
1 parent c88bcbc commit f5dec96

File tree

1 file changed

+3
-14
lines changed

1 file changed

+3
-14
lines changed

Include/internal/pycore_stackref.h

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,9 @@ static const _PyStackRef PyStackRef_NULL = { .bits = PyStackRef_NULL_BITS };
219219

220220
/* We should be able to guarantee that the tag bits are set for immortal objects */
221221

222-
#define PyStackRef_IsTrue(ref) (((ref).bits & (~Py_TAG_BITS)) == ((uintptr_t)&_Py_TrueStruct))
223-
#define PyStackRef_IsFalse(ref) (((ref).bits & (~Py_TAG_BITS)) == ((uintptr_t)&_Py_FalseStruct))
224-
222+
#define PyStackRef_IsTrue(REF) ((REF).bits == (((uintptr_t)&_Py_TrueStruct) | Py_TAG_IMMORTAL))
223+
#define PyStackRef_IsFalse(REF) ((REF).bits == (((uintptr_t)&_Py_FalseStruct) | Py_TAG_IMMORTAL))
224+
#define PyStackRef_IsNone(REF) ((REF).bits == (((uintptr_t)&_Py_NoneStruct) | Py_TAG_IMMORTAL))
225225

226226
#ifdef Py_DEBUG
227227

@@ -244,20 +244,9 @@ static inline void PyStackRef_CheckValid(_PyStackRef ref) {
244244
}
245245
}
246246

247-
static inline int
248-
PyStackRef_IsNone(_PyStackRef ref)
249-
{
250-
if ((ref.bits & (~Py_TAG_BITS)) == ((uintptr_t)&_Py_NoneStruct)) {
251-
assert ((ref.bits & Py_TAG_BITS) == Py_TAG_IMMORTAL);
252-
return 1;
253-
}
254-
return 0;
255-
}
256-
257247
#else
258248

259249
#define PyStackRef_CheckValid(REF) ((void)0)
260-
#define PyStackRef_IsNone(REF) ((REF).bits == (((uintptr_t)&_Py_NoneStruct) | Py_TAG_IMMORTAL))
261250

262251
#endif
263252

0 commit comments

Comments
 (0)