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