8000 gh-90667: Add specializations of Py_DECREF when types are known by sweeneyde · Pull Request #30872 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-90667: Add specializations of Py_DECREF when types are known #30872

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Apr 19, 2022
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
naming: IMMORTAL --> NO_DEALLOC
  • Loading branch information
sweeneyde committed Apr 12, 2022
commit ad146ef86e5cae1cac0affaefd3eabda37bd6a87
4 changes: 2 additions & 2 deletions Include/internal/pycore_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ _Py_DECREF_SPECIALIZED(PyObject *op, const destructor destruct)
}

static inline void
_Py_DECREF_IMMORTAL(PyObject *op)
_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("deallocating a singleton");
_Py_FatalRefcountError("Expected a positive remaining refcount");
}
#endif
}
Expand Down
28 changes: 14 additions & 14 deletions Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -2018,7 +2018,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
* that the string is safe to mutate.
*/
assert(Py_REFCNT(left) >= 2);
Py_DECREF(left); // XXX never need to dealloc
_Py_DECREF_NO_DEALLOC(left);
STACK_SHRINK(2);
PyUnicode_Append(target_local, right);
_Py_DECREF_SPECIALIZED(right, _PyUnicode_ExactDealloc);
Expand Down Expand Up @@ -3940,11 +3940,11 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
PREDICTED(POP_JUMP_BACKWARD_IF_FALSE);
PyObject *cond = POP();
if (Py_IsTrue(cond)) {
_Py_DECREF_IMMORTAL(cond);
_Py_DECREF_NO_DEALLOC(cond);
DISPATCH();
}
if (Py_IsFalse(cond)) {
_Py_DECREF_IMMORTAL(cond);
_Py_DECREF_NO_DEALLOC(cond);
JUMPBY(-oparg);
CHECK_EVAL_BREAKER();
DISPATCH();
Expand All @@ -3966,10 +3966,10 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
PREDICTED(POP_JUMP_FORWARD_IF_FALSE);
PyObject *cond = POP();
if (Py_IsTrue(cond)) {
_Py_DECREF_IMMORTAL(cond);
_Py_DECREF_NO_DEALLOC(cond);
}
else if (Py_IsFalse(cond)) {
_Py_DECREF_IMMORTAL(cond);
_Py_DECREF_NO_DEALLOC(cond);
JUMPBY(oparg);
}
else {
Expand All @@ -3989,11 +3989,11 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
TARGET(POP_JUMP_BACKWARD_IF_TRUE) {
PyObject *cond = POP();
if (Py_IsFalse(cond)) {
_Py_DECREF_IMMORTAL(cond);
_Py_DECREF_NO_DEALLOC(cond);
DISPATCH();
}
if (Py_IsTrue(cond)) {
_Py_DECREF_IMMORTAL(cond);
_Py_DECREF_NO_DEALLOC(cond);
JUMPBY(-oparg);
CHECK_EVAL_BREAKER();
DISPATCH();
Expand All @@ -4014,10 +4014,10 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
TARGET(POP_JUMP_FORWARD_IF_TRUE) {
PyObject *cond = POP();
if (Py_IsFalse(cond)) {
_Py_DECREF_IMMORTAL(cond);
_Py_DECREF_NO_DEALLOC(cond);
}
else if (Py_IsTrue(cond)) {
_Py_DECREF_IMMORTAL(cond);
_Py_DECREF_NO_DEALLOC(cond);
JUMPBY(oparg);
}
else {
Expand All @@ -4042,7 +4042,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
CHECK_EVAL_BREAKER();
DISPATCH();
}
_Py_DECREF_IMMORTAL(value);
_Py_DECREF_NO_DEALLOC(value);
DISPATCH();
}

Expand All @@ -4058,7 +4058,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
TARGET(POP_JUMP_BACKWARD_IF_NONE) {
PyObject *value = POP();
if (Py_IsNone(value)) {
_Py_DECREF_IMMORTAL(value);
_Py_DECREF_NO_DEALLOC(value);
JUMPBY(-oparg);
CHECK_EVAL_BREAKER();
}
Expand All @@ -4071,7 +4071,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
TARGET(POP_JUMP_FORWARD_IF_NONE) {
PyObject *value = POP();
if (Py_IsNone(value)) {
_Py_DECREF_IMMORTAL(value);
_Py_DECREF_NO_DEALLOC(value);
JUMPBY(oparg);
}
else {
Expand All @@ -4085,7 +4085,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
int err;
if (Py_IsTrue(cond)) {
STACK_SHRINK(1);
_Py_DECREF_IMMORTAL(cond);
_Py_DECREF_NO_DEALLOC(cond);
DISPATCH();
}
if (Py_IsFalse(cond)) {
Expand All @@ -4109,7 +4109,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
int err;
if (Py_IsFalse(cond)) {
STACK_SHRINK(1);
_Py_DECREF_IMMORTAL(cond);
_Py_DECREF_NO_DEALLOC(cond);
DISPATCH();
}
if (Py_IsTrue(cond)) {
Expand Down
0