Skip to content

Commit 1f18779

Browse files
committed
Cleans up deleteblock implementation to increase clarity
Procedure can be static void as there was only an unused constant result. Uses consistent naming (_np) for native pointer equivalents of Lisp addresses, and better matches Lisp implementation naming of variables. Adds comments with a little explanation of what the code is doing.
1 parent 357336b commit 1f18779

File tree

2 files changed

+30
-25
lines changed

2 files changed

+30
-25
lines changed

inc/gcfinaldefs.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
void printarrayblock(LispPTR base);
55
LispPTR releasingvmempage(LispPTR ptr);
66
LispPTR checkarrayblock(LispPTR base, LispPTR free, LispPTR onfreelist);
7-
LispPTR deleteblock(LispPTR base);
87
LispPTR linkblock(LispPTR base);
98
LispPTR makefreearrayblock(LispPTR block, DLword length);
109
LispPTR arrayblockmerger(LispPTR base, LispPTR nbase);

src/gcfinal.c

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
#include "gccodedefs.h" // for reclaimcodeblock
5252
#include "gcdata.h" // for DELREF, REC_GCLOOKUP
5353
#include "gchtfinddefs.h" // for htfind, rec_htfind
54-
#include "gcfinaldefs.h" // for arrayblockmerger, checkarrayblock, deleteblock
54+
#include "gcfinaldefs.h" // for arrayblockmerger, checkarrayblock
5555
#include "lispemul.h" // for LispPTR, NIL, T, POINTERMASK, DLword, ATOM_T
5656
#include "llstkdefs.h" // for decusecount68k
5757
#include "lspglob.h" // for FreeBlockBuckets_word, ArrayMerging_word
@@ -243,32 +243,38 @@ LispPTR checkarrayblock(LispPTR base, LispPTR free, LispPTR onfreelist) {
243243
/* */
244244
/* */
245245
/************************************************************************/
246-
247-
LispPTR deleteblock(LispPTR base) {
248-
struct arrayblock *bbase, *fbbase, *bbbase;
249-
LispPTR fwd, bkwd, fbl, freeblocklsp;
250-
LispPTR *freeblock;
251-
bbase = (struct arrayblock *)NativeAligned4FromLAddr(base);
252-
if ((bbase->arlen >= MINARRAYBLOCKSIZE) && (bbase->fwd != NIL)) {
253-
fwd = bbase->fwd;
254-
fbbase = (struct arrayblock *)NativeAligned4FromLAddr(fwd);
255-
bkwd = bbase->bkwd;
256-
bbbase = (struct arrayblock *)NativeAligned4FromLAddr(bkwd);
257-
fbl = FreeBlockChainN(bbase->arlen);
258-
freeblock = (LispPTR *)NativeAligned4FromLAddr(fbl);
259-
freeblocklsp = POINTERMASK & *freeblock;
260-
if (base == fwd) {
261-
if (base == freeblocklsp)
262-
*freeblock = NIL;
246+
/*
247+
* Removes "base", a block from the free list and
248+
* adjusts the forward and backward pointers of the blocks behind and
249+
* ahead of the deleted block.
250+
* The forward and backward pointers of this deleted block are left
251+
* dangling - as in the Lisp implementation. Also does not affect the
252+
* inuse bit in header and trailer.
253+
*/
254+
static void deleteblock(LispPTR base) {
255+
struct arrayblock *base_np, *f_np, *b_np;
256+
LispPTR f, b, fbl, freeblock;
257+
LispPTR *fbl_np;
258+
base_np = (struct arrayblock *)NativeAligned4FromLAddr(base);
259+
if ((base_np->arlen >= MINARRAYBLOCKSIZE) && (base_np->fwd != NIL)) {
260+
f = base_np->fwd;
261+
f_np = (struct arrayblock *)NativeAligned4FromLAddr(f);
262+
b = base_np->bkwd;
263+
b_np = (struct arrayblock *)NativeAligned4FromLAddr(b);
264+
fbl = FreeBlockChainN(base_np->arlen);
265+
fbl_np = (LispPTR *)NativeAligned4FromLAddr(fbl);
266+
freeblock = POINTERMASK & *fbl_np;
267+
if (base == f) {
268+
if (base == freeblock)
269+
*fbl_np = NIL;
263270
else
264271
error("GC error:deleting last list # FREEBLOCKLIST\n");
265-
return (NIL);
266-
} else if (base == freeblocklsp)
267-
*freeblock = fwd;
268-
fbbase->bkwd = bkwd;
269-
bbbase->fwd = fwd;
272+
return;
273+
} else if (base == freeblock)
274+
*fbl_np = f;
275+
f_np->bkwd = b;
276+
b_np->fwd = f;
270277
}
271-
return (NIL);
272278
}
273279

274280
/************************************************************************/

0 commit comments

Comments
 (0)