diff options
author | Dennis Sweeney <36520290+sweeneyde@users.noreply.github.com> | 2022-04-19 18:02:19 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-19 18:02:19 (GMT) |
commit | da6c78584b1f45ce3766bf7f27fb033169715292 (patch) | |
tree | aadde6ee2f5323357a7e0e8eff7a97f1fd44ec4b /Include | |
parent | ab0d35d70dfe0b4c11583f8f735a8cc49b58c58b (diff) | |
download | cpython-da6c78584b1f45ce3766bf7f27fb033169715292.zip cpython-da6c78584b1f45ce3766bf7f27fb033169715292.tar.gz cpython-da6c78584b1f45ce3766bf7f27fb033169715292.tar.bz2 |
gh-90667: Add specializations of Py_DECREF when types are known (GH-30872)
Diffstat (limited to 'Include')
-rw-r--r-- | Include/internal/pycore_floatobject.h | 2 | ||||
-rw-r--r-- | Include/internal/pycore_object.h | 37 | ||||
-rw-r--r-- | Include/internal/pycore_pyerrors.h | 7 | ||||
-rw-r--r-- | Include/internal/pycore_unicodeobject.h | 1 |
4 files changed, 39 insertions, 8 deletions
diff --git a/Include/internal/pycore_floatobject.h b/Include/internal/pycore_floatobject.h index a099f2e..8a65554 100644 --- a/Include/internal/pycore_floatobject.h +++ b/Include/internal/pycore_floatobject.h @@ -38,6 +38,8 @@ struct _Py_float_state { #endif }; +void _PyFloat_ExactDealloc(PyObject *op); + PyAPI_FUNC(void) _PyFloat_DebugMallocStats(FILE* out); diff --git a/Include/internal/pycore_object.h b/Include/internal/pycore_object.h index 177b06e..f022f82 100644 --- a/Include/internal/pycore_object.h +++ b/Include/internal/pycore_object.h @@ -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); diff --git a/Include/internal/pycore_pyerrors.h b/Include/internal/pycore_pyerrors.h index e3c445b..66f3794 100644 --- a/Include/internal/pycore_pyerrors.h +++ b/Include/internal/pycore_pyerrors.h @@ -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 diff --git a/Include/internal/pycore_unicodeobject.h b/Include/internal/pycore_unicodeobject.h index 75b9050..4bee241 100644 --- a/Include/internal/pycore_unicodeobject.h +++ b/Include/internal/pycore_unicodeobject.h @@ -10,6 +10,7 @@ extern "C" { #include "pycore_fileutils.h" // _Py_error_handler +void _PyUnicode_ExactDealloc(PyObject *op); /* runtime lifecycle */ |