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