Python: assert Python start/end/reset are used properly

This commit is contained in:
Campbell Barton
2024-04-05 11:41:12 +11:00
parent 204d282c75
commit 06dcd264ea

View File

@@ -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';