Draft: Fix #243: weak pointer to static array
Add function clear-static-vector-mark
to clear the static vector
mark for all the static vectors in lisp::*static-vectors*
. This is
added to *before-gc-hooks*
so that the marks are cleared before GC
so that GC can set it if the static vector is still in use.
Modify finalize-static-vectors
to delete any element in
lisp::*static-vectors*
which has broken weak pointer. That means GC
has freed the static vectors so we don't need to keep track of it
anymore.
Finally, modify scan_weak_pointers
to free the static vectors. The algorithm (from !188 (comment 13604)) is:
Here is an algorithm:
-
Traverse the weak pointer list and collect all of the weak pointers that point to unmarked static vectors. For lack of a more specific term we will call this the clearable list. (You can combine this traversal with the regular weak pointer clearing to save a traversal of the weak pointer list.)
-
Traverse the clearable list. For each weak pointer, if the value is an unmarked static vector, mark it. Otherwise, if the value is marked static vector, you know it shares a referent with another weak pointer so break the weak pointer and remove it from the clearable list. (If you don't you'll get a double free in the next step.)
-
Finally, traverse the clearable list a final time. The static vectors can be safely freed and all of the weak references on the clearable list can be cleared.
Step 1 established the invariant that all of the weak pointers on the clearable list point to an unmarked static vector.
Step 2 established the invariant that each weak pointer that remains on the clearable list references a unique dead static vector.