mirror of https://github.com/python/cpython
gh-94512: Fix forced arg format in AC-processed resource (GH-94515)
This commit is contained in:
parent
e003b64f40
commit
a739ee412c
|
@ -95,41 +95,42 @@ exit:
|
||||||
#if defined(HAVE_PRLIMIT)
|
#if defined(HAVE_PRLIMIT)
|
||||||
|
|
||||||
PyDoc_STRVAR(resource_prlimit__doc__,
|
PyDoc_STRVAR(resource_prlimit__doc__,
|
||||||
"prlimit(pid, resource, [limits])");
|
"prlimit($module, pid, resource, limits=None, /)\n"
|
||||||
|
"--\n"
|
||||||
|
"\n");
|
||||||
|
|
||||||
#define RESOURCE_PRLIMIT_METHODDEF \
|
#define RESOURCE_PRLIMIT_METHODDEF \
|
||||||
{"prlimit", (PyCFunction)resource_prlimit, METH_VARARGS, resource_prlimit__doc__},
|
{"prlimit", _PyCFunction_CAST(resource_prlimit), METH_FASTCALL, resource_prlimit__doc__},
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
resource_prlimit_impl(PyObject *module, pid_t pid, int resource,
|
resource_prlimit_impl(PyObject *module, pid_t pid, int resource,
|
||||||
int group_right_1, PyObject *limits);
|
PyObject *limits);
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
resource_prlimit(PyObject *module, PyObject *args)
|
resource_prlimit(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
|
||||||
{
|
{
|
||||||
PyObject *return_value = NULL;
|
PyObject *return_value = NULL;
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
int resource;
|
int resource;
|
||||||
int group_right_1 = 0;
|
PyObject *limits = Py_None;
|
||||||
PyObject *limits = NULL;
|
|
||||||
|
|
||||||
switch (PyTuple_GET_SIZE(args)) {
|
if (!_PyArg_CheckPositional("prlimit", nargs, 2, 3)) {
|
||||||
case 2:
|
goto exit;
|
||||||
if (!PyArg_ParseTuple(args, "" _Py_PARSE_PID "i:prlimit", &pid, &resource)) {
|
|
||||||
goto exit;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
if (!PyArg_ParseTuple(args, "" _Py_PARSE_PID "iO:prlimit", &pid, &resource, &limits)) {
|
|
||||||
goto exit;
|
|
||||||
}
|
|
||||||
group_right_1 = 1;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
PyErr_SetString(PyExc_TypeError, "resource.prlimit requires 2 to 3 arguments");
|
|
||||||
goto exit;
|
|
||||||
}
|
}
|
||||||
return_value = resource_prlimit_impl(module, pid, resource, group_right_1, limits);
|
pid = PyLong_AsPid(args[0]);
|
||||||
|
if (pid == -1 && PyErr_Occurred()) {
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
resource = _PyLong_AsInt(args[1]);
|
||||||
|
if (resource == -1 && PyErr_Occurred()) {
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
if (nargs < 3) {
|
||||||
|
goto skip_optional;
|
||||||
|
}
|
||||||
|
limits = args[2];
|
||||||
|
skip_optional:
|
||||||
|
return_value = resource_prlimit_impl(module, pid, resource, limits);
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
return return_value;
|
return return_value;
|
||||||
|
@ -171,4 +172,4 @@ exit:
|
||||||
#ifndef RESOURCE_PRLIMIT_METHODDEF
|
#ifndef RESOURCE_PRLIMIT_METHODDEF
|
||||||
#define RESOURCE_PRLIMIT_METHODDEF
|
#define RESOURCE_PRLIMIT_METHODDEF
|
||||||
#endif /* !defined(RESOURCE_PRLIMIT_METHODDEF) */
|
#endif /* !defined(RESOURCE_PRLIMIT_METHODDEF) */
|
||||||
/*[clinic end generated code: output=7c57d4f3688d3f07 input=a9049054013a1b77]*/
|
/*[clinic end generated code: output=13441806729c6eaa input=a9049054013a1b77]*/
|
||||||
|
|
|
@ -24,8 +24,16 @@ module resource
|
||||||
class pid_t_converter(CConverter):
|
class pid_t_converter(CConverter):
|
||||||
type = 'pid_t'
|
type = 'pid_t'
|
||||||
format_unit = '" _Py_PARSE_PID "'
|
format_unit = '" _Py_PARSE_PID "'
|
||||||
|
|
||||||
|
def parse_arg(self, argname, displayname):
|
||||||
|
return """
|
||||||
|
{paramname} = PyLong_AsPid({argname});
|
||||||
|
if ({paramname} == -1 && PyErr_Occurred()) {{{{
|
||||||
|
goto exit;
|
||||||
|
}}}}
|
||||||
|
""".format(argname=argname, paramname=self.parser_name)
|
||||||
[python start generated code]*/
|
[python start generated code]*/
|
||||||
/*[python end generated code: output=da39a3ee5e6b4b0d input=0c1d19f640d57e48]*/
|
/*[python end generated code: output=da39a3ee5e6b4b0d input=5af1c116d56cbb5a]*/
|
||||||
|
|
||||||
#include "clinic/resource.c.h"
|
#include "clinic/resource.c.h"
|
||||||
|
|
||||||
|
@ -268,17 +276,15 @@ resource.prlimit
|
||||||
|
|
||||||
pid: pid_t
|
pid: pid_t
|
||||||
resource: int
|
resource: int
|
||||||
[
|
limits: object = None
|
||||||
limits: object
|
|
||||||
]
|
|
||||||
/
|
/
|
||||||
|
|
||||||
[clinic start generated code]*/
|
[clinic start generated code]*/
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
resource_prlimit_impl(PyObject *module, pid_t pid, int resource,
|
resource_prlimit_impl(PyObject *module, pid_t pid, int resource,
|
||||||
int group_right_1, PyObject *limits)
|
PyObject *limits)
|
||||||
/*[clinic end generated code: output=ee976b393187a7a3 input=b77743bdccc83564]*/
|
/*[clinic end generated code: output=6ebc49ff8c3a816e input=54bb69c9585e33bf]*/
|
||||||
{
|
{
|
||||||
struct rlimit old_limit, new_limit;
|
struct rlimit old_limit, new_limit;
|
||||||
int retval;
|
int retval;
|
||||||
|
@ -294,7 +300,7 @@ resource_prlimit_impl(PyObject *module, pid_t pid, int resource,
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (group_right_1) {
|
if (limits != Py_None) {
|
||||||
if (py2rlimit(limits, &new_limit) < 0) {
|
if (py2rlimit(limits, &new_limit) < 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue