PyAPI: support persistent handlers for class & static methods

Support methods being used as persistent callbacks.

Resolves T97555.
This commit is contained in:
Campbell Barton 2022-04-26 13:46:06 +10:00
parent 07e2bd443e
commit 0f583d9d60
Notes: blender-bot 2023-02-14 05:16:25 +01:00
Referenced by issue #97555, object member persistent handlers are not persisted across file loads/reloads.
1 changed files with 10 additions and 5 deletions

View File

@ -266,13 +266,18 @@ void BPY_app_handlers_reset(const short do_all)
PyObject *ls = py_cb_array[pos];
Py_ssize_t i;
PyObject *item;
PyObject **dict_ptr;
for (i = PyList_GET_SIZE(ls) - 1; i >= 0; i--) {
PyObject *item = PyList_GET_ITEM(ls, i);
if (PyFunction_Check((item = PyList_GET_ITEM(ls, i))) &&
(dict_ptr = _PyObject_GetDictPtr(item)) && (*dict_ptr) &&
if (PyMethod_Check(item)) {
PyObject *item_test = PyMethod_GET_FUNCTION(item);
if (item_test) {
item = item_test;
}
}
PyObject **dict_ptr;
if (PyFunction_Check(item) && (dict_ptr = _PyObject_GetDictPtr(item)) && (*dict_ptr) &&
(PyDict_GetItem(*dict_ptr, perm_id_str) != NULL)) {
/* keep */
}