From 06dcd264eac0163384d93f428d42bc5acaa6de9c Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 5 Apr 2024 11:41:12 +1100 Subject: [PATCH] Python: assert Python start/end/reset are used properly --- source/blender/python/intern/bpy_interface.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/source/blender/python/intern/bpy_interface.cc b/source/blender/python/intern/bpy_interface.cc index b26e9f3526b..afec2255705 100644 --- a/source/blender/python/intern/bpy_interface.cc +++ b/source/blender/python/intern/bpy_interface.cc @@ -329,6 +329,7 @@ static void pystatus_exit_on_error(const PyStatus &status) void BPY_python_start(bContext *C, int argc, const char **argv) { #ifndef WITH_PYTHON_MODULE + BLI_assert_msg(Py_IsInitialized() == 0, "Python has already been initialized"); /* #PyPreConfig (early-configuration). */ { @@ -552,6 +553,8 @@ void BPY_python_start(bContext *C, int argc, const char **argv) void BPY_python_end(const bool do_python_exit) { + BLI_assert_msg(Py_IsInitialized() != 0, "Python must be initialized"); + PyGILState_STATE gilstate; /* Finalizing, no need to grab the state, except when we are a module. */ @@ -612,6 +615,8 @@ void BPY_python_end(const bool do_python_exit) void BPY_python_reset(bContext *C) { + BLI_assert_msg(Py_IsInitialized() != 0, "Python must be initialized"); + /* Unrelated security stuff. */ G.f &= ~(G_FLAG_SCRIPT_AUTOEXEC_FAIL | G_FLAG_SCRIPT_AUTOEXEC_FAIL_QUIET); G.autoexec_fail[0] = '\0';