mirror of https://github.com/python/cpython
bpo-40521: Cleanup code of free lists (GH-21082)
Add get_xxx_state() function to factorize duplicated code.
This commit is contained in:
parent
bc43f6e212
commit
522691c46e
|
@ -249,6 +249,15 @@ static uint64_t pydict_global_version = 0;
|
||||||
|
|
||||||
#include "clinic/dictobject.c.h"
|
#include "clinic/dictobject.c.h"
|
||||||
|
|
||||||
|
|
||||||
|
static struct _Py_dict_state *
|
||||||
|
get_dict_state(void)
|
||||||
|
{
|
||||||
|
PyInterpreterState *interp = _PyInterpreterState_GET();
|
||||||
|
return &interp->dict_state;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
_PyDict_ClearFreeList(PyThreadState *tstate)
|
_PyDict_ClearFreeList(PyThreadState *tstate)
|
||||||
{
|
{
|
||||||
|
@ -269,8 +278,7 @@ _PyDict_Fini(PyThreadState *tstate)
|
||||||
{
|
{
|
||||||
_PyDict_ClearFreeList(tstate);
|
_PyDict_ClearFreeList(tstate);
|
||||||
#ifdef Py_DEBUG
|
#ifdef Py_DEBUG
|
||||||
PyInterpreterState *interp = _PyInterpreterState_GET();
|
struct _Py_dict_state *state = get_dict_state();
|
||||||
struct _Py_dict_state *state = &interp->dict_state;
|
|
||||||
state->numfree = -1;
|
state->numfree = -1;
|
||||||
state->keys_numfree = -1;
|
state->keys_numfree = -1;
|
||||||
#endif
|
#endif
|
||||||
|
@ -281,8 +289,7 @@ _PyDict_Fini(PyThreadState *tstate)
|
||||||
void
|
void
|
||||||
_PyDict_DebugMallocStats(FILE *out)
|
_PyDict_DebugMallocStats(FILE *out)
|
||||||
{
|
{
|
||||||
PyInterpreterState *interp = _PyInterpreterState_GET();
|
struct _Py_dict_state *state = get_dict_state();
|
||||||
struct _Py_dict_state *state = &interp->dict_state;
|
|
||||||
_PyDebugAllocatorStats(out, "free PyDictObject",
|
_PyDebugAllocatorStats(out, "free PyDictObject",
|
||||||
state->numfree, sizeof(PyDictObject));
|
state->numfree, sizeof(PyDictObject));
|
||||||
}
|
}
|
||||||
|
@ -557,8 +564,7 @@ new_keys_object(Py_ssize_t size)
|
||||||
es = sizeof(Py_ssize_t);
|
es = sizeof(Py_ssize_t);
|
||||||
}
|
}
|
||||||
|
|
||||||
PyInterpreterState *interp = _PyInterpreterState_GET();
|
struct _Py_dict_state *state = get_dict_state();
|
||||||
struct _Py_dict_state *state = &interp->dict_state;
|
|
||||||
#ifdef Py_DEBUG
|
#ifdef Py_DEBUG
|
||||||
// new_keys_object() must not be called after _PyDict_Fini()
|
// new_keys_object() must not be called after _PyDict_Fini()
|
||||||
assert(state->keys_numfree != -1);
|
assert(state->keys_numfree != -1);
|
||||||
|
@ -598,8 +604,7 @@ free_keys_object(PyDictKeysObject *keys)
|
||||||
Py_XDECREF(entries[i].me_key);
|
Py_XDECREF(entries[i].me_key);
|
||||||
Py_XDECREF(entries[i].me_value);
|
Py_XDECREF(entries[i].me_value);
|
||||||
}
|
}
|
||||||
PyInterpreterState *interp = _PyInterpreterState_GET();
|
struct _Py_dict_state *state = get_dict_state();
|
||||||
struct _Py_dict_state *state = &interp->dict_state;
|
|
||||||
#ifdef Py_DEBUG
|
#ifdef Py_DEBUG
|
||||||
// free_keys_object() must not be called after _PyDict_Fini()
|
// free_keys_object() must not be called after _PyDict_Fini()
|
||||||
assert(state->keys_numfree != -1);
|
assert(state->keys_numfree != -1);
|
||||||
|
@ -620,8 +625,7 @@ new_dict(PyDictKeysObject *keys, PyObject **values)
|
||||||
{
|
{
|
||||||
PyDictObject *mp;
|
PyDictObject *mp;
|
||||||
assert(keys != NULL);
|
assert(keys != NULL);
|
||||||
PyInterpreterState *interp = _PyInterpreterState_GET();
|
struct _Py_dict_state *state = get_dict_state();
|
||||||
struct _Py_dict_state *state = &interp->dict_state;
|
|
||||||
#ifdef Py_DEBUG
|
#ifdef Py_DEBUG
|
||||||
// new_dict() must not be called after _PyDict_Fini()
|
// new_dict() must not be called after _PyDict_Fini()
|
||||||
assert(state->numfree != -1);
|
assert(state->numfree != -1);
|
||||||
|
@ -1281,8 +1285,7 @@ dictresize(PyDictObject *mp, Py_ssize_t minsize)
|
||||||
#ifdef Py_REF_DEBUG
|
#ifdef Py_REF_DEBUG
|
||||||
_Py_RefTotal--;
|
_Py_RefTotal--;
|
||||||
#endif
|
#endif
|
||||||
PyInterpreterState *interp = _PyInterpreterState_GET();
|
struct _Py_dict_state *state = get_dict_state();
|
||||||
struct _Py_dict_state *state = &interp->dict_state;
|
|
||||||
#ifdef Py_DEBUG
|
#ifdef Py_DEBUG
|
||||||
// dictresize() must not be called after _PyDict_Fini()
|
// dictresize() must not be called after _PyDict_Fini()
|
||||||
assert(state->keys_numfree != -1);
|
assert(state->keys_numfree != -1);
|
||||||
|
@ -2032,8 +2035,7 @@ dict_dealloc(PyDictObject *mp)
|
||||||
assert(keys->dk_refcnt == 1);
|
assert(keys->dk_refcnt == 1);
|
||||||
dictkeys_decref(keys);
|
dictkeys_decref(keys);
|
||||||
}
|
}
|
||||||
PyInterpreterState *interp = _PyInterpreterState_GET();
|
struct _Py_dict_state *state = get_dict_state();
|
||||||
struct _Py_dict_state *state = &interp->dict_state;
|
|
||||||
#ifdef Py_DEBUG
|
#ifdef Py_DEBUG
|
||||||
// new_dict() must not be called after _PyDict_Fini()
|
// new_dict() must not be called after _PyDict_Fini()
|
||||||
assert(state->numfree != -1);
|
assert(state->numfree != -1);
|
||||||
|
|
|
@ -23,6 +23,15 @@ class float "PyObject *" "&PyFloat_Type"
|
||||||
# define PyFloat_MAXFREELIST 100
|
# define PyFloat_MAXFREELIST 100
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
static struct _Py_float_state *
|
||||||
|
get_float_state(void)
|
||||||
|
{
|
||||||
|
PyInterpreterState *interp = _PyInterpreterState_GET();
|
||||||
|
return &interp->float_state;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
double
|
double
|
||||||
PyFloat_GetMax(void)
|
PyFloat_GetMax(void)
|
||||||
{
|
{
|
||||||
|
@ -113,8 +122,7 @@ PyFloat_GetInfo(void)
|
||||||
PyObject *
|
PyObject *
|
||||||
PyFloat_FromDouble(double fval)
|
PyFloat_FromDouble(double fval)
|
||||||
{
|
{
|
||||||
PyInterpreterState *interp = _PyInterpreterState_GET();
|
struct _Py_float_state *state = get_float_state();
|
||||||
struct _Py_float_state *state = &interp->float_state;
|
|
||||||
PyFloatObject *op = state->free_list;
|
PyFloatObject *op = state->free_list;
|
||||||
if (op != NULL) {
|
if (op != NULL) {
|
||||||
#ifdef Py_DEBUG
|
#ifdef Py_DEBUG
|
||||||
|
@ -222,8 +230,7 @@ static void
|
||||||
float_dealloc(PyFloatObject *op)
|
float_dealloc(PyFloatObject *op)
|
||||||
{
|
{
|
||||||
if (PyFloat_CheckExact(op)) {
|
if (PyFloat_CheckExact(op)) {
|
||||||
PyInterpreterState *interp = _PyInterpreterState_GET();
|
struct _Py_float_state *state = get_float_state();
|
||||||
struct _Py_float_state *state = &interp->float_state;
|
|
||||||
#ifdef Py_DEBUG
|
#ifdef Py_DEBUG
|
||||||
// float_dealloc() must not be called after _PyFloat_Fini()
|
// float_dealloc() must not be called after _PyFloat_Fini()
|
||||||
assert(state->numfree != -1);
|
assert(state->numfree != -1);
|
||||||
|
@ -236,8 +243,9 @@ float_dealloc(PyFloatObject *op)
|
||||||
Py_SET_TYPE(op, (PyTypeObject *)state->free_list);
|
Py_SET_TYPE(op, (PyTypeObject *)state->free_list);
|
||||||
state->free_list = op;
|
state->free_list = op;
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
Py_TYPE(op)->tp_free((PyObject *)op);
|
Py_TYPE(op)->tp_free((PyObject *)op);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
double
|
double
|
||||||
|
@ -2017,8 +2025,7 @@ _PyFloat_Fini(PyThreadState *tstate)
|
||||||
void
|
void
|
||||||
_PyFloat_DebugMallocStats(FILE *out)
|
_PyFloat_DebugMallocStats(FILE *out)
|
||||||
{
|
{
|
||||||
PyInterpreterState *interp = _PyInterpreterState_GET();
|
struct _Py_float_state *state = get_float_state();
|
||||||
struct _Py_float_state *state = &interp->float_state;
|
|
||||||
_PyDebugAllocatorStats(out,
|
_PyDebugAllocatorStats(out,
|
||||||
"free PyFloatObject",
|
"free PyFloatObject",
|
||||||
state->numfree, sizeof(PyFloatObject));
|
state->numfree, sizeof(PyFloatObject));
|
||||||
|
|
|
@ -22,6 +22,15 @@ static PyMemberDef frame_memberlist[] = {
|
||||||
{NULL} /* Sentinel */
|
{NULL} /* Sentinel */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
static struct _Py_frame_state *
|
||||||
|
get_frame_state(void)
|
||||||
|
{
|
||||||
|
PyInterpreterState *interp = _PyInterpreterState_GET();
|
||||||
|
return &interp->frame;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
frame_getlocals(PyFrameObject *f, void *closure)
|
frame_getlocals(PyFrameObject *f, void *closure)
|
||||||
{
|
{
|
||||||
|
@ -593,8 +602,7 @@ frame_dealloc(PyFrameObject *f)
|
||||||
co->co_zombieframe = f;
|
co->co_zombieframe = f;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
PyInterpreterState *interp = _PyInterpreterState_GET();
|
struct _Py_frame_state *state = get_frame_state();
|
||||||
struct _Py_frame_state *state = &interp->frame;
|
|
||||||
#ifdef Py_DEBUG
|
#ifdef Py_DEBUG
|
||||||
// frame_dealloc() must not be called after _PyFrame_Fini()
|
// frame_dealloc() must not be called after _PyFrame_Fini()
|
||||||
assert(state->numfree != -1);
|
assert(state->numfree != -1);
|
||||||
|
@ -784,8 +792,7 @@ frame_alloc(PyCodeObject *code)
|
||||||
Py_ssize_t ncells = PyTuple_GET_SIZE(code->co_cellvars);
|
Py_ssize_t ncells = PyTuple_GET_SIZE(code->co_cellvars);
|
||||||
Py_ssize_t nfrees = PyTuple_GET_SIZE(code->co_freevars);
|
Py_ssize_t nfrees = PyTuple_GET_SIZE(code->co_freevars);
|
||||||
Py_ssize_t extras = code->co_stacksize + code->co_nlocals + ncells + nfrees;
|
Py_ssize_t extras = code->co_stacksize + code->co_nlocals + ncells + nfrees;
|
||||||
PyInterpreterState *interp = _PyInterpreterState_GET();
|
struct _Py_frame_state *state = get_frame_state();
|
||||||
struct _Py_frame_state *state = &interp->frame;
|
|
||||||
if (state->free_list == NULL)
|
if (state->free_list == NULL)
|
||||||
{
|
{
|
||||||
f = PyObject_GC_NewVar(PyFrameObject, &PyFrame_Type, extras);
|
f = PyObject_GC_NewVar(PyFrameObject, &PyFrame_Type, extras);
|
||||||
|
@ -1206,8 +1213,7 @@ _PyFrame_Fini(PyThreadState *tstate)
|
||||||
void
|
void
|
||||||
_PyFrame_DebugMallocStats(FILE *out)
|
_PyFrame_DebugMallocStats(FILE *out)
|
||||||
{
|
{
|
||||||
PyInterpreterState *interp = _PyInterpreterState_GET();
|
struct _Py_frame_state *state = get_frame_state();
|
||||||
struct _Py_frame_state *state = &interp->frame;
|
|
||||||
_PyDebugAllocatorStats(out,
|
_PyDebugAllocatorStats(out,
|
||||||
"free PyFrameObject",
|
"free PyFrameObject",
|
||||||
state->numfree, sizeof(PyFrameObject));
|
state->numfree, sizeof(PyFrameObject));
|
||||||
|
|
|
@ -1389,6 +1389,14 @@ PyTypeObject PyAsyncGen_Type = {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
static struct _Py_async_gen_state *
|
||||||
|
get_async_gen_state(void)
|
||||||
|
{
|
||||||
|
PyInterpreterState *interp = _PyInterpreterState_GET();
|
||||||
|
return &interp->async_gen;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
PyObject *
|
PyObject *
|
||||||
PyAsyncGen_New(PyFrameObject *f, PyObject *name, PyObject *qualname)
|
PyAsyncGen_New(PyFrameObject *f, PyObject *name, PyObject *qualname)
|
||||||
{
|
{
|
||||||
|
@ -1477,8 +1485,7 @@ async_gen_asend_dealloc(PyAsyncGenASend *o)
|
||||||
_PyObject_GC_UNTRACK((PyObject *)o);
|
_PyObject_GC_UNTRACK((PyObject *)o);
|
||||||
Py_CLEAR(o->ags_gen);
|
Py_CLEAR(o->ags_gen);
|
||||||
Py_CLEAR(o->ags_sendval);
|
Py_CLEAR(o->ags_sendval);
|
||||||
PyInterpreterState *interp = _PyInterpreterState_GET();
|
struct _Py_async_gen_state *state = get_async_gen_state();
|
||||||
struct _Py_async_gen_state *state = &interp->async_gen;
|
|
||||||
#ifdef Py_DEBUG
|
#ifdef Py_DEBUG
|
||||||
// async_gen_asend_dealloc() must not be called after _PyAsyncGen_Fini()
|
// async_gen_asend_dealloc() must not be called after _PyAsyncGen_Fini()
|
||||||
assert(state->asend_numfree != -1);
|
assert(state->asend_numfree != -1);
|
||||||
|
@ -1639,8 +1646,7 @@ static PyObject *
|
||||||
async_gen_asend_new(PyAsyncGenObject *gen, PyObject *sendval)
|
async_gen_asend_new(PyAsyncGenObject *gen, PyObject *sendval)
|
||||||
{
|
{
|
||||||
PyAsyncGenASend *o;
|
PyAsyncGenASend *o;
|
||||||
PyInterpreterState *interp = _PyInterpreterState_GET();
|
struct _Py_async_gen_state *state = get_async_gen_state();
|
||||||
struct _Py_async_gen_state *state = &interp->async_gen;
|
|
||||||
#ifdef Py_DEBUG
|
#ifdef Py_DEBUG
|
||||||
// async_gen_asend_new() must not be called after _PyAsyncGen_Fini()
|
// async_gen_asend_new() must not be called after _PyAsyncGen_Fini()
|
||||||
assert(state->asend_numfree != -1);
|
assert(state->asend_numfree != -1);
|
||||||
|
@ -1678,8 +1684,7 @@ async_gen_wrapped_val_dealloc(_PyAsyncGenWrappedValue *o)
|
||||||
{
|
{
|
||||||
_PyObject_GC_UNTRACK((PyObject *)o);
|
_PyObject_GC_UNTRACK((PyObject *)o);
|
||||||
Py_CLEAR(o->agw_val);
|
Py_CLEAR(o->agw_val);
|
||||||
PyInterpreterState *interp = _PyInterpreterState_GET();
|
struct _Py_async_gen_state *state = get_async_gen_state();
|
||||||
struct _Py_async_gen_state *state = &interp->async_gen;
|
|
||||||
#ifdef Py_DEBUG
|
#ifdef Py_DEBUG
|
||||||
// async_gen_wrapped_val_dealloc() must not be called after _PyAsyncGen_Fini()
|
// async_gen_wrapped_val_dealloc() must not be called after _PyAsyncGen_Fini()
|
||||||
assert(state->value_numfree != -1);
|
assert(state->value_numfree != -1);
|
||||||
|
@ -1752,8 +1757,7 @@ _PyAsyncGenValueWrapperNew(PyObject *val)
|
||||||
_PyAsyncGenWrappedValue *o;
|
_PyAsyncGenWrappedValue *o;
|
||||||
assert(val);
|
assert(val);
|
||||||
|
|
||||||
PyInterpreterState *interp = _PyInterpreterState_GET();
|
struct _Py_async_gen_state *state = get_async_gen_state();
|
||||||
struct _Py_async_gen_state *state = &interp->async_gen;
|
|
||||||
#ifdef Py_DEBUG
|
#ifdef Py_DEBUG
|
||||||
// _PyAsyncGenValueWrapperNew() must not be called after _PyAsyncGen_Fini()
|
// _PyAsyncGenValueWrapperNew() must not be called after _PyAsyncGen_Fini()
|
||||||
assert(state->value_numfree != -1);
|
assert(state->value_numfree != -1);
|
||||||
|
|
|
@ -19,6 +19,15 @@ class list "PyListObject *" "&PyList_Type"
|
||||||
|
|
||||||
#include "clinic/listobject.c.h"
|
#include "clinic/listobject.c.h"
|
||||||
|
|
||||||
|
|
||||||
|
static struct _Py_list_state *
|
||||||
|
get_list_state(void)
|
||||||
|
{
|
||||||
|
PyInterpreterState *interp = _PyInterpreterState_GET();
|
||||||
|
return &interp->list;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Ensure ob_item has room for at least newsize elements, and set
|
/* Ensure ob_item has room for at least newsize elements, and set
|
||||||
* ob_size to newsize. If newsize > ob_size on entry, the content
|
* ob_size to newsize. If newsize > ob_size on entry, the content
|
||||||
* of the new slots at exit is undefined heap trash; it's the caller's
|
* of the new slots at exit is undefined heap trash; it's the caller's
|
||||||
|
@ -121,8 +130,7 @@ _PyList_Fini(PyThreadState *tstate)
|
||||||
void
|
void
|
||||||
_PyList_DebugMallocStats(FILE *out)
|
_PyList_DebugMallocStats(FILE *out)
|
||||||
{
|
{
|
||||||
PyInterpreterState *interp = _PyInterpreterState_GET();
|
struct _Py_list_state *state = get_list_state();
|
||||||
struct _Py_list_state *state = &interp->list;
|
|
||||||
_PyDebugAllocatorStats(out,
|
_PyDebugAllocatorStats(out,
|
||||||
"free PyListObject",
|
"free PyListObject",
|
||||||
state->numfree, sizeof(PyListObject));
|
state->numfree, sizeof(PyListObject));
|
||||||
|
@ -136,8 +144,7 @@ PyList_New(Py_ssize_t size)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
PyInterpreterState *interp = _PyInterpreterState_GET();
|
struct _Py_list_state *state = get_list_state();
|
||||||
struct _Py_list_state *state = &interp->list;
|
|
||||||
PyListObject *op;
|
PyListObject *op;
|
||||||
#ifdef Py_DEBUG
|
#ifdef Py_DEBUG
|
||||||
// PyList_New() must not be called after _PyList_Fini()
|
// PyList_New() must not be called after _PyList_Fini()
|
||||||
|
@ -336,8 +343,7 @@ list_dealloc(PyListObject *op)
|
||||||
}
|
}
|
||||||
PyMem_FREE(op->ob_item);
|
PyMem_FREE(op->ob_item);
|
||||||
}
|
}
|
||||||
PyInterpreterState *interp = _PyInterpreterState_GET();
|
struct _Py_list_state *state = get_list_state();
|
||||||
struct _Py_list_state *state = &interp->list;
|
|
||||||
#ifdef Py_DEBUG
|
#ifdef Py_DEBUG
|
||||||
// list_dealloc() must not be called after _PyList_Fini()
|
// list_dealloc() must not be called after _PyList_Fini()
|
||||||
assert(state->numfree != -1);
|
assert(state->numfree != -1);
|
||||||
|
|
|
@ -113,27 +113,35 @@ void _PySlice_Fini(PyThreadState *tstate)
|
||||||
PyObject *
|
PyObject *
|
||||||
PySlice_New(PyObject *start, PyObject *stop, PyObject *step)
|
PySlice_New(PyObject *start, PyObject *stop, PyObject *step)
|
||||||
{
|
{
|
||||||
|
if (step == NULL) {
|
||||||
|
step = Py_None;
|
||||||
|
}
|
||||||
|
if (start == NULL) {
|
||||||
|
start = Py_None;
|
||||||
|
}
|
||||||
|
if (stop == NULL) {
|
||||||
|
stop = Py_None;
|
||||||
|
}
|
||||||
|
|
||||||
PyInterpreterState *interp = _PyInterpreterState_GET();
|
PyInterpreterState *interp = _PyInterpreterState_GET();
|
||||||
PySliceObject *obj;
|
PySliceObject *obj;
|
||||||
if (interp->slice_cache != NULL) {
|
if (interp->slice_cache != NULL) {
|
||||||
obj = interp->slice_cache;
|
obj = interp->slice_cache;
|
||||||
interp->slice_cache = NULL;
|
interp->slice_cache = NULL;
|
||||||
_Py_NewReference((PyObject *)obj);
|
_Py_NewReference((PyObject *)obj);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
obj = PyObject_GC_New(PySliceObject, &PySlice_Type);
|
obj = PyObject_GC_New(PySliceObject, &PySlice_Type);
|
||||||
if (obj == NULL)
|
if (obj == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (step == NULL) step = Py_None;
|
|
||||||
Py_INCREF(step);
|
Py_INCREF(step);
|
||||||
if (start == NULL) start = Py_None;
|
|
||||||
Py_INCREF(start);
|
|
||||||
if (stop == NULL) stop = Py_None;
|
|
||||||
Py_INCREF(stop);
|
|
||||||
|
|
||||||
obj->step = step;
|
obj->step = step;
|
||||||
|
Py_INCREF(start);
|
||||||
obj->start = start;
|
obj->start = start;
|
||||||
|
Py_INCREF(stop);
|
||||||
obj->stop = stop;
|
obj->stop = stop;
|
||||||
|
|
||||||
_PyObject_GC_TRACK(obj);
|
_PyObject_GC_TRACK(obj);
|
||||||
|
|
|
@ -14,19 +14,28 @@ class tuple "PyTupleObject *" "&PyTuple_Type"
|
||||||
|
|
||||||
#include "clinic/tupleobject.c.h"
|
#include "clinic/tupleobject.c.h"
|
||||||
|
|
||||||
|
|
||||||
|
static struct _Py_tuple_state *
|
||||||
|
get_tuple_state(void)
|
||||||
|
{
|
||||||
|
PyInterpreterState *interp = _PyInterpreterState_GET();
|
||||||
|
return &interp->tuple;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
tuple_gc_track(PyTupleObject *op)
|
tuple_gc_track(PyTupleObject *op)
|
||||||
{
|
{
|
||||||
_PyObject_GC_TRACK(op);
|
_PyObject_GC_TRACK(op);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Print summary info about the state of the optimized allocator */
|
/* Print summary info about the state of the optimized allocator */
|
||||||
void
|
void
|
||||||
_PyTuple_DebugMallocStats(FILE *out)
|
_PyTuple_DebugMallocStats(FILE *out)
|
||||||
{
|
{
|
||||||
#if PyTuple_MAXSAVESIZE > 0
|
#if PyTuple_MAXSAVESIZE > 0
|
||||||
PyInterpreterState *interp = _PyInterpreterState_GET();
|
struct _Py_tuple_state *state = get_tuple_state();
|
||||||
struct _Py_tuple_state *state = &interp->tuple;
|
|
||||||
for (int i = 1; i < PyTuple_MAXSAVESIZE; i++) {
|
for (int i = 1; i < PyTuple_MAXSAVESIZE; i++) {
|
||||||
char buf[128];
|
char buf[128];
|
||||||
PyOS_snprintf(buf, sizeof(buf),
|
PyOS_snprintf(buf, sizeof(buf),
|
||||||
|
@ -89,8 +98,7 @@ PyTuple_New(Py_ssize_t size)
|
||||||
{
|
{
|
||||||
PyTupleObject *op;
|
PyTupleObject *op;
|
||||||
#if PyTuple_MAXSAVESIZE > 0
|
#if PyTuple_MAXSAVESIZE > 0
|
||||||
PyInterpreterState *interp = _PyInterpreterState_GET();
|
struct _Py_tuple_state *state = get_tuple_state();
|
||||||
struct _Py_tuple_state *state = &interp->tuple;
|
|
||||||
if (size == 0 && state->free_list[0]) {
|
if (size == 0 && state->free_list[0]) {
|
||||||
op = state->free_list[0];
|
op = state->free_list[0];
|
||||||
Py_INCREF(op);
|
Py_INCREF(op);
|
||||||
|
@ -198,8 +206,7 @@ PyTuple_Pack(Py_ssize_t n, ...)
|
||||||
return PyTuple_New(0);
|
return PyTuple_New(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
PyInterpreterState *interp = _PyInterpreterState_GET();
|
struct _Py_tuple_state *state = get_tuple_state();
|
||||||
struct _Py_tuple_state *state = &interp->tuple;
|
|
||||||
|
|
||||||
va_start(vargs, n);
|
va_start(vargs, n);
|
||||||
PyTupleObject *result = tuple_alloc(state, n);
|
PyTupleObject *result = tuple_alloc(state, n);
|
||||||
|
@ -233,8 +240,7 @@ tupledealloc(PyTupleObject *op)
|
||||||
Py_XDECREF(op->ob_item[i]);
|
Py_XDECREF(op->ob_item[i]);
|
||||||
}
|
}
|
||||||
#if PyTuple_MAXSAVESIZE > 0
|
#if PyTuple_MAXSAVESIZE > 0
|
||||||
PyInterpreterState *interp = _PyInterpreterState_GET();
|
struct _Py_tuple_state *state = get_tuple_state();
|
||||||
struct _Py_tuple_state *state = &interp->tuple;
|
|
||||||
#ifdef Py_DEBUG
|
#ifdef Py_DEBUG
|
||||||
// tupledealloc() must not be called after _PyTuple_Fini()
|
// tupledealloc() must not be called after _PyTuple_Fini()
|
||||||
assert(state->numfree[0] != -1);
|
assert(state->numfree[0] != -1);
|
||||||
|
@ -420,8 +426,7 @@ _PyTuple_FromArray(PyObject *const *src, Py_ssize_t n)
|
||||||
return PyTuple_New(0);
|
return PyTuple_New(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
PyInterpreterState *interp = _PyInterpreterState_GET();
|
struct _Py_tuple_state *state = get_tuple_state();
|
||||||
struct _Py_tuple_state *state = &interp->tuple;
|
|
||||||
PyTupleObject *tuple = tuple_alloc(state, n);
|
PyTupleObject *tuple = tuple_alloc(state, n);
|
||||||
if (tuple == NULL) {
|
if (tuple == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -492,8 +497,7 @@ tupleconcat(PyTupleObject *a, PyObject *bb)
|
||||||
return PyTuple_New(0);
|
return PyTuple_New(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
PyInterpreterState *interp = _PyInterpreterState_GET();
|
struct _Py_tuple_state *state = get_tuple_state();
|
||||||
struct _Py_tuple_state *state = &interp->tuple;
|
|
||||||
np = tuple_alloc(state, size);
|
np = tuple_alloc(state, size);
|
||||||
if (np == NULL) {
|
if (np == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -537,8 +541,7 @@ tuplerepeat(PyTupleObject *a, Py_ssize_t n)
|
||||||
if (n > PY_SSIZE_T_MAX / Py_SIZE(a))
|
if (n > PY_SSIZE_T_MAX / Py_SIZE(a))
|
||||||
return PyErr_NoMemory();
|
return PyErr_NoMemory();
|
||||||
size = Py_SIZE(a) * n;
|
size = Py_SIZE(a) * n;
|
||||||
PyInterpreterState *interp = _PyInterpreterState_GET();
|
struct _Py_tuple_state *state = get_tuple_state();
|
||||||
struct _Py_tuple_state *state = &interp->tuple;
|
|
||||||
np = tuple_alloc(state, size);
|
np = tuple_alloc(state, size);
|
||||||
if (np == NULL)
|
if (np == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -804,8 +807,7 @@ tuplesubscript(PyTupleObject* self, PyObject* item)
|
||||||
return (PyObject *)self;
|
return (PyObject *)self;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
PyInterpreterState *interp = _PyInterpreterState_GET();
|
struct _Py_tuple_state *state = get_tuple_state();
|
||||||
struct _Py_tuple_state *state = &interp->tuple;
|
|
||||||
PyTupleObject* result = tuple_alloc(state, slicelength);
|
PyTupleObject* result = tuple_alloc(state, slicelength);
|
||||||
if (!result) return NULL;
|
if (!result) return NULL;
|
||||||
|
|
||||||
|
|
|
@ -66,6 +66,14 @@ static int
|
||||||
contextvar_del(PyContextVar *var);
|
contextvar_del(PyContextVar *var);
|
||||||
|
|
||||||
|
|
||||||
|
static struct _Py_context_state *
|
||||||
|
get_context_state(void)
|
||||||
|
{
|
||||||
|
PyInterpreterState *interp = _PyInterpreterState_GET();
|
||||||
|
return &interp->context;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
PyObject *
|
PyObject *
|
||||||
_PyContext_NewHamtForTests(void)
|
_PyContext_NewHamtForTests(void)
|
||||||
{
|
{
|
||||||
|
@ -332,8 +340,7 @@ class _contextvars.Context "PyContext *" "&PyContext_Type"
|
||||||
static inline PyContext *
|
static inline PyContext *
|
||||||
_context_alloc(void)
|
_context_alloc(void)
|
||||||
{
|
{
|
||||||
PyInterpreterState *interp = _PyInterpreterState_GET();
|
struct _Py_context_state *state = get_context_state();
|
||||||
struct _Py_context_state *state = &interp->context;
|
|
||||||
PyContext *ctx;
|
PyContext *ctx;
|
||||||
#ifdef Py_DEBUG
|
#ifdef Py_DEBUG
|
||||||
// _context_alloc() must not be called after _PyContext_Fini()
|
// _context_alloc() must not be called after _PyContext_Fini()
|
||||||
|
@ -462,8 +469,7 @@ context_tp_dealloc(PyContext *self)
|
||||||
}
|
}
|
||||||
(void)context_tp_clear(self);
|
(void)context_tp_clear(self);
|
||||||
|
|
||||||
PyInterpreterState *interp = _PyInterpreterState_GET();
|
struct _Py_context_state *state = get_context_state();
|
||||||
struct _Py_context_state *state = &interp->context;
|
|
||||||
#ifdef Py_DEBUG
|
#ifdef Py_DEBUG
|
||||||
// _context_alloc() must not be called after _PyContext_Fini()
|
// _context_alloc() must not be called after _PyContext_Fini()
|
||||||
assert(state->numfree != -1);
|
assert(state->numfree != -1);
|
||||||
|
|
Loading…
Reference in New Issue