diff options
author | Christian Persch <chpe@cvs.gnome.org> | 2005-07-30 03:53:46 +0800 |
---|---|---|
committer | Christian Persch <chpe@src.gnome.org> | 2005-07-30 03:53:46 +0800 |
commit | 2ec6bec12610fd0cfed6bc2612c3a9c23815df62 (patch) | |
tree | 96c0bc607659ac52a7e39c839bee93f5a20178de /src/ephy-python.c | |
parent | 04e7795daadca2b11162a791eb0734163da5acdc (diff) | |
download | gsoc2013-epiphany-2ec6bec12610fd0cfed6bc2612c3a9c23815df62.tar gsoc2013-epiphany-2ec6bec12610fd0cfed6bc2612c3a9c23815df62.tar.gz gsoc2013-epiphany-2ec6bec12610fd0cfed6bc2612c3a9c23815df62.tar.bz2 gsoc2013-epiphany-2ec6bec12610fd0cfed6bc2612c3a9c23815df62.tar.lz gsoc2013-epiphany-2ec6bec12610fd0cfed6bc2612c3a9c23815df62.tar.xz gsoc2013-epiphany-2ec6bec12610fd0cfed6bc2612c3a9c23815df62.tar.zst gsoc2013-epiphany-2ec6bec12610fd0cfed6bc2612c3a9c23815df62.zip |
Be careful not to leave a GC scheduled when terminating python.
2005-07-29 Christian Persch <chpe@cvs.gnome.org>
* src/ephy-python-extension.c: (impl_detach_tab),
(impl_detach_window):
* src/ephy-python-loader.c: (ephy_python_loader_finalize):
* src/ephy-python.c: (ephy_python_init), (idle_shutdown),
(ephy_python_shutdown), (idle_gc), (ephy_python_schedule_gc):
* src/ephy-python.h:
Be careful not to leave a GC scheduled when terminating python.
Diffstat (limited to 'src/ephy-python.c')
-rw-r--r-- | src/ephy-python.c | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/src/ephy-python.c b/src/ephy-python.c index 242d19330..01c255879 100644 --- a/src/ephy-python.c +++ b/src/ephy-python.c @@ -26,6 +26,7 @@ #include "config.h" #include "ephy-python.h" +#include "ephy-debug.h" #include <pygobject.h> #include <pygtk/pygtk.h> @@ -35,6 +36,9 @@ void pyepiphany_add_constants (PyObject *module, const gchar *strip_prefix); extern PyMethodDef pyepiphany_functions[]; +static guint idle_gc_handler = 0; +static guint idle_shutdown_handler = 0; + void ephy_python_init (void) { @@ -55,3 +59,72 @@ ephy_python_init (void) pyepiphany_register_classes (d); pyepiphany_add_constants (m, "EPHY_"); } + +static gboolean +idle_shutdown (void) +{ + g_return_val_if_fail (idle_gc_handler == 0, FALSE); + + Py_Finalize (); + + idle_shutdown_handler = 0; + return FALSE; +} + +void +ephy_python_shutdown (void) +{ + g_return_if_fail (idle_shutdown_handler == 0); + + LOG ("EphyPython shutdown with %s GC scheduled", + idle_gc_handler != 0 ? "a" : "no"); + + if (idle_gc_handler != 0) + { + /* Process remaining GCs now */ + while (PyGC_Collect ()) ; + + g_source_remove (idle_gc_handler); + idle_gc_handler = 0; + + /* IMPORTANT! We get here while running PyGC_Collect from idle! + * Don't do Py_Finalize while inside python! + */ + idle_shutdown_handler = g_idle_add ((GSourceFunc) idle_shutdown, NULL); + } + else + { + Py_Finalize(); + } +} + +static gboolean +idle_gc (void) +{ + long value; + + /* LOG ("Running GC from idle"); */ + + /* FIXME what does the return value of PyGC_Collect mean? */ + value = PyGC_Collect (); + + /* LOG ("Idle GC returned %ld", value); */ + + if (value == 0) + { + idle_gc_handler = 0; + } + + return value != 0; +} + +void +ephy_python_schedule_gc (void) +{ + /* LOG ("Scheduling a GC with %s GC already scheduled", idle_gc_handler != 0 ? "a" : "no"); */ + + if (idle_gc_handler == 0) + { + idle_gc_handler = g_idle_add ((GSourceFunc) idle_gc, NULL); + } +} |