Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
_Py_DECREF_IMMORTAL
  • Loading branch information
sweeneyde committed Jan 25, 2022
commit f58ebcfe7c0025f5991de26f1b33b4dd6700c111
16 changes: 0 additions & 16 deletions Include/boolobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,6 @@ PyAPI_FUNC(int) Py_IsTrue(PyObject *x);
PyAPI_FUNC(int) Py_IsFalse(PyObject *x);
#define Py_IsFalse(x) Py_Is((x), Py_False)

static inline void
_Py_DECREF_BOOL(PyObject *op)
{
assert(PyBool_Check(op));
#ifdef Py_REF_DEBUG
_Py_RefTotal--;
#endif
op->ob_refcnt--;
#ifdef Py_DEBUG
if (op->ob_refcnt <= 0) {
// Calls _Py_FatalRefcountError
_Py_Dealloc(op);
}
#endif
}

/* Macros for returning Py_True or Py_False, respectively */
#define Py_RETURN_TRUE return Py_NewRef(Py_True)
#define Py_RETURN_FALSE return Py_NewRef(Py_False)
Expand Down
31 changes: 15 additions & 16 deletions Include/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,21 @@ _Py_DECREF_SPECIALIZED(PyObject *op, const destructor destruct)
}
}

static inline void
_Py_DECREF_IMMORTAL(PyObject *op)
{
#ifdef Py_REF_DEBUG
_Py_RefTotal--;
#endif
op->ob_refcnt--;
#ifdef Py_DEBUG
if (op->ob_refcnt <= 0) {
// Calls _Py_FatalRefcountError for None, True, and False
_Py_Dealloc(op);
}
#endif
}

/* Safely decref `op` and set `op` to NULL, especially useful in tp_clear
* and tp_dealloc implementations.
*
Expand Down Expand Up @@ -638,22 +653,6 @@ Don't forget to apply Py_INCREF() when returning this value!!!
PyAPI_DATA(PyObject) _Py_NoneStruct; /* Don't use this directly */
#define Py_None (&_Py_NoneStruct)

static inline void
_Py_DECREF_NONE(PyObject *op)
{
assert(op == Py_None);
#ifdef Py_REF_DEBUG
_Py_RefTotal--;
#endif
(void)op;
((PyObject *)Py_None)->ob_refcnt--;
#ifdef Py_DEBUG
if (((PyObject *)Py_None)->ob_refcnt <= 0) {
// Calls _Py_FatalRefcountError
_Py_Dealloc(op);
}
#endif
}

// Test if an object is the None singleton, the same as "x is None" in Python.
PyAPI_FUNC(int) Py_IsNone(PyObject *x);
Expand Down
18 changes: 9 additions & 9 deletions Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -3878,7 +3878,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
}

if (Py_IsNone(match)) {
_Py_DECREF_NONE(match);
_Py_DECREF_IMMORTAL(match);
Py_XDECREF(rest);
/* no match - jump to target */
JUMPTO(oparg);
Expand Down Expand Up @@ -3981,11 +3981,11 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
PyObject *cond = POP();
int err;
if (Py_IsTrue(cond)) {
_Py_DECREF_BOOL(cond);
_Py_DECREF_IMMORTAL(cond);
DISPATCH();
}
if (Py_IsFalse(cond)) {
_Py_DECREF_BOOL(cond);
_Py_DECREF_IMMORTAL(cond);
JUMPTO(oparg);
CHECK_EVAL_BREAKER();
DISPATCH();
Expand All @@ -4008,11 +4008,11 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
PyObject *cond = POP();
int err;
if (Py_IsFalse(cond)) {
_Py_DECREF_BOOL(cond);
_Py_DECREF_IMMORTAL(cond);
DISPATCH();
}
if (Py_IsTrue(cond)) {
_Py_DECREF_BOOL(cond);
_Py_DECREF_IMMORTAL(cond);
JUMPTO(oparg);
CHECK_EVAL_BREAKER();
DISPATCH();
Expand All @@ -4038,14 +4038,14 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
CHECK_EVAL_BREAKER();
DISPATCH();
}
_Py_DECREF_NONE(value);
_Py_DECREF_IMMORTAL(value);
DISPATCH();
}

TARGET(POP_JUMP_IF_NONE) {
PyObject *value = POP();
if (Py_IsNone(value)) {
_Py_DECREF_NONE(value);
_Py_DECREF_IMMORTAL(value);
JUMPTO(oparg);
CHECK_EVAL_BREAKER();
DISPATCH();
Expand All @@ -4059,7 +4059,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
int err;
if (Py_IsTrue(cond)) {
STACK_SHRINK(1);
_Py_DECREF_BOOL(cond);
_Py_DECREF_IMMORTAL(cond);
DISPATCH();
}
if (Py_IsFalse(cond)) {
Expand All @@ -4083,7 +4083,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
int err;
if (Py_IsFalse(cond)) {
STACK_SHRINK(1);
_Py_DECREF_BOOL(cond);
_Py_DECREF_IMMORTAL(cond);
DISPATCH();
}
if (Py_IsTrue(cond)) {
Expand Down