From e0ff9f8ced2b5126e962d3cd83bcb480f2a00cb7 Mon Sep 17 00:00:00 2001 From: Sergey Miryanov Date: Sun, 28 Sep 2025 01:04:43 +0500 Subject: [PATCH 1/6] Fix PyStackRef_IsError for gil-enabled build --- Include/internal/pycore_stackref.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Include/internal/pycore_stackref.h b/Include/internal/pycore_stackref.h index 062834368bcd29..6e8daed3776327 100644 --- a/Include/internal/pycore_stackref.h +++ b/Include/internal/pycore_stackref.h @@ -293,7 +293,7 @@ PyStackRef_Unwrap(_PyStackRef ref) static inline bool PyStackRef_IsError(_PyStackRef ref) { - return ref.bits == Py_TAG_INVALID; + return (ref.bits & Py_TAG_BITS) == Py_TAG_INVALID; } static inline bool From 0780c36fbd711d96115ff003ce768ea9b119a5e9 Mon Sep 17 00:00:00 2001 From: Sergey Miryanov Date: Sun, 28 Sep 2025 01:05:09 +0500 Subject: [PATCH 2/6] Fix dump_item to check is the item valid or no --- Python/ceval.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Python/ceval.c b/Python/ceval.c index 0ccaacaf3ed5b1..81c7466859eec2 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -160,6 +160,10 @@ dump_item(_PyStackRef item) printf(""); return; } + if (PyStackRef_IsError(item)) { + printf(""); + return; + } if (PyStackRef_IsTaggedInt(item)) { printf("%" PRId64, (int64_t)PyStackRef_UntagInt(item)); return; From 58b45641b214f73fbb8fcff6fa57d8643eb07f94 Mon Sep 17 00:00:00 2001 From: Sergey Miryanov Date: Sun, 28 Sep 2025 12:25:13 +0500 Subject: [PATCH 3/6] Fix PyStackRef_IsValid accordingly --- Include/internal/pycore_stackref.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Include/internal/pycore_stackref.h b/Include/internal/pycore_stackref.h index 6e8daed3776327..48fdd0aa93a888 100644 --- a/Include/internal/pycore_stackref.h +++ b/Include/internal/pycore_stackref.h @@ -300,7 +300,7 @@ static inline bool PyStackRef_IsValid(_PyStackRef ref) { /* Invalid values are ERROR and NULL */ - return ref.bits >= Py_INT_TAG; + return (ref.bits & Py_TAG_BITS) >= Py_INT_TAG; } static inline bool From 86be53d63763ab00ea974805dde2fe1bd7a9d13a Mon Sep 17 00:00:00 2001 From: Sergey Miryanov Date: Sun, 28 Sep 2025 12:33:11 +0500 Subject: [PATCH 4/6] Revert "Fix PyStackRef_IsValid accordingly" This reverts commit 58b45641b214f73fbb8fcff6fa57d8643eb07f94. --- Include/internal/pycore_stackref.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Include/internal/pycore_stackref.h b/Include/internal/pycore_stackref.h index 48fdd0aa93a888..6e8daed3776327 100644 --- a/Include/internal/pycore_stackref.h +++ b/Include/internal/pycore_stackref.h @@ -300,7 +300,7 @@ static inline bool PyStackRef_IsValid(_PyStackRef ref) { /* Invalid values are ERROR and NULL */ - return (ref.bits & Py_TAG_BITS) >= Py_INT_TAG; + return ref.bits >= Py_INT_TAG; } static inline bool From 053ee09c558557fb1430613c6ad31700b58d0ed5 Mon Sep 17 00:00:00 2001 From: Sergey Miryanov Date: Sun, 5 Oct 2025 00:32:14 +0500 Subject: [PATCH 5/6] Revert "Fix PyStackRef_IsError for gil-enabled build" This reverts commit e0ff9f8ced2b5126e962d3cd83bcb480f2a00cb7. --- Include/internal/pycore_stackref.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Include/internal/pycore_stackref.h b/Include/internal/pycore_stackref.h index 6e8daed3776327..062834368bcd29 100644 --- a/Include/internal/pycore_stackref.h +++ b/Include/internal/pycore_stackref.h @@ -293,7 +293,7 @@ PyStackRef_Unwrap(_PyStackRef ref) static inline bool PyStackRef_IsError(_PyStackRef ref) { - return (ref.bits & Py_TAG_BITS) == Py_TAG_INVALID; + return ref.bits == Py_TAG_INVALID; } static inline bool From d4f2c37c016982adbc8817ed5f9d5995fce7b8c5 Mon Sep 17 00:00:00 2001 From: Sergey Miryanov Date: Wed, 8 Oct 2025 00:50:04 +0500 Subject: [PATCH 6/6] Add PyStackRef_IsMalformed --- Include/internal/pycore_stackref.h | 6 ++++++ Python/ceval.c | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Include/internal/pycore_stackref.h b/Include/internal/pycore_stackref.h index 062834368bcd29..efe9fb3b6c7c6a 100644 --- a/Include/internal/pycore_stackref.h +++ b/Include/internal/pycore_stackref.h @@ -296,6 +296,12 @@ PyStackRef_IsError(_PyStackRef ref) return ref.bits == Py_TAG_INVALID; } +static inline bool +PyStackRef_IsMalformed(_PyStackRef ref) +{ + return (ref.bits & Py_TAG_BITS) == Py_TAG_INVALID; +} + static inline bool PyStackRef_IsValid(_PyStackRef ref) { diff --git a/Python/ceval.c b/Python/ceval.c index 81c495cfaf30e0..0143998b29d774 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -160,7 +160,7 @@ dump_item(_PyStackRef item) printf(""); return; } - if (PyStackRef_IsError(item)) { + if (PyStackRef_IsMalformed(item)) { printf(""); return; }