mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
gh-90667: Add specializations of Py_DECREF when types are known (GH-30872)
This commit is contained in:
parent
ab0d35d70d
commit
da6c78584b
13 changed files with 147 additions and 85 deletions
|
@ -38,6 +38,8 @@ struct _Py_float_state {
|
|||
#endif
|
||||
};
|
||||
|
||||
void _PyFloat_ExactDealloc(PyObject *op);
|
||||
|
||||
|
||||
PyAPI_FUNC(void) _PyFloat_DebugMallocStats(FILE* out);
|
||||
|
||||
|
|
|
@ -14,7 +14,6 @@ extern "C" {
|
|||
#include "pycore_pystate.h" // _PyInterpreterState_GET()
|
||||
#include "pycore_runtime.h" // _PyRuntime
|
||||
|
||||
|
||||
#define _PyObject_IMMORTAL_INIT(type) \
|
||||
{ \
|
||||
.ob_refcnt = 999999999, \
|
||||
|
@ -26,6 +25,42 @@ extern "C" {
|
|||
.ob_size = size, \
|
||||
}
|
||||
|
||||
PyAPI_FUNC(void) _Py_NO_RETURN _Py_FatalRefcountErrorFunc(
|
||||
const char *func,
|
||||
const char *message);
|
||||
|
||||
#define _Py_FatalRefcountError(message) _Py_FatalRefcountErrorFunc(__func__, message)
|
||||
|
||||
static inline void
|
||||
_Py_DECREF_SPECIALIZED(PyObject *op, const destructor destruct)
|
||||
{
|
||||
#ifdef Py_REF_DEBUG
|
||||
_Py_RefTotal--;
|
||||
#endif
|
||||
if (--op->ob_refcnt != 0) {
|
||||
assert(op->ob_refcnt > 0);
|
||||
}
|
||||
else {
|
||||
#ifdef Py_TRACE_REFS
|
||||
_Py_ForgetReference(op);
|
||||
#endif
|
||||
destruct(op);
|
||||
}
|
||||
}
|
||||
|
||||
static inline void
|
||||
_Py_DECREF_NO_DEALLOC(PyObject *op)
|
||||
{
|
||||
#ifdef Py_REF_DEBUG
|
||||
_Py_RefTotal--;
|
||||
#endif
|
||||
op->ob_refcnt--;
|
||||
#ifdef Py_DEBUG
|
||||
if (op->ob_refcnt <= 0) {
|
||||
_Py_FatalRefcountError("Expected a positive remaining refcount");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
PyAPI_FUNC(int) _PyType_CheckConsistency(PyTypeObject *type);
|
||||
PyAPI_FUNC(int) _PyDict_CheckConsistency(PyObject *mp, int check_content);
|
||||
|
|
|
@ -100,13 +100,6 @@ extern PyObject* _Py_Offer_Suggestions(PyObject* exception);
|
|||
PyAPI_FUNC(Py_ssize_t) _Py_UTF8_Edit_Cost(PyObject *str_a, PyObject *str_b,
|
||||
Py_ssize_t max_cost);
|
||||
|
||||
PyAPI_FUNC(void) _Py_NO_RETURN _Py_FatalRefcountErrorFunc(
|
||||
const char *func,
|
||||
const char *message);
|
||||
|
||||
#define _Py_FatalRefcountError(message) _Py_FatalRefcountErrorFunc(__func__, message)
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -10,6 +10,7 @@ extern "C" {
|
|||
|
||||
#include "pycore_fileutils.h" // _Py_error_handler
|
||||
|
||||
void _PyUnicode_ExactDealloc(PyObject *op);
|
||||
|
||||
/* runtime lifecycle */
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue