8000 Check serializability of the whole type hierarchy · pythonnet/pythonnet@b409a89 · GitHub
[go: up one dir, main page]

Skip to content

Commit b409a89

Browse files
committed
Check serializability of the whole type hierarchy
When serializing wrapper objects on domain shutdown Addresses comment: #958 (comment)
1 parent 598cb77 commit b409a89

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/runtime/runtime_data.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,19 @@ public static void ClearStash()
137137
PySys_SetObject("clr_data", IntPtr.Zero);
138138
}
139139

140+
static bool CheckSerializable (object o)
141+
{
142+
Type type = o.GetType();
143+
do
144+
{
145+
if (!type.IsSerializable)
146+
{
147+
return false;
148+
}
149+
} while ((type = type.BaseType) != null);
150+
return true;
151+
}
152+
140153
private static void SaveRuntimeDataObjects(RuntimeDataStorage storage)
141154
{
142155
var objs = ManagedType.GetManagedObjects();
@@ -151,7 +164,7 @@ private static void SaveRuntimeDataObjects(RuntimeDataStorage storage)
151164
switch (entry.Value)
152165
{
153166
case ManagedType.TrackTypes.Extension:
154-
Debug.Assert(obj.GetType().IsSerializable);
167+
Debug.Assert(CheckSerializable(obj));
155168
var context = new InterDomainContext();
156169
contexts[obj.pyHandle] = context;
157170
obj.Save(context);
@@ -195,7 +208,7 @@ private static void SaveRuntimeDataObjects(RuntimeDataStorage storage)
195208
{
196209
if (!item.Stored)
197210
{
198-
if (!item.Instance.GetType().IsSerializable)
211+
if (!CheckSerializable(item.Instance))
199212
{
200213
continue;
3AEE 201214
}

0 commit comments

Comments
 (0)
0