1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-10 14:00:21 +02:00

Don't register disappearing links for non-heap objects.

* libguile/boehm-gc.h (SCM_I_IS_POINTER_TO_THE_HEAP,
  SCM_I_REGISTER_DISAPPEARING_LINK): New.

* libguile/vectors.c (scm_c_vector_set_x): Use
  `SCM_I_REGISTER_DISAPPEARING_LINK ()' instead of
  `GC_GENERAL_REGISTER_DISAPPEARING_LINK ()'.

* libguile/weaks.c (scm_weak_car_pair, scm_weak_cdr_pair,
  scm_doubly_weak_pair): Likewise.
This commit is contained in:
Ludovic Courtès 2009-01-31 19:14:56 +01:00
parent 2ee5aa25db
commit dbe4d258f6
3 changed files with 32 additions and 13 deletions

View file

@ -1,7 +1,7 @@
#ifndef SCM_BOEHM_GC_H
#define SCM_BOEHM_GC_H
/* Copyright (C) 2006, 2008 Free Software Foundation, Inc.
/* Copyright (C) 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
@ -45,4 +45,23 @@
typedef void *GC_PTR;
#endif
#include <gc/gc_mark.h>
/* Return true if PTR points to the heap. */
#define SCM_I_IS_POINTER_TO_THE_HEAP(ptr) \
((void *) (ptr) >= GC_least_plausible_heap_addr \
&& (void *) (ptr) <= GC_greatest_plausible_heap_addr)
/* Register a disappearing link for the object pointed to by OBJ such that
the pointer pointed to be LINK is cleared when OBJ is reclaimed. Do so
only if OBJ actually points to the heap. See
http://thread.gmane.org/gmane.comp.programming.garbage-collection.boehmgc/2563
for details. */
#define SCM_I_REGISTER_DISAPPEARING_LINK(link, obj) \
((SCM_I_IS_POINTER_TO_THE_HEAP (obj)) \
? GC_GENERAL_REGISTER_DISAPPEARING_LINK ((link), (obj)) \
: 0)
#endif /* SCM_BOEHM_GC_H */

View file

@ -1,4 +1,4 @@
/* Copyright (C) 1995,1996,1998,1999,2000,2001, 2006, 2008 Free Software Foundation, Inc.
/* Copyright (C) 1995,1996,1998,1999,2000,2001, 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
@ -279,7 +279,7 @@ scm_c_vector_set_x (SCM v, size_t k, SCM obj)
{
/* Make it a weak pointer. */
GC_PTR link = (GC_PTR) & ((SCM_I_VECTOR_WELTS (v))[k]);
GC_GENERAL_REGISTER_DISAPPEARING_LINK (link, obj);
SCM_I_REGISTER_DISAPPEARING_LINK (link, obj);
}
}
else if (SCM_I_ARRAYP (v) && SCM_I_ARRAY_NDIM (v) == 1)
@ -297,7 +297,7 @@ scm_c_vector_set_x (SCM v, size_t k, SCM obj)
{
/* Make it a weak pointer. */
GC_PTR link = (GC_PTR) & ((SCM_I_VECTOR_WELTS (vv))[k]);
GC_GENERAL_REGISTER_DISAPPEARING_LINK (link, obj);
SCM_I_REGISTER_DISAPPEARING_LINK (link, obj);
}
}
else

View file

@ -1,4 +1,4 @@
/* Copyright (C) 1995,1996,1998,2000,2001, 2003, 2006, 2008 Free Software Foundation, Inc.
/* Copyright (C) 1995,1996,1998,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
@ -64,8 +64,8 @@ scm_weak_car_pair (SCM car, SCM cdr)
if (SCM_NIMP (car))
{
/* Weak car cells make sense iff the car is non-immediate. */
GC_GENERAL_REGISTER_DISAPPEARING_LINK ((GC_PTR)&cell->word_0,
(GC_PTR)SCM_UNPACK (car));
SCM_I_REGISTER_DISAPPEARING_LINK ((GC_PTR) &cell->word_0,
(GC_PTR) SCM_UNPACK (car));
}
return (SCM_PACK (cell));
@ -85,8 +85,8 @@ scm_weak_cdr_pair (SCM car, SCM cdr)
if (SCM_NIMP (cdr))
{
/* Weak cdr cells make sense iff the cdr is non-immediate. */
GC_GENERAL_REGISTER_DISAPPEARING_LINK ((GC_PTR)&cell->word_1,
(GC_PTR)SCM_UNPACK (cdr));
SCM_I_REGISTER_DISAPPEARING_LINK ((GC_PTR) &cell->word_1,
(GC_PTR) SCM_UNPACK (cdr));
}
return (SCM_PACK (cell));
@ -104,13 +104,13 @@ scm_doubly_weak_pair (SCM car, SCM cdr)
if (SCM_NIMP (car))
{
GC_GENERAL_REGISTER_DISAPPEARING_LINK ((GC_PTR)&cell->word_0,
(GC_PTR)SCM_UNPACK (car));
SCM_I_REGISTER_DISAPPEARING_LINK ((GC_PTR) &cell->word_0,
(GC_PTR) SCM_UNPACK (car));
}
if (SCM_NIMP (cdr))
{
GC_GENERAL_REGISTER_DISAPPEARING_LINK ((GC_PTR)&cell->word_1,
(GC_PTR)SCM_UNPACK (cdr));
SCM_I_REGISTER_DISAPPEARING_LINK ((GC_PTR) &cell->word_1,
(GC_PTR) SCM_UNPACK (cdr));
}
return (SCM_PACK (cell));