Make xundump capable of extending tables
Use ef_ensure_space() in getobj(). This also makes sure objects are properly initialized before undumping writes to them. Clean up how sentinels are appended: instead of keeping its slot reserved while undumping, keep it in the table, and strip it off when done.
This commit is contained in:
parent
d4ac7d94b2
commit
f8a35dda1e
1 changed files with 19 additions and 16 deletions
|
@ -479,17 +479,16 @@ getobj(void)
|
||||||
int need_sentinel = !EF_IS_GAME_STATE(cur_type);
|
int need_sentinel = !EF_IS_GAME_STATE(cur_type);
|
||||||
|
|
||||||
if (!cur_obj) {
|
if (!cur_obj) {
|
||||||
cur_obj_is_blank = cur_id >= ep->fids;
|
cur_obj_is_blank = cur_id >= ep->fids - !!need_sentinel;
|
||||||
if (cur_obj_is_blank) {
|
if (cur_obj_is_blank) {
|
||||||
/* TODO grow cache (and possibly file) unless EFF_STATIC */
|
if (ef_ensure_space(cur_type, cur_id + !!need_sentinel, 1))
|
||||||
if (cur_id < ep->csize - !!need_sentinel)
|
cur_obj = ef_ptr(cur_type, cur_id);
|
||||||
ep->cids = ep->fids = cur_id + 1;
|
/* FIXME diagnose out of dynamic memory vs. static table full */
|
||||||
/* else: ef_ptr() will fail */
|
if (!cur_obj)
|
||||||
}
|
gripe("Can't put ID %d into table %s, it holds only 0..%d.",
|
||||||
cur_obj = ef_ptr(cur_type, cur_id);
|
cur_id, ep->name, ep->fids - !!need_sentinel - 1);
|
||||||
if (!cur_obj)
|
} else
|
||||||
gripe("Can't put ID %d into table %s, it holds only 0..%d.",
|
cur_obj = ef_ptr(cur_type, cur_id);
|
||||||
cur_id, ep->name, ep->fids - 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return cur_obj;
|
return cur_obj;
|
||||||
|
@ -958,8 +957,12 @@ xubody(FILE *fp)
|
||||||
{
|
{
|
||||||
struct empfile *ep = &empfile[cur_type];
|
struct empfile *ep = &empfile[cur_type];
|
||||||
int need_sentinel = !EF_IS_GAME_STATE(cur_type);
|
int need_sentinel = !EF_IS_GAME_STATE(cur_type);
|
||||||
|
int old_maxid = ep->fids;
|
||||||
int i, maxid, ch;
|
int i, maxid, ch;
|
||||||
|
|
||||||
|
if (old_maxid == 0 && need_sentinel)
|
||||||
|
ef_ensure_space(cur_type, 0, 1);
|
||||||
|
|
||||||
maxid = 0;
|
maxid = 0;
|
||||||
for (i = 0;; ++i) {
|
for (i = 0;; ++i) {
|
||||||
while ((ch = skipfs(fp)) == '\n')
|
while ((ch = skipfs(fp)) == '\n')
|
||||||
|
@ -974,6 +977,12 @@ xubody(FILE *fp)
|
||||||
maxid = MAX(maxid, cur_id + 1);
|
maxid = MAX(maxid, cur_id + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (maxid >= old_maxid && need_sentinel) {
|
||||||
|
/* appended a sentinel, strip it off */
|
||||||
|
ep->fids--;
|
||||||
|
ep->cids--;
|
||||||
|
}
|
||||||
|
|
||||||
if (CANT_HAPPEN(maxid > ep->fids))
|
if (CANT_HAPPEN(maxid > ep->fids))
|
||||||
maxid = ep->fids;
|
maxid = ep->fids;
|
||||||
if (maxid < ep->fids) {
|
if (maxid < ep->fids) {
|
||||||
|
@ -988,11 +997,5 @@ xubody(FILE *fp)
|
||||||
ef_nameof(cur_type), ep->fids, maxid);
|
ef_nameof(cur_type), ep->fids, maxid);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (need_sentinel) {
|
|
||||||
if (CANT_HAPPEN(maxid >= ep->csize))
|
|
||||||
return gripe("No space for sentinel");
|
|
||||||
memset(ep->cache + ep->size * maxid, 0, ep->size);
|
|
||||||
}
|
|
||||||
|
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue