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