[guile] Run finalizers from GDB thread
authorAndy Wingo <wingo@igalia.com>
Wed, 11 Mar 2015 12:07:53 +0000 (13:07 +0100)
committerAndy Wingo <wingo@igalia.com>
Wed, 11 Mar 2015 12:07:53 +0000 (13:07 +0100)
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.
* config.in (HAVE_GUILE_MANUAL_FINALIZATION): New definition.
* configure.ac (AC_TRY_LIBGUILE): Add a check for
scm_set_automatic_finalization_enabled.
* configure: Regenerated.

gdb/ChangeLog
gdb/config.in
gdb/configure
gdb/configure.ac
gdb/guile/guile.c
gdb/guile/scm-safe-call.c

index d247a6a31a597457881ab40045fa6f311c10448f..4a943f9758b1e54c3a48281748963b33481db2a9 100644 (file)
@@ -1,3 +1,14 @@
+2015-03-11  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 (AC_TRY_LIBGUILE): Add a check for
+       scm_set_automatic_finalization_enabled.
+       * configure: Regenerated.
+
 2015-03-11  Andreas Arnez  <arnez@linux.vnet.ibm.com>
 
        * s390-linux-tdep.c (s390_skip_prologue): Skip the prologue using
index 4aaadb587449263cd61fef63e91d8b2aa75a7728..3ccac37e2384b8657906fbd1561440408b7c7dce 100644 (file)
 /* Define if Guile interpreter is being linked in. */
 #undef HAVE_GUILE
 
+/* Define if Guile supports manual finalization. */
+#undef HAVE_GUILE_MANUAL_FINALIZATION
+
 /* Define if you have the iconv() function. */
 #undef HAVE_ICONV
 
index 1ddcc62ab8f44109659a051283b54be5bc7da211..cca0aebd5cc9070d4a11f462da94398a19e7f6fc 100755 (executable)
@@ -9229,6 +9229,14 @@ else
 fi
 rm -f core conftest.err conftest.$ac_objext \
     conftest$ac_exeext conftest.$ac_ext
+        ac_fn_c_check_func "$LINENO" "scm_set_automatic_finalization_enabled" "ac_cv_func_scm_set_automatic_finalization_enabled"
+if test "x$ac_cv_func_scm_set_automatic_finalization_enabled" = x""yes; then :
+
+$as_echo "#define HAVE_GUILE_MANUAL_FINALIZATION 1" >>confdefs.h
+
+
+fi
+
     CPPFLAGS=$save_CPPFLAGS
     LIBS=$save_LIBS
     if test "${found_usable_guile}" = no; then
@@ -9305,6 +9313,14 @@ else
 fi
 rm -f core conftest.err conftest.$ac_objext \
     conftest$ac_exeext conftest.$ac_ext
+        ac_fn_c_check_func "$LINENO" "scm_set_automatic_finalization_enabled" "ac_cv_func_scm_set_automatic_finalization_enabled"
+if test "x$ac_cv_func_scm_set_automatic_finalization_enabled" = x""yes; then :
+
+$as_echo "#define HAVE_GUILE_MANUAL_FINALIZATION 1" >>confdefs.h
+
+
+fi
+
     CPPFLAGS=$save_CPPFLAGS
     LIBS=$save_LIBS
     if test "${found_usable_guile}" = no; then
@@ -9378,6 +9394,14 @@ else
 fi
 rm -f core conftest.err conftest.$ac_objext \
     conftest$ac_exeext conftest.$ac_ext
+        ac_fn_c_check_func "$LINENO" "scm_set_automatic_finalization_enabled" "ac_cv_func_scm_set_automatic_finalization_enabled"
+if test "x$ac_cv_func_scm_set_automatic_finalization_enabled" = x""yes; then :
+
+$as_echo "#define HAVE_GUILE_MANUAL_FINALIZATION 1" >>confdefs.h
+
+
+fi
+
     CPPFLAGS=$save_CPPFLAGS
     LIBS=$save_LIBS
     if test "${found_usable_guile}" = no; then
@@ -9461,6 +9485,14 @@ else
 fi
 rm -f core conftest.err conftest.$ac_objext \
     conftest$ac_exeext conftest.$ac_ext
+        ac_fn_c_check_func "$LINENO" "scm_set_automatic_finalization_enabled" "ac_cv_func_scm_set_automatic_finalization_enabled"
+if test "x$ac_cv_func_scm_set_automatic_finalization_enabled" = x""yes; then :
+
+$as_echo "#define HAVE_GUILE_MANUAL_FINALIZATION 1" >>confdefs.h
+
+
+fi
+
     CPPFLAGS=$save_CPPFLAGS
     LIBS=$save_LIBS
     if test "${found_usable_guile}" = no; then
index a4886c93ed16e16eeb4df6146cbbc207470a9b82..4a0b6a3413cf3c49253e34aff3523c07ba5e9469 100644 (file)
@@ -1090,6 +1090,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
index 16d15b7d6c2232295f03b087502093d5750c50a8..4abf5c5bb14537d20767a2e8caef01e30ae34d78 100644 (file)
@@ -704,6 +704,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;
 }
 
@@ -850,6 +854,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
+
 #ifdef HAVE_SIGPROCMASK
     /* Before we initialize Guile, block SIGCHLD.
        This is done so that all threads created during Guile initialization
index 925555681fea91eba017e99e61068bc07ff11485..6052214f15f5c159993e3b3b4384837c425a4bfe 100644 (file)
@@ -155,6 +155,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;
 }