mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
[3.11] gh-116326: Handler errors correctly in getwindowsversion in sysmodule (GH-116339) (#116388)
(cherry picked from commit c91bdf86ef)
This commit is contained in:
parent
4637a1fcbd
commit
23c17f3c1a
1 changed files with 25 additions and 14 deletions
|
|
@ -1479,15 +1479,24 @@ sys_getwindowsversion_impl(PyObject *module)
|
||||||
if (version == NULL)
|
if (version == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
PyStructSequence_SET_ITEM(version, pos++, PyLong_FromLong(ver.dwMajorVersion));
|
#define SET_VERSION_INFO(CALL) \
|
||||||
PyStructSequence_SET_ITEM(version, pos++, PyLong_FromLong(ver.dwMinorVersion));
|
do { \
|
||||||
PyStructSequence_SET_ITEM(version, pos++, PyLong_FromLong(ver.dwBuildNumber));
|
PyObject *item = (CALL); \
|
||||||
PyStructSequence_SET_ITEM(version, pos++, PyLong_FromLong(ver.dwPlatformId));
|
if (item == NULL) { \
|
||||||
PyStructSequence_SET_ITEM(version, pos++, PyUnicode_FromWideChar(ver.szCSDVersion, -1));
|
goto error; \
|
||||||
PyStructSequence_SET_ITEM(version, pos++, PyLong_FromLong(ver.wServicePackMajor));
|
} \
|
||||||
PyStructSequence_SET_ITEM(version, pos++, PyLong_FromLong(ver.wServicePackMinor));
|
PyStructSequence_SET_ITEM(version, pos++, item); \
|
||||||
PyStructSequence_SET_ITEM(version, pos++, PyLong_FromLong(ver.wSuiteMask));
|
} while(0)
|
||||||
PyStructSequence_SET_ITEM(version, pos++, PyLong_FromLong(ver.wProductType));
|
|
||||||
|
SET_VERSION_INFO(PyLong_FromLong(ver.dwMajorVersion));
|
||||||
|
SET_VERSION_INFO(PyLong_FromLong(ver.dwMinorVersion));
|
||||||
|
SET_VERSION_INFO(PyLong_FromLong(ver.dwBuildNumber));
|
||||||
|
SET_VERSION_INFO(PyLong_FromLong(ver.dwPlatformId));
|
||||||
|
SET_VERSION_INFO(PyUnicode_FromWideChar(ver.szCSDVersion, -1));
|
||||||
|
SET_VERSION_INFO(PyLong_FromLong(ver.wServicePackMajor));
|
||||||
|
SET_VERSION_INFO(PyLong_FromLong(ver.wServicePackMinor));
|
||||||
|
SET_VERSION_INFO(PyLong_FromLong(ver.wSuiteMask));
|
||||||
|
SET_VERSION_INFO(PyLong_FromLong(ver.wProductType));
|
||||||
|
|
||||||
realMajor = ver.dwMajorVersion;
|
realMajor = ver.dwMajorVersion;
|
||||||
realMinor = ver.dwMinorVersion;
|
realMinor = ver.dwMinorVersion;
|
||||||
|
|
@ -1514,17 +1523,19 @@ sys_getwindowsversion_impl(PyObject *module)
|
||||||
}
|
}
|
||||||
PyMem_RawFree(verblock);
|
PyMem_RawFree(verblock);
|
||||||
}
|
}
|
||||||
PyStructSequence_SET_ITEM(version, pos++, Py_BuildValue("(kkk)",
|
SET_VERSION_INFO(Py_BuildValue("(kkk)",
|
||||||
realMajor,
|
realMajor,
|
||||||
realMinor,
|
realMinor,
|
||||||
realBuild
|
realBuild
|
||||||
));
|
));
|
||||||
|
|
||||||
if (PyErr_Occurred()) {
|
#undef SET_VERSION_INFO
|
||||||
Py_DECREF(version);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
return version;
|
return version;
|
||||||
|
|
||||||
|
error:
|
||||||
|
Py_DECREF(version);
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma warning(pop)
|
#pragma warning(pop)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue