mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-05-20 03:30:27 +02:00
use the new finalizer helpers
* libguile/foreign.c (scm_set_pointer_finalizer_x) * libguile/ports.c (finalize_port, scm_c_make_port_with_encoding) (open_iconv_descriptors) * libguile/smob.c (scm_i_new_smob, scm_i_new_double_smob) * libguile/struct.c (scm_i_alloc_struct) * libguile/weak-set.c (weak_gc_finalizer) (scm_c_register_weak_gc_callback) * libguile/weak-table.c (scm_c_register_weak_gc_callback) (weak_gc_finalizer) * libguile/numbers.c (make_bignum): Use the new API.
This commit is contained in:
parent
6e9ec86dc0
commit
6978c67339
7 changed files with 21 additions and 86 deletions
|
@ -157,16 +157,8 @@ scm_from_pointer (void *ptr, scm_t_pointer_finalizer finalizer)
|
|||
ret = scm_cell (scm_tc7_pointer, (scm_t_bits) ptr);
|
||||
|
||||
if (finalizer)
|
||||
{
|
||||
/* Register a finalizer for the newly created instance. */
|
||||
GC_finalization_proc prev_finalizer;
|
||||
GC_PTR prev_finalizer_data;
|
||||
GC_REGISTER_FINALIZER_NO_ORDER (SCM2PTR (ret),
|
||||
pointer_finalizer_trampoline,
|
||||
finalizer,
|
||||
&prev_finalizer,
|
||||
&prev_finalizer_data);
|
||||
}
|
||||
scm_i_set_finalizer (SCM2PTR (ret), pointer_finalizer_trampoline,
|
||||
finalizer);
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
@ -316,20 +308,11 @@ SCM_DEFINE (scm_set_pointer_finalizer_x, "set-pointer-finalizer!", 2, 0, 0,
|
|||
"Scheme. If you need a Scheme finalizer, use guardians.")
|
||||
#define FUNC_NAME s_scm_set_pointer_finalizer_x
|
||||
{
|
||||
void *c_finalizer;
|
||||
GC_finalization_proc prev_finalizer;
|
||||
GC_PTR prev_finalizer_data;
|
||||
|
||||
SCM_VALIDATE_POINTER (1, pointer);
|
||||
SCM_VALIDATE_POINTER (2, finalizer);
|
||||
|
||||
c_finalizer = SCM_POINTER_VALUE (finalizer);
|
||||
|
||||
GC_REGISTER_FINALIZER_NO_ORDER (SCM2PTR (pointer),
|
||||
pointer_finalizer_trampoline,
|
||||
c_finalizer,
|
||||
&prev_finalizer,
|
||||
&prev_finalizer_data);
|
||||
scm_i_add_finalizer (SCM2PTR (pointer), pointer_finalizer_trampoline,
|
||||
SCM_POINTER_VALUE (finalizer));
|
||||
|
||||
return SCM_UNSPECIFIED;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004,2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
|
||||
/* Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004,2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
|
||||
*
|
||||
* Portions Copyright 1990, 1991, 1992, 1993 by AT&T Bell Laboratories
|
||||
* and Bellcore. See scm_divide.
|
||||
|
@ -217,17 +217,13 @@ static inline SCM
|
|||
make_bignum (void)
|
||||
{
|
||||
scm_t_bits *p;
|
||||
GC_finalization_proc prev_finalizer;
|
||||
GC_PTR prev_finalizer_data;
|
||||
|
||||
/* Allocate one word for the type tag and enough room for an `mpz_t'. */
|
||||
p = scm_gc_malloc_pointerless (sizeof (scm_t_bits) + sizeof (mpz_t),
|
||||
"bignum");
|
||||
p[0] = scm_tc16_big;
|
||||
|
||||
GC_REGISTER_FINALIZER_NO_ORDER (p, finalize_bignum, NULL,
|
||||
&prev_finalizer,
|
||||
&prev_finalizer_data);
|
||||
scm_i_set_finalizer (p, finalize_bignum, NULL);
|
||||
|
||||
return SCM_PACK (p);
|
||||
}
|
||||
|
|
|
@ -533,22 +533,6 @@ SCM scm_i_port_weak_set;
|
|||
|
||||
/* Port finalization. */
|
||||
|
||||
static void finalize_port (GC_PTR, GC_PTR);
|
||||
|
||||
/* Register a finalizer for PORT. */
|
||||
static SCM_C_INLINE_KEYWORD void
|
||||
register_finalizer_for_port (SCM port)
|
||||
{
|
||||
GC_finalization_proc prev_finalizer;
|
||||
GC_PTR prev_finalization_data;
|
||||
|
||||
/* Register a finalizer for PORT so that its iconv CDs get freed and
|
||||
optionally its type's `free' function gets called. */
|
||||
GC_REGISTER_FINALIZER_NO_ORDER (SCM2PTR (port), finalize_port, 0,
|
||||
&prev_finalizer,
|
||||
&prev_finalization_data);
|
||||
}
|
||||
|
||||
struct do_free_data
|
||||
{
|
||||
scm_t_ptob_descriptor *ptob;
|
||||
|
@ -627,12 +611,12 @@ scm_c_make_port_with_encoding (scm_t_bits tag, unsigned long mode_bits,
|
|||
entry->ilseq_handler = handler;
|
||||
entry->iconv_descriptors = NULL;
|
||||
|
||||
if (SCM_PORT_DESCRIPTOR (ret)->free)
|
||||
scm_i_set_finalizer (SCM2PTR (ret), finalize_port, NULL);
|
||||
|
||||
if (SCM_PORT_DESCRIPTOR (ret)->flags & SCM_PORT_TYPE_HAS_FLUSH)
|
||||
scm_weak_set_add_x (scm_i_port_weak_set, ret);
|
||||
|
||||
if (SCM_PORT_DESCRIPTOR (ret)->free)
|
||||
register_finalizer_for_port (ret);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -906,14 +890,8 @@ open_iconv_descriptors (const char *encoding, int reading, int writing)
|
|||
id->input_cd = input_cd;
|
||||
id->output_cd = output_cd;
|
||||
|
||||
{
|
||||
GC_finalization_proc prev_finalizer;
|
||||
GC_PTR prev_finalization_data;
|
||||
|
||||
/* Register a finalizer to close the descriptors. */
|
||||
GC_REGISTER_FINALIZER_NO_ORDER (id, finalize_iconv_descriptors, 0,
|
||||
&prev_finalizer, &prev_finalization_data);
|
||||
}
|
||||
/* Register a finalizer to close the descriptors. */
|
||||
scm_i_set_finalizer (id, finalize_iconv_descriptors, NULL);
|
||||
|
||||
return id;
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* Copyright (C) 1995,1996,1998,1999,2000,2001, 2003, 2004, 2006, 2009, 2010, 2011 Free Software Foundation, Inc.
|
||||
/* Copyright (C) 1995,1996,1998,1999,2000,2001, 2003, 2004, 2006, 2009, 2010, 2011, 2012 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 License
|
||||
|
@ -597,14 +597,7 @@ scm_i_new_smob (scm_t_bits tc, scm_t_bits data)
|
|||
SCM_SET_CELL_WORD_0 (ret, tc);
|
||||
|
||||
if (scm_smobs[smobnum].free)
|
||||
{
|
||||
GC_finalization_proc prev_finalizer;
|
||||
GC_PTR prev_finalizer_data;
|
||||
|
||||
GC_REGISTER_FINALIZER_NO_ORDER (SCM2PTR (ret),
|
||||
finalize_smob, NULL,
|
||||
&prev_finalizer, &prev_finalizer_data);
|
||||
}
|
||||
scm_i_set_finalizer (SCM2PTR (ret), finalize_smob, NULL);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -631,14 +624,7 @@ scm_i_new_double_smob (scm_t_bits tc, scm_t_bits data1,
|
|||
SCM_SET_CELL_WORD_0 (ret, tc);
|
||||
|
||||
if (scm_smobs[smobnum].free)
|
||||
{
|
||||
GC_finalization_proc prev_finalizer;
|
||||
GC_PTR prev_finalizer_data;
|
||||
|
||||
GC_REGISTER_FINALIZER_NO_ORDER (SCM2PTR (ret),
|
||||
finalize_smob, NULL,
|
||||
&prev_finalizer, &prev_finalizer_data);
|
||||
}
|
||||
scm_i_set_finalizer (SCM2PTR (ret), finalize_smob, NULL);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* Copyright (C) 1996,1997,1998,1999,2000,2001, 2003, 2004, 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
|
||||
/* Copyright (C) 1996,1997,1998,1999,2000,2001, 2003, 2004, 2006, 2007, 2008, 2009, 2010, 2011, 2012 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 License
|
||||
|
@ -444,16 +444,8 @@ scm_i_alloc_struct (scm_t_bits *vtable_data, int n_words)
|
|||
|
||||
/* vtable_data can be null when making a vtable vtable */
|
||||
if (vtable_data && vtable_data[scm_vtable_index_instance_finalize])
|
||||
{
|
||||
/* Register a finalizer for the newly created instance. */
|
||||
GC_finalization_proc prev_finalizer;
|
||||
GC_PTR prev_finalizer_data;
|
||||
GC_REGISTER_FINALIZER_NO_ORDER (SCM2PTR (ret),
|
||||
struct_finalizer_trampoline,
|
||||
NULL,
|
||||
&prev_finalizer,
|
||||
&prev_finalizer_data);
|
||||
}
|
||||
/* Register a finalizer for the newly created instance. */
|
||||
scm_i_set_finalizer (SCM2PTR (ret), struct_finalizer_trampoline, NULL);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -800,7 +800,7 @@ static void
|
|||
weak_gc_finalizer (void *ptr, void *data)
|
||||
{
|
||||
if (weak_gc_callback (ptr))
|
||||
GC_REGISTER_FINALIZER_NO_ORDER (ptr, weak_gc_finalizer, data, NULL, NULL);
|
||||
scm_i_set_finalizer (ptr, weak_gc_finalizer, data);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -816,7 +816,7 @@ scm_c_register_weak_gc_callback (SCM obj, void (*callback) (SCM))
|
|||
#ifdef HAVE_GC_SET_START_CALLBACK
|
||||
scm_c_hook_add (&scm_after_gc_c_hook, weak_gc_hook, weak, 0);
|
||||
#else
|
||||
GC_REGISTER_FINALIZER_NO_ORDER (weak, weak_gc_finalizer, NULL, NULL, NULL);
|
||||
scm_i_set_finalizer (weak, weak_gc_finalizer, NULL);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
@ -927,7 +927,7 @@ static void
|
|||
weak_gc_finalizer (void *ptr, void *data)
|
||||
{
|
||||
if (weak_gc_callback (ptr))
|
||||
GC_REGISTER_FINALIZER_NO_ORDER (ptr, weak_gc_finalizer, data, NULL, NULL);
|
||||
scm_i_set_finalizer (ptr, weak_gc_finalizer, data);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -943,7 +943,7 @@ scm_c_register_weak_gc_callback (SCM obj, void (*callback) (SCM))
|
|||
#ifdef HAVE_GC_TABLE_START_CALLBACK
|
||||
scm_c_hook_add (&scm_after_gc_c_hook, weak_gc_hook, weak, 0);
|
||||
#else
|
||||
GC_REGISTER_FINALIZER_NO_ORDER (weak, weak_gc_finalizer, NULL, NULL, NULL);
|
||||
scm_i_set_finalizer (weak, weak_gc_finalizer, NULL);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue