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
Use PyObject* to avoid casts
  • Loading branch information
sweeneyde committed Jan 27, 2022
commit fa6a26aade7c144df876f6b675758ff311508fe1
2 changes: 1 addition & 1 deletion Include/internal/pycore_floatobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ struct _Py_float_state {
#endif
};

PyAPI_FUNC(void) _PyFloat_ExactDealloc(PyFloatObject *op);
PyAPI_FUNC(void) _PyFloat_ExactDealloc(PyObject *op);

/* _PyFloat_{Pack,Unpack}{4,8}
*
Expand Down
2 changes: 1 addition & 1 deletion Include/internal/pycore_long.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ PyAPI_FUNC(char*) _PyLong_FormatBytesWriter(
int base,
int alternate);

PyAPI_FUNC(void) _PyLong_ExactDealloc(PyLongObject *op);
PyAPI_FUNC(void) _PyLong_ExactDealloc(PyObject *op);

#ifdef __cplusplus
}
Expand Down
2 changes: 1 addition & 1 deletion Include/internal/pycore_unicodeobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ extern "C" {

#include "pycore_fileutils.h" // _Py_error_handler

void _PyUnicode_ExactDealloc(PyUnicodeObject *op);
void _PyUnicode_ExactDealloc(PyObject *op);

/* runtime lifecycle */

Expand Down
10 changes: 6 additions & 4 deletions Objects/floatobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,10 @@ PyFloat_FromString(PyObject *v)
}

void
_PyFloat_ExactDealloc(PyFloatObject *op)
_PyFloat_ExactDealloc(PyObject *obj)
{
assert(PyFloat_CheckExact(op));
assert(PyFloat_CheckExact(obj));
PyFloatObject *op = (PyFloatObject *)obj;
#if PyFloat_MAXFREELIST > 0
struct _Py_float_state *state = get_float_state();
#ifdef Py_DEBUG
Expand All @@ -261,16 +262,17 @@ _PyFloat_ExactDealloc(PyFloatObject *op)
}

static void
float_dealloc(PyFloatObject *op)
float_dealloc(PyObject *op)
{
assert(PyFloat_Check(op));
#if PyFloat_MAXFREELIST > 0
if (PyFloat_CheckExact(op)) {
_PyFloat_ExactDealloc(op);
}
else
#endif
{
Py_TYPE(op)->tp_free((PyObject *)op);
Py_TYPE(op)->tp_free(op);
}
}

Expand Down
2 changes: 1 addition & 1 deletion Objects/longobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -5753,7 +5753,7 @@ int_from_bytes_impl(PyTypeObject *type, PyObject *bytes_obj,
}

void
_PyLong_ExactDealloc(PyLongObject *op)
_PyLong_ExactDealloc(PyObject *op)
{
assert(PyLong_CheckExact(op));
PyObject_Del(op);
Expand Down
4 changes: 2 additions & 2 deletions Objects/unicodeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -15464,10 +15464,10 @@ unicode_subtype_new(PyTypeObject *type, PyObject *unicode)
}

void
_PyUnicode_ExactDealloc(PyUnicodeObject *op)
_PyUnicode_ExactDealloc(PyObject *op)
{
assert(PyUnicode_CheckExact(op));
unicode_dealloc((PyObject *)op);
unicode_dealloc(op);
}

PyDoc_STRVAR(unicode_doc,
Expand Down
54 changes: 27 additions & 27 deletions Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -2024,8 +2024,8 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
STAT_INC(BINARY_OP, hit);
PyObject *prod = _PyLong_Multiply((PyLongObject *)left, (PyLongObject *)right);
SET_SECOND(prod);
_Py_DECREF_SPECIALIZED(right, (destructor)_PyLong_ExactDealloc);
_Py_DECREF_SPECIALIZED(left, (destructor)_PyLong_ExactDealloc);
_Py_DECREF_SPECIALIZED(right, _PyLong_ExactDealloc);
_Py_DECREF_SPECIALIZED(left, _PyLong_ExactDealloc);
STACK_SHRINK(1);
if (prod == NULL) {
goto error;
Expand All @@ -2043,8 +2043,8 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
((PyFloatObject *)right)->ob_fval;
PyObject *prod = PyFloat_FromDouble(dprod);
SET_SECOND(prod);
_Py_DECREF_SPECIALIZED(right, (destructor)_PyFloat_ExactDealloc);
_Py_DECREF_SPECIALIZED(left, (destructor)_PyFloat_ExactDealloc);
_Py_DECREF_SPECIALIZED(right, _PyFloat_ExactDealloc);
_Py_DECREF_SPECIALIZED(left, _PyFloat_ExactDealloc);
STACK_SHRINK(1);
if (prod == NULL) {
goto error;
Expand All @@ -2060,8 +2060,8 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
STAT_INC(BINARY_OP, hit);
PyObject *sub = _PyLong_Subtract((PyLongObject *)left, (PyLongObject *)right);
SET_SECOND(sub);
_Py_DECREF_SPECIALIZED(right, (destructor)_PyLong_ExactDealloc);
_Py_DECREF_SPECIALIZED(left, (destructor)_PyLong_ExactDealloc);
_Py_DECREF_SPECIALIZED(right, _PyLong_ExactDealloc);
_Py_DECREF_SPECIALIZED(left, _PyLong_ExactDealloc);
STACK_SHRINK(1);
if (sub == NULL) {
goto error;
Expand All @@ -2078,8 +2078,8 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
double dsub = ((PyFloatObject *)left)->ob_fval - ((PyFloatObject *)right)->ob_fval;
PyObject *sub = PyFloat_FromDouble(dsub);
SET_SECOND(sub);
_Py_DECREF_SPECIALIZED(right, (destructor)_PyFloat_ExactDealloc);
_Py_DECREF_SPECIALIZED(left, (destructor)_PyFloat_ExactDealloc);
_Py_DECREF_SPECIALIZED(right, _PyFloat_ExactDealloc);
_Py_DECREF_SPECIALIZED(left, _PyFloat_ExactDealloc);
STACK_SHRINK(1);
if (sub == NULL) {
goto error;
Expand All @@ -2096,8 +2096,8 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
PyObject *res = PyUnicode_Concat(left, right);
STACK_SHRINK(1);
SET_TOP(res);
_Py_DECREF_SPECIALIZED(left, (destructor)_PyUnicode_ExactDealloc);
_Py_DECREF_SPECIALIZED(right, (destructor)_PyUnicode_ExactDealloc);
_Py_DECREF_SPECIALIZED(left, _PyUnicode_ExactDealloc);
_Py_DECREF_SPECIALIZED(right, _PyUnicode_ExactDealloc);
if (TOP() == NULL) {
goto error;
}
Expand All @@ -2122,10 +2122,10 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
DEOPT_IF(var != left, BINARY_OP);
STAT_INC(BINARY_OP, hit);
GETLOCAL(next_oparg) = NULL;
_Py_DECREF_SPECIALIZED(left, (destructor)_PyUnicode_ExactDealloc);
_Py_DECREF_SPECIALIZED(left, _PyUnicode_ExactDealloc);
STACK_SHRINK(1);
PyUnicode_Append(&TOP(), right);
_Py_DECREF_SPECIALIZED(right, (destructor)_PyUnicode_ExactDealloc);
_Py_DECREF_SPECIALIZED(right, _PyUnicode_ExactDealloc);
if (TOP() == NULL) {
goto error;
}
Expand All @@ -2142,8 +2142,8 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
((PyFloatObject *)right)->ob_fval;
PyObject *sum = PyFloat_FromDouble(dsum);
SET_SECOND(sum);
_Py_DECREF_SPECIALIZED(right, (destructor)_PyFloat_ExactDealloc);
_Py_DECREF_SPECIALIZED(left, (destructor)_PyFloat_ExactDealloc);
_Py_DECREF_SPECIALIZED(right, _PyFloat_ExactDealloc);
_Py_DECREF_SPECIALIZED(left, _PyFloat_ExactDealloc);
STACK_SHRINK(1);
if (sum == NULL) {
goto error;
Expand All @@ -2159,8 +2159,8 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
STAT_INC(BINARY_OP, hit);
PyObject *sum = _PyLong_Add((PyLongObject *)left, (PyLongObject *)right);
SET_SECOND(sum);
_Py_DECREF_SPECIALIZED(right, (destructor)_PyLong_ExactDealloc);
_Py_DECREF_SPECIALIZED(left, (destructor)_PyLong_ExactDealloc);
_Py_DECREF_SPECIALIZED(right, _PyLong_ExactDealloc);
_Py_DECREF_SPECIALIZED(left, _PyLong_ExactDealloc);
STACK_SHRINK(1);
if (sum == NULL) {
goto error;
Expand Down Expand Up @@ -2218,7 +2218,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
assert(res != NULL);
Py_INCREF(res);
STACK_SHRINK(1);
_Py_DECREF_SPECIALIZED(sub, (destructor)_PyLong_ExactDealloc);
_Py_DECREF_SPECIALIZED(sub, _PyLong_ExactDealloc);
SET_TOP(res);
Py_DECREF(list);
DISPATCH();
Expand All @@ -2241,7 +2241,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
assert(res != NULL);
Py_INCREF(res);
STACK_SHRINK(1);
_Py_DECREF_SPECIALIZED(sub, (destructor)_PyLong_ExactDealloc);
_Py_DECREF_SPECIALIZED(sub, _PyLong_ExactDealloc);
SET_TOP(res);
Py_DECREF(tuple);
DISPATCH();
Expand Down Expand Up @@ -2372,7 +2372,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
STACK_SHRINK(3);
assert(old_value != NULL);
Py_DECREF(old_value);
_Py_DECREF_SPECIALIZED(sub, (destructor)_PyLong_ExactDealloc);
_Py_DECREF_SPECIALIZED(sub, _PyLong_ExactDealloc);
Py_DECREF(list);
DISPATCH();
}
Expand Down Expand Up @@ -3211,12 +3211,12 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
goto error;
}
str = _PyUnicode_JoinArray(empty, stack_pointer - oparg, oparg);
_Py_DECREF_SPECIALIZED(empty, (destructor)_PyUnicode_ExactDealloc);
_Py_DECREF_SPECIALIZED(empty, _PyUnicode_ExactDealloc);
if (str == NULL)
goto error;
while (--oparg >= 0) {
PyObject *item = POP();
_Py_DECREF_SPECIALIZED(item, (destructor)_PyUnicode_ExactDealloc);
_Py_DECREF_SPECIALIZED(item, _PyUnicode_ExactDealloc);
}
PUSH(str);
DISPATCH();
Expand Down Expand Up @@ -3741,8 +3741,8 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
STAT_INC(COMPARE_OP, hit);
NEXTOPARG();
STACK_SHRINK(2);
_Py_DECREF_SPECIALIZED(left, (destructor)_PyFloat_ExactDealloc);
_Py_DECREF_SPECIALIZED(right, (destructor)_PyFloat_ExactDealloc);
_Py_DECREF_SPECIALIZED(left, _PyFloat_ExactDealloc);
_Py_DECREF_SPECIALIZED(right, _PyFloat_ExactDealloc);
assert(opcode == POP_JUMP_IF_TRUE || opcode == POP_JUMP_IF_FALSE);
int jump = (1 << (sign + 1)) & when_to_jump_mask;
if (!jump) {
Expand Down Expand Up @@ -3774,8 +3774,8 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
int sign = (ileft > iright) - (ileft < iright);
NEXTOPARG();
STACK_SHRINK(2);
_Py_DECREF_SPECIALIZED(left, (destructor)_PyLong_ExactDealloc);
_Py_DECREF_SPECIALIZED(right, (destructor)_PyLong_ExactDealloc);
_Py_DECREF_SPECIALIZED(left, _PyLong_ExactDealloc);
_Py_DECREF_SPECIALIZED(right, _PyLong_ExactDealloc);
assert(opcode == POP_JUMP_IF_TRUE || opcode == POP_JUMP_IF_FALSE);
int jump = (1 << (sign + 1)) & when_to_jump_mask;
if (!jump) {
Expand Down Expand Up @@ -3808,8 +3808,8 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
NEXTOPARG();
assert(opcode == POP_JUMP_IF_TRUE || opcode == POP_JUMP_IF_FALSE);
STACK_SHRINK(2);
_Py_DECREF_SPECIALIZED(left, (destructor)_PyUnicode_ExactDealloc);
_Py_DECREF_SPECIALIZED(right, (destructor)_PyUnicode_ExactDealloc);
_Py_DECREF_SPECIALIZED(left, _PyUnicode_ExactDealloc);
_Py_DECREF_SPECIALIZED(right, _PyUnicode_ExactDealloc);
assert(res == 0 || res == 1);
assert(invert == 0 || invert == 1);
int jump = res ^ invert;
Expand Down
0