shithub: mc

Download patch

ref: f358e29be6bb61572de6891a5f098fcbefe5d0b1
parent: 69b4c9840862cdf3b42c877777c79e95a6aa0a42
author: Michael Forney <mforney@mforney.org>
date: Sun Jul 2 22:09:03 EDT 2017

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.

--- a/parse/use.c
+++ b/parse/use.c
@@ -231,7 +231,7 @@
 			if (i < Ntraits)
 				wrint(fd, i | Builtinmask);
 			else
-				wrint(fd, i);
+				wrint(fd, traittab[i]->uid);
 		}
 	}
 	wrint(fd, ty->nsub);
@@ -1145,7 +1145,7 @@
 	}
 
 	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');