cpython: 50958e13c833 (original) (raw)
new file mode 100644 --- /dev/null +++ b/Modules/clinic/gcmodule.c.h @@ -0,0 +1,258 @@ +/[clinic input] +preserve +[clinic start generated code]/ + +PyDoc_STRVAR(gc_enable__doc__, +"enable($module, /)\n" +"--\n" +"\n" +"Enable automatic garbage collection."); + +#define GC_ENABLE_METHODDEF [](#l1.15)
+ +static PyObject * +gc_enable_impl(PyObject *module); + +static PyObject * +gc_enable(PyObject *module, PyObject *Py_UNUSED(ignored)) +{
+} + +PyDoc_STRVAR(gc_disable__doc__, +"disable($module, /)\n" +"--\n" +"\n" +"Disable automatic garbage collection."); + +#define GC_DISABLE_METHODDEF [](#l1.33)
+ +static PyObject * +gc_disable_impl(PyObject *module); + +static PyObject * +gc_disable(PyObject *module, PyObject *Py_UNUSED(ignored)) +{
+} + +PyDoc_STRVAR(gc_isenabled__doc__, +"isenabled($module, /)\n" +"--\n" +"\n" +"Returns true if automatic garbage collection is enabled."); + +#define GC_ISENABLED_METHODDEF [](#l1.51)
+ +static int +gc_isenabled_impl(PyObject *module); + +static PyObject * +gc_isenabled(PyObject *module, PyObject *Py_UNUSED(ignored)) +{
- _return_value = gc_isenabled_impl(module);
- if ((_return_value == -1) && PyErr_Occurred()) {
goto exit;[](#l1.65)
- }
- return_value = PyBool_FromLong((long)_return_value);
+} + +PyDoc_STRVAR(gc_collect__doc__, +"collect($module, /, generation=2)\n" +"--\n" +"\n" +"Run the garbage collector.\n" +"\n" +"With no arguments, run a full collection. The optional argument\n" +"may be an integer specifying which generation to collect. A ValueError\n" +"is raised if the generation number is invalid.\n" +"\n" +"The number of unreachable objects is returned."); + +#define GC_COLLECT_METHODDEF [](#l1.85)
+ +static Py_ssize_t +gc_collect_impl(PyObject *module, int generation); + +static PyObject * +gc_collect(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) +{
- PyObject *return_value = NULL;
- static const char * const _keywords[] = {"generation", NULL};
- static _PyArg_Parser _parser = {"|i:collect", _keywords, 0};
- int generation = NUM_GENERATIONS - 1;
- Py_ssize_t _return_value;
- if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
&generation)) {[](#l1.101)
goto exit;[](#l1.102)
- }
- _return_value = gc_collect_impl(module, generation);
- if ((_return_value == -1) && PyErr_Occurred()) {
goto exit;[](#l1.106)
- }
- return_value = PyLong_FromSsize_t(_return_value);
+} + +PyDoc_STRVAR(gc_set_debug__doc__, +"set_debug($module, flags, /)\n" +"--\n" +"\n" +"Set the garbage collection debugging flags.\n" +"\n" +" flags\n" +" An integer that can have the following bits turned on:\n" +" DEBUG_STATS - Print statistics during collection.\n" +" DEBUG_COLLECTABLE - Print collectable objects found.\n" +" DEBUG_UNCOLLECTABLE - Print unreachable but uncollectable objects\n" +" found.\n" +" DEBUG_SAVEALL - Save objects to gc.garbage rather than freeing them.\n" +" DEBUG_LEAK - Debug leaking programs (everything but STATS).\n" +"\n" +"Debugging information is written to sys.stderr."); + +#define GC_SET_DEBUG_METHODDEF [](#l1.131)
+ +static PyObject * +gc_set_debug_impl(PyObject *module, int flags); + +static PyObject * +gc_set_debug(PyObject *module, PyObject *arg) +{
- if (!PyArg_Parse(arg, "i:set_debug", &flags)) {
goto exit;[](#l1.144)
- }
- return_value = gc_set_debug_impl(module, flags);
+} + +PyDoc_STRVAR(gc_get_debug__doc__, +"get_debug($module, /)\n" +"--\n" +"\n" +"Get the garbage collection debugging flags."); + +#define GC_GET_DEBUG_METHODDEF [](#l1.158)
+ +static int +gc_get_debug_impl(PyObject *module); + +static PyObject * +gc_get_debug(PyObject *module, PyObject *Py_UNUSED(ignored)) +{
- _return_value = gc_get_debug_impl(module);
- if ((_return_value == -1) && PyErr_Occurred()) {
goto exit;[](#l1.172)
- }
- return_value = PyLong_FromLong((long)_return_value);
+} + +PyDoc_STRVAR(gc_get_threshold__doc__, +"get_threshold($module, /)\n" +"--\n" +"\n" +"Return the current collection thresholds."); + +#define GC_GET_THRESHOLD_METHODDEF [](#l1.186)
+ +static PyObject * +gc_get_threshold_impl(PyObject *module); + +static PyObject * +gc_get_threshold(PyObject *module, PyObject *Py_UNUSED(ignored)) +{
+} + +PyDoc_STRVAR(gc_get_count__doc__, +"get_count($module, /)\n" +"--\n" +"\n" +"Return a three-tuple of the current collection counts."); + +#define GC_GET_COUNT_METHODDEF [](#l1.204)
+ +static PyObject * +gc_get_count_impl(PyObject *module); + +static PyObject * +gc_get_count(PyObject *module, PyObject *Py_UNUSED(ignored)) +{
+} + +PyDoc_STRVAR(gc_get_objects__doc__, +"get_objects($module, /)\n" +"--\n" +"\n" +"Return a list of objects tracked by the collector (excluding the list returned)."); + +#define GC_GET_OBJECTS_METHODDEF [](#l1.222)
+ +static PyObject * +gc_get_objects_impl(PyObject *module); + +static PyObject * +gc_get_objects(PyObject *module, PyObject *Py_UNUSED(ignored)) +{
+} + +PyDoc_STRVAR(gc_get_stats__doc__, +"get_stats($module, /)\n" +"--\n" +"\n" +"Return a list of dictionaries containing per-generation statistics."); + +#define GC_GET_STATS_METHODDEF [](#l1.240)
+ +static PyObject * +gc_get_stats_impl(PyObject *module); + +static PyObject * +gc_get_stats(PyObject *module, PyObject *Py_UNUSED(ignored)) +{
+} + +PyDoc_STRVAR(gc_is_tracked__doc__, +"is_tracked($module, obj, /)\n" +"--\n" +"\n" +"Returns true if the object is tracked by the garbage collector.\n" +"\n" +"Simple atomic objects will return false."); + +#define GC_IS_TRACKED_METHODDEF [](#l1.260)
+/[clinic end generated code: output=8f487abc53fe4161 input=a9049054013a1b77]/
--- a/Modules/gcmodule.c +++ b/Modules/gcmodule.c @@ -28,6 +28,11 @@ #include "pydtrace.h" #include "pytime.h" /* for _PyTime_GetMonotonicClock() / +/[clinic input] +module gc +[clinic start generated code]/ +/[clinic end generated code: output=da39a3ee5e6b4b0d input=b5c9690ecc842d79]/ + / Get an object's GC head */ #define AS_GC(o) ((PyGC_Head *)(o)-1) @@ -43,6 +48,8 @@ struct gc_generation { generations / }; +/ If we change this, we need to change the default value in the signature of
#define NUM_GENERATIONS 3 #define GEN_HEAD(n) (&generations[n].head) @@ -1155,107 +1162,123 @@ collect_generations(void) return n; } -PyDoc_STRVAR(gc_enable__doc__, -"enable() -> None\n" -"\n" -"Enable automatic garbage collection.\n"); +#include "clinic/gcmodule.c.h" + +/[clinic input] +gc.enable + +Enable automatic garbage collection. +[clinic start generated code]/ static PyObject -gc_enable(PyObject self, PyObject noargs) +gc_enable_impl(PyObject module) +/[clinic end generated code: output=45a427e9dce9155c input=81ac4940ca579707]/ { enabled = 1; Py_RETURN_NONE; } -PyDoc_STRVAR(gc_disable__doc__, -"disable() -> None\n" -"\n" -"Disable automatic garbage collection.\n"); +/[clinic input] +gc.disable + +Disable automatic garbage collection. +[clinic start generated code]/ static PyObject -gc_disable(PyObject self, PyObject noargs) +gc_disable_impl(PyObject module) +/[clinic end generated code: output=97d1030f7aa9d279 input=8c2e5a14e800d83b]/ { enabled = 0; Py_RETURN_NONE; } -PyDoc_STRVAR(gc_isenabled__doc__, -"isenabled() -> status\n" -"\n" -"Returns true if automatic garbage collection is enabled.\n"); +/[clinic input] +gc.isenabled -> bool + +Returns true if automatic garbage collection is enabled. +[clinic start generated code]/ -static PyObject * -gc_isenabled(PyObject *self, PyObject noargs) +static int +gc_isenabled_impl(PyObject module) +/[clinic end generated code: output=1874298331c49130 input=30005e0422373b31]/ {
} -PyDoc_STRVAR(gc_collect__doc__, -"collect([generation]) -> n\n" -"\n" -"With no arguments, run a full collection. The optional argument\n" -"may be an integer specifying which generation to collect. A ValueError\n" -"is raised if the generation number is invalid.\n\n" -"The number of unreachable objects is returned.\n"); +/*[clinic input] +gc.collect -> Py_ssize_t +
+ +Run the garbage collector. -static PyObject * -gc_collect(PyObject *self, PyObject args, PyObject kws) +With no arguments, run a full collection. The optional argument +may be an integer specifying which generation to collect. A ValueError +is raised if the generation number is invalid. + +The number of unreachable objects is returned. +[clinic start generated code]/ + +static Py_ssize_t +gc_collect_impl(PyObject module, int generation) +/[clinic end generated code: output=b697e633043233c7 input=40720128b682d879]/ {
- static char *keywords[] = {"generation", NULL};
- int genarg = NUM_GENERATIONS - 1; Py_ssize_t n;
- if (!PyArg_ParseTupleAndKeywords(args, kws, "|i", keywords, &genarg))
return NULL;[](#l2.120)
- if (generation < 0 || generation >= NUM_GENERATIONS) { PyErr_SetString(PyExc_ValueError, "invalid generation");
return NULL;[](#l2.125)
} if (collecting) n = 0; /* already collecting, don't do anything */ else { collecting = 1;return -1;[](#l2.126)
n = collect_with_callback(genarg);[](#l2.133)
} -PyDoc_STRVAR(gc_set_debug__doc__, -"set_debug(flags) -> None\n" -"\n" -"Set the garbage collection debugging flags. Debugging information is\n" -"written to sys.stderr.\n" -"\n" -"flags is an integer and can have the following bits turned on:\n" -"\n" -" DEBUG_STATS - Print statistics during collection.\n" -" DEBUG_COLLECTABLE - Print collectable objects found.\n" -" DEBUG_UNCOLLECTABLE - Print unreachable but uncollectable objects found.\n" -" DEBUG_SAVEALL - Save objects to gc.garbage rather than freeing them.\n" -" DEBUG_LEAK - Debug leaking programs (everything but STATS).\n"); +/*[clinic input] +gc.set_debug +
- flags: int
An integer that can have the following bits turned on:[](#l2.159)
DEBUG_STATS - Print statistics during collection.[](#l2.160)
DEBUG_COLLECTABLE - Print collectable objects found.[](#l2.161)
DEBUG_UNCOLLECTABLE - Print unreachable but uncollectable objects[](#l2.162)
found.[](#l2.163)
DEBUG_SAVEALL - Save objects to gc.garbage rather than freeing them.[](#l2.164)
DEBUG_LEAK - Debug leaking programs (everything but STATS).[](#l2.165)
- /
+ +Set the garbage collection debugging flags. + +Debugging information is written to sys.stderr. +[clinic start generated code]*/ static PyObject * -gc_set_debug(PyObject *self, PyObject args) +gc_set_debug_impl(PyObject module, int flags) +/[clinic end generated code: output=7c8366575486b228 input=5e5ce15e84fbed15]/ {
Py_RETURN_NONE; } -PyDoc_STRVAR(gc_get_debug__doc__, -"get_debug() -> flags\n" -"\n" -"Get the garbage collection debugging flags.\n"); +/[clinic input] +gc.get_debug -> int + +Get the garbage collection debugging flags. +[clinic start generated code]/ -static PyObject * -gc_get_debug(PyObject *self, PyObject noargs) +static int +gc_get_debug_impl(PyObject module) +/[clinic end generated code: output=91242f3506cd1e50 input=91a101e1c3b98366]/ {
} PyDoc_STRVAR(gc_set_thresh__doc__, @@ -1281,13 +1304,15 @@ gc_set_thresh(PyObject self, PyObject Py_RETURN_NONE; } -PyDoc_STRVAR(gc_get_thresh__doc__, -"get_threshold() -> (threshold0, threshold1, threshold2)\n" -"\n" -"Return the current collection thresholds\n"); +/[clinic input] +gc.get_threshold + +Return the current collection thresholds. +[clinic start generated code]/ static PyObject * -gc_get_thresh(PyObject *self, PyObject noargs) +gc_get_threshold_impl(PyObject module) +/[clinic end generated code: output=7902bc9f41ecbbd8 input=286d79918034d6e6]/ { return Py_BuildValue("(iii)", generations[0].threshold, @@ -1295,13 +1320,15 @@ gc_get_thresh(PyObject self, PyObject generations[2].threshold); } -PyDoc_STRVAR(gc_get_count__doc__, -"get_count() -> (count0, count1, count2)\n" -"\n" -"Return the current collection counts\n"); +/[clinic input] +gc.get_count + +Return a three-tuple of the current collection counts. +[clinic start generated code]/ static PyObject * -gc_get_count(PyObject self, PyObject noargs) +gc_get_count_impl(PyObject module) +/[clinic end generated code: output=354012e67b16398f input=a392794a08251751]/ { return Py_BuildValue("(iii)", generations[0].count, @@ -1395,14 +1422,15 @@ gc_get_referents(PyObject self, PyObjec return result; } -PyDoc_STRVAR(gc_get_objects__doc__, -"get_objects() -> [...]\n" -"\n" -"Return a list of objects tracked by the collector (excluding the list\n" -"returned).\n"); +/[clinic input] +gc.get_objects + +Return a list of objects tracked by the collector (excluding the list returned). +[clinic start generated code]/ static PyObject -gc_get_objects(PyObject self, PyObject noargs) +gc_get_objects_impl(PyObject module) +/[clinic end generated code: output=fcb95d2e23e1f750 input=9439fe8170bf35d8]/ { int i; PyObject result; @@ -1419,13 +1447,15 @@ gc_get_objects(PyObject self, PyObject return result; } -PyDoc_STRVAR(gc_get_stats__doc__, -"get_stats() -> [...]\n" -"\n" -"Return a list of dictionaries containing per-generation statistics.\n"); +/[clinic input] +gc.get_stats + +Return a list of dictionaries containing per-generation statistics. +[clinic start generated code]/ static PyObject * -gc_get_stats(PyObject *self, PyObject noargs) +gc_get_stats_impl(PyObject module) +/[clinic end generated code: output=a8ab1d8a5d26f3ab input=1ef4ed9d17b1a470]/ { int i; PyObject result; @@ -1465,15 +1495,20 @@ error: } -PyDoc_STRVAR(gc_is_tracked__doc__, -"is_tracked(obj) -> bool\n" -"\n" -"Returns true if the object is tracked by the garbage collector.\n" -"Simple atomic objects will return false.\n" -); +/[clinic input] +gc.is_tracked +
+ +Returns true if the object is tracked by the garbage collector. + +Simple atomic objects will return false. +[clinic start generated code]*/ static PyObject * -gc_is_tracked(PyObject *self, PyObject *obj) +gc_is_tracked(PyObject module, PyObject obj) +/[clinic end generated code: output=14f0103423b28e31 input=d83057f170ea2723]/ { PyObject *result; @@ -1505,19 +1540,18 @@ PyDoc_STRVAR(gc__doc__, "get_referents() -- Return the list of objects that an object refers to.\n"); static PyMethodDef GcMethods[] = {
- {"enable", gc_enable, METH_NOARGS, gc_enable__doc__},
- {"disable", gc_disable, METH_NOARGS, gc_disable__doc__},
- {"isenabled", gc_isenabled, METH_NOARGS, gc_isenabled__doc__},
- {"set_debug", gc_set_debug, METH_VARARGS, gc_set_debug__doc__},
- {"get_debug", gc_get_debug, METH_NOARGS, gc_get_debug__doc__},
- {"get_count", gc_get_count, METH_NOARGS, gc_get_count__doc__},
- GC_ENABLE_METHODDEF
- GC_DISABLE_METHODDEF
- GC_ISENABLED_METHODDEF
- GC_SET_DEBUG_METHODDEF
- GC_GET_DEBUG_METHODDEF
- GC_GET_COUNT_METHODDEF {"set_threshold", gc_set_thresh, METH_VARARGS, gc_set_thresh__doc__},
- {"get_threshold", gc_get_thresh, METH_NOARGS, gc_get_thresh__doc__},
- {"collect", (PyCFunction)gc_collect,
METH_VARARGS | METH_KEYWORDS, gc_collect__doc__},[](#l2.338)
- {"get_objects", gc_get_objects,METH_NOARGS, gc_get_objects__doc__},
- {"get_stats", gc_get_stats, METH_NOARGS, gc_get_stats__doc__},
- {"is_tracked", gc_is_tracked, METH_O, gc_is_tracked__doc__},