PyAPI: don't raise & clear exceptions when setting context members

BPY_context_dict_clear_members_array used PyDict_DelItemString
which raised & cleared the exception when the key didn't exist.

Even though setting/clearing the exception is supported,
it's worth avoiding where possible as it adds some overhead as well as
overwriting the previous error which can free PyObject's which are
unrelated to the code being executed.

Possible fix for T82552, crashing on Windows when setting the exception.
This commit is contained in:
2021-01-07 14:31:23 +11:00
parent f35a38fba7
commit a9dea9cfaa

View File

@@ -195,10 +195,14 @@ void BPY_context_dict_clear_members_array(void **dict_p,
PyObject *dict = *dict_p;
BLI_assert(PyDict_Check(dict));
/* Use #PyDict_Pop instead of #PyDict_DelItemString to avoid setting the exception,
* while supported it's good to avoid for low level functions like this that run often. */
for (uint i = 0; i < context_members_len; i++) {
if (PyDict_DelItemString(dict, context_members[i])) {
PyErr_Clear();
}
PyObject *key = PyUnicode_FromString(context_members[i]);
PyObject *item = _PyDict_Pop(dict, key, Py_None);
Py_DECREF(key);
Py_DECREF(item);
}
if (use_gil) {