Browse files

Tweaks to allow saving and thawing cross-unit deep sub clones, such a…

…s when a proto is imported
  • Loading branch information...
1 parent b5b8434 commit ee02ddf77aaf744d2aadaaae3b8d2cf282724434 @sorear committed Jan 16, 2012
Showing with 32 additions and 15 deletions.
  1. +27 −13 lib/Kernel.cs
  2. +5 −2 lib/Serialize.cs
View
40 lib/Kernel.cs
@@ -1015,9 +1015,11 @@ public sealed class RuntimeUnit : IFreeze {
var fields = new Dictionary<string,FieldInfo>();
foreach (FieldInfo fi in n.type.GetFields())
fields[fi.Name] = fi;
- tb.methods = new Dictionary<string,MethodInfo>();
+ var meth = new Dictionary<string,MethodInfo>();
+
foreach (MethodInfo mi in n.type.GetMethods())
- tb.methods[mi.Name] = mi;
+ meth[mi.Name] = mi;
+ RuntimeUnit.reg.methods[n.asm_name] = meth;
while (ncon-- > 0) {
FieldInfo fi = fields[tb.String()];
object val = tb.ObjRef();
@@ -2021,8 +2023,13 @@ public class UsedInScopeInfo {
if (code != null) {
Type t = code.Method.DeclaringType;
if (t.Assembly == typeof(Kernel).Assembly) {
- tn = t.FullName;
+ fb.Byte(1);
+ } else {
+ fb.Byte(0);
+ if (t.Assembly.GetName().Name != t.FullName)
+ throw new NieczaException("violation of naming protocols? {0} != {1}", t.Assembly.GetName().Name, t.FullName);
}
+ tn = t.FullName;
mn = code.Method.Name;
}
fb.String(mn);
@@ -2077,18 +2084,25 @@ public class UsedInScopeInfo {
internal static SubInfo Thaw(ThawBuffer tb) {
SubInfo n = new SubInfo();
tb.Register(n);
+ bool kernel = tb.Byte() != 0;
string mn = tb.String();
string tn = tb.String();
- if (mn != null) {
- Type t = tn == null ? tb.type :
- typeof(Kernel).Assembly.GetType(tn, true);
-
- n.code = t == null ? null :
- (DynBlockDelegate) Delegate.CreateDelegate(
- typeof(DynBlockDelegate),
- t == tb.type ? tb.methods[mn] :
- t.GetMethod(mn, BindingFlags.Public |
- BindingFlags.NonPublic | BindingFlags.Static));
+ if (mn != null && (kernel || !Backend.cross_level_load)) {
+ MethodInfo mi;
+ if (kernel) {
+ mi = typeof(Kernel).Assembly.GetType(tn, true)
+ .GetMethod(mn, BindingFlags.Public |
+ BindingFlags.NonPublic | BindingFlags.Static);
+ } else {
+ Dictionary<string,MethodInfo> t1;
+
+ if (!RuntimeUnit.reg.methods.TryGetValue(tn, out t1) ||
+ !t1.TryGetValue(mn, out mi)) {
+ throw new Exception("Thawed sub references nonexistant method " + tn + "::" + mn);
+ }
+ }
+ n.code = (DynBlockDelegate) Delegate.CreateDelegate(
+ typeof(DynBlockDelegate), mi);
}
n.nspill = tb.Int();
View
7 lib/Serialize.cs
@@ -2,6 +2,7 @@
using System.IO;
using System.Security.Cryptography;
using System.Collections.Generic;
+using System.Reflection;
using System.Text;
using Niecza.CLRBackend;
@@ -63,8 +64,11 @@ struct ObjRef {
internal static HashAlgorithm NewHash() { return new SHA256Managed(); }
+ internal Dictionary<string,Dictionary<string,MethodInfo>> methods =
+ new Dictionary<string,Dictionary<string,MethodInfo>>();
+
static readonly string signature = "Niecza-Serialized-Module";
- static readonly int version = 23;
+ static readonly int version = 24;
// Routines for use by serialization code
public bool CheckWriteObject(SerUnit into, object o,
@@ -524,7 +528,6 @@ class ThawBuffer {
List<object> revalidate = new List<object>();
public Type type;
- public Dictionary<string,System.Reflection.MethodInfo> methods;
internal ThawBuffer(ObjectRegistry reg, SerUnit unit, byte[] data) {
this.data = data;

0 comments on commit ee02ddf

Please sign in to comment.