From cf5da37e3c4c8ed4bf5e0427d06b0e5c55f2059c Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 10 Sep 2012 23:32:46 +0000 Subject: [PATCH] fix for a bug running a script, then opening a new file. BPY_text_free_code() could run outside the python interpreter which abort()'s blender. --- source/blender/python/intern/bpy_interface.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/source/blender/python/intern/bpy_interface.c b/source/blender/python/intern/bpy_interface.c index 1c63ab512f2..9cd0bdd090a 100644 --- a/source/blender/python/intern/bpy_interface.c +++ b/source/blender/python/intern/bpy_interface.c @@ -163,8 +163,17 @@ void bpy_context_clear(bContext *UNUSED(C), PyGILState_STATE *gilstate) void BPY_text_free_code(Text *text) { if (text->compiled) { + PyGILState_STATE gilstate; + int use_gil = !PYC_INTERPRETER_ACTIVE; + + if (use_gil) + gilstate = PyGILState_Ensure(); + Py_DECREF((PyObject *)text->compiled); text->compiled = NULL; + + if (use_gil) + PyGILState_Release(gilstate); } }