mirror of
https://github.com/python/cpython.git
synced 2025-11-01 10:45:30 +00:00
gh-116404: Handle errors correctly in wait_helper in posixmodule (#116405)
This commit is contained in:
parent
d2f1b0eb49
commit
22ccf13b33
1 changed files with 28 additions and 25 deletions
|
|
@ -9577,36 +9577,39 @@ wait_helper(PyObject *module, pid_t pid, int status, struct rusage *ru)
|
|||
if (!result)
|
||||
return NULL;
|
||||
|
||||
int pos = 0;
|
||||
|
||||
#ifndef doubletime
|
||||
#define doubletime(TV) ((double)(TV).tv_sec + (TV).tv_usec * 0.000001)
|
||||
#endif
|
||||
|
||||
PyStructSequence_SET_ITEM(result, 0,
|
||||
PyFloat_FromDouble(doubletime(ru->ru_utime)));
|
||||
PyStructSequence_SET_ITEM(result, 1,
|
||||
PyFloat_FromDouble(doubletime(ru->ru_stime)));
|
||||
#define SET_INT(result, index, value)\
|
||||
PyStructSequence_SET_ITEM(result, index, PyLong_FromLong(value))
|
||||
SET_INT(result, 2, ru->ru_maxrss);
|
||||
SET_INT(result, 3, ru->ru_ixrss);
|
||||
SET_INT(result, 4, ru->ru_idrss);
|
||||
SET_INT(result, 5, ru->ru_isrss);
|
||||
SET_INT(result, 6, ru->ru_minflt);
|
||||
SET_INT(result, 7, ru->ru_majflt);
|
||||
SET_INT(result, 8, ru->ru_nswap);
|
||||
SET_INT(result, 9, ru->ru_inblock);
|
||||
SET_INT(result, 10, ru->ru_oublock);
|
||||
SET_INT(result, 11, ru->ru_msgsnd);
|
||||
SET_INT(result, 12, ru->ru_msgrcv);
|
||||
SET_INT(result, 13, ru->ru_nsignals);
|
||||
SET_INT(result, 14, ru->ru_nvcsw);
|
||||
SET_INT(result, 15, ru->ru_nivcsw);
|
||||
#undef SET_INT
|
||||
#define SET_RESULT(CALL) \
|
||||
do { \
|
||||
PyObject *item = (CALL); \
|
||||
if (item == NULL) { \
|
||||
Py_DECREF(result); \
|
||||
return NULL; \
|
||||
} \
|
||||
PyStructSequence_SET_ITEM(result, pos++, item); \
|
||||
} while(0)
|
||||
|
||||
if (PyErr_Occurred()) {
|
||||
Py_DECREF(result);
|
||||
return NULL;
|
||||
}
|
||||
SET_RESULT(PyFloat_FromDouble(doubletime(ru->ru_utime)));
|
||||
SET_RESULT(PyFloat_FromDouble(doubletime(ru->ru_stime)));
|
||||
SET_RESULT(PyLong_FromLong(ru->ru_maxrss));
|
||||
SET_RESULT(PyLong_FromLong(ru->ru_ixrss));
|
||||
SET_RESULT(PyLong_FromLong(ru->ru_idrss));
|
||||
SET_RESULT(PyLong_FromLong(ru->ru_isrss));
|
||||
SET_RESULT(PyLong_FromLong(ru->ru_minflt));
|
||||
SET_RESULT(PyLong_FromLong(ru->ru_majflt));
|
||||
SET_RESULT(PyLong_FromLong(ru->ru_nswap));
|
||||
SET_RESULT(PyLong_FromLong(ru->ru_inblock));
|
||||
SET_RESULT(PyLong_FromLong(ru->ru_oublock));
|
||||
SET_RESULT(PyLong_FromLong(ru->ru_msgsnd));
|
||||
SET_RESULT(PyLong_FromLong(ru->ru_msgrcv));
|
||||
SET_RESULT(PyLong_FromLong(ru->ru_nsignals));
|
||||
SET_RESULT(PyLong_FromLong(ru->ru_nvcsw));
|
||||
SET_RESULT(PyLong_FromLong(ru->ru_nivcsw));
|
||||
#undef SET_RESULT
|
||||
|
||||
return Py_BuildValue("NiN", PyLong_FromPid(pid), status, result);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue