Use `scm_gc_malloc ()' when allocating hook entries.
authorLudovic Courtès <ludo@gnu.org>
Sun, 18 Jan 2009 15:13:31 +0000 (16:13 +0100)
committerLudovic Courtès <ludo@gnu.org>
Sun, 18 Jan 2009 15:13:31 +0000 (16:13 +0100)
* libguile/hooks.c (hook_entry_gc_hint): New.
  (scm_c_hook_add): Use `scm_gc_malloc ()' instead of `scm_malloc ()'.
  (scm_c_hook_remove): Don't explicitly free(3) the entry, let the GC do
  its job.

libguile/hooks.c

index aa80151..d175be1 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 1995,1996,1998,1999,2000,2001, 2003, 2006, 2008 Free Software Foundation, Inc.
+/* Copyright (C) 1995,1996,1998,1999,2000,2001, 2003, 2006, 2008, 2009 Free Software Foundation, Inc.
  * 
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -42,6 +42,9 @@
  * using C level hooks.
  */
 
+/* Hint for `scm_gc_malloc ()' and friends.  */
+static const char hook_entry_gc_hint[] = "hook entry";
+
 void
 scm_c_hook_init (scm_t_c_hook *hook, void *hook_data, scm_t_c_hook_type type)
 {
@@ -56,8 +59,10 @@ scm_c_hook_add (scm_t_c_hook *hook,
                void *fn_data, 
                int appendp)
 {
-  scm_t_c_hook_entry *entry = scm_malloc (sizeof (scm_t_c_hook_entry));
+  scm_t_c_hook_entry *entry;
   scm_t_c_hook_entry **loc = &hook->first;
+
+  entry = scm_gc_malloc (sizeof (scm_t_c_hook_entry), hook_entry_gc_hint);
   if (appendp)
     while (*loc)
       loc = &(*loc)->next;
@@ -77,9 +82,7 @@ scm_c_hook_remove (scm_t_c_hook *hook,
     {
       if ((*loc)->func == func && (*loc)->data == fn_data)
        {
-         scm_t_c_hook_entry *entry = *loc;
          *loc = (*loc)->next;
-         free (entry);
          return;
        }
       loc = &(*loc)->next;