Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Forward compatibility for extending the set of kernel-defined types

  • Loading branch information...
commit 1d0c02000903592ece1745d4b3c3f44cfa6e5590 1 parent 71a8938
@sorear authored
Showing with 30 additions and 8 deletions.
  1. +23 −5 lib/Kernel.cs
  2. +7 −3 lib/Serialize.cs
View
28 lib/Kernel.cs
@@ -400,6 +400,8 @@ public class StashEnt : IFreeze {
[AttributeUsage(AttributeTargets.Field)]
class CORESavedAttribute : Attribute { }
[AttributeUsage(AttributeTargets.Field)]
+ class NewSavedAttribute : Attribute { } // temporary hack
+ [AttributeUsage(AttributeTargets.Field)]
class ImmutableAttribute : Attribute { }
[AttributeUsage(AttributeTargets.Field)]
class TrueGlobalAttribute : Attribute { }
@@ -982,9 +984,11 @@ public sealed class RuntimeUnit : IFreeze {
(f1, f2) => string.CompareOrdinal(f1.Name, f2.Name));
foreach (FieldInfo f in kf) {
if (f.GetCustomAttributes(typeof(CORESavedAttribute), true).Length != 0) {
+ fb.String(f.Name);
fb.ObjRef(f.GetValue(setting));
}
}
+ fb.String(null);
}
}
@@ -1069,11 +1073,25 @@ public sealed class RuntimeUnit : IFreeze {
if (n.name == "CORE") {
FieldInfo[] kf = typeof(Compartment).GetFields();
- Array.Sort<FieldInfo>(kf,
- (f1, f2) => string.CompareOrdinal(f1.Name, f2.Name));
- foreach (FieldInfo f in kf) {
- if (f.GetCustomAttributes(typeof(CORESavedAttribute), true).Length != 0) {
- f.SetValue(tb.setting, tb.ObjRef());
+ if (tb.version >= ObjectRegistry.VersionExplicitSave) {
+ var fielddic = new Dictionary<string,FieldInfo>();
+ foreach (FieldInfo fi in kf) {
+ if (Attribute.IsDefined(fi, typeof(CORESavedAttribute))) {
+ fielddic[fi.Name] = fi;
+ }
+ }
+ string fieldname;
+ while ((fieldname = tb.String()) != null) {
+ fielddic[fieldname].SetValue(tb.setting, tb.ObjRef());
+ }
+ } else {
+ Array.Sort<FieldInfo>(kf,
+ (f1, f2) => string.CompareOrdinal(f1.Name, f2.Name));
+ foreach (FieldInfo f in kf) {
+ if (Attribute.IsDefined(f, typeof(CORESavedAttribute)) &&
+ !Attribute.IsDefined(f, typeof(NewSavedAttribute))) {
+ f.SetValue(tb.setting, tb.ObjRef());
+ }
}
}
}
View
10 lib/Serialize.cs
@@ -73,7 +73,9 @@ struct ObjRef {
new Dictionary<string,object>();
static readonly string signature = "Niecza-Serialized-Module";
- static readonly int version = 31;
+ public const int VersionMin = 31;
+ public const int VersionExplicitSave = 32;
+ public const int VersionCur = 32;
public ObjectRegistry(Compartment s) { setting = s; }
@@ -189,8 +191,9 @@ struct ObjRef {
if (rsig != signature)
throw new ThawException("signature mismatch loading " + file);
int rver = tb.Int();
- if (rver != version)
+ if (rver < VersionMin || rver > VersionCur)
throw new ThawException("version mismatch loading " + file);
+ tb.version = rver;
su.root = tb.ObjRef();
tb.RunFixups();
@@ -233,7 +236,7 @@ struct ObjRef {
try {
fb.String(signature);
- fb.Int(version);
+ fb.Int(VersionCur);
fb.ObjRef(root);
byte[] data = fb.GetData();
@@ -587,6 +590,7 @@ class ThawBuffer {
public Type type;
public string file;
+ public int version;
internal ThawBuffer(Compartment setting, ObjectRegistry reg, SerUnit unit, byte[] data) {
this.data = data;

0 comments on commit 1d0c020

Please sign in to comment.
Something went wrong with that request. Please try again.