gh-113755: Fully adapt gcmodule.c to Argument Clinic (#113756)
Adapt the following functions to Argument Clinic: - gc.set_threshold - gc.get_referrers - gc.get_referents
This commit is contained in:
committed by
GitHub
parent
ace4d7ff9a
commit
35fa13d48b
@@ -134,24 +134,41 @@ gc_get_debug_impl(PyObject *module)
|
||||
return gcstate->debug;
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(gc_set_thresh__doc__,
|
||||
"set_threshold(threshold0, [threshold1, threshold2]) -> None\n"
|
||||
"\n"
|
||||
"Sets the collection thresholds. Setting threshold0 to zero disables\n"
|
||||
"collection.\n");
|
||||
/*[clinic input]
|
||||
gc.set_threshold
|
||||
|
||||
threshold0: int
|
||||
[
|
||||
threshold1: int
|
||||
[
|
||||
threshold2: int
|
||||
]
|
||||
]
|
||||
/
|
||||
|
||||
Set the collection thresholds (the collection frequency).
|
||||
|
||||
Setting 'threshold0' to zero disables collection.
|
||||
[clinic start generated code]*/
|
||||
|
||||
static PyObject *
|
||||
gc_set_threshold(PyObject *self, PyObject *args)
|
||||
gc_set_threshold_impl(PyObject *module, int threshold0, int group_right_1,
|
||||
int threshold1, int group_right_2, int threshold2)
|
||||
/*[clinic end generated code: output=2e3c7c7dd59060f3 input=0d9612db50984eec]*/
|
||||
{
|
||||
GCState *gcstate = get_gc_state();
|
||||
if (!PyArg_ParseTuple(args, "i|ii:set_threshold",
|
||||
&gcstate->generations[0].threshold,
|
||||
&gcstate->generations[1].threshold,
|
||||
&gcstate->generations[2].threshold))
|
||||
return NULL;
|
||||
for (int i = 3; i < NUM_GENERATIONS; i++) {
|
||||
|
||||
gcstate->generations[0].threshold = threshold0;
|
||||
if (group_right_1) {
|
||||
gcstate->generations[1].threshold = threshold1;
|
||||
}
|
||||
if (group_right_2) {
|
||||
gcstate->generations[2].threshold = threshold2;
|
||||
|
||||
/* generations higher than 2 get the same threshold */
|
||||
gcstate->generations[i].threshold = gcstate->generations[2].threshold;
|
||||
for (int i = 3; i < NUM_GENERATIONS; i++) {
|
||||
gcstate->generations[i].threshold = gcstate->generations[2].threshold;
|
||||
}
|
||||
}
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
@@ -190,12 +207,17 @@ gc_get_count_impl(PyObject *module)
|
||||
gcstate->generations[2].count);
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(gc_get_referrers__doc__,
|
||||
"get_referrers(*objs) -> list\n\
|
||||
Return the list of objects that directly refer to any of objs.");
|
||||
/*[clinic input]
|
||||
gc.get_referrers
|
||||
|
||||
*objs as args: object
|
||||
|
||||
Return the list of objects that directly refer to any of 'objs'.
|
||||
[clinic start generated code]*/
|
||||
|
||||
static PyObject *
|
||||
gc_get_referrers(PyObject *self, PyObject *args)
|
||||
gc_get_referrers_impl(PyObject *module, PyObject *args)
|
||||
/*[clinic end generated code: output=296a09587f6a86b5 input=bae96961b14a0922]*/
|
||||
{
|
||||
if (PySys_Audit("gc.get_referrers", "(O)", args) < 0) {
|
||||
return NULL;
|
||||
@@ -213,12 +235,17 @@ referentsvisit(PyObject *obj, void *arg)
|
||||
return PyList_Append(list, obj) < 0;
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(gc_get_referents__doc__,
|
||||
"get_referents(*objs) -> list\n\
|
||||
Return the list of objects that are directly referred to by objs.");
|
||||
/*[clinic input]
|
||||
gc.get_referents
|
||||
|
||||
*objs as args: object
|
||||
|
||||
Return the list of objects that are directly referred to by 'objs'.
|
||||
[clinic start generated code]*/
|
||||
|
||||
static PyObject *
|
||||
gc_get_referents(PyObject *self, PyObject *args)
|
||||
gc_get_referents_impl(PyObject *module, PyObject *args)
|
||||
/*[clinic end generated code: output=d47dc02cefd06fe8 input=b3ceab0c34038cbf]*/
|
||||
{
|
||||
Py_ssize_t i;
|
||||
if (PySys_Audit("gc.get_referents", "(O)", args) < 0) {
|
||||
@@ -453,17 +480,15 @@ static PyMethodDef GcMethods[] = {
|
||||
GC_SET_DEBUG_METHODDEF
|
||||
GC_GET_DEBUG_METHODDEF
|
||||
GC_GET_COUNT_METHODDEF
|
||||
{"set_threshold", gc_set_threshold, METH_VARARGS, gc_set_thresh__doc__},
|
||||
GC_SET_THRESHOLD_METHODDEF
|
||||
GC_GET_THRESHOLD_METHODDEF
|
||||
GC_COLLECT_METHODDEF
|
||||
GC_GET_OBJECTS_METHODDEF
|
||||
GC_GET_STATS_METHODDEF
|
||||
GC_IS_TRACKED_METHODDEF
|
||||
GC_IS_FINALIZED_METHODDEF
|
||||
{"get_referrers", gc_get_referrers, METH_VARARGS,
|
||||
gc_get_referrers__doc__},
|
||||
{"get_referents", gc_get_referents, METH_VARARGS,
|
||||
gc_get_referents__doc__},
|
||||
GC_GET_REFERRERS_METHODDEF
|
||||
GC_GET_REFERENTS_METHODDEF
|
||||
GC_FREEZE_METHODDEF
|
||||
GC_UNFREEZE_METHODDEF
|
||||
GC_GET_FREEZE_COUNT_METHODDEF
|
||||
|
||||
Reference in New Issue
Block a user