summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2024-03-04 21:13:38 (GMT)
committerGitHub <noreply@github.com>2024-03-04 21:13:38 (GMT)
commit0f70c14939bd014001f7e37150255a960683717c (patch)
treea71200a403c320cc56a0f861c64c3d41b95e0aed /Python
parent19aa5574241e3c7e554505880a5ddd1102d22a42 (diff)
downloadcpython-0f70c14939bd014001f7e37150255a960683717c.zip
cpython-0f70c14939bd014001f7e37150255a960683717c.tar.gz
cpython-0f70c14939bd014001f7e37150255a960683717c.tar.bz2
[3.12] gh-115320: Refactor `get_hash_info` in `sysmodule.c` not to swallow errors (GH-115321) (#116323)
gh-115320: Refactor `get_hash_info` in `sysmodule.c` not to swallow errors (GH-115321) (cherry picked from commit 207030f5527d405940b79c10c1413c1e8ff696c1) Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Diffstat (limited to 'Python')
-rw-r--r--Python/sysmodule.c48
1 files changed, 25 insertions, 23 deletions
diff --git a/Python/sysmodule.c b/Python/sysmodule.c
index 7874920..7a4e439 100644
--- a/Python/sysmodule.c
+++ b/Python/sysmodule.c
@@ -1439,31 +1439,33 @@ get_hash_info(PyThreadState *tstate)
int field = 0;
PyHash_FuncDef *hashfunc;
hash_info = PyStructSequence_New(&Hash_InfoType);
- if (hash_info == NULL)
- return NULL;
- hashfunc = PyHash_GetFuncDef();
- PyStructSequence_SET_ITEM(hash_info, field++,
- PyLong_FromLong(8*sizeof(Py_hash_t)));
- PyStructSequence_SET_ITEM(hash_info, field++,
- PyLong_FromSsize_t(_PyHASH_MODULUS));
- PyStructSequence_SET_ITEM(hash_info, field++,
- PyLong_FromLong(_PyHASH_INF));
- PyStructSequence_SET_ITEM(hash_info, field++,
- PyLong_FromLong(0)); // This is no longer used
- PyStructSequence_SET_ITEM(hash_info, field++,
- PyLong_FromLong(_PyHASH_IMAG));
- PyStructSequence_SET_ITEM(hash_info, field++,
- PyUnicode_FromString(hashfunc->name));
- PyStructSequence_SET_ITEM(hash_info, field++,
- PyLong_FromLong(hashfunc->hash_bits));
- PyStructSequence_SET_ITEM(hash_info, field++,
- PyLong_FromLong(hashfunc->seed_bits));
- PyStructSequence_SET_ITEM(hash_info, field++,
- PyLong_FromLong(Py_HASH_CUTOFF));
- if (_PyErr_Occurred(tstate)) {
- Py_CLEAR(hash_info);
+ if (hash_info == NULL) {
return NULL;
}
+ hashfunc = PyHash_GetFuncDef();
+
+#define SET_HASH_INFO_ITEM(CALL) \
+ do { \
+ PyObject *item = (CALL); \
+ if (item == NULL) { \
+ Py_CLEAR(hash_info); \
+ return NULL; \
+ } \
+ PyStructSequence_SET_ITEM(hash_info, field++, item); \
+ } while(0)
+
+ SET_HASH_INFO_ITEM(PyLong_FromLong(8 * sizeof(Py_hash_t)));
+ SET_HASH_INFO_ITEM(PyLong_FromSsize_t(_PyHASH_MODULUS));
+ SET_HASH_INFO_ITEM(PyLong_FromLong(_PyHASH_INF));
+ SET_HASH_INFO_ITEM(PyLong_FromLong(0)); // This is no longer used
+ SET_HASH_INFO_ITEM(PyLong_FromLong(_PyHASH_IMAG));
+ SET_HASH_INFO_ITEM(PyUnicode_FromString(hashfunc->name));
+ SET_HASH_INFO_ITEM(PyLong_FromLong(hashfunc->hash_bits));
+ SET_HASH_INFO_ITEM(PyLong_FromLong(hashfunc->seed_bits));
+ SET_HASH_INFO_ITEM(PyLong_FromLong(Py_HASH_CUTOFF));
+
+#undef SET_HASH_INFO_ITEM
+
return hash_info;
}
/*[clinic input]