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
Remove _PyLong_ExactDealloc
  • Loading branch information
sweeneyde committed Apr 19, 2022
commit 3dd308a8d03aacd641a95b0c7126f66134e7d908
2 changes: 0 additions & 2 deletions Include/internal/pycore_long.h
8000
Original file line number Diff line numberDiff line change
Expand Up @@ -73,8 +73,6 @@ PyAPI_FUNC(char*) _PyLong_FormatBytesWriter(
int base,
int alternate);

void _PyLong_ExactDealloc(PyObject *op);

#ifdef __cplusplus
}
#endif
Expand Down
11 changes: 2 additions & 9 deletions Objects/longobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ static inline void
_Py_DECREF_INT(PyLongObject *op)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this ultimately equivalent to

#define _Py_DECREF_INT(op) _Py_DECREF_SPECIALIZED(op, PyObject_Free)

?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed _PyLongExactDealloc, but I'd like to keep the assertion around to make sure we're never accidentally calling this on int subclasses.

{
assert(PyLong_CheckExact(op));
_Py_DECREF_SPECIALIZED((PyObject *)op, _PyLong_ExactDealloc);
_Py_DECREF_SPECIALIZED((PyObject *)op, PyObject_Free);
}

static inline int
Expand Down Expand Up @@ -5860,13 +5860,6 @@ int_from_bytes_impl(PyTypeObject *type, PyObject *bytes_obj,
return long_obj;
}

void
_PyLong_ExactDealloc(PyObject *op)
{
assert(PyLong_CheckExact(op));
PyObject_Del(op);
}

static PyObject *
long_long_meth(PyObject *self, PyObject *Py_UNUSED(ignored))
{
Expand Down Expand Up @@ -6008,7 +6001,7 @@ PyTypeObject PyLong_Type = {
0, /* tp_init */
0, /* tp_alloc */
long_new, /* tp_new */
PyObject_Del, /* tp_free */
PyObject_Free, /* tp_free */
};

static PyTypeObject Int_InfoType;
Expand Down
22 changes: 11 additions & 11 deletions Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -1977,8 +1977,8 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
STAT_INC(BINARY_OP, hit);
PyObject *prod = _PyLong_Multiply((PyLongObject *)left, (PyLongObject *)right);
SET_SECOND(prod);
_Py_DECREF_SPECIALIZED(right, _PyLong_ExactDealloc);
_Py_DECREF_SPECIALIZED(left, _PyLong_ExactDealloc);
_Py_DECREF_SPECIALIZED(right, PyObject_Free);
_Py_DECREF_SPECIALIZED(left, PyObject_Free);
STACK_SHRINK(1);
if (prod == NULL) {
goto error;
Expand Down Expand Up @@ -2017,8 +2017,8 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
STAT_INC(BINARY_OP, hit);
PyObject *sub = _PyLong_Subtract((PyLongObject *)left, (PyLongObject *)right);
SET_SECOND(sub);
_Py_DECREF_SPECIALIZED(right, _PyLong_ExactDealloc);
_Py_DECREF_SPECIALIZED(left, _PyLong_ExactDealloc);
_Py_DECREF_SPECIALIZED(right, PyObject_Free);
_Py_DECREF_SPECIALIZED(left, PyObject_Free);
STACK_SHRINK(1);
if (sub == NULL) {
goto error;
Expand Down Expand Up @@ -2132,8 +2132,8 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
STAT_INC(BINARY_OP, hit);
PyObject *sum = _PyLong_Add((PyLongObject *)left, (PyLongObject *)right);
SET_SECOND(sum);
_Py_DECREF_SPECIALIZED(right, _PyLong_ExactDealloc);
_Py_DECREF_SPECIALIZED(left, _PyLong_ExactDealloc);
_Py_DECREF_SPECIALIZED(right, PyObject_Free);
_Py_DECREF_SPECIALIZED(left, PyObject_Free);
STACK_SHRINK(1);
if (sum == NULL) {
goto error;
Expand Down Expand Up @@ -2192,7 +2192,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
assert(res != NULL);
Py_INCREF(res);
STACK_SHRINK(1);
_Py_DECREF_SPECIALIZED(sub, _PyLong_ExactDealloc);
_Py_DECREF_SPECIALIZED(sub, PyObject_Free);
SET_TOP(res);
Py_DECREF(list);
JUMPBY(INLINE_CACHE_ENTRIES_BINARY_SUBSCR);
Expand All @@ -2217,7 +2217,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
assert(res != NULL);
Py_INCREF(res);
STACK_SHRINK(1);
_Py_DECREF_SPECIALIZED(sub, _PyLong_ExactDealloc);
_Py_DECREF_SPECIALIZED(sub, PyObject_Free);
SET_TOP(res);
Py_DECREF(tuple);
JUMPBY(INLINE_CACHE_ENTRIES_BINARY_SUBSCR);
Expand Down Expand Up @@ -2359,7 +2359,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
STACK_SHRINK(3);
assert(old_value != NULL);
Py_DECREF(old_value);
_Py_DECREF_SPECIALIZED(sub, _PyLong_ExactDealloc);
_Py_DECREF_SPECIALIZED(sub, PyObject_Free);
Py_DECREF(list);
JUMPBY(INLINE_CACHE_ENTRIES_STORE_SUBSCR);
NOTRACE_DISPATCH();
Expand Down Expand Up @@ -3795,8 +3795,8 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
JUMPBY(INLINE_CACHE_ENTRIES_COMPARE_OP);
NEXTOPARG();
STACK_SHRINK(2);
_Py_DECREF_SPECIALIZED(left, _PyLong_ExactDealloc);
_Py_DECREF_SPECIALIZED(right, _PyLong_ExactDealloc);
_Py_DECREF_SPECIALIZED(left, PyObject_Free);
_Py_DECREF_SPECIALIZED(right, PyObject_Free);
assert(opcode == POP_JUMP_FORWARD_IF_FALSE ||
opcode == POP_JUMP_BACKWARD_IF_FALSE ||
opcode == POP_JUMP_FORWARD_IF_TRUE ||
Expand Down
0