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