blob: 771c57387bb8409a74b35c370ed6e31726cee815 [file] [log] [blame]
Serhiy Storchaka93260282017-02-04 11:19:59 +02001/*[clinic input]
2preserve
3[clinic start generated code]*/
4
5PyDoc_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
14static PyObject *
15gc_enable_impl(PyObject *module);
16
17static PyObject *
18gc_enable(PyObject *module, PyObject *Py_UNUSED(ignored))
19{
20 return gc_enable_impl(module);
21}
22
23PyDoc_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
32static PyObject *
33gc_disable_impl(PyObject *module);
34
35static PyObject *
36gc_disable(PyObject *module, PyObject *Py_UNUSED(ignored))
37{
38 return gc_disable_impl(module);
39}
40
41PyDoc_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
50static int
51gc_isenabled_impl(PyObject *module);
52
53static PyObject *
54gc_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
65exit:
66 return return_value;
67}
68
69PyDoc_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 Storchaka6969eaf2017-07-03 21:20:15 +030082 {"collect", (PyCFunction)gc_collect, METH_FASTCALL|METH_KEYWORDS, gc_collect__doc__},
Serhiy Storchaka93260282017-02-04 11:19:59 +020083
84static Py_ssize_t
85gc_collect_impl(PyObject *module, int generation);
86
87static PyObject *
88gc_collect(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
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
106exit:
107 return return_value;
108}
109
110PyDoc_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
130static PyObject *
131gc_set_debug_impl(PyObject *module, int flags);
132
133static PyObject *
134gc_set_debug(PyObject *module, PyObject *arg)
135{
136 PyObject *return_value = NULL;
137 int flags;
138
139 if (!PyArg_Parse(arg, "i:set_debug", &flags)) {
140 goto exit;
141 }
142 return_value = gc_set_debug_impl(module, flags);
143
144exit:
145 return return_value;
146}
147
148PyDoc_STRVAR(gc_get_debug__doc__,
149"get_debug($module, /)\n"
150"--\n"
151"\n"
152"Get the garbage collection debugging flags.");
153
154#define GC_GET_DEBUG_METHODDEF \
155 {"get_debug", (PyCFunction)gc_get_debug, METH_NOARGS, gc_get_debug__doc__},
156
157static int
158gc_get_debug_impl(PyObject *module);
159
160static PyObject *
161gc_get_debug(PyObject *module, PyObject *Py_UNUSED(ignored))
162{
163 PyObject *return_value = NULL;
164 int _return_value;
165
166 _return_value = gc_get_debug_impl(module);
167 if ((_return_value == -1) && PyErr_Occurred()) {
168 goto exit;
169 }
170 return_value = PyLong_FromLong((long)_return_value);
171
172exit:
173 return return_value;
174}
175
176PyDoc_STRVAR(gc_get_threshold__doc__,
177"get_threshold($module, /)\n"
178"--\n"
179"\n"
180"Return the current collection thresholds.");
181
182#define GC_GET_THRESHOLD_METHODDEF \
183 {"get_threshold", (PyCFunction)gc_get_threshold, METH_NOARGS, gc_get_threshold__doc__},
184
185static PyObject *
186gc_get_threshold_impl(PyObject *module);
187
188static PyObject *
189gc_get_threshold(PyObject *module, PyObject *Py_UNUSED(ignored))
190{
191 return gc_get_threshold_impl(module);
192}
193
194PyDoc_STRVAR(gc_get_count__doc__,
195"get_count($module, /)\n"
196"--\n"
197"\n"
198"Return a three-tuple of the current collection counts.");
199
200#define GC_GET_COUNT_METHODDEF \
201 {"get_count", (PyCFunction)gc_get_count, METH_NOARGS, gc_get_count__doc__},
202
203static PyObject *
204gc_get_count_impl(PyObject *module);
205
206static PyObject *
207gc_get_count(PyObject *module, PyObject *Py_UNUSED(ignored))
208{
209 return gc_get_count_impl(module);
210}
211
212PyDoc_STRVAR(gc_get_objects__doc__,
213"get_objects($module, /)\n"
214"--\n"
215"\n"
216"Return a list of objects tracked by the collector (excluding the list returned).");
217
218#define GC_GET_OBJECTS_METHODDEF \
219 {"get_objects", (PyCFunction)gc_get_objects, METH_NOARGS, gc_get_objects__doc__},
220
221static PyObject *
222gc_get_objects_impl(PyObject *module);
223
224static PyObject *
225gc_get_objects(PyObject *module, PyObject *Py_UNUSED(ignored))
226{
227 return gc_get_objects_impl(module);
228}
229
230PyDoc_STRVAR(gc_get_stats__doc__,
231"get_stats($module, /)\n"
232"--\n"
233"\n"
234"Return a list of dictionaries containing per-generation statistics.");
235
236#define GC_GET_STATS_METHODDEF \
237 {"get_stats", (PyCFunction)gc_get_stats, METH_NOARGS, gc_get_stats__doc__},
238
239static PyObject *
240gc_get_stats_impl(PyObject *module);
241
242static PyObject *
243gc_get_stats(PyObject *module, PyObject *Py_UNUSED(ignored))
244{
245 return gc_get_stats_impl(module);
246}
247
248PyDoc_STRVAR(gc_is_tracked__doc__,
249"is_tracked($module, obj, /)\n"
250"--\n"
251"\n"
252"Returns true if the object is tracked by the garbage collector.\n"
253"\n"
254"Simple atomic objects will return false.");
255
256#define GC_IS_TRACKED_METHODDEF \
257 {"is_tracked", (PyCFunction)gc_is_tracked, METH_O, gc_is_tracked__doc__},
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +0300258/*[clinic end generated code: output=5a58583f00ab018e input=a9049054013a1b77]*/