diff -r f35b3a86ade3 Modules/resource.c --- a/Modules/resource.c Tue Jan 14 16:48:31 2014 -0600 +++ b/Modules/resource.c Wed Jan 15 12:22:44 2014 +0800 @@ -18,6 +18,11 @@ #define doubletime(TV) ((double)(TV).tv_sec + (TV).tv_usec * 0.000001) +/*[clinic input] +module resource +[clinic start generated code]*/ +/*[clinic end generated code: checksum=da39a3ee5e6b4b0d3255bfef95601890afd80709]*/ + PyDoc_STRVAR(struct_rusage__doc__, "struct_rusage: Result from getrusage.\n\n" "This object may be accessed either as a tuple of\n" @@ -55,16 +60,46 @@ static int initialized; static PyTypeObject StructRUsageType; +/*[clinic input] +resource.getrusage + + who: int + / + +[clinic start generated code]*/ + +PyDoc_STRVAR(resource_getrusage__doc__, +"getrusage(who)"); + +#define RESOURCE_GETRUSAGE_METHODDEF \ + {"getrusage", (PyCFunction)resource_getrusage, METH_VARARGS, resource_getrusage__doc__}, + static PyObject * -resource_getrusage(PyObject *self, PyObject *args) +resource_getrusage_impl(PyModuleDef *module, int who); + +static PyObject * +resource_getrusage(PyModuleDef *module, PyObject *args) { + PyObject *return_value = NULL; int who; + + if (!PyArg_ParseTuple(args, + "i:getrusage", + &who)) + goto exit; + return_value = resource_getrusage_impl(module, who); + +exit: + return return_value; +} + +static PyObject * +resource_getrusage_impl(PyModuleDef *module, int who) +/*[clinic end generated code: checksum=bf96ead497199e1c78e1b4c184f68583d6a45dd2]*/ +{ struct rusage ru; PyObject *result; - if (!PyArg_ParseTuple(args, "i:getrusage", &who)) - return NULL; - if (getrusage(who, &ru) == -1) { if (errno == EINVAL) { PyErr_SetString(PyExc_ValueError, @@ -145,14 +180,44 @@ return Py_BuildValue("ll", (long) rl.rlim_cur, (long) rl.rlim_max); } +/*[clinic input] +resource.getrlimit + + resource: int + / + +[clinic start generated code]*/ + +PyDoc_STRVAR(resource_getrlimit__doc__, +"getrlimit(resource)"); + +#define RESOURCE_GETRLIMIT_METHODDEF \ + {"getrlimit", (PyCFunction)resource_getrlimit, METH_VARARGS, resource_getrlimit__doc__}, + static PyObject * -resource_getrlimit(PyObject *self, PyObject *args) +resource_getrlimit_impl(PyModuleDef *module, int resource); + +static PyObject * +resource_getrlimit(PyModuleDef *module, PyObject *args) +{ + PyObject *return_value = NULL; + int resource; + + if (!PyArg_ParseTuple(args, + "i:getrlimit", + &resource)) + goto exit; + return_value = resource_getrlimit_impl(module, resource); + +exit: + return return_value; +} + +static PyObject * +resource_getrlimit_impl(PyModuleDef *module, int resource) +/*[clinic end generated code: checksum=b2af08b015c5d8e5c7ae50a6922f5ddcedf6e845]*/ { struct rlimit rl; - int resource; - - if (!PyArg_ParseTuple(args, "i:getrlimit", &resource)) - return NULL; if (resource < 0 || resource >= RLIM_NLIMITS) { PyErr_SetString(PyExc_ValueError, @@ -167,15 +232,47 @@ return rlimit2py(rl); } +/*[clinic input] +resource.setrlimit + + resource: int + limits: object + / + +[clinic start generated code]*/ + +PyDoc_STRVAR(resource_setrlimit__doc__, +"setrlimit(resource, limits)"); + +#define RESOURCE_SETRLIMIT_METHODDEF \ + {"setrlimit", (PyCFunction)resource_setrlimit, METH_VARARGS, resource_setrlimit__doc__}, + static PyObject * -resource_setrlimit(PyObject *self, PyObject *args) +resource_setrlimit_impl(PyModuleDef *module, int resource, PyObject *limits); + +static PyObject * +resource_setrlimit(PyModuleDef *module, PyObject *args) +{ + PyObject *return_value = NULL; + int resource; + PyObject *limits; + + if (!PyArg_ParseTuple(args, + "iO:setrlimit", + &resource, &limits)) + goto exit; + return_value = resource_setrlimit_impl(module, resource, limits); + +exit: + return return_value; +} + +static PyObject * +resource_setrlimit_impl(PyModuleDef *module, int resource, PyObject *limits) +/*[clinic end generated code: checksum=274797f28b5a824d8dfff3caf861acf6cdffca2d]*/ { struct rlimit rl; - int resource; - PyObject *limits, *curobj, *maxobj; - - if (!PyArg_ParseTuple(args, "iO:setrlimit", &resource, &limits)) - return NULL; + PyObject *curobj, *maxobj; if (resource < 0 || resource >= RLIM_NLIMITS) { PyErr_SetString(PyExc_ValueError, @@ -284,12 +381,12 @@ static struct PyMethodDef resource_methods[] = { - {"getrusage", resource_getrusage, METH_VARARGS}, - {"getrlimit", resource_getrlimit, METH_VARARGS}, + RESOURCE_GETRUSAGE_METHODDEF + RESOURCE_GETRLIMIT_METHODDEF #ifdef HAVE_PRLIMIT {"prlimit", resource_prlimit, METH_VARARGS}, #endif - {"setrlimit", resource_setrlimit, METH_VARARGS}, + RESOURCE_SETRLIMIT_METHODDEF {"getpagesize", resource_getpagesize, METH_NOARGS}, {NULL, NULL} /* sentinel */ };