From b6d14e025c017363ce672757332b8e4b1e558653 Mon Sep 17 00:00:00 2001 From: "M. Levinson" Date: Sun, 10 Dec 2006 13:02:34 -0500 Subject: [PATCH] Reset PyObject pointers to NULL when deinitializing. cleanup_python and python_done_keybinding_interface called by it now reset the PyObject *python_hooks, *keybindings variables back to NULL when they release the references. Without this change, dangling pointers left in those variables could cause problems if the Python scripting module were deinitialized and reinitialized. It looks like such reinitialization is not currently possible though, because enhancement request 73 (plugins support) has not yet been implemented. --- src/scripting/python/core.c | 10 +++++++++- src/scripting/python/keybinding.c | 8 +++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/scripting/python/core.c b/src/scripting/python/core.c index 3ce2d435..33bb5c82 100644 --- a/src/scripting/python/core.c +++ b/src/scripting/python/core.c @@ -209,8 +209,16 @@ void cleanup_python(struct module *module) { if (Py_IsInitialized()) { + PyObject *temp; + python_done_keybinding_interface(); - Py_XDECREF(python_hooks); + + /* This is equivalent to Py_CLEAR(), but it works with older + * versions of Python predating that macro: */ + temp = python_hooks; + python_hooks = NULL; + Py_XDECREF(temp); + Py_Finalize(); } } diff --git a/src/scripting/python/keybinding.c b/src/scripting/python/keybinding.c index 2d6668c1..983c1847 100644 --- a/src/scripting/python/keybinding.c +++ b/src/scripting/python/keybinding.c @@ -194,5 +194,11 @@ python_init_keybinding_interface(PyObject *dict, PyObject *name) void python_done_keybinding_interface(void) { - Py_XDECREF(keybindings); + PyObject *temp; + + /* This is equivalent to Py_CLEAR(), but it works with older + * versions of Python predating that macro: */ + temp = keybindings; + keybindings = NULL; + Py_XDECREF(temp); } -- 2.11.4.GIT