mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
gh-137044: Make resource.RLIM_INFINITY always positive (GH-137511)
It is now a positive integer larger larger than any limited resource value. This simplifies comparison of the resource values. Previously, it could be negative, such as -1 or -3, depending on platform. Deprecation warning is emitted if the old negative value is passed.
This commit is contained in:
parent
138ed6db9f
commit
0324c726de
5 changed files with 45 additions and 26 deletions
|
|
@ -164,7 +164,14 @@ py2rlim(PyObject *obj, rlim_t *out)
|
|||
if (bytes < 0) {
|
||||
return -1;
|
||||
}
|
||||
else if (neg && (*out != RLIM_INFINITY || bytes > (Py_ssize_t)sizeof(*out))) {
|
||||
else if (neg && *out == RLIM_INFINITY && bytes <= (Py_ssize_t)sizeof(*out)) {
|
||||
if (PyErr_WarnEx(PyExc_DeprecationWarning,
|
||||
"Use RLIM_INFINITY instead of negative limit value.", 1))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else if (neg) {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"Cannot convert negative int");
|
||||
return -1;
|
||||
|
|
@ -210,9 +217,6 @@ py2rlimit(PyObject *limits, struct rlimit *rl_out)
|
|||
static PyObject*
|
||||
rlim2py(rlim_t value)
|
||||
{
|
||||
if (value == RLIM_INFINITY) {
|
||||
return PyLong_FromNativeBytes(&value, sizeof(value), -1);
|
||||
}
|
||||
return PyLong_FromUnsignedNativeBytes(&value, sizeof(value), -1);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue