| 1 |
/*[clinic input] |
| 2 |
preserve |
| 3 |
[clinic start generated code]*/ |
| 4 |
|
| 5 |
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
| 6 |
# include "pycore_gc.h" // PyGC_Head |
| 7 |
# include "pycore_runtime.h" // _Py_ID() |
| 8 |
#endif |
| 9 |
#include "pycore_abstract.h" // _Py_convert_optional_to_ssize_t() |
| 10 |
#include "pycore_modsupport.h" // _PyArg_UnpackKeywords() |
| 11 |
#include "pycore_tuple.h" // _PyTuple_FromArray() |
| 12 |
|
| 13 |
PyDoc_STRVAR(gc_enable__doc__, |
| 14 |
"enable($module, /)\n" |
| 15 |
"--\n" |
| 16 |
"\n" |
| 17 |
"Enable automatic garbage collection."); |
| 18 |
|
| 19 |
#define GC_ENABLE_METHODDEF \ |
| 20 |
{"enable", (PyCFunction)gc_enable, METH_NOARGS, gc_enable__doc__}, |
| 21 |
|
| 22 |
static PyObject * |
| 23 |
gc_enable_impl(PyObject *module); |
| 24 |
|
| 25 |
static PyObject * |
| 26 |
gc_enable(PyObject *module, PyObject *Py_UNUSED(ignored)) |
| 27 |
{ |
| 28 |
return gc_enable_impl(module); |
| 29 |
} |
| 30 |
|
| 31 |
PyDoc_STRVAR(gc_disable__doc__, |
| 32 |
"disable($module, /)\n" |
| 33 |
"--\n" |
| 34 |
"\n" |
| 35 |
"Disable automatic garbage collection."); |
| 36 |
|
| 37 |
#define GC_DISABLE_METHODDEF \ |
| 38 |
{"disable", (PyCFunction)gc_disable, METH_NOARGS, gc_disable__doc__}, |
| 39 |
|
| 40 |
static PyObject * |
| 41 |
gc_disable_impl(PyObject *module); |
| 42 |
|
| 43 |
static PyObject * |
| 44 |
gc_disable(PyObject *module, PyObject *Py_UNUSED(ignored)) |
| 45 |
{ |
| 46 |
return gc_disable_impl(module); |
| 47 |
} |
| 48 |
|
| 49 |
PyDoc_STRVAR(gc_isenabled__doc__, |
| 50 |
"isenabled($module, /)\n" |
| 51 |
"--\n" |
| 52 |
"\n" |
| 53 |
"Returns true if automatic garbage collection is enabled."); |
| 54 |
|
| 55 |
#define GC_ISENABLED_METHODDEF \ |
| 56 |
{"isenabled", (PyCFunction)gc_isenabled, METH_NOARGS, gc_isenabled__doc__}, |
| 57 |
|
| 58 |
static int |
| 59 |
gc_isenabled_impl(PyObject *module); |
| 60 |
|
| 61 |
static PyObject * |
| 62 |
gc_isenabled(PyObject *module, PyObject *Py_UNUSED(ignored)) |
| 63 |
{ |
| 64 |
PyObject *return_value = NULL; |
| 65 |
int _return_value; |
| 66 |
|
| 67 |
_return_value = gc_isenabled_impl(module); |
| 68 |
if ((_return_value == -1) && PyErr_Occurred()) { |
| 69 |
goto exit; |
| 70 |
} |
| 71 |
return_value = PyBool_FromLong((long)_return_value); |
| 72 |
|
| 73 |
exit: |
| 74 |
return return_value; |
| 75 |
} |
| 76 |
|
| 77 |
PyDoc_STRVAR(gc_collect__doc__, |
| 78 |
"collect($module, /, generation=2)\n" |
| 79 |
"--\n" |
| 80 |
"\n" |
| 81 |
"Run the garbage collector.\n" |
| 82 |
"\n" |
| 83 |
"With no arguments, run a full collection. The optional argument\n" |
| 84 |
"may be an integer specifying which generation to collect. A ValueError\n" |
| 85 |
"is raised if the generation number is invalid.\n" |
| 86 |
"\n" |
| 87 |
"The number of unreachable objects is returned."); |
| 88 |
|
| 89 |
#define GC_COLLECT_METHODDEF \ |
| 90 |
{"collect", _PyCFunction_CAST(gc_collect), METH_FASTCALL|METH_KEYWORDS, gc_collect__doc__}, |
| 91 |
|
| 92 |
static Py_ssize_t |
| 93 |
gc_collect_impl(PyObject *module, int generation); |
| 94 |
|
| 95 |
static PyObject * |
| 96 |
gc_collect(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
| 97 |
{ |
| 98 |
PyObject *return_value = NULL; |
| 99 |
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
| 100 |
|
| 101 |
#define NUM_KEYWORDS 1 |
| 102 |
static struct { |
| 103 |
PyGC_Head _this_is_not_used; |
| 104 |
PyObject_VAR_HEAD |
| 105 |
Py_hash_t ob_hash; |
| 106 |
PyObject *ob_item[NUM_KEYWORDS]; |
| 107 |
} _kwtuple = { |
| 108 |
.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
| 109 |
.ob_hash = -1, |
| 110 |
.ob_item = { &_Py_ID(generation), }, |
| 111 |
}; |
| 112 |
#undef NUM_KEYWORDS |
| 113 |
#define KWTUPLE (&_kwtuple.ob_base.ob_base) |
| 114 |
|
| 115 |
#else // !Py_BUILD_CORE |
| 116 |
# define KWTUPLE NULL |
| 117 |
#endif // !Py_BUILD_CORE |
| 118 |
|
| 119 |
static const char * const _keywords[] = {"generation", NULL}; |
| 120 |
static _PyArg_Parser _parser = { |
| 121 |
.keywords = _keywords, |
| 122 |
.fname = "collect", |
| 123 |
.kwtuple = KWTUPLE, |
| 124 |
}; |
| 125 |
#undef KWTUPLE |
| 126 |
PyObject *argsbuf[1]; |
| 127 |
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; |
| 128 |
int generation = NUM_GENERATIONS - 1; |
| 129 |
Py_ssize_t _return_value; |
| 130 |
|
| 131 |
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
| 132 |
/*minpos*/ 0, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
| 133 |
if (!args) { |
| 134 |
goto exit; |
| 135 |
} |
| 136 |
if (!noptargs) { |
| 137 |
goto skip_optional_pos; |
| 138 |
} |
| 139 |
generation = PyLong_AsInt(args[0]); |
| 140 |
if (generation == -1 && PyErr_Occurred()) { |
| 141 |
goto exit; |
| 142 |
} |
| 143 |
skip_optional_pos: |
| 144 |
_return_value = gc_collect_impl(module, generation); |
| 145 |
if ((_return_value == -1) && PyErr_Occurred()) { |
| 146 |
goto exit; |
| 147 |
} |
| 148 |
return_value = PyLong_FromSsize_t(_return_value); |
| 149 |
|
| 150 |
exit: |
| 151 |
return return_value; |
| 152 |
} |
| 153 |
|
| 154 |
PyDoc_STRVAR(gc_set_debug__doc__, |
| 155 |
"set_debug($module, flags, /)\n" |
| 156 |
"--\n" |
| 157 |
"\n" |
| 158 |
"Set the garbage collection debugging flags.\n" |
| 159 |
"\n" |
| 160 |
" flags\n" |
| 161 |
" An integer that can have the following bits turned on:\n" |
| 162 |
" DEBUG_STATS - Print statistics during collection.\n" |
| 163 |
" DEBUG_COLLECTABLE - Print collectable objects found.\n" |
| 164 |
" DEBUG_UNCOLLECTABLE - Print unreachable but uncollectable objects\n" |
| 165 |
" found.\n" |
| 166 |
" DEBUG_SAVEALL - Save objects to gc.garbage rather than freeing them.\n" |
| 167 |
" DEBUG_LEAK - Debug leaking programs (everything but STATS).\n" |
| 168 |
"\n" |
| 169 |
"Debugging information is written to sys.stderr."); |
| 170 |
|
| 171 |
#define GC_SET_DEBUG_METHODDEF \ |
| 172 |
{"set_debug", (PyCFunction)gc_set_debug, METH_O, gc_set_debug__doc__}, |
| 173 |
|
| 174 |
static PyObject * |
| 175 |
gc_set_debug_impl(PyObject *module, int flags); |
| 176 |
|
| 177 |
static PyObject * |
| 178 |
gc_set_debug(PyObject *module, PyObject *arg) |
| 179 |
{ |
| 180 |
PyObject *return_value = NULL; |
| 181 |
int flags; |
| 182 |
|
| 183 |
flags = PyLong_AsInt(arg); |
| 184 |
if (flags == -1 && PyErr_Occurred()) { |
| 185 |
goto exit; |
| 186 |
} |
| 187 |
return_value = gc_set_debug_impl(module, flags); |
| 188 |
|
| 189 |
exit: |
| 190 |
return return_value; |
| 191 |
} |
| 192 |
|
| 193 |
PyDoc_STRVAR(gc_get_debug__doc__, |
| 194 |
"get_debug($module, /)\n" |
| 195 |
"--\n" |
| 196 |
"\n" |
| 197 |
"Get the garbage collection debugging flags."); |
| 198 |
|
| 199 |
#define GC_GET_DEBUG_METHODDEF \ |
| 200 |
{"get_debug", (PyCFunction)gc_get_debug, METH_NOARGS, gc_get_debug__doc__}, |
| 201 |
|
| 202 |
static int |
| 203 |
gc_get_debug_impl(PyObject *module); |
| 204 |
|
| 205 |
static PyObject * |
| 206 |
gc_get_debug(PyObject *module, PyObject *Py_UNUSED(ignored)) |
| 207 |
{ |
| 208 |
PyObject *return_value = NULL; |
| 209 |
int _return_value; |
| 210 |
|
| 211 |
_return_value = gc_get_debug_impl(module); |
| 212 |
if ((_return_value == -1) && PyErr_Occurred()) { |
| 213 |
goto exit; |
| 214 |
} |
| 215 |
return_value = PyLong_FromLong((long)_return_value); |
| 216 |
|
| 217 |
exit: |
| 218 |
return return_value; |
| 219 |
} |
| 220 |
|
| 221 |
PyDoc_STRVAR(gc_set_threshold__doc__, |
| 222 |
"set_threshold(threshold0, [threshold1, [threshold2]])\n" |
| 223 |
"Set the collection thresholds (the collection frequency).\n" |
| 224 |
"\n" |
| 225 |
"Setting \'threshold0\' to zero disables collection."); |
| 226 |
|
| 227 |
#define GC_SET_THRESHOLD_METHODDEF \ |
| 228 |
{"set_threshold", (PyCFunction)gc_set_threshold, METH_VARARGS, gc_set_threshold__doc__}, |
| 229 |
|
| 230 |
static PyObject * |
| 231 |
gc_set_threshold_impl(PyObject *module, int threshold0, int group_right_1, |
| 232 |
int threshold1, int group_right_2, int threshold2); |
| 233 |
|
| 234 |
static PyObject * |
| 235 |
gc_set_threshold(PyObject *module, PyObject *args) |
| 236 |
{ |
| 237 |
PyObject *return_value = NULL; |
| 238 |
int threshold0; |
| 239 |
int group_right_1 = 0; |
| 240 |
int threshold1 = 0; |
| 241 |
int group_right_2 = 0; |
| 242 |
int threshold2 = 0; |
| 243 |
|
| 244 |
switch (PyTuple_GET_SIZE(args)) { |
| 245 |
case 1: |
| 246 |
if (!PyArg_ParseTuple(args, "i:set_threshold", &threshold0)) { |
| 247 |
goto exit; |
| 248 |
} |
| 249 |
break; |
| 250 |
case 2: |
| 251 |
if (!PyArg_ParseTuple(args, "ii:set_threshold", &threshold0, &threshold1)) { |
| 252 |
goto exit; |
| 253 |
} |
| 254 |
group_right_1 = 1; |
| 255 |
break; |
| 256 |
case 3: |
| 257 |
if (!PyArg_ParseTuple(args, "iii:set_threshold", &threshold0, &threshold1, &threshold2)) { |
| 258 |
goto exit; |
| 259 |
} |
| 260 |
group_right_1 = 1; |
| 261 |
group_right_2 = 1; |
| 262 |
break; |
| 263 |
default: |
| 264 |
PyErr_SetString(PyExc_TypeError, "gc.set_threshold requires 1 to 3 arguments"); |
| 265 |
goto exit; |
| 266 |
} |
| 267 |
return_value = gc_set_threshold_impl(module, threshold0, group_right_1, threshold1, group_right_2, threshold2); |
| 268 |
|
| 269 |
exit: |
| 270 |
return return_value; |
| 271 |
} |
| 272 |
|
| 273 |
PyDoc_STRVAR(gc_get_threshold__doc__, |
| 274 |
"get_threshold($module, /)\n" |
| 275 |
"--\n" |
| 276 |
"\n" |
| 277 |
"Return the current collection thresholds."); |
| 278 |
|
| 279 |
#define GC_GET_THRESHOLD_METHODDEF \ |
| 280 |
{"get_threshold", (PyCFunction)gc_get_threshold, METH_NOARGS, gc_get_threshold__doc__}, |
| 281 |
|
| 282 |
static PyObject * |
| 283 |
gc_get_threshold_impl(PyObject *module); |
| 284 |
|
| 285 |
static PyObject * |
| 286 |
gc_get_threshold(PyObject *module, PyObject *Py_UNUSED(ignored)) |
| 287 |
{ |
| 288 |
return gc_get_threshold_impl(module); |
| 289 |
} |
| 290 |
|
| 291 |
PyDoc_STRVAR(gc_get_count__doc__, |
| 292 |
"get_count($module, /)\n" |
| 293 |
"--\n" |
| 294 |
"\n" |
| 295 |
"Return a three-tuple of the current collection counts."); |
| 296 |
|
| 297 |
#define GC_GET_COUNT_METHODDEF \ |
| 298 |
{"get_count", (PyCFunction)gc_get_count, METH_NOARGS, gc_get_count__doc__}, |
| 299 |
|
| 300 |
static PyObject * |
| 301 |
gc_get_count_impl(PyObject *module); |
| 302 |
|
| 303 |
static PyObject * |
| 304 |
gc_get_count(PyObject *module, PyObject *Py_UNUSED(ignored)) |
| 305 |
{ |
| 306 |
return gc_get_count_impl(module); |
| 307 |
} |
| 308 |
|
| 309 |
PyDoc_STRVAR(gc_get_referrers__doc__, |
| 310 |
"get_referrers($module, /, *objs)\n" |
| 311 |
"--\n" |
| 312 |
"\n" |
| 313 |
"Return the list of objects that directly refer to any of \'objs\'."); |
| 314 |
|
| 315 |
#define GC_GET_REFERRERS_METHODDEF \ |
| 316 |
{"get_referrers", _PyCFunction_CAST(gc_get_referrers), METH_FASTCALL, gc_get_referrers__doc__}, |
| 317 |
|
| 318 |
static PyObject * |
| 319 |
gc_get_referrers_impl(PyObject *module, PyObject *objs); |
| 320 |
|
| 321 |
static PyObject * |
| 322 |
gc_get_referrers(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
| 323 |
{ |
| 324 |
PyObject *return_value = NULL; |
| 325 |
PyObject *objs = NULL; |
| 326 |
|
| 327 |
objs = _PyTuple_FromArray(args, nargs); |
| 328 |
if (objs == NULL) { |
| 329 |
goto exit; |
| 330 |
} |
| 331 |
return_value = gc_get_referrers_impl(module, objs); |
| 332 |
|
| 333 |
exit: |
| 334 |
/* Cleanup for objs */ |
| 335 |
Py_XDECREF(objs); |
| 336 |
|
| 337 |
return return_value; |
| 338 |
} |
| 339 |
|
| 340 |
PyDoc_STRVAR(gc_get_referents__doc__, |
| 341 |
"get_referents($module, /, *objs)\n" |
| 342 |
"--\n" |
| 343 |
"\n" |
| 344 |
"Return the list of objects that are directly referred to by \'objs\'."); |
| 345 |
|
| 346 |
#define GC_GET_REFERENTS_METHODDEF \ |
| 347 |
{"get_referents", _PyCFunction_CAST(gc_get_referents), METH_FASTCALL, gc_get_referents__doc__}, |
| 348 |
|
| 349 |
static PyObject * |
| 350 |
gc_get_referents_impl(PyObject *module, PyObject *objs); |
| 351 |
|
| 352 |
static PyObject * |
| 353 |
gc_get_referents(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
| 354 |
{ |
| 355 |
PyObject *return_value = NULL; |
| 356 |
PyObject *objs = NULL; |
| 357 |
|
| 358 |
objs = _PyTuple_FromArray(args, nargs); |
| 359 |
if (objs == NULL) { |
| 360 |
goto exit; |
| 361 |
} |
| 362 |
return_value = gc_get_referents_impl(module, objs); |
| 363 |
|
| 364 |
exit: |
| 365 |
/* Cleanup for objs */ |
| 366 |
Py_XDECREF(objs); |
| 367 |
|
| 368 |
return return_value; |
| 369 |
} |
| 370 |
|
| 371 |
PyDoc_STRVAR(gc_get_objects__doc__, |
| 372 |
"get_objects($module, /, generation=None)\n" |
| 373 |
"--\n" |
| 374 |
"\n" |
| 375 |
"Return a list of objects tracked by the collector (excluding the list returned).\n" |
| 376 |
"\n" |
| 377 |
" generation\n" |
| 378 |
" Generation to extract the objects from.\n" |
| 379 |
"\n" |
| 380 |
"If generation is not None, return only the objects tracked by the collector\n" |
| 381 |
"that are in that generation."); |
| 382 |
|
| 383 |
#define GC_GET_OBJECTS_METHODDEF \ |
| 384 |
{"get_objects", _PyCFunction_CAST(gc_get_objects), METH_FASTCALL|METH_KEYWORDS, gc_get_objects__doc__}, |
| 385 |
|
| 386 |
static PyObject * |
| 387 |
gc_get_objects_impl(PyObject *module, Py_ssize_t generation); |
| 388 |
|
| 389 |
static PyObject * |
| 390 |
gc_get_objects(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
| 391 |
{ |
| 392 |
PyObject *return_value = NULL; |
| 393 |
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
| 394 |
|
| 395 |
#define NUM_KEYWORDS 1 |
| 396 |
static struct { |
| 397 |
PyGC_Head _this_is_not_used; |
| 398 |
PyObject_VAR_HEAD |
| 399 |
Py_hash_t ob_hash; |
| 400 |
PyObject *ob_item[NUM_KEYWORDS]; |
| 401 |
} _kwtuple = { |
| 402 |
.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
| 403 |
.ob_hash = -1, |
| 404 |
.ob_item = { &_Py_ID(generation), }, |
| 405 |
}; |
| 406 |
#undef NUM_KEYWORDS |
| 407 |
#define KWTUPLE (&_kwtuple.ob_base.ob_base) |
| 408 |
|
| 409 |
#else // !Py_BUILD_CORE |
| 410 |
# define KWTUPLE NULL |
| 411 |
#endif // !Py_BUILD_CORE |
| 412 |
|
| 413 |
static const char * const _keywords[] = {"generation", NULL}; |
| 414 |
static _PyArg_Parser _parser = { |
| 415 |
.keywords = _keywords, |
| 416 |
.fname = "get_objects", |
| 417 |
.kwtuple = KWTUPLE, |
| 418 |
}; |
| 419 |
#undef KWTUPLE |
| 420 |
PyObject *argsbuf[1]; |
| 421 |
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; |
| 422 |
Py_ssize_t generation = -1; |
| 423 |
|
| 424 |
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
| 425 |
/*minpos*/ 0, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
| 426 |
if (!args) { |
| 427 |
goto exit; |
| 428 |
} |
| 429 |
if (!noptargs) { |
| 430 |
goto skip_optional_pos; |
| 431 |
} |
| 432 |
if (!_Py_convert_optional_to_ssize_t(args[0], &generation)) { |
| 433 |
goto exit; |
| 434 |
} |
| 435 |
skip_optional_pos: |
| 436 |
return_value = gc_get_objects_impl(module, generation); |
| 437 |
|
| 438 |
exit: |
| 439 |
return return_value; |
| 440 |
} |
| 441 |
|
| 442 |
PyDoc_STRVAR(gc_get_stats__doc__, |
| 443 |
"get_stats($module, /)\n" |
| 444 |
"--\n" |
| 445 |
"\n" |
| 446 |
"Return a list of dictionaries containing per-generation statistics."); |
| 447 |
|
| 448 |
#define GC_GET_STATS_METHODDEF \ |
| 449 |
{"get_stats", (PyCFunction)gc_get_stats, METH_NOARGS, gc_get_stats__doc__}, |
| 450 |
|
| 451 |
static PyObject * |
| 452 |
gc_get_stats_impl(PyObject *module); |
| 453 |
|
| 454 |
static PyObject * |
| 455 |
gc_get_stats(PyObject *module, PyObject *Py_UNUSED(ignored)) |
| 456 |
{ |
| 457 |
return gc_get_stats_impl(module); |
| 458 |
} |
| 459 |
|
| 460 |
PyDoc_STRVAR(gc_is_tracked__doc__, |
| 461 |
"is_tracked($module, obj, /)\n" |
| 462 |
"--\n" |
| 463 |
"\n" |
| 464 |
"Returns true if the object is tracked by the garbage collector.\n" |
| 465 |
"\n" |
| 466 |
"Simple atomic objects will return false."); |
| 467 |
|
| 468 |
#define GC_IS_TRACKED_METHODDEF \ |
| 469 |
{"is_tracked", (PyCFunction)gc_is_tracked, METH_O, gc_is_tracked__doc__}, |
| 470 |
|
| 471 |
static int |
| 472 |
gc_is_tracked_impl(PyObject *module, PyObject *obj); |
| 473 |
|
| 474 |
static PyObject * |
| 475 |
gc_is_tracked(PyObject *module, PyObject *obj) |
| 476 |
{ |
| 477 |
PyObject *return_value = NULL; |
| 478 |
int _return_value; |
| 479 |
|
| 480 |
_return_value = gc_is_tracked_impl(module, obj); |
| 481 |
if ((_return_value == -1) && PyErr_Occurred()) { |
| 482 |
goto exit; |
| 483 |
} |
| 484 |
return_value = PyBool_FromLong((long)_return_value); |
| 485 |
|
| 486 |
exit: |
| 487 |
return return_value; |
| 488 |
} |
| 489 |
|
| 490 |
PyDoc_STRVAR(gc_is_finalized__doc__, |
| 491 |
"is_finalized($module, obj, /)\n" |
| 492 |
"--\n" |
| 493 |
"\n" |
| 494 |
"Returns true if the object has been already finalized by the GC."); |
| 495 |
|
| 496 |
#define GC_IS_FINALIZED_METHODDEF \ |
| 497 |
{"is_finalized", (PyCFunction)gc_is_finalized, METH_O, gc_is_finalized__doc__}, |
| 498 |
|
| 499 |
static int |
| 500 |
gc_is_finalized_impl(PyObject *module, PyObject *obj); |
| 501 |
|
| 502 |
static PyObject * |
| 503 |
gc_is_finalized(PyObject *module, PyObject *obj) |
| 504 |
{ |
| 505 |
PyObject *return_value = NULL; |
| 506 |
int _return_value; |
| 507 |
|
| 508 |
_return_value = gc_is_finalized_impl(module, obj); |
| 509 |
if ((_return_value == -1) && PyErr_Occurred()) { |
| 510 |
goto exit; |
| 511 |
} |
| 512 |
return_value = PyBool_FromLong((long)_return_value); |
| 513 |
|
| 514 |
exit: |
| 515 |
return return_value; |
| 516 |
} |
| 517 |
|
| 518 |
PyDoc_STRVAR(gc_freeze__doc__, |
| 519 |
"freeze($module, /)\n" |
| 520 |
"--\n" |
| 521 |
"\n" |
| 522 |
"Freeze all current tracked objects and ignore them for future collections.\n" |
| 523 |
"\n" |
| 524 |
"This can be used before a POSIX fork() call to make the gc copy-on-write friendly.\n" |
| 525 |
"Note: collection before a POSIX fork() call may free pages for future allocation\n" |
| 526 |
"which can cause copy-on-write."); |
| 527 |
|
| 528 |
#define GC_FREEZE_METHODDEF \ |
| 529 |
{"freeze", (PyCFunction)gc_freeze, METH_NOARGS, gc_freeze__doc__}, |
| 530 |
|
| 531 |
static PyObject * |
| 532 |
gc_freeze_impl(PyObject *module); |
| 533 |
|
| 534 |
static PyObject * |
| 535 |
gc_freeze(PyObject *module, PyObject *Py_UNUSED(ignored)) |
| 536 |
{ |
| 537 |
return gc_freeze_impl(module); |
| 538 |
} |
| 539 |
|
| 540 |
PyDoc_STRVAR(gc_unfreeze__doc__, |
| 541 |
"unfreeze($module, /)\n" |
| 542 |
"--\n" |
| 543 |
"\n" |
| 544 |
"Unfreeze all objects in the permanent generation.\n" |
| 545 |
"\n" |
| 546 |
"Put all objects in the permanent generation back into oldest generation."); |
| 547 |
|
| 548 |
#define GC_UNFREEZE_METHODDEF \ |
| 549 |
{"unfreeze", (PyCFunction)gc_unfreeze, METH_NOARGS, gc_unfreeze__doc__}, |
| 550 |
|
| 551 |
static PyObject * |
| 552 |
gc_unfreeze_impl(PyObject *module); |
| 553 |
|
| 554 |
static PyObject * |
| 555 |
gc_unfreeze(PyObject *module, PyObject *Py_UNUSED(ignored)) |
| 556 |
{ |
| 557 |
return gc_unfreeze_impl(module); |
| 558 |
} |
| 559 |
|
| 560 |
PyDoc_STRVAR(gc_get_freeze_count__doc__, |
| 561 |
"get_freeze_count($module, /)\n" |
| 562 |
"--\n" |
| 563 |
"\n" |
| 564 |
"Return the number of objects in the permanent generation."); |
| 565 |
|
| 566 |
#define GC_GET_FREEZE_COUNT_METHODDEF \ |
| 567 |
{"get_freeze_count", (PyCFunction)gc_get_freeze_count, METH_NOARGS, gc_get_freeze_count__doc__}, |
| 568 |
|
| 569 |
static Py_ssize_t |
| 570 |
gc_get_freeze_count_impl(PyObject *module); |
| 571 |
|
| 572 |
static PyObject * |
| 573 |
gc_get_freeze_count(PyObject *module, PyObject *Py_UNUSED(ignored)) |
| 574 |
{ |
| 575 |
PyObject *return_value = NULL; |
| 576 |
Py_ssize_t _return_value; |
| 577 |
|
| 578 |
_return_value = gc_get_freeze_count_impl(module); |
| 579 |
if ((_return_value == -1) && PyErr_Occurred()) { |
| 580 |
goto exit; |
| 581 |
} |
| 582 |
return_value = PyLong_FromSsize_t(_return_value); |
| 583 |
|
| 584 |
exit: |
| 585 |
return return_value; |
| 586 |
} |
| 587 |
/*[clinic end generated code: output=96d057eac558e6ca input=a9049054013a1b77]*/ |