Skip to content

Commit c58336f

Browse files
committed
Cleans up checkarrayblock implementation
Uses consistent naming (_np) for native pointer equivalents of Lisp addresses Ensures non-zero return value if arrayblock fails check
1 parent f2bf026 commit c58336f

File tree

1 file changed

+29
-17
lines changed

1 file changed

+29
-17
lines changed

src/gcfinal.c

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,9 @@ LispPTR releasingvmempage(LispPTR ptr) {
181181
/* Given an array block, do consistency checks on it. */
182182
/* */
183183
/************************************************************************/
184-
185184
LispPTR checkarrayblock(LispPTR base, LispPTR free, LispPTR onfreelist) {
186-
struct arrayblock *bbase, *btrailer;
187-
struct arrayblock *bfwd, *bbwd, *rbase;
185+
struct arrayblock *base_np, *trailer_np;
186+
struct arrayblock *fwd_np, *bkwd_np, *rbase;
188187
LispPTR fbl;
189188
LispPTR *rover, *tmprover;
190189
#ifdef ARRAYCHECK
@@ -193,38 +192,51 @@ LispPTR checkarrayblock(LispPTR base, LispPTR free, LispPTR onfreelist) {
193192
if (*Array_Block_Checking_word != NIL)
194193
#endif
195194
{
196-
bbase = (struct arrayblock *)NativeAligned4FromLAddr(base);
197-
btrailer = (struct arrayblock *)NativeAligned4FromLAddr(Trailer(base, bbase));
198-
if (bbase->password != ARRAYBLOCKPASSWORD) {
195+
base_np = (struct arrayblock *)NativeAligned4FromLAddr(base);
196+
trailer_np = (struct arrayblock *)NativeAligned4FromLAddr(Trailer(base, base_np));
197+
#if 0
198+
printf("cblock: 0x%x free: %x onfreelist: %x pw: %x arlen %d\n",
199+
base, free, onfreelist, base_np->password, base_np->arlen);
200+
#endif
201+
if (base_np->password != ARRAYBLOCKPASSWORD) {
199202
printarrayblock(base);
200203
error("ARRAYBLOCK password wrong\n");
201-
} else if (bbase->inuse == free) {
204+
return(T);
205+
} else if (base_np->inuse == free) {
202206
printarrayblock(base);
203207
error("ARRAYBLOCK INUSE bit set wrong\n");
204-
} else if (btrailer->password != ARRAYBLOCKPASSWORD) {
208+
return(T);
209+
} else if (trailer_np->password != ARRAYBLOCKPASSWORD) {
205210
printarrayblock(base);
206211
error("ARRAYBLOCK trailer password wrong\n");
207-
} else if (bbase->arlen != btrailer->arlen) {
212+
return(T);
213+
} else if (base_np->arlen != trailer_np->arlen) {
208214
printarrayblock(base);
209215
error("ARRAYBLOCK Header and Trailer length don't match\n");
210-
} else if (btrailer->inuse == free)
216+
return(T);
217+
} else if (trailer_np->inuse == free)
211218
/* This is not original source.(in original,
212-
btrailer -> bbase) maybe, this is correction. */
219+
trailer_np -> base_np) maybe, this is correction. */
213220
{
214221
printarrayblock(base);
215222
error("ARRAYBLOCK Trailer INUSE bit set wrong\n");
216-
} else if (!onfreelist || (bbase->arlen < MINARRAYBLOCKSIZE))
223+
return(T);
224+
} else if (!onfreelist || (base_np->arlen < MINARRAYBLOCKSIZE))
217225
return (NIL);
218226
/* Remaining tests only for free list. */
219-
bfwd = (struct arrayblock *)NativeAligned4FromLAddr(bbase->fwd);
220-
bbwd = (struct arrayblock *)NativeAligned4FromLAddr(bbase->bkwd);
221-
if ((bbwd->fwd != base) || (bfwd->bkwd != base)) {
227+
fwd_np = (struct arrayblock *)NativeAligned4FromLAddr(base_np->fwd);
228+
bkwd_np = (struct arrayblock *)NativeAligned4FromLAddr(base_np->bkwd);
229+
if ((bkwd_np->fwd != base) || (fwd_np->bkwd != base)) {
222230
error("ARRAYBLOCK links fouled\n");
231+
return(T);
223232
} else {
224-
fbl = FreeBlockChainN(bbase->arlen);
233+
fbl = FreeBlockChainN(base_np->arlen);
225234
rover = tmprover = (LispPTR *)NativeAligned4FromLAddr(fbl);
226235
/* GETBASEPTR */
227-
if ((*rover & POINTERMASK) == NIL) error("Free Block's bucket empty\n");
236+
if ((*rover & POINTERMASK) == NIL) {
237+
error("Free Block's bucket empty\n");
238+
return(T);
239+
}
228240
do {
229241
if ((*rover & POINTERMASK) == base) return (NIL);
230242
checkarrayblock((*rover & POINTERMASK), T, NIL);

0 commit comments

Comments
 (0)