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