Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
eendebakpt committed Dec 27, 2024
1 parent 46c8d45 commit 42ac9f7
Show file tree
Hide file tree
Showing 14 changed files with 27 additions and 23 deletions.
2 changes: 1 addition & 1 deletion Include/cpython/pystats.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ PyAPI_DATA(PyStats*) _Py_stats;
PyAPI_FUNC(PyStats *) get_pystats(void);
PyAPI_FUNC(void) OBJECT_STAT_INCREMENT(const char *tag);
PyAPI_FUNC(void) OBJECT_STAT_FREELIST_INCREMENT(const char *tag);
PyAPI_FUNC(void) OBJECT_STAT_ALLOC_INCREMENT(const char *tag);
PyAPI_FUNC(void) OBJECT_STAT_ALLOC_INCREMENT(const char *tag, const char *sub_tag=0);
PyAPI_FUNC(void) _guard_stats_table(void);

#ifdef _PY_INTERPRETER
Expand Down
2 changes: 1 addition & 1 deletion Include/internal/pycore_freelist.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ extern "C" {

PyAPI_FUNC(void) OBJECT_STAT_INCREMENT(const char *tag);
PyAPI_FUNC(void) OBJECT_STAT_INCREMENT(const char *tag);
PyAPI_FUNC(void) OBJECT_STAT_ALLOC_INCREMENT(const char *tag);
PyAPI_FUNC(void) OBJECT_STAT_ALLOC_INCREMENT(const char *tag, const char *sub_tag=0);
PyAPI_FUNC(void) OBJECT_STAT_FREELIST_INCREMENT(const char *tag);
PyAPI_FUNC(void) OBJECT_STAT_INCREMENT_STRING(const char* message, ...);

Expand Down
5 changes: 2 additions & 3 deletions Include/internal/pycore_obmalloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ typedef unsigned int pymem_uint; /* assuming >= 16 bits */
#define uint pymem_uint

PyAPI_FUNC(void) OBJECT_STAT_INCREMENT(const char *tag);
///void OBJECT_STAT_FREELIST_INCREMENT(const char *tag);
//void OBJECT_STAT_ALLOC_INCREMENT(const char *tag); // allocation for a new object, but not a freelist
PyAPI_FUNC(void) OBJECT_STAT_ALLOCATION_TYPE(PyTypeObject *tp);
//PyAPI_FUNC(void) OBJECT_STAT_ALLOCATION_TYPE(PyTypeObject *tp);
//PyAPI_FUNC(void) OBJECT_STAT_ALLOC_INCREMENT(const char *tag, const char *sub_tag=0);

/* An object allocator for Python.
Expand Down
1 change: 0 additions & 1 deletion Objects/codeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,6 @@ intern_code_constants(struct _PyCodeConstructor *con)
PyCodeObject *
_PyCode_New(struct _PyCodeConstructor *con)
{
OBJECT_STAT_ALLOC_INCREMENT("_PyCode_New");
if (intern_code_constants(con) < 0) {
return NULL;
}
Expand Down
2 changes: 2 additions & 0 deletions Objects/complexobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,8 @@ PyObject *
PyComplex_FromCComplex(Py_complex cval)
{
/* Inline PyObject_New */
OBJECT_STAT_ALLOC_INCREMENT("PyComplex_FromCComplex");

PyComplexObject *op = PyObject_Malloc(sizeof(PyComplexObject));
if (op == NULL) {
return PyErr_NoMemory();
Expand Down
1 change: 0 additions & 1 deletion Objects/dictobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -871,7 +871,6 @@ new_dict(PyInterpreterState *interp,
assert(keys != NULL);
PyDictObject *mp = _Py_FREELIST_POP(PyDictObject, dicts);
if (mp == NULL) {
OBJECT_STAT_ALLOC_INCREMENT("new_dict_alloc");
mp = PyObject_GC_New(PyDictObject, &PyDict_Type);
if (mp == NULL) {
dictkeys_decref(interp, keys, false);
Expand Down
1 change: 1 addition & 0 deletions Objects/iterobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ PySeqIter_New(PyObject *seq)
PyErr_BadInternalCall();
return NULL;
}
OBJECT_STAT_ALLOC_INCREMENT("PySeqIter_New");
it = PyObject_GC_New(seqiterobject, &PySeqIter_Type);
if (it == NULL)
return NULL;
Expand Down
4 changes: 4 additions & 0 deletions Objects/longobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,10 @@ _PyLong_New(Py_ssize_t size)
OBJECT_STAT_ALLOC_INCREMENT("_PyLong_New_digits_1");
} else if (ndigits==2) {
OBJECT_STAT_ALLOC_INCREMENT("_PyLong_New_digits_2");
} else if (ndigits==3) {
OBJECT_STAT_ALLOC_INCREMENT("_PyLong_New_digits_3");
} else if (ndigits==4) {
OBJECT_STAT_ALLOC_INCREMENT("_PyLong_New_digits_4");
} else if (ndigits==0) {
OBJECT_STAT_ALLOC_INCREMENT("_PyLong_New_digits_0");
}
Expand Down
10 changes: 2 additions & 8 deletions Objects/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -549,17 +549,11 @@ void _guard_stats_table()
}


void OBJECT_STAT_ALLOCATION_TYPE(PyTypeObject *tp)
{
#ifdef Py_STATS
OBJECT_STAT_ALLOC_INCREMENT(tp->tp_name);
#endif
}

PyObject *
_PyObject_New(PyTypeObject *tp)
{
OBJECT_STAT_ALLOCATION_TYPE(tp);
OBJECT_STAT_ALLOC_INCREMENT(tp->tp_name, "_PyObject_New");
PyObject *op = (PyObject *) PyObject_Malloc(_PyObject_SIZE(tp));
if (op == NULL) {
return PyErr_NoMemory();
Expand All @@ -571,7 +565,7 @@ _PyObject_New(PyTypeObject *tp)
PyVarObject *
_PyObject_NewVar(PyTypeObject *tp, Py_ssize_t nitems)
{
OBJECT_STAT_ALLOCATION_TYPE(tp);
OBJECT_STAT_ALLOC_INCREMENT(tp->tp_name, "_PyObject_NewVar");

PyVarObject *op;
const size_t size = _PyObject_VAR_SIZE(tp, nitems);
Expand Down
11 changes: 7 additions & 4 deletions Objects/obmalloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,16 @@ void OBJECT_STAT_FREELIST_INCREMENT(const char *tag)
#endif
}

void OBJECT_STAT_ALLOC_INCREMENT(const char *tag)
void OBJECT_STAT_ALLOC_INCREMENT(const char *tag, const char *sub_tag)
{
#ifdef Py_STATS
if (_Py_stats) {
char sub_tag[200] = "Allocate type #";
strncat(sub_tag, tag, 200-6-1);
OBJECT_STAT_INCREMENT(sub_tag);
if (subtag==0) {
OBJECT_STAT_INCREMENT_STRING("Allocate type #%s", tag);
} else {
OBJECT_STAT_INCREMENT_STRING("Allocate %s type #%s", sub_tag, tag);

}
}
#endif
}
Expand Down
2 changes: 1 addition & 1 deletion Objects/rangeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ make_range_object(PyTypeObject *type, PyObject *start,
return NULL;
}

OBJECT_STAT_ALLOC_INCREMENT("rangeobject");
OBJECT_STAT_ALLOC_INCREMENT("rangeobject_check");
obj = PyObject_New(rangeobject, type);
if (obj == NULL) {
Py_DECREF(length);
Expand Down
1 change: 1 addition & 0 deletions Objects/setobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -1086,6 +1086,7 @@ make_new_set(PyTypeObject *type, PyObject *iterable)
assert(PyType_Check(type));
PySetObject *so;

OBJECT_STAT_ALLOC_INCREMENT(type->tp_name);
so = (PySetObject *)type->tp_alloc(type, 0);
if (so == NULL)
return NULL;
Expand Down
5 changes: 2 additions & 3 deletions Objects/tupleobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,15 @@ tuple_alloc(Py_ssize_t size)
assert(size != 0); // The empty tuple is statically allocated.
Py_ssize_t index = size - 1;
if (index < PyTuple_MAXSAVESIZE) {
OBJECT_STAT_FREELIST_INCREMENT("tuple");
PyTupleObject *op = _Py_FREELIST_POP(PyTupleObject, tuples[index]);
if (op != NULL) {
return op;
}
}
if (size<2*PyTuple_MAXSAVESIZE)
OBJECT_STAT_INCREMENT_STRING("tuple_size_%ld", size);
OBJECT_STAT_ALLOC_INCREMENT("tuple");

else
OBJECT_STAT_INCREMENT_STRING("tuple_size_large");
/* Check for overflow */
if ((size_t)size > ((size_t)PY_SSIZE_T_MAX - (sizeof(PyTupleObject) -
sizeof(PyObject *))) / sizeof(PyObject *)) {
Expand Down
3 changes: 3 additions & 0 deletions Python/gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -2272,6 +2272,7 @@ _PyObject_GC_New(PyTypeObject *tp)
if (_PyType_HasFeature(tp, Py_TPFLAGS_INLINE_VALUES)) {
size += _PyInlineValuesSize(tp);
}
OBJECT_STAT_ALLOC_INCREMENT(tp->tp_name);
PyObject *op = gc_alloc(tp, size, presize);
if (op == NULL) {
return NULL;
Expand All @@ -2294,6 +2295,7 @@ _PyObject_GC_NewVar(PyTypeObject *tp, Py_ssize_t nitems)
}
size_t presize = _PyType_PreHeaderSize(tp);
size_t size = _PyObject_VAR_SIZE(tp, nitems);
OBJECT_STAT_ALLOC_INCREMENT(tp->tp_name);
op = (PyVarObject *)gc_alloc(tp, size, presize);
if (op == NULL) {
return NULL;
Expand All @@ -2306,6 +2308,7 @@ PyObject *
PyUnstable_Object_GC_NewWithExtraData(PyTypeObject *tp, size_t extra_size)
{
size_t presize = _PyType_PreHeaderSize(tp);
OBJECT_STAT_ALLOC_INCREMENT(tp->tp_name);
PyObject *op = gc_alloc(tp, _PyObject_SIZE(tp) + extra_size, presize);
if (op == NULL) {
return NULL;
Expand Down

0 comments on commit 42ac9f7

Please sign in to comment.