8000 Removed `ShutdownMode`. Now always behaves like original `Reload` by lostmsu · Pull Request #1638 · pythonnet/pythonnet · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixed InterfaceObject and MethodObject not being serializable
  • Loading branch information
lostmsu committed Dec 21, 2021
commit 84a4ae0526474f687fd57d79125baa12c8a00b2d
22 changes: 17 additions & 5 deletions src/runtime/interfaceobject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,18 @@ namespace Python.Runtime
[Serializable]
internal class InterfaceObject : ClassBase
{
[NonSerialized]
internal ConstructorInfo? ctor;

internal InterfaceObject(Type tp) : base(tp)
{
var coclass = (CoClassAttribute)Attribute.GetCustomAttribute(tp, cc_attr);
if (coclass != null)
{
ctor = coclass.CoClass.GetConstructor(Type.EmptyTypes);
}
this.ctor = TryGetCOMConstructor(tp);
}

static ConstructorInfo? TryGetCOMConstructor(Type tp)
{
var comClass = (CoClassAttribute?)Attribute.GetCustomAttribute(tp, cc_attr);
return comClass?.CoClass.GetConstructor(Type.EmptyTypes);
}

private static Type cc_attr;
Expand Down Expand Up @@ -113,5 +116,14 @@ public static NewReference tp_getattro(BorrowedReference ob, BorrowedReference k

return Runtime.PyObject_GenericGetAttr(ob, key);
}

protected override void OnDeserialization(object sender)
{
base.OnDeserialization(sender);
if (this.type.Valid)
{
this.ctor = TryGetCOMConstructor(this.type.Value);
}
}
}
}
13 changes: 9 additions & 4 deletions src/runtime/methodobject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ internal class MethodObject : ExtensionType
internal bool is_static = false;

internal PyString? doc;
internal Type type;
internal MaybeType type;

public MethodObject(Type type, string name, MethodInfo[] info, bool allow_threads = MethodBinder.DefaultAllowThreads)
{
Expand Down Expand Up @@ -157,6 +157,11 @@ public static NewReference tp_descr_get(BorrowedReference ds, BorrowedReference
{
var self = (MethodObject)GetManagedObject(ds)!;

if (!self.type.Valid)
{
return Exceptions.RaiseTypeError(self.type.DeletedMessage);
}

// If the method is accessed through its type (rather than via
// an instance) we return an 'unbound' MethodBinding that will
// cached for future accesses through the type.
Expand All @@ -178,11 +183,11 @@ public static NewReference tp_descr_get(BorrowedReference ds, BorrowedReference
// In which case create a MethodBinding bound to the base class.
var obj = GetManagedObject(ob) as CLRObject;
if (obj != null
&& obj.inst.GetType() != self.type
&& obj.inst.GetType() != self.type.Value
&& obj.inst is IPythonDerivedType
&& self.type.IsInstanceOfType(obj.inst))
&& self.type.Value.IsInstanceOfType(obj.inst))
{
var basecls = ClassManager.GetClass(self.type);
var basecls = ClassManager.GetClass(self.type.Value);
return new MethodBinding(self, new PyObject(ob), basecls).Alloc();
}

Expand Down
0