blob: 4615ebaab5de2b5e7f6bc7569376ee860d051bce [file] [log] [blame]
Nathaniel J. Smithfc2f4072018-01-21 06:44:07 -08001/*[clinic input]
2preserve
3[clinic start generated code]*/
4
Steve Dowerb82e17e2019-05-23 08:45:22 -07005PyDoc_STRVAR(sys_addaudithook__doc__,
6"addaudithook($module, /, hook)\n"
7"--\n"
8"\n"
9"Adds a new audit hook callback.");
10
11#define SYS_ADDAUDITHOOK_METHODDEF \
12 {"addaudithook", (PyCFunction)(void(*)(void))sys_addaudithook, METH_FASTCALL|METH_KEYWORDS, sys_addaudithook__doc__},
13
14static PyObject *
15sys_addaudithook_impl(PyObject *module, PyObject *hook);
16
17static PyObject *
18sys_addaudithook(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
19{
20 PyObject *return_value = NULL;
21 static const char * const _keywords[] = {"hook", NULL};
22 static _PyArg_Parser _parser = {NULL, _keywords, "addaudithook", 0};
23 PyObject *argsbuf[1];
24 PyObject *hook;
25
26 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
27 if (!args) {
28 goto exit;
29 }
30 hook = args[0];
31 return_value = sys_addaudithook_impl(module, hook);
32
33exit:
34 return return_value;
35}
36
Tal Einatede0b6f2018-12-31 17:12:08 +020037PyDoc_STRVAR(sys_displayhook__doc__,
38"displayhook($module, object, /)\n"
39"--\n"
40"\n"
41"Print an object to sys.stdout and also save it in builtins._");
42
43#define SYS_DISPLAYHOOK_METHODDEF \
44 {"displayhook", (PyCFunction)sys_displayhook, METH_O, sys_displayhook__doc__},
45
46PyDoc_STRVAR(sys_excepthook__doc__,
47"excepthook($module, exctype, value, traceback, /)\n"
48"--\n"
49"\n"
50"Handle an exception by displaying it with a traceback on sys.stderr.");
51
52#define SYS_EXCEPTHOOK_METHODDEF \
53 {"excepthook", (PyCFunction)(void(*)(void))sys_excepthook, METH_FASTCALL, sys_excepthook__doc__},
54
55static PyObject *
56sys_excepthook_impl(PyObject *module, PyObject *exctype, PyObject *value,
57 PyObject *traceback);
58
59static PyObject *
60sys_excepthook(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
61{
62 PyObject *return_value = NULL;
63 PyObject *exctype;
64 PyObject *value;
65 PyObject *traceback;
66
Serhiy Storchaka2a39d252019-01-11 18:01:42 +020067 if (!_PyArg_CheckPositional("excepthook", nargs, 3, 3)) {
Tal Einatede0b6f2018-12-31 17:12:08 +020068 goto exit;
69 }
Serhiy Storchaka2a39d252019-01-11 18:01:42 +020070 exctype = args[0];
71 value = args[1];
72 traceback = args[2];
Tal Einatede0b6f2018-12-31 17:12:08 +020073 return_value = sys_excepthook_impl(module, exctype, value, traceback);
74
75exit:
76 return return_value;
77}
78
79PyDoc_STRVAR(sys_exc_info__doc__,
80"exc_info($module, /)\n"
81"--\n"
82"\n"
83"Return current exception information: (type, value, traceback).\n"
84"\n"
85"Return information about the most recent exception caught by an except\n"
86"clause in the current stack frame or in an older stack frame.");
87
88#define SYS_EXC_INFO_METHODDEF \
89 {"exc_info", (PyCFunction)sys_exc_info, METH_NOARGS, sys_exc_info__doc__},
90
91static PyObject *
92sys_exc_info_impl(PyObject *module);
93
94static PyObject *
95sys_exc_info(PyObject *module, PyObject *Py_UNUSED(ignored))
96{
97 return sys_exc_info_impl(module);
98}
99
Victor Stinneref9d9b62019-05-22 11:28:22 +0200100PyDoc_STRVAR(sys_unraisablehook__doc__,
101"unraisablehook($module, unraisable, /)\n"
102"--\n"
103"\n"
104"Handle an unraisable exception.\n"
105"\n"
106"The unraisable argument has the following attributes:\n"
107"\n"
108"* exc_type: Exception type.\n"
Victor Stinner71c52e32019-05-27 08:57:14 +0200109"* exc_value: Exception value, can be None.\n"
110"* exc_traceback: Exception traceback, can be None.\n"
111"* err_msg: Error message, can be None.\n"
112"* object: Object causing the exception, can be None.");
Victor Stinneref9d9b62019-05-22 11:28:22 +0200113
114#define SYS_UNRAISABLEHOOK_METHODDEF \
115 {"unraisablehook", (PyCFunction)sys_unraisablehook, METH_O, sys_unraisablehook__doc__},
116
Tal Einatede0b6f2018-12-31 17:12:08 +0200117PyDoc_STRVAR(sys_exit__doc__,
118"exit($module, status=None, /)\n"
119"--\n"
120"\n"
121"Exit the interpreter by raising SystemExit(status).\n"
122"\n"
123"If the status is omitted or None, it defaults to zero (i.e., success).\n"
124"If the status is an integer, it will be used as the system exit status.\n"
125"If it is another kind of object, it will be printed and the system\n"
126"exit status will be one (i.e., failure).");
127
128#define SYS_EXIT_METHODDEF \
129 {"exit", (PyCFunction)(void(*)(void))sys_exit, METH_FASTCALL, sys_exit__doc__},
130
131static PyObject *
132sys_exit_impl(PyObject *module, PyObject *status);
133
134static PyObject *
135sys_exit(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
136{
137 PyObject *return_value = NULL;
Serhiy Storchaka279f4462019-09-14 12:24:05 +0300138 PyObject *status = Py_None;
Tal Einatede0b6f2018-12-31 17:12:08 +0200139
Serhiy Storchaka2a39d252019-01-11 18:01:42 +0200140 if (!_PyArg_CheckPositional("exit", nargs, 0, 1)) {
Tal Einatede0b6f2018-12-31 17:12:08 +0200141 goto exit;
142 }
Serhiy Storchaka2a39d252019-01-11 18:01:42 +0200143 if (nargs < 1) {
144 goto skip_optional;
145 }
146 status = args[0];
147skip_optional:
Tal Einatede0b6f2018-12-31 17:12:08 +0200148 return_value = sys_exit_impl(module, status);
149
150exit:
151 return return_value;
152}
153
154PyDoc_STRVAR(sys_getdefaultencoding__doc__,
155"getdefaultencoding($module, /)\n"
156"--\n"
157"\n"
158"Return the current default encoding used by the Unicode implementation.");
159
160#define SYS_GETDEFAULTENCODING_METHODDEF \
161 {"getdefaultencoding", (PyCFunction)sys_getdefaultencoding, METH_NOARGS, sys_getdefaultencoding__doc__},
162
163static PyObject *
164sys_getdefaultencoding_impl(PyObject *module);
165
166static PyObject *
167sys_getdefaultencoding(PyObject *module, PyObject *Py_UNUSED(ignored))
168{
169 return sys_getdefaultencoding_impl(module);
170}
171
172PyDoc_STRVAR(sys_getfilesystemencoding__doc__,
173"getfilesystemencoding($module, /)\n"
174"--\n"
175"\n"
176"Return the encoding used to convert Unicode filenames to OS filenames.");
177
178#define SYS_GETFILESYSTEMENCODING_METHODDEF \
179 {"getfilesystemencoding", (PyCFunction)sys_getfilesystemencoding, METH_NOARGS, sys_getfilesystemencoding__doc__},
180
181static PyObject *
182sys_getfilesystemencoding_impl(PyObject *module);
183
184static PyObject *
185sys_getfilesystemencoding(PyObject *module, PyObject *Py_UNUSED(ignored))
186{
187 return sys_getfilesystemencoding_impl(module);
188}
189
190PyDoc_STRVAR(sys_getfilesystemencodeerrors__doc__,
191"getfilesystemencodeerrors($module, /)\n"
192"--\n"
193"\n"
194"Return the error mode used Unicode to OS filename conversion.");
195
196#define SYS_GETFILESYSTEMENCODEERRORS_METHODDEF \
197 {"getfilesystemencodeerrors", (PyCFunction)sys_getfilesystemencodeerrors, METH_NOARGS, sys_getfilesystemencodeerrors__doc__},
198
199static PyObject *
200sys_getfilesystemencodeerrors_impl(PyObject *module);
201
202static PyObject *
203sys_getfilesystemencodeerrors(PyObject *module, PyObject *Py_UNUSED(ignored))
204{
205 return sys_getfilesystemencodeerrors_impl(module);
206}
207
208PyDoc_STRVAR(sys_intern__doc__,
209"intern($module, string, /)\n"
210"--\n"
211"\n"
212"``Intern\'\' the given string.\n"
213"\n"
214"This enters the string in the (global) table of interned strings whose\n"
215"purpose is to speed up dictionary lookups. Return the string itself or\n"
216"the previously interned string object with the same value.");
217
218#define SYS_INTERN_METHODDEF \
219 {"intern", (PyCFunction)sys_intern, METH_O, sys_intern__doc__},
220
221static PyObject *
222sys_intern_impl(PyObject *module, PyObject *s);
223
224static PyObject *
225sys_intern(PyObject *module, PyObject *arg)
226{
227 PyObject *return_value = NULL;
228 PyObject *s;
229
230 if (!PyUnicode_Check(arg)) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +0200231 _PyArg_BadArgument("intern", "argument", "str", arg);
Tal Einatede0b6f2018-12-31 17:12:08 +0200232 goto exit;
233 }
234 if (PyUnicode_READY(arg) == -1) {
235 goto exit;
236 }
237 s = arg;
238 return_value = sys_intern_impl(module, s);
239
240exit:
241 return return_value;
242}
243
244PyDoc_STRVAR(sys_gettrace__doc__,
245"gettrace($module, /)\n"
246"--\n"
247"\n"
248"Return the global debug tracing function set with sys.settrace.\n"
249"\n"
250"See the debugger chapter in the library manual.");
251
252#define SYS_GETTRACE_METHODDEF \
253 {"gettrace", (PyCFunction)sys_gettrace, METH_NOARGS, sys_gettrace__doc__},
254
255static PyObject *
256sys_gettrace_impl(PyObject *module);
257
258static PyObject *
259sys_gettrace(PyObject *module, PyObject *Py_UNUSED(ignored))
260{
261 return sys_gettrace_impl(module);
262}
263
264PyDoc_STRVAR(sys_getprofile__doc__,
265"getprofile($module, /)\n"
266"--\n"
267"\n"
268"Return the profiling function set with sys.setprofile.\n"
269"\n"
270"See the profiler chapter in the library manual.");
271
272#define SYS_GETPROFILE_METHODDEF \
273 {"getprofile", (PyCFunction)sys_getprofile, METH_NOARGS, sys_getprofile__doc__},
274
275static PyObject *
276sys_getprofile_impl(PyObject *module);
277
278static PyObject *
279sys_getprofile(PyObject *module, PyObject *Py_UNUSED(ignored))
280{
281 return sys_getprofile_impl(module);
282}
283
Tal Einatede0b6f2018-12-31 17:12:08 +0200284PyDoc_STRVAR(sys_setswitchinterval__doc__,
285"setswitchinterval($module, interval, /)\n"
286"--\n"
287"\n"
288"Set the ideal thread switching delay inside the Python interpreter.\n"
289"\n"
290"The actual frequency of switching threads can be lower if the\n"
291"interpreter executes long sequences of uninterruptible code\n"
292"(this is implementation-specific and workload-dependent).\n"
293"\n"
294"The parameter must represent the desired switching delay in seconds\n"
295"A typical value is 0.005 (5 milliseconds).");
296
297#define SYS_SETSWITCHINTERVAL_METHODDEF \
298 {"setswitchinterval", (PyCFunction)sys_setswitchinterval, METH_O, sys_setswitchinterval__doc__},
299
300static PyObject *
301sys_setswitchinterval_impl(PyObject *module, double interval);
302
303static PyObject *
304sys_setswitchinterval(PyObject *module, PyObject *arg)
305{
306 PyObject *return_value = NULL;
307 double interval;
308
Raymond Hettingeraef9ad82019-08-24 19:10:39 -0700309 if (PyFloat_CheckExact(arg)) {
310 interval = PyFloat_AS_DOUBLE(arg);
311 }
312 else
313 {
314 interval = PyFloat_AsDouble(arg);
315 if (interval == -1.0 && PyErr_Occurred()) {
316 goto exit;
317 }
Tal Einatede0b6f2018-12-31 17:12:08 +0200318 }
319 return_value = sys_setswitchinterval_impl(module, interval);
320
321exit:
322 return return_value;
323}
324
325PyDoc_STRVAR(sys_getswitchinterval__doc__,
326"getswitchinterval($module, /)\n"
327"--\n"
328"\n"
329"Return the current thread switch interval; see sys.setswitchinterval().");
330
331#define SYS_GETSWITCHINTERVAL_METHODDEF \
332 {"getswitchinterval", (PyCFunction)sys_getswitchinterval, METH_NOARGS, sys_getswitchinterval__doc__},
333
334static double
335sys_getswitchinterval_impl(PyObject *module);
336
337static PyObject *
338sys_getswitchinterval(PyObject *module, PyObject *Py_UNUSED(ignored))
339{
340 PyObject *return_value = NULL;
341 double _return_value;
342
343 _return_value = sys_getswitchinterval_impl(module);
344 if ((_return_value == -1.0) && PyErr_Occurred()) {
345 goto exit;
346 }
347 return_value = PyFloat_FromDouble(_return_value);
348
349exit:
350 return return_value;
351}
352
353PyDoc_STRVAR(sys_setrecursionlimit__doc__,
354"setrecursionlimit($module, limit, /)\n"
355"--\n"
356"\n"
357"Set the maximum depth of the Python interpreter stack to n.\n"
358"\n"
359"This limit prevents infinite recursion from causing an overflow of the C\n"
360"stack and crashing Python. The highest possible limit is platform-\n"
361"dependent.");
362
363#define SYS_SETRECURSIONLIMIT_METHODDEF \
364 {"setrecursionlimit", (PyCFunction)sys_setrecursionlimit, METH_O, sys_setrecursionlimit__doc__},
365
366static PyObject *
367sys_setrecursionlimit_impl(PyObject *module, int new_limit);
368
369static PyObject *
370sys_setrecursionlimit(PyObject *module, PyObject *arg)
371{
372 PyObject *return_value = NULL;
373 int new_limit;
374
375 if (PyFloat_Check(arg)) {
376 PyErr_SetString(PyExc_TypeError,
377 "integer argument expected, got float" );
378 goto exit;
379 }
380 new_limit = _PyLong_AsInt(arg);
381 if (new_limit == -1 && PyErr_Occurred()) {
382 goto exit;
383 }
384 return_value = sys_setrecursionlimit_impl(module, new_limit);
385
386exit:
387 return return_value;
388}
389
Nathaniel J. Smithfc2f4072018-01-21 06:44:07 -0800390PyDoc_STRVAR(sys_set_coroutine_origin_tracking_depth__doc__,
391"set_coroutine_origin_tracking_depth($module, /, depth)\n"
392"--\n"
393"\n"
394"Enable or disable origin tracking for coroutine objects in this thread.\n"
395"\n"
Tal Einatede0b6f2018-12-31 17:12:08 +0200396"Coroutine objects will track \'depth\' frames of traceback information\n"
397"about where they came from, available in their cr_origin attribute.\n"
398"\n"
399"Set a depth of 0 to disable.");
Nathaniel J. Smithfc2f4072018-01-21 06:44:07 -0800400
401#define SYS_SET_COROUTINE_ORIGIN_TRACKING_DEPTH_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200402 {"set_coroutine_origin_tracking_depth", (PyCFunction)(void(*)(void))sys_set_coroutine_origin_tracking_depth, METH_FASTCALL|METH_KEYWORDS, sys_set_coroutine_origin_tracking_depth__doc__},
Nathaniel J. Smithfc2f4072018-01-21 06:44:07 -0800403
404static PyObject *
405sys_set_coroutine_origin_tracking_depth_impl(PyObject *module, int depth);
406
407static PyObject *
408sys_set_coroutine_origin_tracking_depth(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
409{
410 PyObject *return_value = NULL;
411 static const char * const _keywords[] = {"depth", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +0200412 static _PyArg_Parser _parser = {NULL, _keywords, "set_coroutine_origin_tracking_depth", 0};
413 PyObject *argsbuf[1];
Nathaniel J. Smithfc2f4072018-01-21 06:44:07 -0800414 int depth;
415
Serhiy Storchaka31913912019-03-14 10:32:22 +0200416 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
417 if (!args) {
418 goto exit;
419 }
420 if (PyFloat_Check(args[0])) {
421 PyErr_SetString(PyExc_TypeError,
422 "integer argument expected, got float" );
423 goto exit;
424 }
425 depth = _PyLong_AsInt(args[0]);
426 if (depth == -1 && PyErr_Occurred()) {
Nathaniel J. Smithfc2f4072018-01-21 06:44:07 -0800427 goto exit;
428 }
429 return_value = sys_set_coroutine_origin_tracking_depth_impl(module, depth);
430
431exit:
432 return return_value;
433}
434
435PyDoc_STRVAR(sys_get_coroutine_origin_tracking_depth__doc__,
436"get_coroutine_origin_tracking_depth($module, /)\n"
437"--\n"
438"\n"
439"Check status of origin tracking for coroutine objects in this thread.");
440
441#define SYS_GET_COROUTINE_ORIGIN_TRACKING_DEPTH_METHODDEF \
442 {"get_coroutine_origin_tracking_depth", (PyCFunction)sys_get_coroutine_origin_tracking_depth, METH_NOARGS, sys_get_coroutine_origin_tracking_depth__doc__},
443
444static int
445sys_get_coroutine_origin_tracking_depth_impl(PyObject *module);
446
447static PyObject *
448sys_get_coroutine_origin_tracking_depth(PyObject *module, PyObject *Py_UNUSED(ignored))
449{
450 PyObject *return_value = NULL;
451 int _return_value;
452
453 _return_value = sys_get_coroutine_origin_tracking_depth_impl(module);
454 if ((_return_value == -1) && PyErr_Occurred()) {
455 goto exit;
456 }
457 return_value = PyLong_FromLong((long)_return_value);
458
459exit:
460 return return_value;
461}
Tal Einatede0b6f2018-12-31 17:12:08 +0200462
Tal Einatede0b6f2018-12-31 17:12:08 +0200463PyDoc_STRVAR(sys_get_asyncgen_hooks__doc__,
464"get_asyncgen_hooks($module, /)\n"
465"--\n"
466"\n"
467"Return the installed asynchronous generators hooks.\n"
468"\n"
469"This returns a namedtuple of the form (firstiter, finalizer).");
470
471#define SYS_GET_ASYNCGEN_HOOKS_METHODDEF \
472 {"get_asyncgen_hooks", (PyCFunction)sys_get_asyncgen_hooks, METH_NOARGS, sys_get_asyncgen_hooks__doc__},
473
474static PyObject *
475sys_get_asyncgen_hooks_impl(PyObject *module);
476
477static PyObject *
478sys_get_asyncgen_hooks(PyObject *module, PyObject *Py_UNUSED(ignored))
479{
480 return sys_get_asyncgen_hooks_impl(module);
481}
482
483PyDoc_STRVAR(sys_getrecursionlimit__doc__,
484"getrecursionlimit($module, /)\n"
485"--\n"
486"\n"
487"Return the current value of the recursion limit.\n"
488"\n"
489"The recursion limit is the maximum depth of the Python interpreter\n"
490"stack. This limit prevents infinite recursion from causing an overflow\n"
491"of the C stack and crashing Python.");
492
493#define SYS_GETRECURSIONLIMIT_METHODDEF \
494 {"getrecursionlimit", (PyCFunction)sys_getrecursionlimit, METH_NOARGS, sys_getrecursionlimit__doc__},
495
496static PyObject *
497sys_getrecursionlimit_impl(PyObject *module);
498
499static PyObject *
500sys_getrecursionlimit(PyObject *module, PyObject *Py_UNUSED(ignored))
501{
502 return sys_getrecursionlimit_impl(module);
503}
504
505#if defined(MS_WINDOWS)
506
507PyDoc_STRVAR(sys_getwindowsversion__doc__,
508"getwindowsversion($module, /)\n"
509"--\n"
510"\n"
511"Return info about the running version of Windows as a named tuple.\n"
512"\n"
513"The members are named: major, minor, build, platform, service_pack,\n"
514"service_pack_major, service_pack_minor, suite_mask, product_type and\n"
515"platform_version. For backward compatibility, only the first 5 items\n"
516"are available by indexing. All elements are numbers, except\n"
517"service_pack and platform_type which are strings, and platform_version\n"
518"which is a 3-tuple. Platform is always 2. Product_type may be 1 for a\n"
519"workstation, 2 for a domain controller, 3 for a server.\n"
520"Platform_version is a 3-tuple containing a version number that is\n"
521"intended for identifying the OS rather than feature detection.");
522
523#define SYS_GETWINDOWSVERSION_METHODDEF \
524 {"getwindowsversion", (PyCFunction)sys_getwindowsversion, METH_NOARGS, sys_getwindowsversion__doc__},
525
526static PyObject *
527sys_getwindowsversion_impl(PyObject *module);
528
529static PyObject *
530sys_getwindowsversion(PyObject *module, PyObject *Py_UNUSED(ignored))
531{
532 return sys_getwindowsversion_impl(module);
533}
534
535#endif /* defined(MS_WINDOWS) */
536
537#if defined(MS_WINDOWS)
538
539PyDoc_STRVAR(sys__enablelegacywindowsfsencoding__doc__,
540"_enablelegacywindowsfsencoding($module, /)\n"
541"--\n"
542"\n"
543"Changes the default filesystem encoding to mbcs:replace.\n"
544"\n"
545"This is done for consistency with earlier versions of Python. See PEP\n"
546"529 for more information.\n"
547"\n"
548"This is equivalent to defining the PYTHONLEGACYWINDOWSFSENCODING\n"
549"environment variable before launching Python.");
550
551#define SYS__ENABLELEGACYWINDOWSFSENCODING_METHODDEF \
552 {"_enablelegacywindowsfsencoding", (PyCFunction)sys__enablelegacywindowsfsencoding, METH_NOARGS, sys__enablelegacywindowsfsencoding__doc__},
553
554static PyObject *
555sys__enablelegacywindowsfsencoding_impl(PyObject *module);
556
557static PyObject *
558sys__enablelegacywindowsfsencoding(PyObject *module, PyObject *Py_UNUSED(ignored))
559{
560 return sys__enablelegacywindowsfsencoding_impl(module);
561}
562
563#endif /* defined(MS_WINDOWS) */
564
565#if defined(HAVE_DLOPEN)
566
567PyDoc_STRVAR(sys_setdlopenflags__doc__,
568"setdlopenflags($module, flags, /)\n"
569"--\n"
570"\n"
571"Set the flags used by the interpreter for dlopen calls.\n"
572"\n"
573"This is used, for example, when the interpreter loads extension\n"
574"modules. Among other things, this will enable a lazy resolving of\n"
575"symbols when importing a module, if called as sys.setdlopenflags(0).\n"
576"To share symbols across extension modules, call as\n"
577"sys.setdlopenflags(os.RTLD_GLOBAL). Symbolic names for the flag\n"
578"modules can be found in the os module (RTLD_xxx constants, e.g.\n"
579"os.RTLD_LAZY).");
580
581#define SYS_SETDLOPENFLAGS_METHODDEF \
582 {"setdlopenflags", (PyCFunction)sys_setdlopenflags, METH_O, sys_setdlopenflags__doc__},
583
584static PyObject *
585sys_setdlopenflags_impl(PyObject *module, int new_val);
586
587static PyObject *
588sys_setdlopenflags(PyObject *module, PyObject *arg)
589{
590 PyObject *return_value = NULL;
591 int new_val;
592
593 if (PyFloat_Check(arg)) {
594 PyErr_SetString(PyExc_TypeError,
595 "integer argument expected, got float" );
596 goto exit;
597 }
598 new_val = _PyLong_AsInt(arg);
599 if (new_val == -1 && PyErr_Occurred()) {
600 goto exit;
601 }
602 return_value = sys_setdlopenflags_impl(module, new_val);
603
604exit:
605 return return_value;
606}
607
608#endif /* defined(HAVE_DLOPEN) */
609
610#if defined(HAVE_DLOPEN)
611
612PyDoc_STRVAR(sys_getdlopenflags__doc__,
613"getdlopenflags($module, /)\n"
614"--\n"
615"\n"
616"Return the current value of the flags that are used for dlopen calls.\n"
617"\n"
618"The flag constants are defined in the os module.");
619
620#define SYS_GETDLOPENFLAGS_METHODDEF \
621 {"getdlopenflags", (PyCFunction)sys_getdlopenflags, METH_NOARGS, sys_getdlopenflags__doc__},
622
623static PyObject *
624sys_getdlopenflags_impl(PyObject *module);
625
626static PyObject *
627sys_getdlopenflags(PyObject *module, PyObject *Py_UNUSED(ignored))
628{
629 return sys_getdlopenflags_impl(module);
630}
631
632#endif /* defined(HAVE_DLOPEN) */
633
634#if defined(USE_MALLOPT)
635
636PyDoc_STRVAR(sys_mdebug__doc__,
637"mdebug($module, flag, /)\n"
638"--\n"
639"\n");
640
641#define SYS_MDEBUG_METHODDEF \
642 {"mdebug", (PyCFunction)sys_mdebug, METH_O, sys_mdebug__doc__},
643
644static PyObject *
645sys_mdebug_impl(PyObject *module, int flag);
646
647static PyObject *
648sys_mdebug(PyObject *module, PyObject *arg)
649{
650 PyObject *return_value = NULL;
651 int flag;
652
653 if (PyFloat_Check(arg)) {
654 PyErr_SetString(PyExc_TypeError,
655 "integer argument expected, got float" );
656 goto exit;
657 }
658 flag = _PyLong_AsInt(arg);
659 if (flag == -1 && PyErr_Occurred()) {
660 goto exit;
661 }
662 return_value = sys_mdebug_impl(module, flag);
663
664exit:
665 return return_value;
666}
667
668#endif /* defined(USE_MALLOPT) */
669
670PyDoc_STRVAR(sys_getrefcount__doc__,
671"getrefcount($module, object, /)\n"
672"--\n"
673"\n"
674"Return the reference count of object.\n"
675"\n"
676"The count returned is generally one higher than you might expect,\n"
677"because it includes the (temporary) reference as an argument to\n"
678"getrefcount().");
679
680#define SYS_GETREFCOUNT_METHODDEF \
681 {"getrefcount", (PyCFunction)sys_getrefcount, METH_O, sys_getrefcount__doc__},
682
683static Py_ssize_t
684sys_getrefcount_impl(PyObject *module, PyObject *object);
685
686static PyObject *
687sys_getrefcount(PyObject *module, PyObject *object)
688{
689 PyObject *return_value = NULL;
690 Py_ssize_t _return_value;
691
692 _return_value = sys_getrefcount_impl(module, object);
693 if ((_return_value == -1) && PyErr_Occurred()) {
694 goto exit;
695 }
696 return_value = PyLong_FromSsize_t(_return_value);
697
698exit:
699 return return_value;
700}
701
702#if defined(Py_REF_DEBUG)
703
704PyDoc_STRVAR(sys_gettotalrefcount__doc__,
705"gettotalrefcount($module, /)\n"
706"--\n"
707"\n");
708
709#define SYS_GETTOTALREFCOUNT_METHODDEF \
710 {"gettotalrefcount", (PyCFunction)sys_gettotalrefcount, METH_NOARGS, sys_gettotalrefcount__doc__},
711
712static Py_ssize_t
713sys_gettotalrefcount_impl(PyObject *module);
714
715static PyObject *
716sys_gettotalrefcount(PyObject *module, PyObject *Py_UNUSED(ignored))
717{
718 PyObject *return_value = NULL;
719 Py_ssize_t _return_value;
720
721 _return_value = sys_gettotalrefcount_impl(module);
722 if ((_return_value == -1) && PyErr_Occurred()) {
723 goto exit;
724 }
725 return_value = PyLong_FromSsize_t(_return_value);
726
727exit:
728 return return_value;
729}
730
731#endif /* defined(Py_REF_DEBUG) */
732
733PyDoc_STRVAR(sys_getallocatedblocks__doc__,
734"getallocatedblocks($module, /)\n"
735"--\n"
736"\n"
737"Return the number of memory blocks currently allocated.");
738
739#define SYS_GETALLOCATEDBLOCKS_METHODDEF \
740 {"getallocatedblocks", (PyCFunction)sys_getallocatedblocks, METH_NOARGS, sys_getallocatedblocks__doc__},
741
742static Py_ssize_t
743sys_getallocatedblocks_impl(PyObject *module);
744
745static PyObject *
746sys_getallocatedblocks(PyObject *module, PyObject *Py_UNUSED(ignored))
747{
748 PyObject *return_value = NULL;
749 Py_ssize_t _return_value;
750
751 _return_value = sys_getallocatedblocks_impl(module);
752 if ((_return_value == -1) && PyErr_Occurred()) {
753 goto exit;
754 }
755 return_value = PyLong_FromSsize_t(_return_value);
756
757exit:
758 return return_value;
759}
760
Tal Einatede0b6f2018-12-31 17:12:08 +0200761PyDoc_STRVAR(sys__getframe__doc__,
762"_getframe($module, depth=0, /)\n"
763"--\n"
764"\n"
765"Return a frame object from the call stack.\n"
766"\n"
767"If optional integer depth is given, return the frame object that many\n"
768"calls below the top of the stack. If that is deeper than the call\n"
769"stack, ValueError is raised. The default for depth is zero, returning\n"
770"the frame at the top of the call stack.\n"
771"\n"
772"This function should be used for internal and specialized purposes\n"
773"only.");
774
775#define SYS__GETFRAME_METHODDEF \
776 {"_getframe", (PyCFunction)(void(*)(void))sys__getframe, METH_FASTCALL, sys__getframe__doc__},
777
778static PyObject *
779sys__getframe_impl(PyObject *module, int depth);
780
781static PyObject *
782sys__getframe(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
783{
784 PyObject *return_value = NULL;
785 int depth = 0;
786
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200787 if (!_PyArg_CheckPositional("_getframe", nargs, 0, 1)) {
Tal Einatede0b6f2018-12-31 17:12:08 +0200788 goto exit;
789 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200790 if (nargs < 1) {
791 goto skip_optional;
792 }
793 if (PyFloat_Check(args[0])) {
794 PyErr_SetString(PyExc_TypeError,
795 "integer argument expected, got float" );
796 goto exit;
797 }
798 depth = _PyLong_AsInt(args[0]);
799 if (depth == -1 && PyErr_Occurred()) {
800 goto exit;
801 }
802skip_optional:
Tal Einatede0b6f2018-12-31 17:12:08 +0200803 return_value = sys__getframe_impl(module, depth);
804
805exit:
806 return return_value;
807}
808
809PyDoc_STRVAR(sys__current_frames__doc__,
810"_current_frames($module, /)\n"
811"--\n"
812"\n"
813"Return a dict mapping each thread\'s thread id to its current stack frame.\n"
814"\n"
815"This function should be used for specialized purposes only.");
816
817#define SYS__CURRENT_FRAMES_METHODDEF \
818 {"_current_frames", (PyCFunction)sys__current_frames, METH_NOARGS, sys__current_frames__doc__},
819
820static PyObject *
821sys__current_frames_impl(PyObject *module);
822
823static PyObject *
824sys__current_frames(PyObject *module, PyObject *Py_UNUSED(ignored))
825{
826 return sys__current_frames_impl(module);
827}
828
829PyDoc_STRVAR(sys_call_tracing__doc__,
830"call_tracing($module, func, args, /)\n"
831"--\n"
832"\n"
833"Call func(*args), while tracing is enabled.\n"
834"\n"
835"The tracing state is saved, and restored afterwards. This is intended\n"
836"to be called from a debugger from a checkpoint, to recursively debug\n"
837"some other code.");
838
839#define SYS_CALL_TRACING_METHODDEF \
840 {"call_tracing", (PyCFunction)(void(*)(void))sys_call_tracing, METH_FASTCALL, sys_call_tracing__doc__},
841
842static PyObject *
843sys_call_tracing_impl(PyObject *module, PyObject *func, PyObject *funcargs);
844
845static PyObject *
846sys_call_tracing(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
847{
848 PyObject *return_value = NULL;
849 PyObject *func;
850 PyObject *funcargs;
851
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200852 if (!_PyArg_CheckPositional("call_tracing", nargs, 2, 2)) {
Tal Einatede0b6f2018-12-31 17:12:08 +0200853 goto exit;
854 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200855 func = args[0];
856 if (!PyTuple_Check(args[1])) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +0200857 _PyArg_BadArgument("call_tracing", "argument 2", "tuple", args[1]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200858 goto exit;
859 }
860 funcargs = args[1];
Tal Einatede0b6f2018-12-31 17:12:08 +0200861 return_value = sys_call_tracing_impl(module, func, funcargs);
862
863exit:
864 return return_value;
865}
866
Tal Einatede0b6f2018-12-31 17:12:08 +0200867PyDoc_STRVAR(sys__debugmallocstats__doc__,
868"_debugmallocstats($module, /)\n"
869"--\n"
870"\n"
871"Print summary info to stderr about the state of pymalloc\'s structures.\n"
872"\n"
873"In Py_DEBUG mode, also perform some expensive internal consistency\n"
874"checks.");
875
876#define SYS__DEBUGMALLOCSTATS_METHODDEF \
877 {"_debugmallocstats", (PyCFunction)sys__debugmallocstats, METH_NOARGS, sys__debugmallocstats__doc__},
878
879static PyObject *
880sys__debugmallocstats_impl(PyObject *module);
881
882static PyObject *
883sys__debugmallocstats(PyObject *module, PyObject *Py_UNUSED(ignored))
884{
885 return sys__debugmallocstats_impl(module);
886}
887
888PyDoc_STRVAR(sys__clear_type_cache__doc__,
889"_clear_type_cache($module, /)\n"
890"--\n"
891"\n"
892"Clear the internal type lookup cache.");
893
894#define SYS__CLEAR_TYPE_CACHE_METHODDEF \
895 {"_clear_type_cache", (PyCFunction)sys__clear_type_cache, METH_NOARGS, sys__clear_type_cache__doc__},
896
897static PyObject *
898sys__clear_type_cache_impl(PyObject *module);
899
900static PyObject *
901sys__clear_type_cache(PyObject *module, PyObject *Py_UNUSED(ignored))
902{
903 return sys__clear_type_cache_impl(module);
904}
905
906PyDoc_STRVAR(sys_is_finalizing__doc__,
907"is_finalizing($module, /)\n"
908"--\n"
909"\n"
910"Return True if Python is exiting.");
911
912#define SYS_IS_FINALIZING_METHODDEF \
913 {"is_finalizing", (PyCFunction)sys_is_finalizing, METH_NOARGS, sys_is_finalizing__doc__},
914
915static PyObject *
916sys_is_finalizing_impl(PyObject *module);
917
918static PyObject *
919sys_is_finalizing(PyObject *module, PyObject *Py_UNUSED(ignored))
920{
921 return sys_is_finalizing_impl(module);
922}
923
924#if defined(ANDROID_API_LEVEL)
925
926PyDoc_STRVAR(sys_getandroidapilevel__doc__,
927"getandroidapilevel($module, /)\n"
928"--\n"
929"\n"
930"Return the build time API version of Android as an integer.");
931
932#define SYS_GETANDROIDAPILEVEL_METHODDEF \
933 {"getandroidapilevel", (PyCFunction)sys_getandroidapilevel, METH_NOARGS, sys_getandroidapilevel__doc__},
934
935static PyObject *
936sys_getandroidapilevel_impl(PyObject *module);
937
938static PyObject *
939sys_getandroidapilevel(PyObject *module, PyObject *Py_UNUSED(ignored))
940{
941 return sys_getandroidapilevel_impl(module);
942}
943
944#endif /* defined(ANDROID_API_LEVEL) */
945
946#ifndef SYS_GETWINDOWSVERSION_METHODDEF
947 #define SYS_GETWINDOWSVERSION_METHODDEF
948#endif /* !defined(SYS_GETWINDOWSVERSION_METHODDEF) */
949
950#ifndef SYS__ENABLELEGACYWINDOWSFSENCODING_METHODDEF
951 #define SYS__ENABLELEGACYWINDOWSFSENCODING_METHODDEF
952#endif /* !defined(SYS__ENABLELEGACYWINDOWSFSENCODING_METHODDEF) */
953
954#ifndef SYS_SETDLOPENFLAGS_METHODDEF
955 #define SYS_SETDLOPENFLAGS_METHODDEF
956#endif /* !defined(SYS_SETDLOPENFLAGS_METHODDEF) */
957
958#ifndef SYS_GETDLOPENFLAGS_METHODDEF
959 #define SYS_GETDLOPENFLAGS_METHODDEF
960#endif /* !defined(SYS_GETDLOPENFLAGS_METHODDEF) */
961
962#ifndef SYS_MDEBUG_METHODDEF
963 #define SYS_MDEBUG_METHODDEF
964#endif /* !defined(SYS_MDEBUG_METHODDEF) */
965
966#ifndef SYS_GETTOTALREFCOUNT_METHODDEF
967 #define SYS_GETTOTALREFCOUNT_METHODDEF
968#endif /* !defined(SYS_GETTOTALREFCOUNT_METHODDEF) */
969
Tal Einatede0b6f2018-12-31 17:12:08 +0200970#ifndef SYS_GETANDROIDAPILEVEL_METHODDEF
971 #define SYS_GETANDROIDAPILEVEL_METHODDEF
972#endif /* !defined(SYS_GETANDROIDAPILEVEL_METHODDEF) */
Victor Stinnerc6e5c112020-02-03 15:17:15 +0100973/*[clinic end generated code: output=39eb34a01fb9a919 input=a9049054013a1b77]*/