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