path: root/parse/use.c
diff options
authorMichael Forney <>2017-07-03 02:09:03 -0700
committerOri Bernstein <>2017-07-03 12:43:37 -0700
commitf358e29be6bb61572de6891a5f098fcbefe5d0b1 (patch)
treef2a61eccf85bd75f0f869f10b99304a10fc200f3 /parse/use.c
parent69b4c9840862cdf3b42c877777c79e95a6aa0a42 (diff)
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.
Diffstat (limited to 'parse/use.c')
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);
- 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)
if (traittab[i]->vis == Visexport || traittab[i]->vis == Vishidden) {
wrbyte(f, 'R');