run WM_exit(C) when blender as a python module exits

This commit is contained in:
Campbell Barton 2011-07-10 18:54:02 +00:00
parent 1f6a79ecb5
commit 80eb1eae42
2 changed files with 22 additions and 5 deletions

View File

@ -663,7 +663,9 @@ int BPY_context_member_get(bContext *C, const char *member, bContextDataResult *
#include "BLI_storage.h"
/* TODO, reloading the module isnt functional at the moment. */
extern int main_python(int argc, const char **argv);
static void bpy_module_free(void *mod);
extern int main_python_enter(int argc, const char **argv);
extern void main_python_exit(void);
static struct PyModuleDef bpy_proxy_def= {
PyModuleDef_HEAD_INIT,
"bpy", /* m_name */
@ -673,8 +675,8 @@ static struct PyModuleDef bpy_proxy_def= {
NULL, /* m_reload */
NULL, /* m_traverse */
NULL, /* m_clear */
NULL, /* m_free */
};
bpy_module_free, /* m_free */
};
typedef struct {
PyObject_HEAD
@ -699,7 +701,7 @@ void bpy_module_delay_init(PyObject *bpy_proxy)
// printf("module found %s\n", argv[0]);
main_python(argc, argv);
main_python_enter(argc, argv);
/* initialized in BPy_init_modules() */
PyDict_Update(PyModule_GetDict(bpy_proxy), PyModule_GetDict(bpy_package_py));
@ -756,4 +758,9 @@ PyInit_bpy(void)
return bpy_proxy;
}
static void bpy_module_free(void *UNUSED(mod))
{
main_python_exit();
}
#endif

View File

@ -1134,7 +1134,8 @@ static void setupArguments(bContext *C, bArgs *ba, SYS_SystemHandle *syshandle)
#ifdef WITH_PYTHON_MODULE
/* allow python module to call main */
#define main main_python
#define main main_python_enter
static void *evil_C= NULL;
#endif
int main(int argc, const char **argv)
@ -1145,6 +1146,7 @@ int main(int argc, const char **argv)
#ifdef WITH_PYTHON_MODULE
#undef main
evil_C= C;
#endif
#ifdef WITH_BINRELOC
@ -1313,6 +1315,14 @@ int main(int argc, const char **argv)
return 0;
} /* end of int main(argc,argv) */
#ifdef WITH_PYTHON_MODULE
void main_python_exit(void)
{
WM_exit((bContext *)evil_C);
evil_C= NULL;
}
#endif
static void error_cb(const char *err)
{