Patchwork [guile] Run finalizers from GDB thread

login
register
mail settings
Submitter Andy Wingo
Date April 17, 2014, 1:39 p.m.
Message ID <87sipcqdmo.fsf@igalia.com>
Download mbox | patch
Permalink /patch/608/
State New
Headers show

Comments

Andy Wingo - April 17, 2014, 1:39 p.m.
gdb/ChangeLog:
	* guile/guile.c (_initialize_guile): Disable automatic
	finalization, if Guile offers us that possibility.

	* guile/guile.c (call_initialize_gdb_module):
	* guile/scm-safe-call.c (gdbscm_with_catch): Arrange to run
	finalizers in appropriate places.

	* configure.ac: Add a check for
	scm_set_automatic_finalization_enabled.
---
 gdb/ChangeLog             | 12 ++++++++++++
 gdb/configure.ac          |  5 +++++
 gdb/guile/guile.c         | 11 +++++++++++
 gdb/guile/scm-safe-call.c |  4 ++++
 4 files changed, 32 insertions(+)
Doug Evans - April 26, 2014, 8:26 p.m.
Andy Wingo <wingo@igalia.com> writes:

> gdb/ChangeLog:
> 	* guile/guile.c (_initialize_guile): Disable automatic
> 	finalization, if Guile offers us that possibility.
>
> 	* guile/guile.c (call_initialize_gdb_module):
> 	* guile/scm-safe-call.c (gdbscm_with_catch): Arrange to run
> 	finalizers in appropriate places.
>
> 	* configure.ac: Add a check for
> 	scm_set_automatic_finalization_enabled.

Hi.  Ok with a few nits.

1) Since all of these changes are related, don't separate them with
blank lines in the changelog entry.

2) Write the configure.ac entry as:
	* configure.ac (AC_TRY_LIBGUILE): Add a check for
	scm_set_automatic_finalization_enabled.

3) Include the changelog entry for configure being regenerated, even
though it's not included in the patch:
	* configure: Regenerate.

Thanks!

Patch

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index e408e2e..73c147f 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,17 @@ 
 2014-04-17  Andy Wingo  <wingo@igalia.com>
 
+	* guile/guile.c (_initialize_guile): Disable automatic
+	finalization, if Guile offers us that possibility.
+
+	* guile/guile.c (call_initialize_gdb_module):
+	* guile/scm-safe-call.c (gdbscm_with_catch): Arrange to run
+	finalizers in appropriate places.
+
+	* configure.ac: Add a check for
+	scm_set_automatic_finalization_enabled.
+
+2014-04-17  Andy Wingo  <wingo@igalia.com>
+
 	* guile/scm-symtab.c (stscm_free_sal_smob): Remove useless free
 	function.  (This was the only useless free function.)
 
diff --git a/gdb/configure.ac b/gdb/configure.ac
index ff84a2e..06f2bf1 100644
--- a/gdb/configure.ac
+++ b/gdb/configure.ac
@@ -1112,6 +1112,11 @@  AC_DEFUN([AC_TRY_LIBGUILE],
                     GUILE_CPPFLAGS=$new_CPPFLAGS
                     GUILE_LIBS=$new_LIBS],
                    [found_usable_guile=no])
+    dnl scm_set_automatic_finalization_enabled added in Guile 2.2.
+    AC_CHECK_FUNC(scm_set_automatic_finalization_enabled,
+      AC_DEFINE(HAVE_GUILE_MANUAL_FINALIZATION, 1,
+                [Define if Guile supports manual finalization.])
+    )
     CPPFLAGS=$save_CPPFLAGS
     LIBS=$save_LIBS
     if test "${found_usable_guile}" = no; then
diff --git a/gdb/guile/guile.c b/gdb/guile/guile.c
index f2fd8d8..f488e12 100644
--- a/gdb/guile/guile.c
+++ b/gdb/guile/guile.c
@@ -572,6 +572,10 @@  call_initialize_gdb_module (void *data)
      performed within the desired module.  */
   scm_c_define_module (gdbscm_module_name, initialize_gdb_module, NULL);
 
+#if HAVE_GUILE_MANUAL_FINALIZATION
+  scm_run_finalizers ();
+#endif
+
   return NULL;
 }
 
@@ -715,6 +719,13 @@  _initialize_guile (void)
      side to define module "gdb" which imports "_gdb".  There is evidently no
      similar convention in Guile so we skip this.  */
 
+#if HAVE_GUILE_MANUAL_FINALIZATION
+  /* Our SMOB free functions are not thread-safe, as GDB itself is not intended
+     to be thread-safe.  Disable automatic finalization so that finalizers
+     aren't run in other threads.  */
+  scm_set_automatic_finalization_enabled (0);
+#endif
+
   /* scm_with_guile is the most portable way to initialize Guile.
      Plus we need to initialize the Guile support while in Guile mode
      (e.g., called from within a call to scm_with_guile).  */
diff --git a/gdb/guile/scm-safe-call.c b/gdb/guile/scm-safe-call.c
index 147d7f5..6b6de93 100644
--- a/gdb/guile/scm-safe-call.c
+++ b/gdb/guile/scm-safe-call.c
@@ -156,6 +156,10 @@  gdbscm_with_catch (void *data)
 		   d->unwind_handler, d,
 		   d->pre_unwind_handler, d);
 
+#if HAVE_GUILE_MANUAL_FINALIZATION
+  scm_run_finalizers ();
+#endif
+
   return NULL;
 }