Skip to content
Closed
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
20 changes: 17 additions & 3 deletions gmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ MPZ_new(void)
if (global.freelist_size) {
res = global.freelist[--global.freelist_size];
(void)zz_set(0, &res->z);
Py_INCREF((PyObject *)res);
}
else {
#endif
Expand Down Expand Up @@ -607,16 +606,28 @@ new(PyTypeObject *type, PyObject *args, PyObject *keywds)
return new_impl(type, arg, base);
}

#ifdef ON_CPYTHON
static void
dealloc(PyObject *self)
finalize(PyObject *self)
{
MPZ_Object *u = (MPZ_Object *)self;

#ifdef ON_CPYTHON
if (global.freelist_size < MAX_FREELIST_SIZE
&& zz_sizeof(&u->z) <= MAX_FREELIST_SIZEOF
&& MPZ_CheckExact(self))
{
Py_INCREF(self);
}
}
#endif

static void
dealloc(PyObject *self)
{
MPZ_Object *u = (MPZ_Object *)self;

#ifdef ON_CPYTHON
if (PyObject_CallFinalizerFromDealloc(self)) {
global.freelist[global.freelist_size++] = u;
}
else {
Expand Down Expand Up @@ -1949,6 +1960,9 @@ PyTypeObject MPZ_Type = {
.tp_basicsize = sizeof(MPZ_Object),
.tp_new = new,
.tp_dealloc = dealloc,
#ifdef ON_CPYTHON
.tp_finalize = finalize,
#endif
.tp_repr = repr,
.tp_str = str,
.tp_richcompare = richcompare,
Expand Down
Loading