17 |
|
|
18 |
|
|
19 |
|
static struct ohtab { |
20 |
< |
int hsiz; /* current table size */ |
21 |
< |
OBJECT *htab; /* table, if allocated */ |
20 |
> |
int hsiz; /* current table size */ |
21 |
> |
OBJECT *htab; /* table, if allocated */ |
22 |
|
} modtab = {100, NULL}, objtab = {1000, NULL}; /* modifiers and objects */ |
23 |
|
|
24 |
|
static int otndx(char *, struct ohtab *); |
29 |
|
OBJREC *op |
30 |
|
) |
31 |
|
{ |
32 |
< |
int i, j; |
32 |
> |
int i; |
33 |
> |
ssize_t j; |
34 |
|
|
35 |
< |
for (i = nobjects>>OBJBLKSHFT; i >= 0; i--) { |
35 |
> |
for (i = (nobjects-1)>>OBJBLKSHFT; i >= 0; i--) { |
36 |
|
j = op - objblock[i]; |
37 |
< |
if ((j >= 0) & (j < OBJBLKSIZ)) |
38 |
< |
return((i<<OBJBLKSHFT) + j); |
37 |
> |
if ((0 <= j) & (j < OBJBLKSIZ)) |
38 |
> |
return(((OBJECT)i<<OBJBLKSHFT) + (OBJECT)j); |
39 |
|
} |
40 |
< |
return(OVOID); |
40 |
> |
return(OVOID); /* not in our array -- may still be valid */ |
41 |
|
} |
42 |
|
|
43 |
|
|
48 |
|
) |
49 |
|
{ |
50 |
|
OBJREC *op; |
51 |
< |
int i; |
51 |
> |
OBJECT i; |
52 |
|
|
53 |
|
i = modifier(mname); /* try hash table first */ |
54 |
|
if ((obj == OVOID) | (i < obj)) |
55 |
|
return(i); |
56 |
|
for (i = obj; i-- > 0; ) { /* need to search */ |
57 |
|
op = objptr(i); |
58 |
< |
if (ismodifier(op->otype) && op->oname[0] == mname[0] && |
59 |
< |
!strcmp(op->oname, mname)) |
58 |
> |
if ((ismodifier(op->otype) != 0) & (op->oname[0] == mname[0]) |
59 |
> |
&& !strcmp(op->oname, mname)) |
60 |
|
return(i); |
61 |
|
} |
62 |
|
return(OVOID); |
190 |
|
|
191 |
|
|
192 |
|
void |
193 |
< |
clearobjndx(void) /* clear object hash tables */ |
193 |
> |
truncobjndx(void) /* remove bogus table entries past end */ |
194 |
|
{ |
195 |
< |
if (modtab.htab != NULL) { |
196 |
< |
free((void *)modtab.htab); |
197 |
< |
modtab.htab = NULL; |
198 |
< |
modtab.hsiz = 100; |
195 |
> |
int ndx; |
196 |
> |
|
197 |
> |
if (nobjects <= 0) { |
198 |
> |
if (modtab.htab != NULL) { |
199 |
> |
free(modtab.htab); |
200 |
> |
modtab.htab = NULL; |
201 |
> |
modtab.hsiz = 100; |
202 |
> |
} |
203 |
> |
if (objtab.htab != NULL) { |
204 |
> |
free(objtab.htab); |
205 |
> |
objtab.htab = NULL; |
206 |
> |
objtab.hsiz = 100; |
207 |
> |
} |
208 |
> |
return; |
209 |
|
} |
210 |
< |
if (objtab.htab != NULL) { |
211 |
< |
free((void *)objtab.htab); |
212 |
< |
objtab.htab = NULL; |
213 |
< |
objtab.hsiz = 100; |
214 |
< |
} |
210 |
> |
for (ndx = modtab.hsiz*(modtab.htab != NULL); ndx--; ) |
211 |
> |
if (modtab.htab[ndx] >= nobjects) |
212 |
> |
modtab.htab[ndx] = OVOID; |
213 |
> |
|
214 |
> |
for (ndx = objtab.hsiz*(objtab.htab != NULL); ndx--; ) |
215 |
> |
if (objtab.htab[ndx] >= nobjects) |
216 |
> |
objtab.htab[ndx] = OVOID; |
217 |
|
} |
218 |
|
|
219 |
|
|
223 |
|
) |
224 |
|
{ |
225 |
|
static int hsiztab[] = { |
226 |
< |
251, 509, 1021, 2039, 4093, 8191, 16381, 0 |
226 |
> |
251, 509, 1021, 2039, 4093, 8191, 16381, |
227 |
> |
32749, 65521, 131071, 262139, 0 |
228 |
|
}; |
229 |
|
int *hsp; |
230 |
|
|
241 |
|
struct ohtab *tab |
242 |
|
) |
243 |
|
{ |
244 |
+ |
char *onm; |
245 |
|
OBJECT *oldhtab; |
246 |
|
int hval, i; |
247 |
|
int ndx; |
260 |
|
tryagain: |
261 |
|
for (i = 0; i < tab->hsiz; i++) { |
262 |
|
ndx = (hval + (unsigned long)i*i) % tab->hsiz; |
263 |
< |
if (tab->htab[ndx] == OVOID || |
249 |
< |
!strcmp(objptr(tab->htab[ndx])->oname, name)) |
263 |
> |
if (tab->htab[ndx] == OVOID) |
264 |
|
return(ndx); |
265 |
+ |
onm = objptr(tab->htab[ndx])->oname; |
266 |
+ |
if (onm != NULL && !strcmp(onm, name)) |
267 |
+ |
return(ndx); |
268 |
|
} |
269 |
|
/* table is full, reallocate */ |
270 |
|
oldhtab = tab->htab; |
272 |
|
tab->htab = NULL; |
273 |
|
while (ndx--) |
274 |
|
if (oldhtab[ndx] != OVOID) { |
275 |
< |
i = otndx(objptr(oldhtab[ndx])->oname, tab); |
275 |
> |
onm = objptr(oldhtab[ndx])->oname; |
276 |
> |
if (onm == NULL) |
277 |
> |
continue; |
278 |
> |
i = otndx(onm, tab); |
279 |
|
tab->htab[i] = oldhtab[ndx]; |
280 |
|
} |
281 |
< |
free((void *)oldhtab); |
281 |
> |
free(oldhtab); |
282 |
|
goto tryagain; /* should happen only once! */ |
283 |
|
} |