Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite9c3a3d

Browse files
committed
fixed InterfaceObject and MethodObject not being serializable
1 parent53836de commite9c3a3d

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

‎src/runtime/interfaceobject.cs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,18 @@ namespace Python.Runtime
1313
[Serializable]
1414
internalclassInterfaceObject:ClassBase
1515
{
16+
[NonSerialized]
1617
internalConstructorInfo?ctor;
1718

1819
internalInterfaceObject(Typetp):base(tp)
1920
{
20-
varcoclass=(CoClassAttribute)Attribute.GetCustomAttribute(tp,cc_attr);
21-
if(coclass!=null)
22-
{
23-
ctor=coclass.CoClass.GetConstructor(Type.EmptyTypes);
24-
}
21+
this.ctor=TryGetCOMConstructor(tp);
22+
}
23+
24+
staticConstructorInfo?TryGetCOMConstructor(Typetp)
25+
{
26+
varcomClass=(CoClassAttribute?)Attribute.GetCustomAttribute(tp,cc_attr);
27+
returncomClass?.CoClass.GetConstructor(Type.EmptyTypes);
2528
}
2629

2730
privatestaticTypecc_attr;
@@ -113,5 +116,14 @@ public static NewReference tp_getattro(BorrowedReference ob, BorrowedReference k
113116

114117
returnRuntime.PyObject_GenericGetAttr(ob,key);
115118
}
119+
120+
protectedoverridevoidOnDeserialization(objectsender)
121+
{
122+
base.OnDeserialization(sender);
123+
if(this.type.Valid)
124+
{
125+
this.ctor=TryGetCOMConstructor(this.type.Value);
126+
}
127+
}
116128
}
117129
}

‎src/runtime/methodobject.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ internal class MethodObject : ExtensionType
2525
internalboolis_static=false;
2626

2727
internalPyString?doc;
28-
internalTypetype;
28+
internalMaybeTypetype;
2929

3030
publicMethodObject(Typetype,stringname,MethodInfo[]info,boolallow_threads=MethodBinder.DefaultAllowThreads)
3131
{
@@ -157,6 +157,11 @@ public static NewReference tp_descr_get(BorrowedReference ds, BorrowedReference
157157
{
158158
varself=(MethodObject)GetManagedObject(ds)!;
159159

160+
if(!self.type.Valid)
161+
{
162+
returnExceptions.RaiseTypeError(self.type.DeletedMessage);
163+
}
164+
160165
// If the method is accessed through its type (rather than via
161166
// an instance) we return an 'unbound' MethodBinding that will
162167
// cached for future accesses through the type.
@@ -178,11 +183,11 @@ public static NewReference tp_descr_get(BorrowedReference ds, BorrowedReference
178183
// In which case create a MethodBinding bound to the base class.
179184
varobj=GetManagedObject(ob)asCLRObject;
180185
if(obj!=null
181-
&&obj.inst.GetType()!=self.type
186+
&&obj.inst.GetType()!=self.type.Value
182187
&&obj.instisIPythonDerivedType
183-
&&self.type.IsInstanceOfType(obj.inst))
188+
&&self.type.Value.IsInstanceOfType(obj.inst))
184189
{
185-
varbasecls=ClassManager.GetClass(self.type);
190+
varbasecls=ClassManager.GetClass(self.type.Value);
186191
returnnewMethodBinding(self,newPyObject(ob),basecls).Alloc();
187192
}
188193

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp