Skip to content

Commit fa7f278

Browse files
[3.11] gh-116448: Handle errors correctly in os_waitid_impl in posixmodule (GH-116449) (#116453)
gh-116448: Handle errors correctly in `os_waitid_impl` in `posixmodule` (GH-116449) (cherry picked from commit 882fced) Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
1 parent e89f2a0 commit fa7f278

1 file changed

Lines changed: 19 additions & 9 deletions

File tree

Modules/posixmodule.c

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8547,15 +8547,25 @@ os_waitid_impl(PyObject *module, idtype_t idtype, id_t id, int options)
85478547
if (!result)
85488548
return NULL;
85498549

8550-
PyStructSequence_SET_ITEM(result, 0, PyLong_FromPid(si.si_pid));
8551-
PyStructSequence_SET_ITEM(result, 1, _PyLong_FromUid(si.si_uid));
8552-
PyStructSequence_SET_ITEM(result, 2, PyLong_FromLong((long)(si.si_signo)));
8553-
PyStructSequence_SET_ITEM(result, 3, PyLong_FromLong((long)(si.si_status)));
8554-
PyStructSequence_SET_ITEM(result, 4, PyLong_FromLong((long)(si.si_code)));
8555-
if (PyErr_Occurred()) {
8556-
Py_DECREF(result);
8557-
return NULL;
8558-
}
8550+
int pos = 0;
8551+
8552+
#define SET_RESULT(CALL) \
8553+
do { \
8554+
PyObject *item = (CALL); \
8555+
if (item == NULL) { \
8556+
Py_DECREF(result); \
8557+
return NULL; \
8558+
} \
8559+
PyStructSequence_SET_ITEM(result, pos++, item); \
8560+
} while(0)
8561+
8562+
SET_RESULT(PyLong_FromPid(si.si_pid));
8563+
SET_RESULT(_PyLong_FromUid(si.si_uid));
8564+
SET_RESULT(PyLong_FromLong((long)(si.si_signo)));
8565+
SET_RESULT(PyLong_FromLong((long)(si.si_status)));
8566+
SET_RESULT(PyLong_FromLong((long)(si.si_code)));
8567+
8568+
#undef SET_RESULT
85598569

85608570
return result;
85618571
}

0 commit comments

Comments
 (0)