Skip to content

Commit 810d782

Browse files
committed
address feedback
1 parent 362f6cf commit 810d782

10 files changed

Lines changed: 1538 additions & 1931 deletions

File tree

Include/internal/pycore_opcode_metadata.h

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_stackref.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,21 @@ static const _PyStackRef PyStackRef_ERROR = { .index = (1 << Py_TAGGED_SHIFT) };
7979
#define PyStackRef_False ((_PyStackRef){ .index = _Py_STACKREF_FALSE_INDEX })
8080
#define PyStackRef_True ((_PyStackRef){ .index = _Py_STACKREF_TRUE_INDEX })
8181

82+
static inline _PyStackRef
83+
PyStackRef_WrapBit(int truthy)
84+
{
85+
return (_PyStackRef){ .index = truthy ? _Py_STACKREF_BIT_1_INDEX
86+
: _Py_STACKREF_BIT_0_INDEX };
87+
}
88+
89+
static inline int
90+
PyStackRef_UnwrapBit(_PyStackRef bit)
91+
{
92+
assert(bit.index == _Py_STACKREF_BIT_0_INDEX ||
93+
bit.index == _Py_STACKREF_BIT_1_INDEX);
94+
return (bit.index == _Py_STACKREF_BIT_1_INDEX) ? 1 : 0;
95+
}
96+
8297
#define INITIAL_STACKREF_INDEX (7 << Py_TAGGED_SHIFT)
8398

8499
#define PyStackRef_ZERO_BITS PyStackRef_NULL
@@ -475,6 +490,19 @@ static const _PyStackRef PyStackRef_NULL = { .bits = PyStackRef_NULL_BITS };
475490
#define PyStackRef_False ((_PyStackRef){.bits = ((uintptr_t)&_Py_FalseStruct) | Py_TAG_REFCNT })
476491
#define PyStackRef_None ((_PyStackRef){.bits = ((uintptr_t)&_Py_NoneStruct) | Py_TAG_REFCNT })
477492

493+
static inline _PyStackRef
494+
PyStackRef_WrapBit(int truthy)
495+
{
496+
return (_PyStackRef){ .bits = (uintptr_t)(truthy ? 1 : 0) };
497+
}
498+
499+
static inline int
500+
PyStackRef_UnwrapBit(_PyStackRef bit)
501+
{
502+
assert(bit.bits == 0 || bit.bits == 1);
503+
return (int)bit.bits;
504+
}
505+
478506
#ifdef Py_GIL_DISABLED
479507
// Checks that mask out the deferred bit in the free threading build.
480508
#define PyStackRef_IsNone(REF) (((REF).bits & ~Py_TAG_REFCNT) == (uintptr_t)&_Py_NoneStruct)

0 commit comments

Comments
 (0)