Serhiy Storchaka | 9326028 | 2017-02-04 11:19:59 +0200 | [diff] [blame] | 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 | gc_enable(PyObject *module, PyObject *Py_UNUSED(ignored)) |
| 19 | { |
| 20 | 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 | gc_disable(PyObject *module, PyObject *Py_UNUSED(ignored)) |
| 37 | { |
| 38 | 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 | gc_isenabled(PyObject *module, PyObject *Py_UNUSED(ignored)) |
| 55 | { |
| 56 | PyObject *return_value = NULL; |
| 57 | int _return_value; |
| 58 | |
| 59 | _return_value = gc_isenabled_impl(module); |
| 60 | if ((_return_value == -1) && PyErr_Occurred()) { |
| 61 | goto exit; |
| 62 | } |
| 63 | return_value = PyBool_FromLong((long)_return_value); |
| 64 | |
| 65 | exit: |
| 66 | 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 \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 82 | {"collect", (PyCFunction)(void(*)(void))gc_collect, METH_FASTCALL|METH_KEYWORDS, gc_collect__doc__}, |
Serhiy Storchaka | 9326028 | 2017-02-04 11:19:59 +0200 | [diff] [blame] | 83 | |
| 84 | static Py_ssize_t |
| 85 | gc_collect_impl(PyObject *module, int generation); |
| 86 | |
| 87 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 88 | gc_collect(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 9326028 | 2017-02-04 11:19:59 +0200 | [diff] [blame] | 89 | { |
| 90 | PyObject *return_value = NULL; |
| 91 | static const char * const _keywords[] = {"generation", NULL}; |
| 92 | static _PyArg_Parser _parser = {"|i:collect", _keywords, 0}; |
| 93 | int generation = NUM_GENERATIONS - 1; |
| 94 | Py_ssize_t _return_value; |
| 95 | |
| 96 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
| 97 | &generation)) { |
| 98 | goto exit; |
| 99 | } |
| 100 | _return_value = gc_collect_impl(module, generation); |
| 101 | if ((_return_value == -1) && PyErr_Occurred()) { |
| 102 | goto exit; |
| 103 | } |
| 104 | return_value = PyLong_FromSsize_t(_return_value); |
| 105 | |
| 106 | exit: |
| 107 | return return_value; |
| 108 | } |
| 109 | |
| 110 | PyDoc_STRVAR(gc_set_debug__doc__, |
| 111 | "set_debug($module, flags, /)\n" |
| 112 | "--\n" |
| 113 | "\n" |
| 114 | "Set the garbage collection debugging flags.\n" |
| 115 | "\n" |
| 116 | " flags\n" |
| 117 | " An integer that can have the following bits turned on:\n" |
| 118 | " DEBUG_STATS - Print statistics during collection.\n" |
| 119 | " DEBUG_COLLECTABLE - Print collectable objects found.\n" |
| 120 | " DEBUG_UNCOLLECTABLE - Print unreachable but uncollectable objects\n" |
| 121 | " found.\n" |
| 122 | " DEBUG_SAVEALL - Save objects to gc.garbage rather than freeing them.\n" |
| 123 | " DEBUG_LEAK - Debug leaking programs (everything but STATS).\n" |
| 124 | "\n" |
| 125 | "Debugging information is written to sys.stderr."); |
| 126 | |
| 127 | #define GC_SET_DEBUG_METHODDEF \ |
| 128 | {"set_debug", (PyCFunction)gc_set_debug, METH_O, gc_set_debug__doc__}, |
| 129 | |
| 130 | static PyObject * |
| 131 | gc_set_debug_impl(PyObject *module, int flags); |
| 132 | |
| 133 | static PyObject * |
| 134 | gc_set_debug(PyObject *module, PyObject *arg) |
| 135 | { |
| 136 | PyObject *return_value = NULL; |
| 137 | int flags; |
| 138 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 139 | if (PyFloat_Check(arg)) { |
| 140 | PyErr_SetString(PyExc_TypeError, |
| 141 | "integer argument expected, got float" ); |
| 142 | goto exit; |
| 143 | } |
| 144 | flags = _PyLong_AsInt(arg); |
| 145 | if (flags == -1 && PyErr_Occurred()) { |
Serhiy Storchaka | 9326028 | 2017-02-04 11:19:59 +0200 | [diff] [blame] | 146 | goto exit; |
| 147 | } |
| 148 | return_value = gc_set_debug_impl(module, flags); |
| 149 | |
| 150 | exit: |
| 151 | return return_value; |
| 152 | } |
| 153 | |
| 154 | PyDoc_STRVAR(gc_get_debug__doc__, |
| 155 | "get_debug($module, /)\n" |
| 156 | "--\n" |
| 157 | "\n" |
| 158 | "Get the garbage collection debugging flags."); |
| 159 | |
| 160 | #define GC_GET_DEBUG_METHODDEF \ |
| 161 | {"get_debug", (PyCFunction)gc_get_debug, METH_NOARGS, gc_get_debug__doc__}, |
| 162 | |
| 163 | static int |
| 164 | gc_get_debug_impl(PyObject *module); |
| 165 | |
| 166 | static PyObject * |
| 167 | gc_get_debug(PyObject *module, PyObject *Py_UNUSED(ignored)) |
| 168 | { |
| 169 | PyObject *return_value = NULL; |
| 170 | int _return_value; |
| 171 | |
| 172 | _return_value = gc_get_debug_impl(module); |
| 173 | if ((_return_value == -1) && PyErr_Occurred()) { |
| 174 | goto exit; |
| 175 | } |
| 176 | return_value = PyLong_FromLong((long)_return_value); |
| 177 | |
| 178 | exit: |
| 179 | return return_value; |
| 180 | } |
| 181 | |
| 182 | PyDoc_STRVAR(gc_get_threshold__doc__, |
| 183 | "get_threshold($module, /)\n" |
| 184 | "--\n" |
| 185 | "\n" |
| 186 | "Return the current collection thresholds."); |
| 187 | |
| 188 | #define GC_GET_THRESHOLD_METHODDEF \ |
| 189 | {"get_threshold", (PyCFunction)gc_get_threshold, METH_NOARGS, gc_get_threshold__doc__}, |
| 190 | |
| 191 | static PyObject * |
| 192 | gc_get_threshold_impl(PyObject *module); |
| 193 | |
| 194 | static PyObject * |
| 195 | gc_get_threshold(PyObject *module, PyObject *Py_UNUSED(ignored)) |
| 196 | { |
| 197 | return gc_get_threshold_impl(module); |
| 198 | } |
| 199 | |
| 200 | PyDoc_STRVAR(gc_get_count__doc__, |
| 201 | "get_count($module, /)\n" |
| 202 | "--\n" |
| 203 | "\n" |
| 204 | "Return a three-tuple of the current collection counts."); |
| 205 | |
| 206 | #define GC_GET_COUNT_METHODDEF \ |
| 207 | {"get_count", (PyCFunction)gc_get_count, METH_NOARGS, gc_get_count__doc__}, |
| 208 | |
| 209 | static PyObject * |
| 210 | gc_get_count_impl(PyObject *module); |
| 211 | |
| 212 | static PyObject * |
| 213 | gc_get_count(PyObject *module, PyObject *Py_UNUSED(ignored)) |
| 214 | { |
| 215 | return gc_get_count_impl(module); |
| 216 | } |
| 217 | |
| 218 | PyDoc_STRVAR(gc_get_objects__doc__, |
Pablo Galindo | 175421b | 2019-02-23 03:02:06 +0000 | [diff] [blame] | 219 | "get_objects($module, /, generation=None)\n" |
Serhiy Storchaka | 9326028 | 2017-02-04 11:19:59 +0200 | [diff] [blame] | 220 | "--\n" |
| 221 | "\n" |
Pablo Galindo | 175421b | 2019-02-23 03:02:06 +0000 | [diff] [blame] | 222 | "Return a list of objects tracked by the collector (excluding the list returned).\n" |
| 223 | "\n" |
| 224 | " generation\n" |
| 225 | " Generation to extract the objects from.\n" |
| 226 | "\n" |
| 227 | "If generation is not None, return only the objects tracked by the collector\n" |
| 228 | "that are in that generation."); |
Serhiy Storchaka | 9326028 | 2017-02-04 11:19:59 +0200 | [diff] [blame] | 229 | |
| 230 | #define GC_GET_OBJECTS_METHODDEF \ |
Pablo Galindo | 175421b | 2019-02-23 03:02:06 +0000 | [diff] [blame] | 231 | {"get_objects", (PyCFunction)(void(*)(void))gc_get_objects, METH_FASTCALL|METH_KEYWORDS, gc_get_objects__doc__}, |
Serhiy Storchaka | 9326028 | 2017-02-04 11:19:59 +0200 | [diff] [blame] | 232 | |
| 233 | static PyObject * |
Pablo Galindo | 175421b | 2019-02-23 03:02:06 +0000 | [diff] [blame] | 234 | gc_get_objects_impl(PyObject *module, Py_ssize_t generation); |
Serhiy Storchaka | 9326028 | 2017-02-04 11:19:59 +0200 | [diff] [blame] | 235 | |
| 236 | static PyObject * |
Pablo Galindo | 175421b | 2019-02-23 03:02:06 +0000 | [diff] [blame] | 237 | gc_get_objects(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 9326028 | 2017-02-04 11:19:59 +0200 | [diff] [blame] | 238 | { |
Pablo Galindo | 175421b | 2019-02-23 03:02:06 +0000 | [diff] [blame] | 239 | PyObject *return_value = NULL; |
| 240 | static const char * const _keywords[] = {"generation", NULL}; |
| 241 | static _PyArg_Parser _parser = {"|O&:get_objects", _keywords, 0}; |
| 242 | Py_ssize_t generation = -1; |
| 243 | |
| 244 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
| 245 | _Py_convert_optional_to_ssize_t, &generation)) { |
| 246 | goto exit; |
| 247 | } |
| 248 | return_value = gc_get_objects_impl(module, generation); |
| 249 | |
| 250 | exit: |
| 251 | return return_value; |
Serhiy Storchaka | 9326028 | 2017-02-04 11:19:59 +0200 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | PyDoc_STRVAR(gc_get_stats__doc__, |
| 255 | "get_stats($module, /)\n" |
| 256 | "--\n" |
| 257 | "\n" |
| 258 | "Return a list of dictionaries containing per-generation statistics."); |
| 259 | |
| 260 | #define GC_GET_STATS_METHODDEF \ |
| 261 | {"get_stats", (PyCFunction)gc_get_stats, METH_NOARGS, gc_get_stats__doc__}, |
| 262 | |
| 263 | static PyObject * |
| 264 | gc_get_stats_impl(PyObject *module); |
| 265 | |
| 266 | static PyObject * |
| 267 | gc_get_stats(PyObject *module, PyObject *Py_UNUSED(ignored)) |
| 268 | { |
| 269 | return gc_get_stats_impl(module); |
| 270 | } |
| 271 | |
| 272 | PyDoc_STRVAR(gc_is_tracked__doc__, |
| 273 | "is_tracked($module, obj, /)\n" |
| 274 | "--\n" |
| 275 | "\n" |
| 276 | "Returns true if the object is tracked by the garbage collector.\n" |
| 277 | "\n" |
| 278 | "Simple atomic objects will return false."); |
| 279 | |
| 280 | #define GC_IS_TRACKED_METHODDEF \ |
| 281 | {"is_tracked", (PyCFunction)gc_is_tracked, METH_O, gc_is_tracked__doc__}, |
brainfvck | c75edab | 2017-10-16 12:49:41 -0700 | [diff] [blame] | 282 | |
| 283 | PyDoc_STRVAR(gc_freeze__doc__, |
| 284 | "freeze($module, /)\n" |
| 285 | "--\n" |
| 286 | "\n" |
| 287 | "Freeze all current tracked objects and ignore them for future collections.\n" |
| 288 | "\n" |
| 289 | "This can be used before a POSIX fork() call to make the gc copy-on-write friendly.\n" |
| 290 | "Note: collection before a POSIX fork() call may free pages for future allocation\n" |
| 291 | "which can cause copy-on-write."); |
| 292 | |
| 293 | #define GC_FREEZE_METHODDEF \ |
| 294 | {"freeze", (PyCFunction)gc_freeze, METH_NOARGS, gc_freeze__doc__}, |
| 295 | |
| 296 | static PyObject * |
| 297 | gc_freeze_impl(PyObject *module); |
| 298 | |
| 299 | static PyObject * |
| 300 | gc_freeze(PyObject *module, PyObject *Py_UNUSED(ignored)) |
| 301 | { |
| 302 | return gc_freeze_impl(module); |
| 303 | } |
| 304 | |
| 305 | PyDoc_STRVAR(gc_unfreeze__doc__, |
| 306 | "unfreeze($module, /)\n" |
| 307 | "--\n" |
| 308 | "\n" |
| 309 | "Unfreeze all objects in the permanent generation.\n" |
| 310 | "\n" |
| 311 | "Put all objects in the permanent generation back into oldest generation."); |
| 312 | |
| 313 | #define GC_UNFREEZE_METHODDEF \ |
| 314 | {"unfreeze", (PyCFunction)gc_unfreeze, METH_NOARGS, gc_unfreeze__doc__}, |
| 315 | |
| 316 | static PyObject * |
| 317 | gc_unfreeze_impl(PyObject *module); |
| 318 | |
| 319 | static PyObject * |
| 320 | gc_unfreeze(PyObject *module, PyObject *Py_UNUSED(ignored)) |
| 321 | { |
| 322 | return gc_unfreeze_impl(module); |
| 323 | } |
| 324 | |
| 325 | PyDoc_STRVAR(gc_get_freeze_count__doc__, |
| 326 | "get_freeze_count($module, /)\n" |
| 327 | "--\n" |
| 328 | "\n" |
| 329 | "Return the number of objects in the permanent generation."); |
| 330 | |
| 331 | #define GC_GET_FREEZE_COUNT_METHODDEF \ |
| 332 | {"get_freeze_count", (PyCFunction)gc_get_freeze_count, METH_NOARGS, gc_get_freeze_count__doc__}, |
| 333 | |
Victor Stinner | 05d68a8 | 2018-01-18 11:15:25 +0100 | [diff] [blame] | 334 | static Py_ssize_t |
brainfvck | c75edab | 2017-10-16 12:49:41 -0700 | [diff] [blame] | 335 | gc_get_freeze_count_impl(PyObject *module); |
| 336 | |
| 337 | static PyObject * |
| 338 | gc_get_freeze_count(PyObject *module, PyObject *Py_UNUSED(ignored)) |
| 339 | { |
| 340 | PyObject *return_value = NULL; |
Victor Stinner | 05d68a8 | 2018-01-18 11:15:25 +0100 | [diff] [blame] | 341 | Py_ssize_t _return_value; |
brainfvck | c75edab | 2017-10-16 12:49:41 -0700 | [diff] [blame] | 342 | |
| 343 | _return_value = gc_get_freeze_count_impl(module); |
| 344 | if ((_return_value == -1) && PyErr_Occurred()) { |
| 345 | goto exit; |
| 346 | } |
Victor Stinner | 05d68a8 | 2018-01-18 11:15:25 +0100 | [diff] [blame] | 347 | return_value = PyLong_FromSsize_t(_return_value); |
brainfvck | c75edab | 2017-10-16 12:49:41 -0700 | [diff] [blame] | 348 | |
| 349 | exit: |
| 350 | return return_value; |
| 351 | } |
Pablo Galindo | 175421b | 2019-02-23 03:02:06 +0000 | [diff] [blame] | 352 | /*[clinic end generated code: output=d692bf475f0bb096 input=a9049054013a1b77]*/ |