1818
1919#define doubletime (TV ) ((double)(TV).tv_sec + (TV).tv_usec * 0.000001)
2020
21+ /*[clinic input]
22+ module resource
23+ [clinic start generated code]*/
24+ /*[clinic end generated code: output=da39a3ee5e6b4b0d input=e89d38ed52609d7c]*/
25+
26+ /*[python input]
27+ class pid_t_converter(CConverter):
28+ type = 'pid_t'
29+ format_unit = '" _Py_PARSE_PID "'
30+ [python start generated code]*/
31+ /*[python end generated code: output=da39a3ee5e6b4b0d input=0c1d19f640d57e48]*/
32+
33+ #include "clinic/resource.c.h"
34+
2135PyDoc_STRVAR (struct_rusage__doc__ ,
2236"struct_rusage: Result from getrusage.\n\n"
2337"This object may be accessed either as a tuple of\n"
@@ -55,16 +69,21 @@ static PyStructSequence_Desc struct_rusage_desc = {
5569static int initialized ;
5670static PyTypeObject StructRUsageType ;
5771
72+ /*[clinic input]
73+ resource.getrusage
74+
75+ who: int
76+ /
77+
78+ [clinic start generated code]*/
79+
5880static PyObject *
59- resource_getrusage (PyObject * self , PyObject * args )
81+ resource_getrusage_impl (PyObject * module , int who )
82+ /*[clinic end generated code: output=8fad2880ba6a9843 input=5c857bcc5b9ccb1b]*/
6083{
61- int who ;
6284 struct rusage ru ;
6385 PyObject * result ;
6486
65- if (!PyArg_ParseTuple (args , "i:getrusage" , & who ))
66- return NULL ;
67-
6887 if (getrusage (who , & ru ) == -1 ) {
6988 if (errno == EINVAL ) {
7089 PyErr_SetString (PyExc_ValueError ,
@@ -160,14 +179,19 @@ rlimit2py(struct rlimit rl)
160179 return Py_BuildValue ("ll" , (long ) rl .rlim_cur , (long ) rl .rlim_max );
161180}
162181
182+ /*[clinic input]
183+ resource.getrlimit
184+
185+ resource: int
186+ /
187+
188+ [clinic start generated code]*/
189+
163190static PyObject *
164- resource_getrlimit (PyObject * self , PyObject * args )
191+ resource_getrlimit_impl (PyObject * module , int resource )
192+ /*[clinic end generated code: output=98327b25061ffe39 input=a697cb0004cb3c36]*/
165193{
166194 struct rlimit rl ;
167- int resource ;
168-
169- if (!PyArg_ParseTuple (args , "i:getrlimit" , & resource ))
170- return NULL ;
171195
172196 if (resource < 0 || resource >= RLIM_NLIMITS ) {
173197 PyErr_SetString (PyExc_ValueError ,
@@ -182,15 +206,20 @@ resource_getrlimit(PyObject *self, PyObject *args)
182206 return rlimit2py (rl );
183207}
184208
209+ /*[clinic input]
210+ resource.setrlimit
211+
212+ resource: int
213+ limits: object
214+ /
215+
216+ [clinic start generated code]*/
217+
185218static PyObject *
186- resource_setrlimit (PyObject * self , PyObject * args )
219+ resource_setrlimit_impl (PyObject * module , int resource , PyObject * limits )
220+ /*[clinic end generated code: output=4e82ec3f34d013d1 input=6235a6ce23b4ca75]*/
187221{
188222 struct rlimit rl ;
189- int resource ;
190- PyObject * limits ;
191-
192- if (!PyArg_ParseTuple (args , "iO:setrlimit" , & resource , & limits ))
193- return NULL ;
194223
195224 if (resource < 0 || resource >= RLIM_NLIMITS ) {
196225 PyErr_SetString (PyExc_ValueError ,
@@ -217,25 +246,33 @@ resource_setrlimit(PyObject *self, PyObject *args)
217246}
218247
219248#ifdef HAVE_PRLIMIT
249+ /*[clinic input]
250+ resource.prlimit
251+
252+ pid: pid_t
253+ resource: int
254+ [
255+ limits: object
256+ ]
257+ /
258+
259+ [clinic start generated code]*/
260+
220261static PyObject *
221- resource_prlimit (PyObject * self , PyObject * args )
262+ resource_prlimit_impl (PyObject * module , pid_t pid , int resource ,
263+ int group_right_1 , PyObject * limits )
264+ /*[clinic end generated code: output=ee976b393187a7a3 input=b77743bdccc83564]*/
222265{
223266 struct rlimit old_limit , new_limit ;
224- int resource , retval ;
225- pid_t pid ;
226- PyObject * limits = NULL ;
227-
228- if (!PyArg_ParseTuple (args , _Py_PARSE_PID "i|O:prlimit" ,
229- & pid , & resource , & limits ))
230- return NULL ;
267+ int retval ;
231268
232269 if (resource < 0 || resource >= RLIM_NLIMITS ) {
233270 PyErr_SetString (PyExc_ValueError ,
234271 "invalid resource specified" );
235272 return NULL ;
236273 }
237274
238- if (limits != NULL ) {
275+ if (group_right_1 ) {
239276 if (py2rlimit (limits , & new_limit ) < 0 ) {
240277 return NULL ;
241278 }
@@ -258,8 +295,13 @@ resource_prlimit(PyObject *self, PyObject *args)
258295}
259296#endif /* HAVE_PRLIMIT */
260297
261- static PyObject *
262- resource_getpagesize (PyObject * self , PyObject * unused )
298+ /*[clinic input]
299+ resource.getpagesize -> int
300+ [clinic start generated code]*/
301+
302+ static int
303+ resource_getpagesize_impl (PyObject * module )
304+ /*[clinic end generated code: output=9ba93eb0f3d6c3a9 input=546545e8c1f42085]*/
263305{
264306 long pagesize = 0 ;
265307#if defined(HAVE_GETPAGESIZE )
@@ -272,21 +314,18 @@ resource_getpagesize(PyObject *self, PyObject *unused)
272314 pagesize = sysconf (_SC_PAGESIZE );
273315#endif
274316#endif
275- return Py_BuildValue ("i" , pagesize );
276-
317+ return pagesize ;
277318}
278319
279320/* List of functions */
280321
281322static struct PyMethodDef
282323resource_methods [] = {
283- {"getrusage" , resource_getrusage , METH_VARARGS },
284- {"getrlimit" , resource_getrlimit , METH_VARARGS },
285- #ifdef HAVE_PRLIMIT
286- {"prlimit" , resource_prlimit , METH_VARARGS },
287- #endif
288- {"setrlimit" , resource_setrlimit , METH_VARARGS },
289- {"getpagesize" , resource_getpagesize , METH_NOARGS },
324+ RESOURCE_GETRUSAGE_METHODDEF
325+ RESOURCE_GETRLIMIT_METHODDEF
326+ RESOURCE_PRLIMIT_METHODDEF
327+ RESOURCE_SETRLIMIT_METHODDEF
328+ RESOURCE_GETPAGESIZE_METHODDEF
290329 {NULL , NULL } /* sentinel */
291330};
292331
0 commit comments