Fix T38541: sys.exit fails when blender is built as a py-module

This commit is contained in:
Campbell Barton 2014-02-13 06:53:42 +11:00
parent 70905a6e02
commit a397009181
3 changed files with 19 additions and 14 deletions

@ -361,8 +361,10 @@ void BPY_python_start(int argc, const char **argv)
void BPY_python_end(void) void BPY_python_end(void)
{ {
// fprintf(stderr, "Ending Python!\n"); // fprintf(stderr, "Ending Python!\n");
PyGILState_STATE gilstate;
PyGILState_Ensure(); /* finalizing, no need to grab the state */ /* finalizing, no need to grab the state, except when we are a module */
gilstate = PyGILState_Ensure();
/* free other python data. */ /* free other python data. */
pyrna_free_types(); pyrna_free_types();
@ -373,9 +375,11 @@ void BPY_python_end(void)
#ifndef WITH_PYTHON_MODULE #ifndef WITH_PYTHON_MODULE
BPY_atexit_unregister(); /* without this we get recursive calls to WM_exit */ BPY_atexit_unregister(); /* without this we get recursive calls to WM_exit */
#endif
Py_Finalize(); Py_Finalize();
#else
PyGILState_Release(gilstate);
#endif
#ifdef TIME_PY_RUN #ifdef TIME_PY_RUN
/* measure time since py started */ /* measure time since py started */

@ -522,6 +522,11 @@ void WM_exit_ext(bContext *C, const bool do_python)
MEM_printmemlist(); MEM_printmemlist();
} }
wm_autosave_delete(); wm_autosave_delete();
}
void WM_exit(bContext *C)
{
WM_exit_ext(C, 1);
printf("\nBlender quit\n"); printf("\nBlender quit\n");
@ -532,10 +537,6 @@ void WM_exit_ext(bContext *C, const bool do_python)
wait_for_console_key(); wait_for_console_key();
} }
#endif #endif
}
void WM_exit(bContext *C)
{
WM_exit_ext(C, 1);
exit(G.is_break == TRUE); exit(G.is_break == TRUE);
} }

@ -1746,7 +1746,7 @@ int main(int argc, const char **argv)
#ifdef WITH_PYTHON_MODULE #ifdef WITH_PYTHON_MODULE
void main_python_exit(void) void main_python_exit(void)
{ {
WM_exit((bContext *)evil_C); WM_exit_ext((bContext *)evil_C, true);
evil_C = NULL; evil_C = NULL;
} }
#endif #endif