LCOV - code coverage report
Current view: top level - Modules/clinic - resource.c.h (source / functions) Hit Total Coverage
Test: CPython lcov report Lines: 49 55 89.1 %
Date: 2022-07-07 18:19:46 Functions: 5 5 100.0 %

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

Generated by: LCOV version 1.14