diff -r 259857de72e1 Modules/gcmodule.c --- a/Modules/gcmodule.c Thu Feb 06 00:18:48 2014 -0500 +++ b/Modules/gcmodule.c Thu Feb 06 22:23:47 2014 +0800 @@ -26,6 +26,11 @@ #include "Python.h" #include "frameobject.h" /* for PyFrame_ClearFreeList */ +/*[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) @@ -1155,39 +1160,93 @@ return n; } +/*[clinic input] +gc.enable + +Enable automatic garbage collection. +[clinic start generated code]*/ + PyDoc_STRVAR(gc_enable__doc__, -"enable() -> None\n" -"\n" -"Enable automatic garbage collection.\n"); +"sig=($module)\n" +"Enable automatic garbage collection."); + +#define GC_ENABLE_METHODDEF \ + {"enable", (PyCFunction)gc_enable, METH_NOARGS, gc_enable__doc__}, static PyObject * -gc_enable(PyObject *self, PyObject *noargs) +gc_enable_impl(PyModuleDef *module); + +static PyObject * +gc_enable(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) +{ + return gc_enable_impl(module); +} + +static PyObject * +gc_enable_impl(PyModuleDef *module) +/*[clinic end generated code: output=476c0b07b0098d24 input=81ac4940ca579707]*/ { enabled = 1; Py_INCREF(Py_None); return Py_None; } +/*[clinic input] +gc.disable + +Disable automatic garbage collection. +[clinic start generated code]*/ + PyDoc_STRVAR(gc_disable__doc__, -"disable() -> None\n" -"\n" -"Disable automatic garbage collection.\n"); +"sig=($module)\n" +"Disable automatic garbage collection."); + +#define GC_DISABLE_METHODDEF \ + {"disable", (PyCFunction)gc_disable, METH_NOARGS, gc_disable__doc__}, static PyObject * -gc_disable(PyObject *self, PyObject *noargs) +gc_disable_impl(PyModuleDef *module); + +static PyObject * +gc_disable(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) +{ + return gc_disable_impl(module); +} + +static PyObject * +gc_disable_impl(PyModuleDef *module) +/*[clinic end generated code: output=b5f25c21f0d61be1 input=8c2e5a14e800d83b]*/ { enabled = 0; Py_INCREF(Py_None); return Py_None; } +/*[clinic input] +gc.isenabled + +Returns true if automatic garbage collection is enabled. +[clinic start generated code]*/ + PyDoc_STRVAR(gc_isenabled__doc__, -"isenabled() -> status\n" -"\n" -"Returns true if automatic garbage collection is enabled.\n"); +"sig=($module)\n" +"Returns true if automatic garbage collection is enabled."); + +#define GC_ISENABLED_METHODDEF \ + {"isenabled", (PyCFunction)gc_isenabled, METH_NOARGS, gc_isenabled__doc__}, static PyObject * -gc_isenabled(PyObject *self, PyObject *noargs) +gc_isenabled_impl(PyModuleDef *module); + +static PyObject * +gc_isenabled(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) +{ + return gc_isenabled_impl(module); +} + +static PyObject * +gc_isenabled_impl(PyModuleDef *module) +/*[clinic end generated code: output=7befbad8dcb585e6 input=f0aa82d8e827f177]*/ { return PyBool_FromLong((long)enabled); } @@ -1226,39 +1285,107 @@ return PyLong_FromSsize_t(n); } +/*[clinic input] +gc.set_debug + + flags: int + An integer and can have the following bits turned on: + DEBUG_STATS - Print statistics during collection. + DEBUG_COLLECTABLE - Print collectable objects found. + DEBUG_UNCOLLECTABLE - Print unreachable but uncollectable objects + found. + DEBUG_SAVEALL - Save objects to gc.garbage rather than freeing them. + DEBUG_LEAK - Debug leaking programs (everything but STATS). + / + +Set the garbage collection debugging flags. + +Debugging information is written to sys.stderr. +[clinic start generated code]*/ + PyDoc_STRVAR(gc_set_debug__doc__, -"set_debug(flags) -> None\n" +"sig=($module, flags)\n" +"Set the garbage collection debugging flags.\n" "\n" -"Set the garbage collection debugging flags. Debugging information is\n" -"written to sys.stderr.\n" +" flags\n" +" An integer and 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" -"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"); +"Debugging information is written to sys.stderr."); + +#define GC_SET_DEBUG_METHODDEF \ + {"set_debug", (PyCFunction)gc_set_debug, METH_VARARGS, gc_set_debug__doc__}, static PyObject * -gc_set_debug(PyObject *self, PyObject *args) +gc_set_debug_impl(PyModuleDef *module, int flags); + +static PyObject * +gc_set_debug(PyModuleDef *module, PyObject *args) { - if (!PyArg_ParseTuple(args, "i:set_debug", &debug)) - return NULL; + PyObject *return_value = NULL; + int flags; + + if (!PyArg_ParseTuple(args, + "i:set_debug", + &flags)) + goto exit; + return_value = gc_set_debug_impl(module, flags); + +exit: + return return_value; +} + +static PyObject * +gc_set_debug_impl(PyModuleDef *module, int flags) +/*[clinic end generated code: output=ffd50605bbe959ae input=aa25c647b7d12311]*/ +{ + debug = flags; Py_INCREF(Py_None); return Py_None; } +/*[clinic input] +gc.get_debug -> int + +Get the garbage collection debugging flags. +[clinic start generated code]*/ + PyDoc_STRVAR(gc_get_debug__doc__, -"get_debug() -> flags\n" -"\n" -"Get the garbage collection debugging flags.\n"); +"sig=($module)\n" +"Get the garbage collection debugging flags."); + +#define GC_GET_DEBUG_METHODDEF \ + {"get_debug", (PyCFunction)gc_get_debug, METH_NOARGS, gc_get_debug__doc__}, + +static int +gc_get_debug_impl(PyModuleDef *module); static PyObject * -gc_get_debug(PyObject *self, PyObject *noargs) +gc_get_debug(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) { - return Py_BuildValue("i", debug); + PyObject *return_value = NULL; + int _return_value; + + _return_value = gc_get_debug_impl(module); + if ((_return_value == -1) && PyErr_Occurred()) + goto exit; + return_value = PyLong_FromLong((long)_return_value); + +exit: + return return_value; +} + +static int +gc_get_debug_impl(PyModuleDef *module) +/*[clinic end generated code: output=26923c7652716fe0 input=91a101e1c3b98366]*/ +{ + return debug; } PyDoc_STRVAR(gc_set_thresh__doc__, @@ -1285,13 +1412,31 @@ return Py_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]*/ + +PyDoc_STRVAR(gc_get_threshold__doc__, +"sig=($module)\n" +"Return the current collection thresholds."); + +#define GC_GET_THRESHOLD_METHODDEF \ + {"get_threshold", (PyCFunction)gc_get_threshold, METH_NOARGS, gc_get_threshold__doc__}, static PyObject * -gc_get_thresh(PyObject *self, PyObject *noargs) +gc_get_threshold_impl(PyModuleDef *module); + +static PyObject * +gc_get_threshold(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) +{ + return gc_get_threshold_impl(module); +} + +static PyObject * +gc_get_threshold_impl(PyModuleDef *module) +/*[clinic end generated code: output=6d46e093f94d36f1 input=286d79918034d6e6]*/ { return Py_BuildValue("(iii)", generations[0].threshold, @@ -1299,13 +1444,31 @@ generations[2].threshold); } +/*[clinic input] +gc.get_count + +Return the current collection counts. +[clinic start generated code]*/ + PyDoc_STRVAR(gc_get_count__doc__, -"get_count() -> (count0, count1, count2)\n" -"\n" -"Return the current collection counts\n"); +"sig=($module)\n" +"Return the current collection counts."); + +#define GC_GET_COUNT_METHODDEF \ + {"get_count", (PyCFunction)gc_get_count, METH_NOARGS, gc_get_count__doc__}, static PyObject * -gc_get_count(PyObject *self, PyObject *noargs) +gc_get_count_impl(PyModuleDef *module); + +static PyObject * +gc_get_count(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) +{ + return gc_get_count_impl(module); +} + +static PyObject * +gc_get_count_impl(PyModuleDef *module) +/*[clinic end generated code: output=5be1308251cb4610 input=85a958f5505cbd23]*/ { return Py_BuildValue("(iii)", generations[0].count, @@ -1399,14 +1562,31 @@ return result; } +/*[clinic input] +gc.get_objects + +Return a list of objects tracked by the collector (excluding the list returned). +[clinic start generated code]*/ + 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"); +"sig=($module)\n" +"Return a list of objects tracked by the collector (excluding the list returned)."); + +#define GC_GET_OBJECTS_METHODDEF \ + {"get_objects", (PyCFunction)gc_get_objects, METH_NOARGS, gc_get_objects__doc__}, static PyObject * -gc_get_objects(PyObject *self, PyObject *noargs) +gc_get_objects_impl(PyModuleDef *module); + +static PyObject * +gc_get_objects(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) +{ + return gc_get_objects_impl(module); +} + +static PyObject * +gc_get_objects_impl(PyModuleDef *module) +/*[clinic end generated code: output=d617facc6fc6f61f input=9439fe8170bf35d8]*/ { int i; PyObject* result; @@ -1423,13 +1603,31 @@ return result; } +/*[clinic input] +gc.get_stats + +Return a list of dictionaries containing per-generation statistics. +[clinic start generated code]*/ + PyDoc_STRVAR(gc_get_stats__doc__, -"get_stats() -> [...]\n" -"\n" -"Return a list of dictionaries containing per-generation statistics.\n"); +"sig=($module)\n" +"Return a list of dictionaries containing per-generation statistics."); + +#define GC_GET_STATS_METHODDEF \ + {"get_stats", (PyCFunction)gc_get_stats, METH_NOARGS, gc_get_stats__doc__}, static PyObject * -gc_get_stats(PyObject *self, PyObject *noargs) +gc_get_stats_impl(PyModuleDef *module); + +static PyObject * +gc_get_stats(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) +{ + return gc_get_stats_impl(module); +} + +static PyObject * +gc_get_stats_impl(PyModuleDef *module) +/*[clinic end generated code: output=728b4e278f4e69dd input=1ef4ed9d17b1a470]*/ { int i; PyObject *result; @@ -1469,15 +1667,29 @@ } +/*[clinic input] +gc.is_tracked + + obj: object + / + +Returns true if the object is tracked by the garbage collector. + +Simple atomic objects will return false. +[clinic start generated code]*/ + PyDoc_STRVAR(gc_is_tracked__doc__, -"is_tracked(obj) -> bool\n" +"sig=($module, obj)\n" +"Returns true if the object is tracked by the garbage collector.\n" "\n" -"Returns true if the object is tracked by the garbage collector.\n" -"Simple atomic objects will return false.\n" -); +"Simple atomic objects will return false."); + +#define GC_IS_TRACKED_METHODDEF \ + {"is_tracked", (PyCFunction)gc_is_tracked, METH_O, gc_is_tracked__doc__}, static PyObject * -gc_is_tracked(PyObject *self, PyObject *obj) +gc_is_tracked(PyModuleDef *module, PyObject *obj) +/*[clinic end generated code: output=c1ce9399e6a88ec6 input=d83057f170ea2723]*/ { PyObject *result; @@ -1509,19 +1721,19 @@ "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__}, + GC_GET_THRESHOLD_METHODDEF {"collect", (PyCFunction)gc_collect, METH_VARARGS | METH_KEYWORDS, gc_collect__doc__}, - {"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__}, + GC_GET_OBJECTS_METHODDEF + GC_GET_STATS_METHODDEF + GC_IS_TRACKED_METHODDEF {"get_referrers", gc_get_referrers, METH_VARARGS, gc_get_referrers__doc__}, {"get_referents", gc_get_referents, METH_VARARGS,