[Bf-blender-cvs] [83c0f6ac374] master: Python: clear Py-driver variables on exit
Campbell Barton
noreply at git.blender.org
Thu Jul 7 04:35:22 CEST 2022
Commit: 83c0f6ac3740cc8d7fb17a8b837ac95a8956805c
Author: Campbell Barton
Date: Thu Jul 7 12:30:45 2022 +1000
Branches: master
https://developer.blender.org/rB83c0f6ac3740cc8d7fb17a8b837ac95a8956805c
Python: clear Py-driver variables on exit
These kinds of leaks are relatively harmless, it reduces the number of
un-freed data reported by valgrind on exit.
===================================================================
M source/blender/python/BPY_extern.h
M source/blender/python/intern/bpy_driver.c
M source/blender/python/intern/bpy_interface.c
===================================================================
diff --git a/source/blender/python/BPY_extern.h b/source/blender/python/BPY_extern.h
index 0ab26fde34f..8075e4ecd22 100644
--- a/source/blender/python/BPY_extern.h
+++ b/source/blender/python/BPY_extern.h
@@ -69,6 +69,11 @@ void BPY_modules_load_user(struct bContext *C);
void BPY_app_handlers_reset(bool do_all);
+/**
+ * Run on exit to free any cached data.
+ */
+void BPY_driver_exit(void);
+
/**
* Update function, it gets rid of python-drivers global dictionary: `bpy.app.driver_namespace`,
* forcing #BPY_driver_exec to recreate it. Use this when loading a new `.blend` file
diff --git a/source/blender/python/intern/bpy_driver.c b/source/blender/python/intern/bpy_driver.c
index aa627a42a2b..3134969d21c 100644
--- a/source/blender/python/intern/bpy_driver.c
+++ b/source/blender/python/intern/bpy_driver.c
@@ -233,15 +233,8 @@ static void bpy_pydriver_namespace_update_depsgraph(struct Depsgraph *depsgraph)
}
}
-void BPY_driver_reset(void)
+void BPY_driver_exit(void)
{
- PyGILState_STATE gilstate;
- const bool use_gil = true; /* !PyC_IsInterpreterActive(); */
-
- if (use_gil) {
- gilstate = PyGILState_Ensure();
- }
-
if (bpy_pydriver_Dict) { /* Free the global dict used by python-drivers. */
PyDict_Clear(bpy_pydriver_Dict);
Py_DECREF(bpy_pydriver_Dict);
@@ -261,6 +254,19 @@ void BPY_driver_reset(void)
/* Freed when clearing driver dictionary. */
g_pydriver_state_prev.self = NULL;
g_pydriver_state_prev.depsgraph = NULL;
+}
+
+void BPY_driver_reset(void)
+{
+ PyGILState_STATE gilstate;
+ const bool use_gil = true; /* !PyC_IsInterpreterActive(); */
+
+ if (use_gil) {
+ gilstate = PyGILState_Ensure();
+ }
+
+ /* Currently exit/reset are practically the same besides the GIL check. */
+ BPY_driver_exit();
if (use_gil) {
PyGILState_Release(gilstate);
diff --git a/source/blender/python/intern/bpy_interface.c b/source/blender/python/intern/bpy_interface.c
index ea64fa6c098..939fa475344 100644
--- a/source/blender/python/intern/bpy_interface.c
+++ b/source/blender/python/intern/bpy_interface.c
@@ -512,6 +512,9 @@ void BPY_python_end(void)
/* finalizing, no need to grab the state, except when we are a module */
gilstate = PyGILState_Ensure();
+ /* Frees the python-driver name-space & cached data. */
+ BPY_driver_exit();
+
/* Clear Python values in the context so freeing the context after Python exits doesn't crash. */
bpy_context_end(BPY_context_get());
More information about the Bf-blender-cvs
mailing list