mirror of
https://github.com/python/cpython.git
synced 2025-10-14 18:59:46 +00:00
GH-122034: Add StackRef variants of type checks to reduce the number of PyStackRef_AsPyObjectBorrow calls (GH-122037)
This commit is contained in:
parent
aef95eb107
commit
5e686ff57d
4 changed files with 60 additions and 27 deletions
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue