Skip to content

Commit cbd94fd

Browse files
[3.12] gh-116448: Handle errors correctly in os_waitid_impl in posixmodule (GH-116449) (#116451)
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 1e75fe1 commit cbd94fd

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

Modules/posixmodule.c

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

9403-
PyStructSequence_SET_ITEM(result, 0, PyLong_FromPid(si.si_pid));
9404-
PyStructSequence_SET_ITEM(result, 1, _PyLong_FromUid(si.si_uid));
9405-
PyStructSequence_SET_ITEM(result, 2, PyLong_FromLong((long)(si.si_signo)));
9406-
PyStructSequence_SET_ITEM(result, 3, PyLong_FromLong((long)(si.si_status)));
9407-
PyStructSequence_SET_ITEM(result, 4, PyLong_FromLong((long)(si.si_code)));
9408-
if (PyErr_Occurred()) {
9409-
Py_DECREF(result);
9410-
return NULL;
9411-
}
9403+
int pos = 0;
9404+
9405+
#define SET_RESULT(CALL) \
9406+
do { \
9407+
PyObject *item = (CALL); \
9408+
if (item == NULL) { \
9409+
Py_DECREF(result); \
9410+
return NULL; \
9411+
} \
9412+
PyStructSequence_SET_ITEM(result, pos++, item); \
9413+
} while(0)
9414+
9415+
SET_RESULT(PyLong_FromPid(si.si_pid));
9416+
SET_RESULT(_PyLong_FromUid(si.si_uid));
9417+
SET_RESULT(PyLong_FromLong((long)(si.si_signo)));
9418+
SET_RESULT(PyLong_FromLong((long)(si.si_status)));
9419+
SET_RESULT(PyLong_FromLong((long)(si.si_code)));
9420+
9421+
#undef SET_RESULT
94129422

94139423
return result;
94149424
}

0 commit comments

Comments
 (0)