Guido van Rossum | f84a539 | 1997-08-15 00:04:24 +0000 | [diff] [blame] | 1 | |
Guido van Rossum | 2e63139 | 1996-12-18 18:37:27 +0000 | [diff] [blame] | 2 | #include "Python.h" |
Martin v. Löwis | 688357e | 2002-04-08 21:28:20 +0000 | [diff] [blame] | 3 | #include "structseq.h" |
Guido van Rossum | 2e63139 | 1996-12-18 18:37:27 +0000 | [diff] [blame] | 4 | #include <sys/resource.h> |
| 5 | #include <sys/time.h> |
Guido van Rossum | 2e63139 | 1996-12-18 18:37:27 +0000 | [diff] [blame] | 6 | #include <string.h> |
| 7 | #include <errno.h> |
Martin v. Löwis | f26d63b | 2003-03-30 17:23:49 +0000 | [diff] [blame] | 8 | /* for sysconf */ |
| 9 | #if defined(HAVE_UNISTD_H) |
| 10 | #include <unistd.h> |
| 11 | #endif |
Guido van Rossum | 2e63139 | 1996-12-18 18:37:27 +0000 | [diff] [blame] | 12 | |
Guido van Rossum | 607b33a | 1997-08-17 16:24:30 +0000 | [diff] [blame] | 13 | /* On some systems, these aren't in any header file. |
| 14 | On others they are, with inconsistent prototypes. |
| 15 | We declare the (default) return type, to shut up gcc -Wall; |
| 16 | but we can't declare the prototype, to avoid errors |
| 17 | when the header files declare it different. |
| 18 | Worse, on some Linuxes, getpagesize() returns a size_t... */ |
Guido van Rossum | 2e63139 | 1996-12-18 18:37:27 +0000 | [diff] [blame] | 19 | |
| 20 | #define doubletime(TV) ((double)(TV).tv_sec + (TV).tv_usec * 0.000001) |
| 21 | |
| 22 | static PyObject *ResourceError; |
| 23 | |
Martin v. Löwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 24 | PyDoc_STRVAR(struct_rusage__doc__, |
| 25 | "struct_rusage: Result from getrusage.\n\n" |
| 26 | "This object may be accessed either as a tuple of\n" |
| 27 | " (utime,stime,maxrss,ixrss,idrss,isrss,minflt,majflt,\n" |
| 28 | " nswap,inblock,oublock,msgsnd,msgrcv,nsignals,nvcsw,nivcsw)\n" |
| 29 | "or via the attributes ru_utime, ru_stime, ru_maxrss, and so on."); |
Martin v. Löwis | 688357e | 2002-04-08 21:28:20 +0000 | [diff] [blame] | 30 | |
| 31 | static PyStructSequence_Field struct_rusage_fields[] = { |
| 32 | {"ru_utime", "user time used"}, |
| 33 | {"ru_stime", "system time used"}, |
| 34 | {"ru_maxrss", "max. resident set size"}, |
| 35 | {"ru_ixrss", "shared memory size"}, |
| 36 | {"ru_idrss", "unshared data size"}, |
| 37 | {"ru_isrss", "unshared stack size"}, |
| 38 | {"ru_minflt", "page faults not requiring I/O"}, |
| 39 | {"ru_majflt", "page faults requiring I/O"}, |
| 40 | {"ru_nswap", "number of swap outs"}, |
| 41 | {"ru_inblock", "block input operations"}, |
| 42 | {"ru_oublock", "block output operations"}, |
| 43 | {"ru_msgsnd", "IPC messages sent"}, |
| 44 | {"ru_msgrcv", "IPC messages received"}, |
| 45 | {"ru_nsignals", "signals received"}, |
| 46 | {"ru_nvcsw", "voluntary context switches"}, |
| 47 | {"ru_nivcsw", "involuntary context switches"}, |
| 48 | {0} |
| 49 | }; |
| 50 | |
| 51 | static PyStructSequence_Desc struct_rusage_desc = { |
| 52 | "resource.struct_rusage", /* name */ |
| 53 | struct_rusage__doc__, /* doc */ |
| 54 | struct_rusage_fields, /* fields */ |
| 55 | 16 /* n_in_sequence */ |
| 56 | }; |
| 57 | |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 58 | static int initialized; |
Martin v. Löwis | 688357e | 2002-04-08 21:28:20 +0000 | [diff] [blame] | 59 | static PyTypeObject StructRUsageType; |
| 60 | |
Guido van Rossum | 2e63139 | 1996-12-18 18:37:27 +0000 | [diff] [blame] | 61 | static PyObject * |
Peter Schneider-Kamp | 416d413 | 2000-07-10 12:15:54 +0000 | [diff] [blame] | 62 | resource_getrusage(PyObject *self, PyObject *args) |
Guido van Rossum | 2e63139 | 1996-12-18 18:37:27 +0000 | [diff] [blame] | 63 | { |
| 64 | int who; |
| 65 | struct rusage ru; |
Martin v. Löwis | 688357e | 2002-04-08 21:28:20 +0000 | [diff] [blame] | 66 | PyObject *result; |
Guido van Rossum | 2e63139 | 1996-12-18 18:37:27 +0000 | [diff] [blame] | 67 | |
Guido van Rossum | 43713e5 | 2000-02-29 13:59:29 +0000 | [diff] [blame] | 68 | if (!PyArg_ParseTuple(args, "i:getrusage", &who)) |
Guido van Rossum | 2e63139 | 1996-12-18 18:37:27 +0000 | [diff] [blame] | 69 | return NULL; |
| 70 | |
| 71 | if (getrusage(who, &ru) == -1) { |
| 72 | if (errno == EINVAL) { |
| 73 | PyErr_SetString(PyExc_ValueError, |
| 74 | "invalid who parameter"); |
| 75 | return NULL; |
| 76 | } |
| 77 | PyErr_SetFromErrno(ResourceError); |
| 78 | return NULL; |
| 79 | } |
| 80 | |
Martin v. Löwis | 688357e | 2002-04-08 21:28:20 +0000 | [diff] [blame] | 81 | result = PyStructSequence_New(&StructRUsageType); |
| 82 | if (!result) |
| 83 | return NULL; |
| 84 | |
| 85 | PyStructSequence_SET_ITEM(result, 0, |
| 86 | PyFloat_FromDouble(doubletime(ru.ru_utime))); |
| 87 | PyStructSequence_SET_ITEM(result, 1, |
| 88 | PyFloat_FromDouble(doubletime(ru.ru_stime))); |
Christian Heimes | 217cfd1 | 2007-12-02 14:31:20 +0000 | [diff] [blame] | 89 | PyStructSequence_SET_ITEM(result, 2, PyLong_FromLong(ru.ru_maxrss)); |
| 90 | PyStructSequence_SET_ITEM(result, 3, PyLong_FromLong(ru.ru_ixrss)); |
| 91 | PyStructSequence_SET_ITEM(result, 4, PyLong_FromLong(ru.ru_idrss)); |
| 92 | PyStructSequence_SET_ITEM(result, 5, PyLong_FromLong(ru.ru_isrss)); |
| 93 | PyStructSequence_SET_ITEM(result, 6, PyLong_FromLong(ru.ru_minflt)); |
| 94 | PyStructSequence_SET_ITEM(result, 7, PyLong_FromLong(ru.ru_majflt)); |
| 95 | PyStructSequence_SET_ITEM(result, 8, PyLong_FromLong(ru.ru_nswap)); |
| 96 | PyStructSequence_SET_ITEM(result, 9, PyLong_FromLong(ru.ru_inblock)); |
| 97 | PyStructSequence_SET_ITEM(result, 10, PyLong_FromLong(ru.ru_oublock)); |
| 98 | PyStructSequence_SET_ITEM(result, 11, PyLong_FromLong(ru.ru_msgsnd)); |
| 99 | PyStructSequence_SET_ITEM(result, 12, PyLong_FromLong(ru.ru_msgrcv)); |
| 100 | PyStructSequence_SET_ITEM(result, 13, PyLong_FromLong(ru.ru_nsignals)); |
| 101 | PyStructSequence_SET_ITEM(result, 14, PyLong_FromLong(ru.ru_nvcsw)); |
| 102 | PyStructSequence_SET_ITEM(result, 15, PyLong_FromLong(ru.ru_nivcsw)); |
Martin v. Löwis | 688357e | 2002-04-08 21:28:20 +0000 | [diff] [blame] | 103 | |
| 104 | if (PyErr_Occurred()) { |
| 105 | Py_DECREF(result); |
| 106 | return NULL; |
| 107 | } |
| 108 | |
| 109 | return result; |
Guido van Rossum | 2e63139 | 1996-12-18 18:37:27 +0000 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | |
| 113 | static PyObject * |
Peter Schneider-Kamp | 416d413 | 2000-07-10 12:15:54 +0000 | [diff] [blame] | 114 | resource_getrlimit(PyObject *self, PyObject *args) |
Guido van Rossum | 2e63139 | 1996-12-18 18:37:27 +0000 | [diff] [blame] | 115 | { |
| 116 | struct rlimit rl; |
| 117 | int resource; |
Guido van Rossum | 2e63139 | 1996-12-18 18:37:27 +0000 | [diff] [blame] | 118 | |
Guido van Rossum | 43713e5 | 2000-02-29 13:59:29 +0000 | [diff] [blame] | 119 | if (!PyArg_ParseTuple(args, "i:getrlimit", &resource)) |
Guido van Rossum | 2e63139 | 1996-12-18 18:37:27 +0000 | [diff] [blame] | 120 | return NULL; |
| 121 | |
| 122 | if (resource < 0 || resource >= RLIM_NLIMITS) { |
| 123 | PyErr_SetString(PyExc_ValueError, |
| 124 | "invalid resource specified"); |
| 125 | return NULL; |
| 126 | } |
| 127 | |
| 128 | if (getrlimit(resource, &rl) == -1) { |
| 129 | PyErr_SetFromErrno(ResourceError); |
| 130 | return NULL; |
| 131 | } |
Guido van Rossum | 763737b | 1999-01-06 18:44:57 +0000 | [diff] [blame] | 132 | |
| 133 | #if defined(HAVE_LONG_LONG) |
| 134 | if (sizeof(rl.rlim_cur) > sizeof(long)) { |
| 135 | return Py_BuildValue("LL", |
Martin v. Löwis | b9a0f91 | 2003-03-29 10:06:18 +0000 | [diff] [blame] | 136 | (PY_LONG_LONG) rl.rlim_cur, |
| 137 | (PY_LONG_LONG) rl.rlim_max); |
Guido van Rossum | 763737b | 1999-01-06 18:44:57 +0000 | [diff] [blame] | 138 | } |
| 139 | #endif |
Neal Norwitz | 94a83fd | 2002-11-02 17:46:24 +0000 | [diff] [blame] | 140 | return Py_BuildValue("ll", (long) rl.rlim_cur, (long) rl.rlim_max); |
Guido van Rossum | 2e63139 | 1996-12-18 18:37:27 +0000 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | static PyObject * |
Peter Schneider-Kamp | 416d413 | 2000-07-10 12:15:54 +0000 | [diff] [blame] | 144 | resource_setrlimit(PyObject *self, PyObject *args) |
Guido van Rossum | 2e63139 | 1996-12-18 18:37:27 +0000 | [diff] [blame] | 145 | { |
| 146 | struct rlimit rl; |
| 147 | int resource; |
Guido van Rossum | 763737b | 1999-01-06 18:44:57 +0000 | [diff] [blame] | 148 | PyObject *curobj, *maxobj; |
Guido van Rossum | 2e63139 | 1996-12-18 18:37:27 +0000 | [diff] [blame] | 149 | |
Jeremy Hylton | d95efe4 | 2002-04-23 20:15:04 +0000 | [diff] [blame] | 150 | if (!PyArg_ParseTuple(args, "i(OO):setrlimit", |
| 151 | &resource, &curobj, &maxobj)) |
Guido van Rossum | 2e63139 | 1996-12-18 18:37:27 +0000 | [diff] [blame] | 152 | return NULL; |
| 153 | |
| 154 | if (resource < 0 || resource >= RLIM_NLIMITS) { |
| 155 | PyErr_SetString(PyExc_ValueError, |
| 156 | "invalid resource specified"); |
| 157 | return NULL; |
| 158 | } |
| 159 | |
Guido van Rossum | 763737b | 1999-01-06 18:44:57 +0000 | [diff] [blame] | 160 | #if !defined(HAVE_LARGEFILE_SUPPORT) |
Christian Heimes | 217cfd1 | 2007-12-02 14:31:20 +0000 | [diff] [blame] | 161 | rl.rlim_cur = PyLong_AsLong(curobj); |
Jeremy Hylton | d95efe4 | 2002-04-23 20:15:04 +0000 | [diff] [blame] | 162 | if (rl.rlim_cur == -1 && PyErr_Occurred()) |
| 163 | return NULL; |
Christian Heimes | 217cfd1 | 2007-12-02 14:31:20 +0000 | [diff] [blame] | 164 | rl.rlim_max = PyLong_AsLong(maxobj); |
Jeremy Hylton | d95efe4 | 2002-04-23 20:15:04 +0000 | [diff] [blame] | 165 | if (rl.rlim_max == -1 && PyErr_Occurred()) |
| 166 | return NULL; |
Guido van Rossum | 763737b | 1999-01-06 18:44:57 +0000 | [diff] [blame] | 167 | #else |
| 168 | /* The limits are probably bigger than a long */ |
| 169 | rl.rlim_cur = PyLong_Check(curobj) ? |
Christian Heimes | 217cfd1 | 2007-12-02 14:31:20 +0000 | [diff] [blame] | 170 | PyLong_AsLongLong(curobj) : PyLong_AsLong(curobj); |
Jeremy Hylton | d95efe4 | 2002-04-23 20:15:04 +0000 | [diff] [blame] | 171 | if (rl.rlim_cur == -1 && PyErr_Occurred()) |
| 172 | return NULL; |
Guido van Rossum | 763737b | 1999-01-06 18:44:57 +0000 | [diff] [blame] | 173 | rl.rlim_max = PyLong_Check(maxobj) ? |
Christian Heimes | 217cfd1 | 2007-12-02 14:31:20 +0000 | [diff] [blame] | 174 | PyLong_AsLongLong(maxobj) : PyLong_AsLong(maxobj); |
Jeremy Hylton | d95efe4 | 2002-04-23 20:15:04 +0000 | [diff] [blame] | 175 | if (rl.rlim_max == -1 && PyErr_Occurred()) |
| 176 | return NULL; |
Guido van Rossum | 763737b | 1999-01-06 18:44:57 +0000 | [diff] [blame] | 177 | #endif |
| 178 | |
Guido van Rossum | 2e63139 | 1996-12-18 18:37:27 +0000 | [diff] [blame] | 179 | rl.rlim_cur = rl.rlim_cur & RLIM_INFINITY; |
| 180 | rl.rlim_max = rl.rlim_max & RLIM_INFINITY; |
| 181 | if (setrlimit(resource, &rl) == -1) { |
| 182 | if (errno == EINVAL) |
| 183 | PyErr_SetString(PyExc_ValueError, |
| 184 | "current limit exceeds maximum limit"); |
| 185 | else if (errno == EPERM) |
| 186 | PyErr_SetString(PyExc_ValueError, |
| 187 | "not allowed to raise maximum limit"); |
| 188 | else |
| 189 | PyErr_SetFromErrno(ResourceError); |
| 190 | return NULL; |
| 191 | } |
| 192 | Py_INCREF(Py_None); |
| 193 | return Py_None; |
| 194 | } |
| 195 | |
| 196 | static PyObject * |
Thomas Wouters | 4d70c3d | 2006-06-08 14:42:34 +0000 | [diff] [blame] | 197 | resource_getpagesize(PyObject *self, PyObject *unused) |
Guido van Rossum | 2e63139 | 1996-12-18 18:37:27 +0000 | [diff] [blame] | 198 | { |
Neal Norwitz | 1ac3e39 | 2003-03-30 20:51:29 +0000 | [diff] [blame] | 199 | long pagesize = 0; |
Martin v. Löwis | f26d63b | 2003-03-30 17:23:49 +0000 | [diff] [blame] | 200 | #if defined(HAVE_GETPAGESIZE) |
| 201 | pagesize = getpagesize(); |
| 202 | #elif defined(HAVE_SYSCONF) |
Martin v. Löwis | 0cb3c63 | 2004-08-12 13:26:56 +0000 | [diff] [blame] | 203 | #if defined(_SC_PAGE_SIZE) |
Martin v. Löwis | f26d63b | 2003-03-30 17:23:49 +0000 | [diff] [blame] | 204 | pagesize = sysconf(_SC_PAGE_SIZE); |
Martin v. Löwis | 0cb3c63 | 2004-08-12 13:26:56 +0000 | [diff] [blame] | 205 | #else |
| 206 | /* Irix 5.3 has _SC_PAGESIZE, but not _SC_PAGE_SIZE */ |
| 207 | pagesize = sysconf(_SC_PAGESIZE); |
| 208 | #endif |
Martin v. Löwis | f26d63b | 2003-03-30 17:23:49 +0000 | [diff] [blame] | 209 | #endif |
| 210 | return Py_BuildValue("i", pagesize); |
| 211 | |
Guido van Rossum | 2e63139 | 1996-12-18 18:37:27 +0000 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | /* List of functions */ |
| 215 | |
| 216 | static struct PyMethodDef |
| 217 | resource_methods[] = { |
Martin v. Löwis | 43b936d | 2002-01-17 23:15:58 +0000 | [diff] [blame] | 218 | {"getrusage", resource_getrusage, METH_VARARGS}, |
| 219 | {"getrlimit", resource_getrlimit, METH_VARARGS}, |
| 220 | {"setrlimit", resource_setrlimit, METH_VARARGS}, |
Thomas Wouters | 4d70c3d | 2006-06-08 14:42:34 +0000 | [diff] [blame] | 221 | {"getpagesize", resource_getpagesize, METH_NOARGS}, |
Guido van Rossum | 2e63139 | 1996-12-18 18:37:27 +0000 | [diff] [blame] | 222 | {NULL, NULL} /* sentinel */ |
| 223 | }; |
| 224 | |
| 225 | |
| 226 | /* Module initialization */ |
| 227 | |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame^] | 228 | |
| 229 | static struct PyModuleDef resourcemodule = { |
| 230 | PyModuleDef_HEAD_INIT, |
| 231 | "resource", |
| 232 | NULL, |
| 233 | -1, |
| 234 | resource_methods, |
| 235 | NULL, |
| 236 | NULL, |
| 237 | NULL, |
| 238 | NULL |
| 239 | }; |
| 240 | |
Mark Hammond | fe51c6d | 2002-08-02 02:27:13 +0000 | [diff] [blame] | 241 | PyMODINIT_FUNC |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame^] | 242 | PyInit_resource(void) |
Guido van Rossum | 2e63139 | 1996-12-18 18:37:27 +0000 | [diff] [blame] | 243 | { |
Neil Schemenauer | 29ac3cb | 2002-03-24 22:27:39 +0000 | [diff] [blame] | 244 | PyObject *m, *v; |
Guido van Rossum | 2e63139 | 1996-12-18 18:37:27 +0000 | [diff] [blame] | 245 | |
| 246 | /* Create the module and add the functions */ |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame^] | 247 | m = PyModule_Create(&resourcemodule); |
Neal Norwitz | 1ac754f | 2006-01-19 06:09:39 +0000 | [diff] [blame] | 248 | if (m == NULL) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame^] | 249 | return NULL; |
Guido van Rossum | 2e63139 | 1996-12-18 18:37:27 +0000 | [diff] [blame] | 250 | |
| 251 | /* Add some symbolic constants to the module */ |
Fred Drake | cca657b | 2002-02-14 06:59:26 +0000 | [diff] [blame] | 252 | if (ResourceError == NULL) { |
| 253 | ResourceError = PyErr_NewException("resource.error", |
| 254 | NULL, NULL); |
| 255 | } |
| 256 | Py_INCREF(ResourceError); |
| 257 | PyModule_AddObject(m, "error", ResourceError); |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 258 | if (!initialized) |
| 259 | PyStructSequence_InitType(&StructRUsageType, |
| 260 | &struct_rusage_desc); |
| 261 | Py_INCREF(&StructRUsageType); |
Martin v. Löwis | 688357e | 2002-04-08 21:28:20 +0000 | [diff] [blame] | 262 | PyModule_AddObject(m, "struct_rusage", |
| 263 | (PyObject*) &StructRUsageType); |
Guido van Rossum | 2e63139 | 1996-12-18 18:37:27 +0000 | [diff] [blame] | 264 | |
| 265 | /* insert constants */ |
| 266 | #ifdef RLIMIT_CPU |
Fred Drake | cca657b | 2002-02-14 06:59:26 +0000 | [diff] [blame] | 267 | PyModule_AddIntConstant(m, "RLIMIT_CPU", RLIMIT_CPU); |
Guido van Rossum | 2e63139 | 1996-12-18 18:37:27 +0000 | [diff] [blame] | 268 | #endif |
| 269 | |
| 270 | #ifdef RLIMIT_FSIZE |
Fred Drake | cca657b | 2002-02-14 06:59:26 +0000 | [diff] [blame] | 271 | PyModule_AddIntConstant(m, "RLIMIT_FSIZE", RLIMIT_FSIZE); |
Guido van Rossum | 2e63139 | 1996-12-18 18:37:27 +0000 | [diff] [blame] | 272 | #endif |
| 273 | |
| 274 | #ifdef RLIMIT_DATA |
Fred Drake | cca657b | 2002-02-14 06:59:26 +0000 | [diff] [blame] | 275 | PyModule_AddIntConstant(m, "RLIMIT_DATA", RLIMIT_DATA); |
Guido van Rossum | 2e63139 | 1996-12-18 18:37:27 +0000 | [diff] [blame] | 276 | #endif |
| 277 | |
| 278 | #ifdef RLIMIT_STACK |
Fred Drake | cca657b | 2002-02-14 06:59:26 +0000 | [diff] [blame] | 279 | PyModule_AddIntConstant(m, "RLIMIT_STACK", RLIMIT_STACK); |
Guido van Rossum | 2e63139 | 1996-12-18 18:37:27 +0000 | [diff] [blame] | 280 | #endif |
| 281 | |
| 282 | #ifdef RLIMIT_CORE |
Fred Drake | cca657b | 2002-02-14 06:59:26 +0000 | [diff] [blame] | 283 | PyModule_AddIntConstant(m, "RLIMIT_CORE", RLIMIT_CORE); |
Guido van Rossum | 2e63139 | 1996-12-18 18:37:27 +0000 | [diff] [blame] | 284 | #endif |
| 285 | |
| 286 | #ifdef RLIMIT_NOFILE |
Fred Drake | cca657b | 2002-02-14 06:59:26 +0000 | [diff] [blame] | 287 | PyModule_AddIntConstant(m, "RLIMIT_NOFILE", RLIMIT_NOFILE); |
Guido van Rossum | 2e63139 | 1996-12-18 18:37:27 +0000 | [diff] [blame] | 288 | #endif |
| 289 | |
| 290 | #ifdef RLIMIT_OFILE |
Fred Drake | cca657b | 2002-02-14 06:59:26 +0000 | [diff] [blame] | 291 | PyModule_AddIntConstant(m, "RLIMIT_OFILE", RLIMIT_OFILE); |
Guido van Rossum | 2e63139 | 1996-12-18 18:37:27 +0000 | [diff] [blame] | 292 | #endif |
| 293 | |
| 294 | #ifdef RLIMIT_VMEM |
Fred Drake | cca657b | 2002-02-14 06:59:26 +0000 | [diff] [blame] | 295 | PyModule_AddIntConstant(m, "RLIMIT_VMEM", RLIMIT_VMEM); |
Guido van Rossum | 2e63139 | 1996-12-18 18:37:27 +0000 | [diff] [blame] | 296 | #endif |
| 297 | |
| 298 | #ifdef RLIMIT_AS |
Fred Drake | cca657b | 2002-02-14 06:59:26 +0000 | [diff] [blame] | 299 | PyModule_AddIntConstant(m, "RLIMIT_AS", RLIMIT_AS); |
Guido van Rossum | 2e63139 | 1996-12-18 18:37:27 +0000 | [diff] [blame] | 300 | #endif |
| 301 | |
| 302 | #ifdef RLIMIT_RSS |
Fred Drake | cca657b | 2002-02-14 06:59:26 +0000 | [diff] [blame] | 303 | PyModule_AddIntConstant(m, "RLIMIT_RSS", RLIMIT_RSS); |
Guido van Rossum | 2e63139 | 1996-12-18 18:37:27 +0000 | [diff] [blame] | 304 | #endif |
| 305 | |
| 306 | #ifdef RLIMIT_NPROC |
Fred Drake | cca657b | 2002-02-14 06:59:26 +0000 | [diff] [blame] | 307 | PyModule_AddIntConstant(m, "RLIMIT_NPROC", RLIMIT_NPROC); |
Guido van Rossum | 2e63139 | 1996-12-18 18:37:27 +0000 | [diff] [blame] | 308 | #endif |
| 309 | |
| 310 | #ifdef RLIMIT_MEMLOCK |
Fred Drake | cca657b | 2002-02-14 06:59:26 +0000 | [diff] [blame] | 311 | PyModule_AddIntConstant(m, "RLIMIT_MEMLOCK", RLIMIT_MEMLOCK); |
Guido van Rossum | 2e63139 | 1996-12-18 18:37:27 +0000 | [diff] [blame] | 312 | #endif |
| 313 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 314 | #ifdef RLIMIT_SBSIZE |
| 315 | PyModule_AddIntConstant(m, "RLIMIT_SBSIZE", RLIMIT_SBSIZE); |
| 316 | #endif |
| 317 | |
Guido van Rossum | 2e63139 | 1996-12-18 18:37:27 +0000 | [diff] [blame] | 318 | #ifdef RUSAGE_SELF |
Fred Drake | cca657b | 2002-02-14 06:59:26 +0000 | [diff] [blame] | 319 | PyModule_AddIntConstant(m, "RUSAGE_SELF", RUSAGE_SELF); |
Guido van Rossum | 2e63139 | 1996-12-18 18:37:27 +0000 | [diff] [blame] | 320 | #endif |
| 321 | |
Guido van Rossum | ebd05eb | 1997-12-09 19:35:48 +0000 | [diff] [blame] | 322 | #ifdef RUSAGE_CHILDREN |
Fred Drake | cca657b | 2002-02-14 06:59:26 +0000 | [diff] [blame] | 323 | PyModule_AddIntConstant(m, "RUSAGE_CHILDREN", RUSAGE_CHILDREN); |
Guido van Rossum | 2e63139 | 1996-12-18 18:37:27 +0000 | [diff] [blame] | 324 | #endif |
| 325 | |
| 326 | #ifdef RUSAGE_BOTH |
Fred Drake | cca657b | 2002-02-14 06:59:26 +0000 | [diff] [blame] | 327 | PyModule_AddIntConstant(m, "RUSAGE_BOTH", RUSAGE_BOTH); |
Guido van Rossum | 2e63139 | 1996-12-18 18:37:27 +0000 | [diff] [blame] | 328 | #endif |
Neil Schemenauer | 29ac3cb | 2002-03-24 22:27:39 +0000 | [diff] [blame] | 329 | |
| 330 | #if defined(HAVE_LONG_LONG) |
| 331 | if (sizeof(RLIM_INFINITY) > sizeof(long)) { |
Martin v. Löwis | b9a0f91 | 2003-03-29 10:06:18 +0000 | [diff] [blame] | 332 | v = PyLong_FromLongLong((PY_LONG_LONG) RLIM_INFINITY); |
Neil Schemenauer | 29ac3cb | 2002-03-24 22:27:39 +0000 | [diff] [blame] | 333 | } else |
| 334 | #endif |
| 335 | { |
Christian Heimes | 217cfd1 | 2007-12-02 14:31:20 +0000 | [diff] [blame] | 336 | v = PyLong_FromLong((long) RLIM_INFINITY); |
Neil Schemenauer | 29ac3cb | 2002-03-24 22:27:39 +0000 | [diff] [blame] | 337 | } |
| 338 | if (v) { |
| 339 | PyModule_AddObject(m, "RLIM_INFINITY", v); |
| 340 | } |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 341 | initialized = 1; |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame^] | 342 | return m; |
Guido van Rossum | 2e63139 | 1996-12-18 18:37:27 +0000 | [diff] [blame] | 343 | } |