blob: 80efb714bb6b642f83a760c1d2a4b7d0ea3b5cd7 [file] [log] [blame]
Serhiy Storchaka19897632017-03-12 13:08:30 +02001/*[clinic input]
2preserve
3[clinic start generated code]*/
4
5PyDoc_STRVAR(resource_getrusage__doc__,
6"getrusage($module, who, /)\n"
7"--\n"
8"\n");
9
10#define RESOURCE_GETRUSAGE_METHODDEF \
11 {"getrusage", (PyCFunction)resource_getrusage, METH_O, resource_getrusage__doc__},
12
13static PyObject *
14resource_getrusage_impl(PyObject *module, int who);
15
16static PyObject *
17resource_getrusage(PyObject *module, PyObject *arg)
18{
19 PyObject *return_value = NULL;
20 int who;
21
Serhiy Storchaka32d96a22018-12-25 13:23:47 +020022 if (PyFloat_Check(arg)) {
23 PyErr_SetString(PyExc_TypeError,
24 "integer argument expected, got float" );
25 goto exit;
26 }
27 who = _PyLong_AsInt(arg);
28 if (who == -1 && PyErr_Occurred()) {
Serhiy Storchaka19897632017-03-12 13:08:30 +020029 goto exit;
30 }
31 return_value = resource_getrusage_impl(module, who);
32
33exit:
34 return return_value;
35}
36
37PyDoc_STRVAR(resource_getrlimit__doc__,
38"getrlimit($module, resource, /)\n"
39"--\n"
40"\n");
41
42#define RESOURCE_GETRLIMIT_METHODDEF \
43 {"getrlimit", (PyCFunction)resource_getrlimit, METH_O, resource_getrlimit__doc__},
44
45static PyObject *
46resource_getrlimit_impl(PyObject *module, int resource);
47
48static PyObject *
49resource_getrlimit(PyObject *module, PyObject *arg)
50{
51 PyObject *return_value = NULL;
52 int resource;
53
Serhiy Storchaka32d96a22018-12-25 13:23:47 +020054 if (PyFloat_Check(arg)) {
55 PyErr_SetString(PyExc_TypeError,
56 "integer argument expected, got float" );
57 goto exit;
58 }
59 resource = _PyLong_AsInt(arg);
60 if (resource == -1 && PyErr_Occurred()) {
Serhiy Storchaka19897632017-03-12 13:08:30 +020061 goto exit;
62 }
63 return_value = resource_getrlimit_impl(module, resource);
64
65exit:
66 return return_value;
67}
68
69PyDoc_STRVAR(resource_setrlimit__doc__,
70"setrlimit($module, resource, limits, /)\n"
71"--\n"
72"\n");
73
74#define RESOURCE_SETRLIMIT_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +020075 {"setrlimit", (PyCFunction)(void(*)(void))resource_setrlimit, METH_FASTCALL, resource_setrlimit__doc__},
Serhiy Storchaka19897632017-03-12 13:08:30 +020076
77static PyObject *
78resource_setrlimit_impl(PyObject *module, int resource, PyObject *limits);
79
80static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +020081resource_setrlimit(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka19897632017-03-12 13:08:30 +020082{
83 PyObject *return_value = NULL;
84 int resource;
85 PyObject *limits;
86
Serhiy Storchaka4fa95912019-01-11 16:01:14 +020087 if (!_PyArg_CheckPositional("setrlimit", nargs, 2, 2)) {
Serhiy Storchaka19897632017-03-12 13:08:30 +020088 goto exit;
89 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +020090 if (PyFloat_Check(args[0])) {
91 PyErr_SetString(PyExc_TypeError,
92 "integer argument expected, got float" );
93 goto exit;
94 }
95 resource = _PyLong_AsInt(args[0]);
96 if (resource == -1 && PyErr_Occurred()) {
97 goto exit;
98 }
99 limits = args[1];
Serhiy Storchaka19897632017-03-12 13:08:30 +0200100 return_value = resource_setrlimit_impl(module, resource, limits);
101
102exit:
103 return return_value;
104}
105
106#if defined(HAVE_PRLIMIT)
107
108PyDoc_STRVAR(resource_prlimit__doc__,
109"prlimit(pid, resource, [limits])");
110
111#define RESOURCE_PRLIMIT_METHODDEF \
112 {"prlimit", (PyCFunction)resource_prlimit, METH_VARARGS, resource_prlimit__doc__},
113
114static PyObject *
115resource_prlimit_impl(PyObject *module, pid_t pid, int resource,
116 int group_right_1, PyObject *limits);
117
118static PyObject *
119resource_prlimit(PyObject *module, PyObject *args)
120{
121 PyObject *return_value = NULL;
122 pid_t pid;
123 int resource;
124 int group_right_1 = 0;
125 PyObject *limits = NULL;
126
127 switch (PyTuple_GET_SIZE(args)) {
128 case 2:
129 if (!PyArg_ParseTuple(args, "" _Py_PARSE_PID "i:prlimit", &pid, &resource)) {
130 goto exit;
131 }
132 break;
133 case 3:
134 if (!PyArg_ParseTuple(args, "" _Py_PARSE_PID "iO:prlimit", &pid, &resource, &limits)) {
135 goto exit;
136 }
137 group_right_1 = 1;
138 break;
139 default:
140 PyErr_SetString(PyExc_TypeError, "resource.prlimit requires 2 to 3 arguments");
141 goto exit;
142 }
143 return_value = resource_prlimit_impl(module, pid, resource, group_right_1, limits);
144
145exit:
146 return return_value;
147}
148
149#endif /* defined(HAVE_PRLIMIT) */
150
151PyDoc_STRVAR(resource_getpagesize__doc__,
152"getpagesize($module, /)\n"
153"--\n"
154"\n");
155
156#define RESOURCE_GETPAGESIZE_METHODDEF \
157 {"getpagesize", (PyCFunction)resource_getpagesize, METH_NOARGS, resource_getpagesize__doc__},
158
159static int
160resource_getpagesize_impl(PyObject *module);
161
162static PyObject *
163resource_getpagesize(PyObject *module, PyObject *Py_UNUSED(ignored))
164{
165 PyObject *return_value = NULL;
166 int _return_value;
167
168 _return_value = resource_getpagesize_impl(module);
169 if ((_return_value == -1) && PyErr_Occurred()) {
170 goto exit;
171 }
172 return_value = PyLong_FromLong((long)_return_value);
173
174exit:
175 return return_value;
176}
177
178#ifndef RESOURCE_PRLIMIT_METHODDEF
179 #define RESOURCE_PRLIMIT_METHODDEF
180#endif /* !defined(RESOURCE_PRLIMIT_METHODDEF) */
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200181/*[clinic end generated code: output=ef3034f291156a34 input=a9049054013a1b77]*/