diff --git a/src/weakptr.c b/src/weakptr.c index 5de44596b5..89c9c4e901 100644 --- a/src/weakptr.c +++ b/src/weakptr.c @@ -200,7 +200,8 @@ Obj FuncWeakPointerObj( Obj self, Obj list ) { ** trailing items may evaporate. ** ** Any identifiers of trailing objects that have evaporated in a garbage -** collection are cleaned up by this function +** collection are cleaned up by this function, if we have exclusive +** write access, otherwise they stay around. */ Int LengthWPObj(Obj wp) @@ -208,24 +209,25 @@ Int LengthWPObj(Obj wp) Int len; Obj elm; Int changed = 0; + len = STORED_LEN_WPOBJ(wp); + if (CheckExclusiveWriteAccess(wp)) { #ifndef BOEHM_GC - for (len = STORED_LEN_WPOBJ(wp); - len > 0 && - (!(elm = ELM_WPOBJ(wp,len)) || - IS_WEAK_DEAD_BAG(elm)); - len --) - { + for (; len > 0 && + (!(elm = ELM_WPOBJ(wp,len)) || + IS_WEAK_DEAD_BAG(elm)); + len --) + { + changed = 1; + if (elm) + ELM_WPOBJ(wp,len) = 0; + } +#else + while (len > 0 && !ELM_WPOBJ(wp, len)) { changed = 1; - if (elm) - ELM_WPOBJ(wp,len) = 0; + len--; } -#else - len = STORED_LEN_WPOBJ(wp); - while (len > 0 && !ELM_WPOBJ(wp, len)) { - changed = 1; - len--; - } #endif + } if (changed) STORE_LEN_WPOBJ(wp,len); return len;