LCOV - code coverage report
Current view: top level - Modules/clinic - gcmodule.c.h (source / functions) Hit Total Coverage
Test: CPython lcov report Lines: 72 80 90.0 %
Date: 2022-07-07 18:19:46 Functions: 13 13 100.0 %

          Line data    Source code
       1             : /*[clinic input]
       2             : preserve
       3             : [clinic start generated code]*/
       4             : 
       5             : PyDoc_STRVAR(gc_enable__doc__,
       6             : "enable($module, /)\n"
       7             : "--\n"
       8             : "\n"
       9             : "Enable automatic garbage collection.");
      10             : 
      11             : #define GC_ENABLE_METHODDEF    \
      12             :     {"enable", (PyCFunction)gc_enable, METH_NOARGS, gc_enable__doc__},
      13             : 
      14             : static PyObject *
      15             : gc_enable_impl(PyObject *module);
      16             : 
      17             : static PyObject *
      18         445 : gc_enable(PyObject *module, PyObject *Py_UNUSED(ignored))
      19             : {
      20         445 :     return gc_enable_impl(module);
      21             : }
      22             : 
      23             : PyDoc_STRVAR(gc_disable__doc__,
      24             : "disable($module, /)\n"
      25             : "--\n"
      26             : "\n"
      27             : "Disable automatic garbage collection.");
      28             : 
      29             : #define GC_DISABLE_METHODDEF    \
      30             :     {"disable", (PyCFunction)gc_disable, METH_NOARGS, gc_disable__doc__},
      31             : 
      32             : static PyObject *
      33             : gc_disable_impl(PyObject *module);
      34             : 
      35             : static PyObject *
      36         447 : gc_disable(PyObject *module, PyObject *Py_UNUSED(ignored))
      37             : {
      38         447 :     return gc_disable_impl(module);
      39             : }
      40             : 
      41             : PyDoc_STRVAR(gc_isenabled__doc__,
      42             : "isenabled($module, /)\n"
      43             : "--\n"
      44             : "\n"
      45             : "Returns true if automatic garbage collection is enabled.");
      46             : 
      47             : #define GC_ISENABLED_METHODDEF    \
      48             :     {"isenabled", (PyCFunction)gc_isenabled, METH_NOARGS, gc_isenabled__doc__},
      49             : 
      50             : static int
      51             : gc_isenabled_impl(PyObject *module);
      52             : 
      53             : static PyObject *
      54         450 : gc_isenabled(PyObject *module, PyObject *Py_UNUSED(ignored))
      55             : {
      56         450 :     PyObject *return_value = NULL;
      57             :     int _return_value;
      58             : 
      59         450 :     _return_value = gc_isenabled_impl(module);
      60         450 :     if ((_return_value == -1) && PyErr_Occurred()) {
      61           0 :         goto exit;
      62             :     }
      63         450 :     return_value = PyBool_FromLong((long)_return_value);
      64             : 
      65         450 : exit:
      66         450 :     return return_value;
      67             : }
      68             : 
      69             : PyDoc_STRVAR(gc_collect__doc__,
      70             : "collect($module, /, generation=2)\n"
      71             : "--\n"
      72             : "\n"
      73             : "Run the garbage collector.\n"
      74             : "\n"
      75             : "With no arguments, run a full collection.  The optional argument\n"
      76             : "may be an integer specifying which generation to collect.  A ValueError\n"
      77             : "is raised if the generation number is invalid.\n"
      78             : "\n"
      79             : "The number of unreachable objects is returned.");
      80             : 
      81             : #define GC_COLLECT_METHODDEF    \
      82             :     {"collect", _PyCFunction_CAST(gc_collect), METH_FASTCALL|METH_KEYWORDS, gc_collect__doc__},
      83             : 
      84             : static Py_ssize_t
      85             : gc_collect_impl(PyObject *module, int generation);
      86             : 
      87             : static PyObject *
      88       15311 : gc_collect(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
      89             : {
      90       15311 :     PyObject *return_value = NULL;
      91             :     static const char * const _keywords[] = {"generation", NULL};
      92             :     static _PyArg_Parser _parser = {NULL, _keywords, "collect", 0};
      93             :     PyObject *argsbuf[1];
      94       15311 :     Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
      95       15311 :     int generation = NUM_GENERATIONS - 1;
      96             :     Py_ssize_t _return_value;
      97             : 
      98       15311 :     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
      99       15311 :     if (!args) {
     100           0 :         goto exit;
     101             :     }
     102       15311 :     if (!noptargs) {
     103       15005 :         goto skip_optional_pos;
     104             :     }
     105         306 :     generation = _PyLong_AsInt(args[0]);
     106         306 :     if (generation == -1 && PyErr_Occurred()) {
     107           0 :         goto exit;
     108             :     }
     109         306 : skip_optional_pos:
     110       15311 :     _return_value = gc_collect_impl(module, generation);
     111       15311 :     if ((_return_value == -1) && PyErr_Occurred()) {
     112           0 :         goto exit;
     113             :     }
     114       15311 :     return_value = PyLong_FromSsize_t(_return_value);
     115             : 
     116       15311 : exit:
     117       15311 :     return return_value;
     118             : }
     119             : 
     120             : PyDoc_STRVAR(gc_set_debug__doc__,
     121             : "set_debug($module, flags, /)\n"
     122             : "--\n"
     123             : "\n"
     124             : "Set the garbage collection debugging flags.\n"
     125             : "\n"
     126             : "  flags\n"
     127             : "    An integer that can have the following bits turned on:\n"
     128             : "      DEBUG_STATS - Print statistics during collection.\n"
     129             : "      DEBUG_COLLECTABLE - Print collectable objects found.\n"
     130             : "      DEBUG_UNCOLLECTABLE - Print unreachable but uncollectable objects\n"
     131             : "        found.\n"
     132             : "      DEBUG_SAVEALL - Save objects to gc.garbage rather than freeing them.\n"
     133             : "      DEBUG_LEAK - Debug leaking programs (everything but STATS).\n"
     134             : "\n"
     135             : "Debugging information is written to sys.stderr.");
     136             : 
     137             : #define GC_SET_DEBUG_METHODDEF    \
     138             :     {"set_debug", (PyCFunction)gc_set_debug, METH_O, gc_set_debug__doc__},
     139             : 
     140             : static PyObject *
     141             : gc_set_debug_impl(PyObject *module, int flags);
     142             : 
     143             : static PyObject *
     144          15 : gc_set_debug(PyObject *module, PyObject *arg)
     145             : {
     146          15 :     PyObject *return_value = NULL;
     147             :     int flags;
     148             : 
     149          15 :     flags = _PyLong_AsInt(arg);
     150          15 :     if (flags == -1 && PyErr_Occurred()) {
     151           0 :         goto exit;
     152             :     }
     153          15 :     return_value = gc_set_debug_impl(module, flags);
     154             : 
     155          15 : exit:
     156          15 :     return return_value;
     157             : }
     158             : 
     159             : PyDoc_STRVAR(gc_get_debug__doc__,
     160             : "get_debug($module, /)\n"
     161             : "--\n"
     162             : "\n"
     163             : "Get the garbage collection debugging flags.");
     164             : 
     165             : #define GC_GET_DEBUG_METHODDEF    \
     166             :     {"get_debug", (PyCFunction)gc_get_debug, METH_NOARGS, gc_get_debug__doc__},
     167             : 
     168             : static int
     169             : gc_get_debug_impl(PyObject *module);
     170             : 
     171             : static PyObject *
     172           6 : gc_get_debug(PyObject *module, PyObject *Py_UNUSED(ignored))
     173             : {
     174           6 :     PyObject *return_value = NULL;
     175             :     int _return_value;
     176             : 
     177           6 :     _return_value = gc_get_debug_impl(module);
     178           6 :     if ((_return_value == -1) && PyErr_Occurred()) {
     179           0 :         goto exit;
     180             :     }
     181           6 :     return_value = PyLong_FromLong((long)_return_value);
     182             : 
     183           6 : exit:
     184           6 :     return return_value;
     185             : }
     186             : 
     187             : PyDoc_STRVAR(gc_get_threshold__doc__,
     188             : "get_threshold($module, /)\n"
     189             : "--\n"
     190             : "\n"
     191             : "Return the current collection thresholds.");
     192             : 
     193             : #define GC_GET_THRESHOLD_METHODDEF    \
     194             :     {"get_threshold", (PyCFunction)gc_get_threshold, METH_NOARGS, gc_get_threshold__doc__},
     195             : 
     196             : static PyObject *
     197             : gc_get_threshold_impl(PyObject *module);
     198             : 
     199             : static PyObject *
     200          14 : gc_get_threshold(PyObject *module, PyObject *Py_UNUSED(ignored))
     201             : {
     202          14 :     return gc_get_threshold_impl(module);
     203             : }
     204             : 
     205             : PyDoc_STRVAR(gc_get_count__doc__,
     206             : "get_count($module, /)\n"
     207             : "--\n"
     208             : "\n"
     209             : "Return a three-tuple of the current collection counts.");
     210             : 
     211             : #define GC_GET_COUNT_METHODDEF    \
     212             :     {"get_count", (PyCFunction)gc_get_count, METH_NOARGS, gc_get_count__doc__},
     213             : 
     214             : static PyObject *
     215             : gc_get_count_impl(PyObject *module);
     216             : 
     217             : static PyObject *
     218           5 : gc_get_count(PyObject *module, PyObject *Py_UNUSED(ignored))
     219             : {
     220           5 :     return gc_get_count_impl(module);
     221             : }
     222             : 
     223             : PyDoc_STRVAR(gc_get_objects__doc__,
     224             : "get_objects($module, /, generation=None)\n"
     225             : "--\n"
     226             : "\n"
     227             : "Return a list of objects tracked by the collector (excluding the list returned).\n"
     228             : "\n"
     229             : "  generation\n"
     230             : "    Generation to extract the objects from.\n"
     231             : "\n"
     232             : "If generation is not None, return only the objects tracked by the collector\n"
     233             : "that are in that generation.");
     234             : 
     235             : #define GC_GET_OBJECTS_METHODDEF    \
     236             :     {"get_objects", _PyCFunction_CAST(gc_get_objects), METH_FASTCALL|METH_KEYWORDS, gc_get_objects__doc__},
     237             : 
     238             : static PyObject *
     239             : gc_get_objects_impl(PyObject *module, Py_ssize_t generation);
     240             : 
     241             : static PyObject *
     242          23 : gc_get_objects(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
     243             : {
     244          23 :     PyObject *return_value = NULL;
     245             :     static const char * const _keywords[] = {"generation", NULL};
     246             :     static _PyArg_Parser _parser = {NULL, _keywords, "get_objects", 0};
     247             :     PyObject *argsbuf[1];
     248          23 :     Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
     249          23 :     Py_ssize_t generation = -1;
     250             : 
     251          23 :     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
     252          23 :     if (!args) {
     253           0 :         goto exit;
     254             :     }
     255          23 :     if (!noptargs) {
     256           5 :         goto skip_optional_pos;
     257             :     }
     258          18 :     if (!_Py_convert_optional_to_ssize_t(args[0], &generation)) {
     259           2 :         goto exit;
     260             :     }
     261          16 : skip_optional_pos:
     262          21 :     return_value = gc_get_objects_impl(module, generation);
     263             : 
     264          23 : exit:
     265          23 :     return return_value;
     266             : }
     267             : 
     268             : PyDoc_STRVAR(gc_get_stats__doc__,
     269             : "get_stats($module, /)\n"
     270             : "--\n"
     271             : "\n"
     272             : "Return a list of dictionaries containing per-generation statistics.");
     273             : 
     274             : #define GC_GET_STATS_METHODDEF    \
     275             :     {"get_stats", (PyCFunction)gc_get_stats, METH_NOARGS, gc_get_stats__doc__},
     276             : 
     277             : static PyObject *
     278             : gc_get_stats_impl(PyObject *module);
     279             : 
     280             : static PyObject *
     281           9 : gc_get_stats(PyObject *module, PyObject *Py_UNUSED(ignored))
     282             : {
     283           9 :     return gc_get_stats_impl(module);
     284             : }
     285             : 
     286             : PyDoc_STRVAR(gc_is_tracked__doc__,
     287             : "is_tracked($module, obj, /)\n"
     288             : "--\n"
     289             : "\n"
     290             : "Returns true if the object is tracked by the garbage collector.\n"
     291             : "\n"
     292             : "Simple atomic objects will return false.");
     293             : 
     294             : #define GC_IS_TRACKED_METHODDEF    \
     295             :     {"is_tracked", (PyCFunction)gc_is_tracked, METH_O, gc_is_tracked__doc__},
     296             : 
     297             : PyDoc_STRVAR(gc_is_finalized__doc__,
     298             : "is_finalized($module, obj, /)\n"
     299             : "--\n"
     300             : "\n"
     301             : "Returns true if the object has been already finalized by the GC.");
     302             : 
     303             : #define GC_IS_FINALIZED_METHODDEF    \
     304             :     {"is_finalized", (PyCFunction)gc_is_finalized, METH_O, gc_is_finalized__doc__},
     305             : 
     306             : PyDoc_STRVAR(gc_freeze__doc__,
     307             : "freeze($module, /)\n"
     308             : "--\n"
     309             : "\n"
     310             : "Freeze all current tracked objects and ignore them for future collections.\n"
     311             : "\n"
     312             : "This can be used before a POSIX fork() call to make the gc copy-on-write friendly.\n"
     313             : "Note: collection before a POSIX fork() call may free pages for future allocation\n"
     314             : "which can cause copy-on-write.");
     315             : 
     316             : #define GC_FREEZE_METHODDEF    \
     317             :     {"freeze", (PyCFunction)gc_freeze, METH_NOARGS, gc_freeze__doc__},
     318             : 
     319             : static PyObject *
     320             : gc_freeze_impl(PyObject *module);
     321             : 
     322             : static PyObject *
     323           1 : gc_freeze(PyObject *module, PyObject *Py_UNUSED(ignored))
     324             : {
     325           1 :     return gc_freeze_impl(module);
     326             : }
     327             : 
     328             : PyDoc_STRVAR(gc_unfreeze__doc__,
     329             : "unfreeze($module, /)\n"
     330             : "--\n"
     331             : "\n"
     332             : "Unfreeze all objects in the permanent generation.\n"
     333             : "\n"
     334             : "Put all objects in the permanent generation back into oldest generation.");
     335             : 
     336             : #define GC_UNFREEZE_METHODDEF    \
     337             :     {"unfreeze", (PyCFunction)gc_unfreeze, METH_NOARGS, gc_unfreeze__doc__},
     338             : 
     339             : static PyObject *
     340             : gc_unfreeze_impl(PyObject *module);
     341             : 
     342             : static PyObject *
     343           1 : gc_unfreeze(PyObject *module, PyObject *Py_UNUSED(ignored))
     344             : {
     345           1 :     return gc_unfreeze_impl(module);
     346             : }
     347             : 
     348             : PyDoc_STRVAR(gc_get_freeze_count__doc__,
     349             : "get_freeze_count($module, /)\n"
     350             : "--\n"
     351             : "\n"
     352             : "Return the number of objects in the permanent generation.");
     353             : 
     354             : #define GC_GET_FREEZE_COUNT_METHODDEF    \
     355             :     {"get_freeze_count", (PyCFunction)gc_get_freeze_count, METH_NOARGS, gc_get_freeze_count__doc__},
     356             : 
     357             : static Py_ssize_t
     358             : gc_get_freeze_count_impl(PyObject *module);
     359             : 
     360             : static PyObject *
     361           2 : gc_get_freeze_count(PyObject *module, PyObject *Py_UNUSED(ignored))
     362             : {
     363           2 :     PyObject *return_value = NULL;
     364             :     Py_ssize_t _return_value;
     365             : 
     366           2 :     _return_value = gc_get_freeze_count_impl(module);
     367           2 :     if ((_return_value == -1) && PyErr_Occurred()) {
     368           0 :         goto exit;
     369             :     }
     370           2 :     return_value = PyLong_FromSsize_t(_return_value);
     371             : 
     372           2 : exit:
     373           2 :     return return_value;
     374             : }
     375             : /*[clinic end generated code: output=71f7136d6e3f2323 input=a9049054013a1b77]*/

Generated by: LCOV version 1.14