diff options
author | Campbell Barton <ideasman42@gmail.com> | 2021-01-07 06:31:23 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2021-01-07 06:41:52 +0300 |
commit | a9dea9cfaa756396153223f1eb2d8dc3161ded01 (patch) | |
tree | 0c71a42ff95d0e3cb25e3ae299758f90503d7a3f | |
parent | f35a38fba7083e217a778f7cb3e237d611d39beb (diff) |
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.
-rw-r--r-- | source/blender/python/intern/bpy_interface.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/source/blender/python/intern/bpy_interface.c b/source/blender/python/intern/bpy_interface.c index 0b11ac639c7..2bd71c27320 100644 --- a/source/blender/python/intern/bpy_interface.c +++ b/source/blender/python/intern/bpy_interface.c @@ -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) { |