[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [40401] trunk/blender/source/blender/ python/intern:
Campbell Barton
ideasman42 at gmail.com
Tue Sep 20 17:19:04 CEST 2011
ack, QtCreator lets you commit blank messages!
This fixes recent crash on exit bug with atexit.register/unregister,
WM_exit was being called recursively.
On Wed, Sep 21, 2011 at 1:17 AM, Campbell Barton <ideasman42 at gmail.com> wrote:
> Revision: 40401
> http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=40401
> Author: campbellbarton
> Date: 2011-09-20 15:17:24 +0000 (Tue, 20 Sep 2011)
> Log Message:
> -----------
>
>
> Modified Paths:
> --------------
> trunk/blender/source/blender/python/intern/bpy.h
> trunk/blender/source/blender/python/intern/bpy_interface.c
> trunk/blender/source/blender/python/intern/bpy_interface_atexit.c
>
> Modified: trunk/blender/source/blender/python/intern/bpy.h
> ===================================================================
> --- trunk/blender/source/blender/python/intern/bpy.h 2011-09-20 15:11:17 UTC (rev 40400)
> +++ trunk/blender/source/blender/python/intern/bpy.h 2011-09-20 15:17:24 UTC (rev 40401)
> @@ -30,4 +30,5 @@
> extern PyObject *bpy_package_py;
>
> /* bpy_interface_atexit.c */
> -void BPY_atexit_init(void);
> +void BPY_atexit_register(void);
> +void BPY_atexit_unregister(void);
>
> Modified: trunk/blender/source/blender/python/intern/bpy_interface.c
> ===================================================================
> --- trunk/blender/source/blender/python/intern/bpy_interface.c 2011-09-20 15:11:17 UTC (rev 40400)
> +++ trunk/blender/source/blender/python/intern/bpy_interface.c 2011-09-20 15:17:24 UTC (rev 40401)
> @@ -241,7 +241,7 @@
>
> pyrna_alloc_types();
>
> - BPY_atexit_init(); /* this can init any time */
> + BPY_atexit_register(); /* this can init any time */
>
> #ifndef WITH_PYTHON_MODULE
> py_tstate= PyGILState_GetThisThreadState();
> @@ -262,6 +262,8 @@
>
> bpy_intern_string_exit();
>
> + BPY_atexit_unregister(); /* without this we get recursive calls to WM_exit */
> +
> Py_Finalize();
>
> #ifdef TIME_PY_RUN
>
> Modified: trunk/blender/source/blender/python/intern/bpy_interface_atexit.c
> ===================================================================
> --- trunk/blender/source/blender/python/intern/bpy_interface_atexit.c 2011-09-20 15:11:17 UTC (rev 40400)
> +++ trunk/blender/source/blender/python/intern/bpy_interface_atexit.c 2011-09-20 15:17:24 UTC (rev 40401)
> @@ -46,24 +46,26 @@
> }
>
> static PyMethodDef meth_bpy_atexit= {"bpy_atexit", (PyCFunction)bpy_atexit, METH_NOARGS, NULL};
> +static PyObject *func_bpy_atregister= NULL; /* borrowed referebce, atexit holds */
>
> -void BPY_atexit_init(void)
> +static void atexit_func_call(const char *func_name, PyObject *atexit_func_arg)
> {
> /* 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 *atexit_func= PyObject_GetAttrString(atexit_mod, func_name);
> PyObject *args= PyTuple_New(1);
> PyObject *ret;
>
> - PyTuple_SET_ITEM(args, 0, (PyObject *)PyCFunction_New(&meth_bpy_atexit, NULL));
> + PyTuple_SET_ITEM(args, 0, atexit_func_arg);
> + Py_INCREF(atexit_func_arg); /* only incref so we dont dec'ref along with 'args' */
>
> - ret= PyObject_CallObject(atexit_register, args);
> + ret= PyObject_CallObject(atexit_func, args);
>
> Py_DECREF(atexit_mod);
> - Py_DECREF(atexit_register);
> + Py_DECREF(atexit_func);
> Py_DECREF(args);
>
> if(ret) {
> @@ -72,5 +74,19 @@
> else { /* should never happen */
> PyErr_Print();
> }
> +}
>
> +void BPY_atexit_register(void)
> +{
> + /* atexit module owns this new function reference */
> + BLI_assert(func_bpy_atregister ==NULL);
> +
> + func_bpy_atregister= (PyObject *)PyCFunction_New(&meth_bpy_atexit, NULL);
> + atexit_func_call("register", func_bpy_atregister);
> }
> +
> +void BPY_atexit_unregister(void)
> +{
> + atexit_func_call("unregister", func_bpy_atregister);
> + func_bpy_atregister= NULL; /* don't really need to set but just incase */
> +}
>
> _______________________________________________
> Bf-blender-cvs mailing list
> Bf-blender-cvs at blender.org
> http://lists.blender.org/mailman/listinfo/bf-blender-cvs
>
--
- Campbell
More information about the Bf-blender-cvs
mailing list