Fix T86332: Error using lambda in annotations in Python 3.10

Callbacks used in `bpy.props` didn't hold a references to the functions
they used.

While this has been the case since early 2.5x it didn't cause any
problems as long as the class held a reference.

With Python 3.10 or when using `from __future__ import annotations`,
the annotations are no longer owned by the class once evaluated.

Resolve this by holding a reference in the module, which now supports
traverse & clear callbacks so the objects are visible to Python's
garbage collector.

Also refactor storage of Python data, moving from an array into a struct.
This commit is contained in:
2021-03-16 12:18:56 +11:00
parent be51d671b5
commit e125305af4
9 changed files with 245 additions and 140 deletions

View File

@@ -45,6 +45,7 @@
#include "bpy_capi_utils.h"
#include "bpy_intern_string.h"
#include "bpy_path.h"
#include "bpy_props.h"
#include "bpy_rna.h"
#include "bpy_traceback.h"
@@ -523,6 +524,9 @@ void BPY_python_end(void)
/* finalizing, no need to grab the state, except when we are a module */
gilstate = PyGILState_Ensure();
/* Decrement user counts of all callback functions. */
BPY_rna_props_clear_all();
/* free other python data. */
pyrna_free_types();