mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-04-30 11:50:28 +02:00
Allow guardians to be GC'd before the objects they guard.
* libguile/guardians.c (finalize_guarded): While traversing GUARDIANS_LIST, check for deleted weak-car pairs. (scm_i_guard): Instantiate GUARDIANS_FOR_OBJ using `scm_weak_car_pair ()' rather than `scm_cons ()'. git-archimport-id: lcourtes@laas.fr--2005-libre/guile-core--boehm-gc--1.9--patch-41
This commit is contained in:
parent
72c9d17bf3
commit
9778b58a19
1 changed files with 10 additions and 2 deletions
|
@ -124,8 +124,13 @@ finalize_guarded (GC_PTR ptr, GC_PTR finalizer_data)
|
||||||
guardian_list = SCM_CDR (guardian_list))
|
guardian_list = SCM_CDR (guardian_list))
|
||||||
{
|
{
|
||||||
SCM zombies;
|
SCM zombies;
|
||||||
t_guardian *g = GUARDIAN_DATA (SCM_CAR (guardian_list));
|
t_guardian *g;
|
||||||
|
|
||||||
|
if (SCM_WEAK_PAIR_CAR_DELETED_P (guardian_list))
|
||||||
|
/* The guardian itself vanished in the meantime. */
|
||||||
|
continue;
|
||||||
|
|
||||||
|
g = GUARDIAN_DATA (SCM_CAR (guardian_list));
|
||||||
if (g->live == 0)
|
if (g->live == 0)
|
||||||
abort ();
|
abort ();
|
||||||
|
|
||||||
|
@ -191,7 +196,10 @@ scm_i_guard (SCM guardian, SCM obj)
|
||||||
SCM guardians_for_obj, finalizer_data;
|
SCM guardians_for_obj, finalizer_data;
|
||||||
|
|
||||||
g->live++;
|
g->live++;
|
||||||
guardians_for_obj = scm_cons (guardian, SCM_EOL);
|
|
||||||
|
/* Note: GUARDIANS_FOR_OBJ is a weak list so that a guardian can be
|
||||||
|
collected before the objects it guards (see `guardians.test'). */
|
||||||
|
guardians_for_obj = scm_weak_car_pair (guardian, SCM_EOL);
|
||||||
finalizer_data = scm_cons (SCM_BOOL_F, guardians_for_obj);
|
finalizer_data = scm_cons (SCM_BOOL_F, guardians_for_obj);
|
||||||
|
|
||||||
GC_REGISTER_FINALIZER_NO_ORDER (SCM2PTR (obj), finalize_guarded,
|
GC_REGISTER_FINALIZER_NO_ORDER (SCM2PTR (obj), finalize_guarded,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue