18
18
19
19
#define doubletime (TV ) ((double)(TV).tv_sec + (TV).tv_usec * 0.000001)
20
20
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
+
21
35
PyDoc_STRVAR (struct_rusage__doc__ ,
22
36
"struct_rusage: Result from getrusage.\n\n"
23
37
"This object may be accessed either as a tuple of\n"
@@ -55,16 +69,21 @@ static PyStructSequence_Desc struct_rusage_desc = {
55
69
static int initialized ;
56
70
static PyTypeObject StructRUsageType ;
57
71
72
+ /*[clinic input]
73
+ resource.getrusage
74
+
75
+ who: int
76
+ /
77
+
78
+ [clinic start generated code]*/
79
+
58
80
static 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]*/
60
83
{
61
- int who ;
62
84
struct rusage ru ;
63
85
PyObject * result ;
64
86
65
- if (!PyArg_ParseTuple (args , "i:getrusage" , & who ))
66
- return NULL ;
67
-
68
87
if (getrusage (who , & ru ) == -1 ) {
69
88
if (errno == EINVAL ) {
70
89
PyErr_SetString (PyExc_ValueError ,
@@ -160,14 +179,19 @@ rlimit2py(struct rlimit rl)
160
179
return Py_BuildValue ("ll" , (long ) rl .rlim_cur , (long ) rl .rlim_max );
161
180
}
162
181
182
+ /*[clinic input]
183
+ resource.getrlimit
184
+
185
+ resource: int
186
+ /
187
+
188
+ [clinic start generated code]*/
189
+
163
190
static 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]*/
165
193
{
166
194
struct rlimit rl ;
167
- int resource ;
168
-
169
- if (!PyArg_ParseTuple (args , "i:getrlimit" , & resource ))
170
- return NULL ;
171
195
172
196
if (resource < 0 || resource >= RLIM_NLIMITS ) {
173
197
PyErr_SetString (PyExc_ValueError ,
@@ -182,15 +206,20 @@ resource_getrlimit(PyObject *self, PyObject *args)
182
206
return rlimit2py (rl );
183
207
}
184
208
209
+ /*[clinic input]
210
+ resource.setrlimit
211
+
212
+ resource: int
213
+ limits: object
214
+ /
215
+
216
+ [clinic start generated code]*/
217
+
185
218
static 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]*/
187
221
{
188
222
struct rlimit rl ;
189
- int resource ;
190
- PyObject * limits ;
191
-
192
- if (!PyArg_ParseTuple (args , "iO:setrlimit" , & resource , & limits ))
193
- return NULL ;
194
223
195
224
if (resource < 0 || resource >= RLIM_NLIMITS ) {
196
225
PyErr_SetString (PyExc_ValueError ,
@@ -217,25 +246,33 @@ resource_setrlimit(PyObject *self, PyObject *args)
217
246
}
218
247
219
248
#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
+
220
261
static 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]*/
222
265
{
223
266
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 ;
231
268
232
269
if (resource < 0 || resource >= RLIM_NLIMITS ) {
233
270
PyErr_SetString (PyExc_ValueError ,
234
271
"invalid resource specified" );
235
272
return NULL ;
236
273
}
237
274
238
- if (limits != NULL ) {
275
+ if (group_right_1 ) {
239
276
if (py2rlimit (limits , & new_limit ) < 0 ) {
240
277
return NULL ;
241
278
}
@@ -258,8 +295,13 @@ resource_prlimit(PyObject *self, PyObject *args)
258
295
}
259
296
#endif /* HAVE_PRLIMIT */
260
297
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]*/
263
305
{
264
306
long pagesize = 0 ;
265
307
#if defined(HAVE_GETPAGESIZE )
@@ -272,21 +314,18 @@ resource_getpagesize(PyObject *self, PyObject *unused)
272
314
pagesize = sysconf (_SC_PAGESIZE );
273
315
#endif
274
316
#endif
275
- return Py_BuildValue ("i" , pagesize );
276
-
317
+ return pagesize ;
277
318
}
278
319
279
320
/* List of functions */
280
321
281
322
static struct PyMethodDef
282
323
resource_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
290
329
{NULL , NULL } /* sentinel */
291
330
};
292
331
0 commit comments