bpo-32030: Add more options to _PyCoreConfig (#4485)
Py_Main() now handles two more -X options:
* -X showrefcount: new _PyCoreConfig.show_ref_count field
* -X showalloccount: new _PyCoreConfig.show_alloc_count field
diff --git a/Objects/listobject.c b/Objects/listobject.c
index 7eba61e..8576b7a 100644
--- a/Objects/listobject.c
+++ b/Objects/listobject.c
@@ -85,15 +85,10 @@
static void
show_alloc(void)
{
- PyObject *xoptions, *value;
- _Py_IDENTIFIER(showalloccount);
-
- xoptions = PySys_GetXOptions();
- if (xoptions == NULL)
+ PyInterpreterState *interp = PyThreadState_GET()->interp;
+ if (!inter->core_config.show_alloc_count) {
return;
- value = _PyDict_GetItemId(xoptions, &PyId_showalloccount);
- if (value != Py_True)
- return;
+ }
fprintf(stderr, "List allocations: %" PY_FORMAT_SIZE_T "d\n",
count_alloc);
diff --git a/Objects/object.c b/Objects/object.c
index ed8a62a..674180d 100644
--- a/Objects/object.c
+++ b/Objects/object.c
@@ -29,17 +29,6 @@
return total;
}
-PyObject *
-_PyDebug_XOptionShowRefCount(void)
-{
- PyObject *xoptions = PySys_GetXOptions();
- if (xoptions == NULL)
- return NULL;
-
- _Py_IDENTIFIER(showrefcount);
- return _PyDict_GetItemId(xoptions, &PyId_showrefcount);
-}
-
void
_PyDebug_PrintTotalRefs(void) {
fprintf(stderr,
@@ -106,16 +95,10 @@
void
dump_counts(FILE* f)
{
- PyTypeObject *tp;
- PyObject *xoptions, *value;
- _Py_IDENTIFIER(showalloccount);
-
- xoptions = PySys_GetXOptions();
- if (xoptions == NULL)
+ PyInterpreterState *interp = PyThreadState_GET()->interp;
+ if (!inter->core_config.show_alloc_count) {
return;
- value = _PyDict_GetItemId(xoptions, &PyId_showalloccount);
- if (value != Py_True)
- return;
+ }
for (tp = type_list; tp; tp = tp->tp_next)
fprintf(f, "%s alloc'd: %" PY_FORMAT_SIZE_T "d, "
diff --git a/Objects/tupleobject.c b/Objects/tupleobject.c
index 35decd8..964db3b 100644
--- a/Objects/tupleobject.c
+++ b/Objects/tupleobject.c
@@ -44,15 +44,10 @@
static void
show_track(void)
{
- PyObject *xoptions, *value;
- _Py_IDENTIFIER(showalloccount);
-
- xoptions = PySys_GetXOptions();
- if (xoptions == NULL)
+ PyInterpreterState *interp = PyThreadState_GET()->interp;
+ if (!inter->core_config.show_alloc_count) {
return;
- value = _PyDict_GetItemId(xoptions, &PyId_showalloccount);
- if (value != Py_True)
- return;
+ }
fprintf(stderr, "Tuples created: %" PY_FORMAT_SIZE_T "d\n",
count_tracked + count_untracked);