Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
eendebakpt committed Dec 22, 2024
1 parent 342e997 commit 052faee
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 48 deletions.
1 change: 1 addition & 0 deletions Include/cpython/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ PyAPI_FUNC(void) _Py_NewReference(PyObject *op);
PyAPI_FUNC(void) _Py_NewReferenceNoTotal(PyObject *op);
PyAPI_FUNC(void) _Py_ResurrectReference(PyObject *op);


#ifdef Py_REF_DEBUG
/* These are useful as debugging aids when chasing down refleaks. */
PyAPI_FUNC(Py_ssize_t) _Py_GetGlobalRefTotal(void);
Expand Down
4 changes: 0 additions & 4 deletions Include/internal/pycore_freelist_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ extern "C" {
# define Py_floats_MAXFREELIST 100
# define Py_ints_MAXFREELIST 100
# define Py_slices_MAXFREELIST 1
# define Py_ranges_MAXFREELIST 10
# define Py_shared_iters_MAXFREELIST 24
# define Py_contexts_MAXFREELIST 255
# define Py_async_gens_MAXFREELIST 80
# define Py_async_gen_asends_MAXFREELIST 80
Expand All @@ -44,8 +42,6 @@ struct _Py_freelists {
struct _Py_freelist dicts;
struct _Py_freelist dictkeys;
struct _Py_freelist slices;
struct _Py_freelist ranges;
struct _Py_freelist shared_iters;
struct _Py_freelist contexts;
struct _Py_freelist async_gens;
struct _Py_freelist async_gen_asends;
Expand Down
16 changes: 6 additions & 10 deletions Objects/listobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -3910,19 +3910,15 @@ PyTypeObject PyListIter_Type = {
static PyObject *
list_iter(PyObject *seq)
{
_PyListIterObject *it;

if (!PyList_Check(seq)) {
PyErr_BadInternalCall();
return NULL;
}
_PyListIterObject *it = _Py_FREELIST_POP(_PyListIterObject, shared_iters);
if (it == NULL) {
it = PyObject_GC_New(_PyListIterObject, &PyListIter_Type);
if (it == NULL) {
return NULL;
}
} else {
Py_SET_TYPE(it, &PyListIter_Type);
}
it = PyObject_GC_New(_PyListIterObject, &PyListIter_Type);
if (it == NULL)
return NULL;
it->it_index = 0;
it->it_seq = (PyListObject *)Py_NewRef(seq);
_PyObject_GC_TRACK(it);
Expand All @@ -3935,7 +3931,7 @@ listiter_dealloc(PyObject *self)
_PyListIterObject *it = (_PyListIterObject *)self;
_PyObject_GC_UNTRACK(it);
Py_XDECREF(it->it_seq);
_Py_FREELIST_FREE(shared_iters, it, PyObject_GC_Del);
PyObject_GC_Del(it);
}

static int
Expand Down
32 changes: 9 additions & 23 deletions Objects/rangeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include "Python.h"
#include "pycore_abstract.h" // _PyIndex_Check()
#include "pycore_ceval.h" // _PyEval_GetBuiltin()
#include "pycore_freelist.h" // _Py_FREELIST_FREE(), _Py_FREELIST_POP()
#include "pycore_long.h" // _PyLong_GetZero()
#include "pycore_modsupport.h" // _PyArg_NoKwnames()
#include "pycore_range.h"
Expand Down Expand Up @@ -52,18 +51,16 @@ static rangeobject *
make_range_object(PyTypeObject *type, PyObject *start,
PyObject *stop, PyObject *step)
{
rangeobject *obj = NULL;
PyObject *length;
length = compute_range_length(start, stop, step);
if (length == NULL) {
return NULL;
}
rangeobject *obj = _Py_FREELIST_POP(rangeobject, ranges);
obj = PyObject_New(rangeobject, type);
if (obj == NULL) {
obj = PyObject_New(rangeobject, type);
if (obj == NULL) {
Py_DECREF(length);
return NULL;
}
Py_DECREF(length);
return NULL;
}
obj->start = start;
obj->stop = stop;
Expand Down Expand Up @@ -173,7 +170,7 @@ range_dealloc(rangeobject *r)
Py_DECREF(r->stop);
Py_DECREF(r->step);
Py_DECREF(r->length);
_Py_FREELIST_FREE(ranges, r, PyObject_Free);
PyObject_Free(r);
}

static unsigned long
Expand Down Expand Up @@ -883,11 +880,6 @@ rangeiter_setstate(_PyRangeIterObject *r, PyObject *state)
Py_RETURN_NONE;
}

static void
rangeiter_dealloc(_PyRangeIterObject *r)
{
_Py_FREELIST_FREE(shared_iters, r, PyObject_Free);
}

PyDoc_STRVAR(reduce_doc, "Return state information for pickling.");
PyDoc_STRVAR(setstate_doc, "Set state information for unpickling.");
Expand All @@ -908,7 +900,7 @@ PyTypeObject PyRangeIter_Type = {
sizeof(_PyRangeIterObject), /* tp_basicsize */
0, /* tp_itemsize */
/* methods */
(destructor)rangeiter_dealloc, /* tp_dealloc */
(destructor)PyObject_Free, /* tp_dealloc */
0, /* tp_vectorcall_offset */
0, /* tp_getattr */
0, /* tp_setattr */
Expand Down Expand Up @@ -969,15 +961,9 @@ get_len_of_range(long lo, long hi, long step)
static PyObject *
fast_range_iter(long start, long stop, long step, long len)
{
_PyRangeIterObject *it = _Py_FREELIST_POP(_PyRangeIterObject, shared_iters);
if (it == NULL) {
it = PyObject_New(_PyRangeIterObject, &PyRangeIter_Type);
if (it == NULL)
return NULL;
}
else {
Py_SET_TYPE(it, &PyRangeIter_Type);
}
_PyRangeIterObject *it = PyObject_New(_PyRangeIterObject, &PyRangeIter_Type);
if (it == NULL)
return NULL;
it->start = start;
it->step = step;
it->len = len;
Expand Down
14 changes: 4 additions & 10 deletions Objects/tupleobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -994,8 +994,7 @@ tupleiter_dealloc(_PyTupleIterObject *it)
{
_PyObject_GC_UNTRACK(it);
Py_XDECREF(it->it_seq);
assert(sizeof(_PyTupleIterObject)==sizeof(_PyListIterObject));
_Py_FREELIST_FREE(shared_iters, it, PyObject_GC_Del);
PyObject_GC_Del(it);
}

static int
Expand Down Expand Up @@ -1123,15 +1122,10 @@ tuple_iter(PyObject *seq)
PyErr_BadInternalCall();
return NULL;
}
it = _Py_FREELIST_POP(_PyTupleIterObject, shared_iters);

if (it == NULL) {
it = PyObject_GC_New(_PyTupleIterObject, &PyTupleIter_Type);
if (it == NULL)
return NULL;
} else {
Py_SET_TYPE(it, &PyTupleIter_Type);
}
it = PyObject_GC_New(_PyTupleIterObject, &PyTupleIter_Type);
if (it == NULL)
return NULL;
it->it_index = 0;
it->it_seq = (PyTupleObject *)Py_NewRef(seq);
_PyObject_GC_TRACK(it);
Expand Down
2 changes: 1 addition & 1 deletion PCbuild/build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ echo on
/p:UseTestMarker=%UseTestMarker% %GITProperty%^
/p:UseJIT=%UseJIT%^
/p:UseTIER2=%UseTIER2%^
/p:Py_Stats=%Py_Stats%^
/p:PyStats=%PyStats%^
%1 %2 %3 %4 %5 %6 %7 %8 %9

@echo off
Expand Down

0 comments on commit 052faee

Please sign in to comment.