summaryrefslogtreecommitdiff
path: root/Modules/resource.c
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2017-03-12 13:08:30 +0200
committerGitHub <noreply@github.com>2017-03-12 13:08:30 +0200
commit1989763f0d0858ce6274f5e1d725b5b8da91a780 (patch)
treebf1653613dc1450a466849554a72742b87c0dbe5 /Modules/resource.c
parentd2977a3ae2cc6802921b1e3b6e9d13fcfbda872d (diff)
downloadcpython-git-1989763f0d0858ce6274f5e1d725b5b8da91a780.tar.gz
bpo-20185: Convert the resource moduel to Argument Clinic. (#545)
Based on patch by Vajrasky Kok.
Diffstat (limited to 'Modules/resource.c')
-rw-r--r--Modules/resource.c111
1 files changed, 75 insertions, 36 deletions
diff --git a/Modules/resource.c b/Modules/resource.c
index 113ad5c3d0..e59280f249 100644
--- a/Modules/resource.c
+++ b/Modules/resource.c
@@ -18,6 +18,20 @@
#define doubletime(TV) ((double)(TV).tv_sec + (TV).tv_usec * 0.000001)
+/*[clinic input]
+module resource
+[clinic start generated code]*/
+/*[clinic end generated code: output=da39a3ee5e6b4b0d input=e89d38ed52609d7c]*/
+
+/*[python input]
+class pid_t_converter(CConverter):
+ type = 'pid_t'
+ format_unit = '" _Py_PARSE_PID "'
+[python start generated code]*/
+/*[python end generated code: output=da39a3ee5e6b4b0d input=0c1d19f640d57e48]*/
+
+#include "clinic/resource.c.h"
+
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 +69,21 @@ static PyStructSequence_Desc struct_rusage_desc = {
static int initialized;
static PyTypeObject StructRUsageType;
+/*[clinic input]
+resource.getrusage
+
+ who: int
+ /
+
+[clinic start generated code]*/
+
static PyObject *
-resource_getrusage(PyObject *self, PyObject *args)
+resource_getrusage_impl(PyObject *module, int who)
+/*[clinic end generated code: output=8fad2880ba6a9843 input=5c857bcc5b9ccb1b]*/
{
- int who;
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,
@@ -160,14 +179,19 @@ rlimit2py(struct rlimit rl)
return Py_BuildValue("ll", (long) rl.rlim_cur, (long) rl.rlim_max);
}
+/*[clinic input]
+resource.getrlimit
+
+ resource: int
+ /
+
+[clinic start generated code]*/
+
static PyObject *
-resource_getrlimit(PyObject *self, PyObject *args)
+resource_getrlimit_impl(PyObject *module, int resource)
+/*[clinic end generated code: output=98327b25061ffe39 input=a697cb0004cb3c36]*/
{
struct rlimit rl;
- int resource;
-
- if (!PyArg_ParseTuple(args, "i:getrlimit", &resource))
- return NULL;
if (resource < 0 || resource >= RLIM_NLIMITS) {
PyErr_SetString(PyExc_ValueError,
@@ -182,15 +206,20 @@ resource_getrlimit(PyObject *self, PyObject *args)
return rlimit2py(rl);
}
+/*[clinic input]
+resource.setrlimit
+
+ resource: int
+ limits: object
+ /
+
+[clinic start generated code]*/
+
static PyObject *
-resource_setrlimit(PyObject *self, PyObject *args)
+resource_setrlimit_impl(PyObject *module, int resource, PyObject *limits)
+/*[clinic end generated code: output=4e82ec3f34d013d1 input=6235a6ce23b4ca75]*/
{
struct rlimit rl;
- int resource;
- PyObject *limits;
-
- if (!PyArg_ParseTuple(args, "iO:setrlimit", &resource, &limits))
- return NULL;
if (resource < 0 || resource >= RLIM_NLIMITS) {
PyErr_SetString(PyExc_ValueError,
@@ -217,17 +246,25 @@ resource_setrlimit(PyObject *self, PyObject *args)
}
#ifdef HAVE_PRLIMIT
+/*[clinic input]
+resource.prlimit
+
+ pid: pid_t
+ resource: int
+ [
+ limits: object
+ ]
+ /
+
+[clinic start generated code]*/
+
static PyObject *
-resource_prlimit(PyObject *self, PyObject *args)
+resource_prlimit_impl(PyObject *module, pid_t pid, int resource,
+ int group_right_1, PyObject *limits)
+/*[clinic end generated code: output=ee976b393187a7a3 input=b77743bdccc83564]*/
{
struct rlimit old_limit, new_limit;
- int resource, retval;
- pid_t pid;
- PyObject *limits = NULL;
-
- if (!PyArg_ParseTuple(args, _Py_PARSE_PID "i|O:prlimit",
- &pid, &resource, &limits))
- return NULL;
+ int retval;
if (resource < 0 || resource >= RLIM_NLIMITS) {
PyErr_SetString(PyExc_ValueError,
@@ -235,7 +272,7 @@ resource_prlimit(PyObject *self, PyObject *args)
return NULL;
}
- if (limits != NULL) {
+ if (group_right_1) {
if (py2rlimit(limits, &new_limit) < 0) {
return NULL;
}
@@ -258,8 +295,13 @@ resource_prlimit(PyObject *self, PyObject *args)
}
#endif /* HAVE_PRLIMIT */
-static PyObject *
-resource_getpagesize(PyObject *self, PyObject *unused)
+/*[clinic input]
+resource.getpagesize -> int
+[clinic start generated code]*/
+
+static int
+resource_getpagesize_impl(PyObject *module)
+/*[clinic end generated code: output=9ba93eb0f3d6c3a9 input=546545e8c1f42085]*/
{
long pagesize = 0;
#if defined(HAVE_GETPAGESIZE)
@@ -272,21 +314,18 @@ resource_getpagesize(PyObject *self, PyObject *unused)
pagesize = sysconf(_SC_PAGESIZE);
#endif
#endif
- return Py_BuildValue("i", pagesize);
-
+ return pagesize;
}
/* List of functions */
static struct PyMethodDef
resource_methods[] = {
- {"getrusage", resource_getrusage, METH_VARARGS},
- {"getrlimit", resource_getrlimit, METH_VARARGS},
-#ifdef HAVE_PRLIMIT
- {"prlimit", resource_prlimit, METH_VARARGS},
-#endif
- {"setrlimit", resource_setrlimit, METH_VARARGS},
- {"getpagesize", resource_getpagesize, METH_NOARGS},
+ RESOURCE_GETRUSAGE_METHODDEF
+ RESOURCE_GETRLIMIT_METHODDEF
+ RESOURCE_PRLIMIT_METHODDEF
+ RESOURCE_SETRLIMIT_METHODDEF
+ RESOURCE_GETPAGESIZE_METHODDEF
{NULL, NULL} /* sentinel */
};