mirror of https://github.com/python/cpython
gh-116541: Handle errors correctly in `_pystatvfs_fromstructstatvfs` (#116542)
This commit is contained in:
parent
d308d33e09
commit
f8147d01da
|
@ -12980,46 +12980,50 @@ _pystatvfs_fromstructstatvfs(PyObject *module, struct statvfs st) {
|
|||
if (v == NULL)
|
||||
return NULL;
|
||||
|
||||
int pos = 0;
|
||||
|
||||
#define SET_RESULT(CALL) \
|
||||
do { \
|
||||
PyObject *item = (CALL); \
|
||||
if (item == NULL) { \
|
||||
Py_DECREF(v); \
|
||||
return NULL; \
|
||||
} \
|
||||
PyStructSequence_SET_ITEM(v, pos++, item); \
|
||||
} while(0)
|
||||
|
||||
#if !defined(HAVE_LARGEFILE_SUPPORT)
|
||||
PyStructSequence_SET_ITEM(v, 0, PyLong_FromLong((long) st.f_bsize));
|
||||
PyStructSequence_SET_ITEM(v, 1, PyLong_FromLong((long) st.f_frsize));
|
||||
PyStructSequence_SET_ITEM(v, 2, PyLong_FromLong((long) st.f_blocks));
|
||||
PyStructSequence_SET_ITEM(v, 3, PyLong_FromLong((long) st.f_bfree));
|
||||
PyStructSequence_SET_ITEM(v, 4, PyLong_FromLong((long) st.f_bavail));
|
||||
PyStructSequence_SET_ITEM(v, 5, PyLong_FromLong((long) st.f_files));
|
||||
PyStructSequence_SET_ITEM(v, 6, PyLong_FromLong((long) st.f_ffree));
|
||||
PyStructSequence_SET_ITEM(v, 7, PyLong_FromLong((long) st.f_favail));
|
||||
PyStructSequence_SET_ITEM(v, 8, PyLong_FromLong((long) st.f_flag));
|
||||
PyStructSequence_SET_ITEM(v, 9, PyLong_FromLong((long) st.f_namemax));
|
||||
SET_RESULT(PyLong_FromLong((long) st.f_bsize));
|
||||
SET_RESULT(PyLong_FromLong((long) st.f_frsize));
|
||||
SET_RESULT(PyLong_FromLong((long) st.f_blocks));
|
||||
SET_RESULT(PyLong_FromLong((long) st.f_bfree));
|
||||
SET_RESULT(PyLong_FromLong((long) st.f_bavail));
|
||||
SET_RESULT(PyLong_FromLong((long) st.f_files));
|
||||
SET_RESULT(PyLong_FromLong((long) st.f_ffree));
|
||||
SET_RESULT(PyLong_FromLong((long) st.f_favail));
|
||||
SET_RESULT(PyLong_FromLong((long) st.f_flag));
|
||||
SET_RESULT(PyLong_FromLong((long) st.f_namemax));
|
||||
#else
|
||||
PyStructSequence_SET_ITEM(v, 0, PyLong_FromLong((long) st.f_bsize));
|
||||
PyStructSequence_SET_ITEM(v, 1, PyLong_FromLong((long) st.f_frsize));
|
||||
PyStructSequence_SET_ITEM(v, 2,
|
||||
PyLong_FromLongLong((long long) st.f_blocks));
|
||||
PyStructSequence_SET_ITEM(v, 3,
|
||||
PyLong_FromLongLong((long long) st.f_bfree));
|
||||
PyStructSequence_SET_ITEM(v, 4,
|
||||
PyLong_FromLongLong((long long) st.f_bavail));
|
||||
PyStructSequence_SET_ITEM(v, 5,
|
||||
PyLong_FromLongLong((long long) st.f_files));
|
||||
PyStructSequence_SET_ITEM(v, 6,
|
||||
PyLong_FromLongLong((long long) st.f_ffree));
|
||||
PyStructSequence_SET_ITEM(v, 7,
|
||||
PyLong_FromLongLong((long long) st.f_favail));
|
||||
PyStructSequence_SET_ITEM(v, 8, PyLong_FromLong((long) st.f_flag));
|
||||
PyStructSequence_SET_ITEM(v, 9, PyLong_FromLong((long) st.f_namemax));
|
||||
SET_RESULT(PyLong_FromLong((long) st.f_bsize));
|
||||
SET_RESULT(PyLong_FromLong((long) st.f_frsize));
|
||||
SET_RESULT(PyLong_FromLongLong((long long) st.f_blocks));
|
||||
SET_RESULT(PyLong_FromLongLong((long long) st.f_bfree));
|
||||
SET_RESULT(PyLong_FromLongLong((long long) st.f_bavail));
|
||||
SET_RESULT(PyLong_FromLongLong((long long) st.f_files));
|
||||
SET_RESULT(PyLong_FromLongLong((long long) st.f_ffree));
|
||||
SET_RESULT(PyLong_FromLongLong((long long) st.f_favail));
|
||||
SET_RESULT(PyLong_FromLong((long) st.f_flag));
|
||||
SET_RESULT(PyLong_FromLong((long) st.f_namemax));
|
||||
#endif
|
||||
/* The _ALL_SOURCE feature test macro defines f_fsid as a structure
|
||||
* (issue #32390). */
|
||||
#if defined(_AIX) && defined(_ALL_SOURCE)
|
||||
PyStructSequence_SET_ITEM(v, 10, PyLong_FromUnsignedLong(st.f_fsid.val[0]));
|
||||
SET_RESULT(PyLong_FromUnsignedLong(st.f_fsid.val[0]));
|
||||
#else
|
||||
PyStructSequence_SET_ITEM(v, 10, PyLong_FromUnsignedLong(st.f_fsid));
|
||||
SET_RESULT(PyLong_FromUnsignedLong(st.f_fsid));
|
||||
#endif
|
||||
if (PyErr_Occurred()) {
|
||||
Py_DECREF(v);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#undef SET_RESULT
|
||||
|
||||
return v;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue