Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions Include/internal/pycore_freelist_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ extern "C" {
# define Py_dictkeys_MAXFREELIST 80
# define Py_floats_MAXFREELIST 100
# define Py_complexes_MAXFREELIST 100
# define Py_decimals_MAXFREELIST 100
# define Py_ints_MAXFREELIST 100
# define Py_slices_MAXFREELIST 1
# define Py_ranges_MAXFREELIST 6
Expand Down Expand Up @@ -47,6 +48,7 @@ struct _Py_freelists {
struct _Py_freelist floats;
struct _Py_freelist complexes;
struct _Py_freelist ints;
struct _Py_freelist decimals;
struct _Py_freelist tuples[PyTuple_MAXSAVESIZE];
struct _Py_freelist lists;
struct _Py_freelist list_iters;
Expand Down
22 changes: 15 additions & 7 deletions Modules/_decimal/_decimal.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#endif

#include <Python.h>
#include "pycore_freelist.h" // _Py_FREELIST_POP()
#include "pycore_object.h" // _PyObject_VisitType()
#include "pycore_pystate.h" // _PyThreadState_GET()
#include "pycore_tuple.h" // _PyTuple_FromPair
Expand Down Expand Up @@ -2197,7 +2198,11 @@ PyDecType_New(decimal_state *state, PyTypeObject *type)
PyDecObject *dec;

if (type == state->PyDec_Type) {
dec = PyObject_GC_New(PyDecObject, state->PyDec_Type);
dec = _Py_FREELIST_POP(PyDecObject, decimals);
if (dec == NULL) {
dec = PyObject_GC_New(PyDecObject, state->PyDec_Type);
PyObject_GC_Track(dec);
}
}
else {
dec = (PyDecObject *)type->tp_alloc(type, 0);
Expand All @@ -2215,9 +2220,6 @@ PyDecType_New(decimal_state *state, PyTypeObject *type)
MPD(dec)->alloc = _Py_DEC_MINALLOC;
MPD(dec)->data = dec->data;

if (type == state->PyDec_Type) {
PyObject_GC_Track(dec);
}
assert(PyObject_GC_IsTracked((PyObject *)dec));
return (PyObject *)dec;
}
Expand All @@ -2227,10 +2229,16 @@ static void
dec_dealloc(PyObject *dec)
{
PyTypeObject *tp = Py_TYPE(dec);
PyObject_GC_UnTrack(dec);
decimal_state *state = get_module_state_by_def(tp);

mpd_del(MPD(dec));
tp->tp_free(dec);
Py_DECREF(tp);
if (!PyDec_CheckExact(state, dec)
|| !_Py_FREELIST_PUSH(decimals, dec, Py_decimals_MAXFREELIST))
{
PyObject_GC_UnTrack(dec);
tp->tp_free(dec);
Py_DECREF(tp);
}
}


Expand Down
1 change: 1 addition & 0 deletions Objects/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -955,6 +955,7 @@ _PyObject_ClearFreeLists(struct _Py_freelists *freelists, int is_finalization)
clear_freelist(&freelists->pycfunctionobject, is_finalization, PyObject_GC_Del);
clear_freelist(&freelists->pycmethodobject, is_finalization, PyObject_GC_Del);
clear_freelist(&freelists->pymethodobjects, is_finalization, free_object);
clear_freelist(&freelists->decimals, is_finalization, free_object);
}

/*
Expand Down
Loading