Index: xldmem.c
===================================================================
RCS file: /NOKOMIS/users/luke/SRC/xlispstat/xldmem.c,v
retrieving revision 1.29
diff -r1.29 xldmem.c
9a10,13
> static LVAL finalize_registered, finalize_pending;
> static VOID check_finalize(V);
> static VOID do_finalize(V);
> 
311a316,318
> 
>     finalize_registered = NIL;
>     finalize_pending = NIL;
1107a1115,1125
>   check_finalize();
>   if (finalize_registered != NIL || finalize_pending != NIL) {
>     forward_node(finalize_registered);
>     forward_node(finalize_pending);
>     while ((tmp = forwarded_nodes) != NIL) {
>       forwarded_nodes = NEXT_NODE_PTR(tmp);
>       forward_children(tmp);
>       TENURE_NODE(tmp);
>       unset_to_new_node(tmp);
>     }
>   }
1133a1152,1153
>   if (! null(finalize_pending))
>     do_finalize();
1630a1651,1653
> 
>     finalize_registered = NIL;
>     finalize_pending = NIL;
2864a2888,2937
> 
> static VOID check_finalize(V)
> {
>   LVAL last = NIL, next = finalize_registered, head, tail;
> 
>   while (consp(next)) {
>     if (is_new_node(car(car(next)))) {
>       head = next;
>       tail = cdr(next);
>       if (null(last))
>         finalize_registered = tail;
>       else
>         Rplacd(last, tail);
>       next = tail;
>       Rplacd(head, finalize_pending);
>       finalize_pending = head;
>     }
>     else {
>       last = next;
>       next = cdr(next);
>     }
>   }
> }
> 
> static VOID do_finalize(V)
> {
>   CONTEXT cntxt;
>   LVAL next;
> 
>   xlsave1(next);
>   xlbegin(&cntxt,CF_UNWIND|CF_ERROR,NIL);
>   setjmp(cntxt.c_jmpbuf);
>   while (consp(finalize_pending)) {
>     next = finalize_pending;
>     finalize_pending = cdr(next);
>     xlapp1(cdr(car(next)), car(car(next)));
>   }
>   xlend(&cntxt);
>   xlpop();
> }
> 
> LVAL xregfinal(V)
> {
>   LVAL arg, fun;
>   arg = xlgetarg();
>   fun = xlgetarg();
>   xllastarg();
>   finalize_registered = cons(cons(arg, fun), finalize_registered);
>   return NIL;
> }
Index: xlftab.c
===================================================================
RCS file: /NOKOMIS/users/luke/SRC/xlispstat/xlftab.c,v
retrieving revision 1.20
diff -r1.20 xlftab.c
309a310
> {   "REGISTER-FINALIZER",S, xregfinal    },
826d826
< {   NULL,               S, xnotimp      },
Index: xlftab.h
===================================================================
RCS file: /NOKOMIS/users/luke/SRC/xlispstat/xlftab.h,v
retrieving revision 1.21
diff -r1.21 xlftab.h
124c124
<     xgc(V),xexpand(V),xalloc(V),xmem(V);
---
>     xgc(V),xexpand(V),xalloc(V),xmem(V),xregfinal(V);
