GH-122034: Add StackRef variants of type checks to reduce the number of PyStackRef_AsPyObjectBorrow calls (GH-122037)

This commit is contained in:
Mark Shannon 2024-07-25 18:32:43 +01:00 committed by GitHub
parent aef95eb107
commit 5e686ff57d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 60 additions and 27 deletions

View file

@ -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
}