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

* gc.c (scm_unprotect_object): Change this so that calls to

scm_protect_object and scm_unprotect_object nest properly.
(scm_protect_object): Doc fixes.
This commit is contained in:
Jim Blandy 1998-10-07 20:05:56 +00:00
parent a14e47910e
commit dab7f56692

View file

@ -1800,21 +1800,22 @@ scm_permanent_object (obj)
even if all other references are dropped, until someone applies even if all other references are dropped, until someone applies
scm_unprotect_object to it. This function returns OBJ. scm_unprotect_object to it. This function returns OBJ.
Note that calls to scm_protect_object do not nest. You can call Calls to scm_protect_object nest. For every object O, there is a
scm_protect_object any number of times on a given object, and the counter which scm_protect_object(O) increments and
next call to scm_unprotect_object will unprotect it completely. scm_unprotect_object(O) decrements, if it is greater than zero. If
an object's counter is greater than zero, the garbage collector
will not free it.
Basically, scm_protect_object and scm_unprotect_object just Of course, that's not how it's implemented. scm_protect_object and
maintain a list of references to things. Since the GC knows about scm_unprotect_object just maintain a list of references to things.
this list, all objects it mentions stay alive. scm_protect_object Since the GC knows about this list, all objects it mentions stay
adds its argument to the list; scm_unprotect_object remove its alive. scm_protect_object adds its argument to the list;
argument from the list. */ scm_unprotect_object removes the first occurrence of its argument
to the list. */
SCM SCM
scm_protect_object (obj) scm_protect_object (obj)
SCM obj; SCM obj;
{ {
/* This function really should use address hashing tables, but I
don't know how to use them yet. For now we just use a list. */
scm_protects = scm_cons (obj, scm_protects); scm_protects = scm_cons (obj, scm_protects);
return obj; return obj;
@ -1822,14 +1823,23 @@ scm_protect_object (obj)
/* Remove any protection for OBJ established by a prior call to /* Remove any protection for OBJ established by a prior call to
scm_protect_obj. This function returns OBJ. scm_protect_object. This function returns OBJ.
See scm_protect_obj for more information. */ See scm_protect_object for more information. */
SCM SCM
scm_unprotect_object (obj) scm_unprotect_object (obj)
SCM obj; SCM obj;
{ {
scm_protects = scm_delq_x (obj, scm_protects); SCM *tail_ptr = &scm_protects;
while (SCM_NIMP (*tail_ptr) && SCM_CONSP (*tail_ptr))
if (SCM_CAR (*tail_ptr) == obj)
{
*tail_ptr = SCM_CDR (*tail_ptr);
break;
}
else
tail_ptr = SCM_CDRLOC (*tail_ptr);
return obj; return obj;
} }