Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2011-09-23 11:20:27 +0400
committerCampbell Barton <ideasman42@gmail.com>2011-09-23 11:20:27 +0400
commitd92b5ea04ac8b661bb8caa7a1ca813e8f33a5a1c (patch)
tree238bc3e3511b6d26c49012e958599a8a883aa842 /source/blender/python
parentea4b3fee1f51db4e6cd53daf8071429991dc95e3 (diff)
parent1657cbe61a756222feac5107f87d0d699a92b4a6 (diff)
svn merge ^/trunk/blender -r40390:40394
Diffstat (limited to 'source/blender/python')
-rw-r--r--source/blender/python/intern/CMakeLists.txt1
-rw-r--r--source/blender/python/intern/bpy.h3
-rw-r--r--source/blender/python/intern/bpy_interface.c4
-rw-r--r--source/blender/python/intern/bpy_interface_atexit.c76
4 files changed, 83 insertions, 1 deletions
diff --git a/source/blender/python/intern/CMakeLists.txt b/source/blender/python/intern/CMakeLists.txt
index 9ed08591eea..acdee5328e7 100644
--- a/source/blender/python/intern/CMakeLists.txt
+++ b/source/blender/python/intern/CMakeLists.txt
@@ -47,6 +47,7 @@ set(SRC
bpy_app_handlers.c
bpy_driver.c
bpy_interface.c
+ bpy_interface_atexit.c
bpy_intern_string.c
bpy_library.c
bpy_operator.c
diff --git a/source/blender/python/intern/bpy.h b/source/blender/python/intern/bpy.h
index 0ebc6bb2438..6844d6637ed 100644
--- a/source/blender/python/intern/bpy.h
+++ b/source/blender/python/intern/bpy.h
@@ -28,3 +28,6 @@
void BPy_init_modules(void);
extern PyObject *bpy_package_py;
+
+/* bpy_interface_atexit.c */
+void BPY_atexit_init(void);
diff --git a/source/blender/python/intern/bpy_interface.c b/source/blender/python/intern/bpy_interface.c
index e5bfc1d633f..87edf9303ef 100644
--- a/source/blender/python/intern/bpy_interface.c
+++ b/source/blender/python/intern/bpy_interface.c
@@ -30,7 +30,7 @@
/* grr, python redefines */
#ifdef _POSIX_C_SOURCE
-#undef _POSIX_C_SOURCE
+# undef _POSIX_C_SOURCE
#endif
#include <Python.h>
@@ -241,6 +241,8 @@ void BPY_python_start(int argc, const char **argv)
pyrna_alloc_types();
+ BPY_atexit_init(); /* this can init any time */
+
#ifndef WITH_PYTHON_MODULE
py_tstate= PyGILState_GetThisThreadState();
PyEval_ReleaseThread(py_tstate);
diff --git a/source/blender/python/intern/bpy_interface_atexit.c b/source/blender/python/intern/bpy_interface_atexit.c
new file mode 100644
index 00000000000..0230a3bad90
--- /dev/null
+++ b/source/blender/python/intern/bpy_interface_atexit.c
@@ -0,0 +1,76 @@
+/*
+ * $Id:
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Campbell Barton
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/python/intern/bpy_interface_atexit.c
+ * \ingroup pythonintern
+ */
+
+
+#include <Python.h>
+
+#include "bpy_util.h"
+
+#include "WM_api.h"
+
+#include "BLI_utildefines.h"
+
+static PyObject *bpy_atexit(PyObject *UNUSED(self), PyObject *UNUSED(args), PyObject *UNUSED(kw))
+{
+ /* close down enough of blender at least not to crash */
+ struct bContext *C= BPy_GetContext();
+
+ WM_exit_ext(C, 0);
+
+ Py_RETURN_NONE;
+}
+
+static PyMethodDef meth_bpy_atexit= {"bpy_atexit", (PyCFunction)bpy_atexit, METH_NOARGS, NULL};
+
+void BPY_atexit_init(void)
+{
+ /* note - no error checking, if any of these fail we'll get a crash
+ * this is intended, but if its problematic it could be changed
+ * - campbell */
+
+ PyObject *atexit_mod= PyImport_ImportModuleLevel((char *)"atexit", NULL, NULL, NULL, 0);
+ PyObject *atexit_register= PyObject_GetAttrString(atexit_mod, "register");
+ PyObject *args= PyTuple_New(1);
+ PyObject *ret;
+
+ PyTuple_SET_ITEM(args, 0, (PyObject *)PyCFunction_New(&meth_bpy_atexit, NULL));
+
+ ret= PyObject_CallObject(atexit_register, args);
+
+ Py_DECREF(atexit_mod);
+ Py_DECREF(atexit_register);
+ Py_DECREF(args);
+
+ if(ret) {
+ Py_DECREF(ret);
+ }
+ else { /* should never happen */
+ PyErr_Print();
+ }
+
+}