resource.c.h 4.4 KB

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