diff options
author | Mark Shannon <mark@hotpy.org> | 2024-07-25 17:32:43 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-25 17:32:43 (GMT) |
commit | 5e686ff57d6bc2fd8c675bd2c59a064be6da2839 (patch) | |
tree | c792148ac53c8d5df02058e6ec3015f2367093be /Include | |
parent | aef95eb107fef9355c66461612aedd31265f8c21 (diff) | |
download | cpython-5e686ff57d6bc2fd8c675bd2c59a064be6da2839.zip cpython-5e686ff57d6bc2fd8c675bd2c59a064be6da2839.tar.gz cpython-5e686ff57d6bc2fd8c675bd2c59a064be6da2839.tar.bz2 |
GH-122034: Add StackRef variants of type checks to reduce the number of PyStackRef_AsPyObjectBorrow calls (GH-122037)
Diffstat (limited to 'Include')
-rw-r--r-- | Include/internal/pycore_stackref.h | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/Include/internal/pycore_stackref.h b/Include/internal/pycore_stackref.h index 8d3d559..1b35a3e 100644 --- a/Include/internal/pycore_stackref.h +++ b/Include/internal/pycore_stackref.h @@ -11,6 +11,7 @@ extern "C" { #include "pycore_object_deferred.h" #include <stddef.h> +#include <stdbool.h> /* This file introduces a new API for handling references on the stack, called @@ -237,6 +238,38 @@ _PyObjectStack_FromStackRefStack(PyObject **dst, const _PyStackRef *src, size_t } } +// StackRef type checks + +static inline bool +PyStackRef_GenCheck(_PyStackRef stackref) +{ + return PyGen_Check(PyStackRef_AsPyObjectBorrow(stackref)); +} + +static inline bool +PyStackRef_BoolCheck(_PyStackRef stackref) +{ + return PyBool_Check(PyStackRef_AsPyObjectBorrow(stackref)); +} + +static inline bool +PyStackRef_LongCheck(_PyStackRef stackref) +{ + return PyLong_Check(PyStackRef_AsPyObjectBorrow(stackref)); +} + +static inline bool +PyStackRef_ExceptionInstanceCheck(_PyStackRef stackref) +{ + return PyExceptionInstance_Check(PyStackRef_AsPyObjectBorrow(stackref)); +} + + +static inline bool +PyStackRef_FunctionCheck(_PyStackRef stackref) +{ + return PyFunction_Check(PyStackRef_AsPyObjectBorrow(stackref)); +} #ifdef __cplusplus } |