From 052faee33d073b76cb4cf097944ad3c76be42944 Mon Sep 17 00:00:00 2001 From: Pieter Eendebak Date: Sun, 22 Dec 2024 20:37:02 +0100 Subject: [PATCH] cleanup --- Include/cpython/object.h | 1 + Include/internal/pycore_freelist_state.h | 4 --- Objects/listobject.c | 16 +++++------- Objects/rangeobject.c | 32 +++++++----------------- Objects/tupleobject.c | 14 +++-------- PCbuild/build.bat | 2 +- 6 files changed, 21 insertions(+), 48 deletions(-) diff --git a/Include/cpython/object.h b/Include/cpython/object.h index e4797029da431e..6ebda99a5e2d7b 100644 --- a/Include/cpython/object.h +++ b/Include/cpython/object.h @@ -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); diff --git a/Include/internal/pycore_freelist_state.h b/Include/internal/pycore_freelist_state.h index db8363aa8c75ce..a1a94c1f2dc880 100644 --- a/Include/internal/pycore_freelist_state.h +++ b/Include/internal/pycore_freelist_state.h @@ -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 @@ -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; diff --git a/Objects/listobject.c b/Objects/listobject.c index c91ebe42a0f638..a877bad66be45f 100644 --- a/Objects/listobject.c +++ b/Objects/listobject.c @@ -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); @@ -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 diff --git a/Objects/rangeobject.c b/Objects/rangeobject.c index 529525e106b3c6..345d1f1643cdbe 100644 --- a/Objects/rangeobject.c +++ b/Objects/rangeobject.c @@ -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" @@ -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; @@ -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 @@ -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."); @@ -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 */ @@ -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; diff --git a/Objects/tupleobject.c b/Objects/tupleobject.c index d2a18f8f7ac11b..60e4fa785663cf 100644 --- a/Objects/tupleobject.c +++ b/Objects/tupleobject.c @@ -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 @@ -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); diff --git a/PCbuild/build.bat b/PCbuild/build.bat index c1d1980beef2ef..d3e3894c203a65 100644 --- a/PCbuild/build.bat +++ b/PCbuild/build.bat @@ -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