Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 29 additions & 26 deletions Modules/posixmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -9245,36 +9245,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

if (PyErr_Occurred()) {
Py_DECREF(result);
return NULL;
}
#define SET_RESULT(CALL) \
do { \
PyObject *item = (CALL); \
if (item == NULL) { \
Py_DECREF(result); \
return NULL; \
} \
PyStructSequence_SET_ITEM(result, pos++, item); \
} while(0)

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);
}
Expand Down