diff options
author | Michael Forney <mforney@mforney.org> | 2017-07-03 02:09:03 -0700 |
---|---|---|
committer | Ori Bernstein <ori@markovcorp.com> | 2017-07-03 12:43:37 -0700 |
commit | f358e29be6bb61572de6891a5f098fcbefe5d0b1 (patch) | |
tree | f2a61eccf85bd75f0f869f10b99304a10fc200f3 | |
parent | 69b4c9840862cdf3b42c877777c79e95a6aa0a42 (diff) | |
download | mc-f358e29be6bb61572de6891a5f098fcbefe5d0b1.tar.gz |
Write trait IDs instead of indices in typickle
If trait prototypes are used and merged with the actual trait, there may
be entries in the trait table which have an ID corresponding to some
other entry.
When pickling types, write the trait ID instead of the index since the
trait definitions are written with their IDs. Otherwise, we may end up
reading types referring to non-existent traits, resulting in an error
like
Unable to find trait for id 7
Also, only pickle traits whose index matches its ID to avoid duplicates.
-rw-r--r-- | parse/use.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/parse/use.c b/parse/use.c index 49eba1d..83fde08 100644 --- a/parse/use.c +++ b/parse/use.c @@ -231,7 +231,7 @@ static void typickle(FILE *fd, Type *ty) if (i < Ntraits) wrint(fd, i | Builtinmask); else - wrint(fd, i); + wrint(fd, traittab[i]->uid); } } wrint(fd, ty->nsub); @@ -1145,7 +1145,7 @@ void writeuse(FILE *f, Node *file) } for (i = 0; i < ntraittab; i++) { - if (i < Ntraits) + if (i < Ntraits || i != traittab[i]->uid) continue; if (traittab[i]->vis == Visexport || traittab[i]->vis == Vishidden) { wrbyte(f, 'R'); |