Branch data Line data Source code
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 : :
10 : :
11 : : #if defined(HAVE_GETRUSAGE)
12 : :
13 : : PyDoc_STRVAR(resource_getrusage__doc__,
14 : : "getrusage($module, who, /)\n"
15 : : "--\n"
16 : : "\n");
17 : :
18 : : #define RESOURCE_GETRUSAGE_METHODDEF \
19 : : {"getrusage", (PyCFunction)resource_getrusage, METH_O, resource_getrusage__doc__},
20 : :
21 : : static PyObject *
22 : : resource_getrusage_impl(PyObject *module, int who);
23 : :
24 : : static PyObject *
25 : 0 : resource_getrusage(PyObject *module, PyObject *arg)
26 : : {
27 : 0 : PyObject *return_value = NULL;
28 : : int who;
29 : :
30 : 0 : who = _PyLong_AsInt(arg);
31 [ # # # # ]: 0 : if (who == -1 && PyErr_Occurred()) {
32 : 0 : goto exit;
33 : : }
34 : 0 : return_value = resource_getrusage_impl(module, who);
35 : :
36 : 0 : exit:
37 : 0 : return return_value;
38 : : }
39 : :
40 : : #endif /* defined(HAVE_GETRUSAGE) */
41 : :
42 : : PyDoc_STRVAR(resource_getrlimit__doc__,
43 : : "getrlimit($module, resource, /)\n"
44 : : "--\n"
45 : : "\n");
46 : :
47 : : #define RESOURCE_GETRLIMIT_METHODDEF \
48 : : {"getrlimit", (PyCFunction)resource_getrlimit, METH_O, resource_getrlimit__doc__},
49 : :
50 : : static PyObject *
51 : : resource_getrlimit_impl(PyObject *module, int resource);
52 : :
53 : : static PyObject *
54 : 1 : resource_getrlimit(PyObject *module, PyObject *arg)
55 : : {
56 : 1 : PyObject *return_value = NULL;
57 : : int resource;
58 : :
59 : 1 : resource = _PyLong_AsInt(arg);
60 [ - + - - ]: 1 : if (resource == -1 && PyErr_Occurred()) {
61 : 0 : goto exit;
62 : : }
63 : 1 : return_value = resource_getrlimit_impl(module, resource);
64 : :
65 : 1 : exit:
66 : 1 : return return_value;
67 : : }
68 : :
69 : : PyDoc_STRVAR(resource_setrlimit__doc__,
70 : : "setrlimit($module, resource, limits, /)\n"
71 : : "--\n"
72 : : "\n");
73 : :
74 : : #define RESOURCE_SETRLIMIT_METHODDEF \
75 : : {"setrlimit", _PyCFunction_CAST(resource_setrlimit), METH_FASTCALL, resource_setrlimit__doc__},
76 : :
77 : : static PyObject *
78 : : resource_setrlimit_impl(PyObject *module, int resource, PyObject *limits);
79 : :
80 : : static PyObject *
81 : 0 : resource_setrlimit(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
82 : : {
83 : 0 : PyObject *return_value = NULL;
84 : : int resource;
85 : : PyObject *limits;
86 : :
87 [ # # # # : 0 : if (!_PyArg_CheckPositional("setrlimit", nargs, 2, 2)) {
# # ]
88 : 0 : goto exit;
89 : : }
90 : 0 : resource = _PyLong_AsInt(args[0]);
91 [ # # # # ]: 0 : if (resource == -1 && PyErr_Occurred()) {
92 : 0 : goto exit;
93 : : }
94 : 0 : limits = args[1];
95 : 0 : return_value = resource_setrlimit_impl(module, resource, limits);
96 : :
97 : 0 : exit:
98 : 0 : return return_value;
99 : : }
100 : :
101 : : #if defined(HAVE_PRLIMIT)
102 : :
103 : : PyDoc_STRVAR(resource_prlimit__doc__,
104 : : "prlimit($module, pid, resource, limits=None, /)\n"
105 : : "--\n"
106 : : "\n");
107 : :
108 : : #define RESOURCE_PRLIMIT_METHODDEF \
109 : : {"prlimit", _PyCFunction_CAST(resource_prlimit), METH_FASTCALL, resource_prlimit__doc__},
110 : :
111 : : static PyObject *
112 : : resource_prlimit_impl(PyObject *module, pid_t pid, int resource,
113 : : PyObject *limits);
114 : :
115 : : static PyObject *
116 : 0 : resource_prlimit(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
117 : : {
118 : 0 : PyObject *return_value = NULL;
119 : : pid_t pid;
120 : : int resource;
121 : 0 : PyObject *limits = Py_None;
122 : :
123 [ # # # # : 0 : if (!_PyArg_CheckPositional("prlimit", nargs, 2, 3)) {
# # ]
124 : 0 : goto exit;
125 : : }
126 : 0 : pid = PyLong_AsPid(args[0]);
127 [ # # # # ]: 0 : if (pid == -1 && PyErr_Occurred()) {
128 : 0 : goto exit;
129 : : }
130 : 0 : resource = _PyLong_AsInt(args[1]);
131 [ # # # # ]: 0 : if (resource == -1 && PyErr_Occurred()) {
132 : 0 : goto exit;
133 : : }
134 [ # # ]: 0 : if (nargs < 3) {
135 : 0 : goto skip_optional;
136 : : }
137 : 0 : limits = args[2];
138 : 0 : skip_optional:
139 : 0 : return_value = resource_prlimit_impl(module, pid, resource, limits);
140 : :
141 : 0 : exit:
142 : 0 : return return_value;
143 : : }
144 : :
145 : : #endif /* defined(HAVE_PRLIMIT) */
146 : :
147 : : PyDoc_STRVAR(resource_getpagesize__doc__,
148 : : "getpagesize($module, /)\n"
149 : : "--\n"
150 : : "\n");
151 : :
152 : : #define RESOURCE_GETPAGESIZE_METHODDEF \
153 : : {"getpagesize", (PyCFunction)resource_getpagesize, METH_NOARGS, resource_getpagesize__doc__},
154 : :
155 : : static int
156 : : resource_getpagesize_impl(PyObject *module);
157 : :
158 : : static PyObject *
159 : 0 : resource_getpagesize(PyObject *module, PyObject *Py_UNUSED(ignored))
160 : : {
161 : 0 : PyObject *return_value = NULL;
162 : : int _return_value;
163 : :
164 : 0 : _return_value = resource_getpagesize_impl(module);
165 [ # # # # ]: 0 : if ((_return_value == -1) && PyErr_Occurred()) {
166 : 0 : goto exit;
167 : : }
168 : 0 : return_value = PyLong_FromLong((long)_return_value);
169 : :
170 : 0 : exit:
171 : 0 : return return_value;
172 : : }
173 : :
174 : : #ifndef RESOURCE_GETRUSAGE_METHODDEF
175 : : #define RESOURCE_GETRUSAGE_METHODDEF
176 : : #endif /* !defined(RESOURCE_GETRUSAGE_METHODDEF) */
177 : :
178 : : #ifndef RESOURCE_PRLIMIT_METHODDEF
179 : : #define RESOURCE_PRLIMIT_METHODDEF
180 : : #endif /* !defined(RESOURCE_PRLIMIT_METHODDEF) */
181 : : /*[clinic end generated code: output=2fbec74335a57230 input=a9049054013a1b77]*/
|