1 /*[clinic input]
2 preserve
3 [clinic start generated code]*/
4
5 PyDoc_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
13 static PyObject *
14 resource_getrusage_impl(PyObject *module, int who);
15
16 static PyObject *
resource_getrusage(PyObject * module,PyObject * arg)17 resource_getrusage(PyObject *module, PyObject *arg)
18 {
19 PyObject *return_value = NULL;
20 int who;
21
22 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()) {
29 goto exit;
30 }
31 return_value = resource_getrusage_impl(module, who);
32
33 exit:
34 return return_value;
35 }
36
37 PyDoc_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
45 static PyObject *
46 resource_getrlimit_impl(PyObject *module, int resource);
47
48 static PyObject *
resource_getrlimit(PyObject * module,PyObject * arg)49 resource_getrlimit(PyObject *module, PyObject *arg)
50 {
51 PyObject *return_value = NULL;
52 int resource;
53
54 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()) {
61 goto exit;
62 }
63 return_value = resource_getrlimit_impl(module, resource);
64
65 exit:
66 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)(void(*)(void))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 *
resource_setrlimit(PyObject * module,PyObject * const * args,Py_ssize_t nargs)81 resource_setrlimit(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
82 {
83 PyObject *return_value = NULL;
84 int resource;
85 PyObject *limits;
86
87 if (!_PyArg_CheckPositional("setrlimit", nargs, 2, 2)) {
88 goto exit;
89 }
90 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];
100 return_value = resource_setrlimit_impl(module, resource, limits);
101
102 exit:
103 return return_value;
104 }
105
106 #if defined(HAVE_PRLIMIT)
107
108 PyDoc_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
114 static PyObject *
115 resource_prlimit_impl(PyObject *module, pid_t pid, int resource,
116 int group_right_1, PyObject *limits);
117
118 static PyObject *
resource_prlimit(PyObject * module,PyObject * args)119 resource_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
145 exit:
146 return return_value;
147 }
148
149 #endif /* defined(HAVE_PRLIMIT) */
150
151 PyDoc_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
159 static int
160 resource_getpagesize_impl(PyObject *module);
161
162 static PyObject *
resource_getpagesize(PyObject * module,PyObject * Py_UNUSED (ignored))163 resource_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
174 exit:
175 return return_value;
176 }
177
178 #ifndef RESOURCE_PRLIMIT_METHODDEF
179 #define RESOURCE_PRLIMIT_METHODDEF
180 #endif /* !defined(RESOURCE_PRLIMIT_METHODDEF) */
181 /*[clinic end generated code: output=ef3034f291156a34 input=a9049054013a1b77]*/
182