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

Commit79516f1

Browse files
committed
Code review fixes
1 parent44b4800 commit79516f1

File tree

10 files changed

+54
-44
lines changed

10 files changed

+54
-44
lines changed

‎src/domain_tests/TestRunner.cs‎

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,22 @@ namespace Python.DomainReloadTests
1616
/// 3. This class at runtime creates a directory that has both C# and
1717
/// python code, and compiles the C#.
1818
/// 4. This class then runs the C# code.
19-
///
20-
/// But wait there's more indirection. The C# code that's run -- known as
21-
/// the test runner --
22-
/// This class compiles a DLL that contains the class which code will change
23-
/// and a runner executable that will run Python code referencing the class.
24-
/// Each test case:
19+
///
20+
/// But there's a bit more indirection. This class compiles a DLL that
21+
/// contains code that will change.
22+
/// Then, the test case:
2523
/// * Compiles some code, loads it into a domain, runs python that refers to it.
26-
/// * Unload the domain.
27-
/// * Compile a new piece of code, load it into a domain, run a new piece of python that accesses the code.
24+
/// * Unload the domain, re-runs the domain to make sure domain reload happens correctly.
25+
/// * Compile a new piece of code, load it into a new domain, run a new piece of
26+
/// Python code to test the objects after they've been deleted or modified in C#.
2827
/// * Unload the domain. Reload the domain, run the same python again.
28+
///
2929
/// This class gets built into an executable which takes one argument:
3030
/// which test case to run. That's because pytest assumes we'll run
3131
/// everything in one process, but we really want a clean process on each
32-
/// test case to test the init/reload/teardown parts of the domain reload
33-
/// code.
32+
/// test case to test the init/reload/teardown parts of the domain reload.
3433
/// </summary>
34+
///
3535
classTestRunner
3636
{
3737
conststringTestAssemblyName="DomainTests";
@@ -347,12 +347,6 @@ assert called is True
347347
called = False
348348
Cls.Call()
349349
assert called is False
350-
#try:
351-
# assert 2 == Cls.Before
352-
#except TypeError:
353-
# print('Caught expected exception')
354-
#else:
355-
# raise AssertionError('Failed to throw exception')
356350
",
357351
},
358352

@@ -398,7 +392,6 @@ def before_reload():
398392
def after_reload():
399393
try:
400394
TestNamespace.Cls(2)
401-
sys.my_cls.Member()
402395
except AttributeError:
403396
print('Caught expected exception')
404397
else:
@@ -845,7 +838,7 @@ raise AssertionError('failed to raise')
845838
# foo should have changed
846839
assert foo.num == 7
847840
assert bar.num == 7
848-
# Pythonnet also returns a new object with `ref`-quialified parameters
841+
# Pythonnet also returns a new object with `ref`-qualified parameters
849842
assert foo is not bar
850843
",
851844
},
@@ -1029,7 +1022,6 @@ static string CreateCaseRunnerAssembly(string verb, string shutdownMode = "Shutd
10291022
}
10301023
staticstringCreateAssembly(stringname,stringcode,boolexe=false)
10311024
{
1032-
// Console.WriteLine(code);
10331025
// Never return or hold the Assembly instance. This will cause
10341026
// the assembly to be loaded into the current domain and this
10351027
// interferes with the tests. The Domain can execute fine from a

‎src/runtime/StateSerialization/MaybeMethodBase.cs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ internal MaybeMethodBase(SerializationInfo serializationInfo, StreamingContext c
105105
deserializationException=null;
106106
try
107107
{
108-
//Retrive the reflected type of the method;
108+
//Retrieve the reflected type of the method;
109109
vartypeName=serializationInfo.GetString(SerializationType);
110110
vartp=Type.GetType(typeName);
111111
if(tp==null)
@@ -144,7 +144,7 @@ internal MaybeMethodBase(SerializationInfo serializationInfo, StreamingContext c
144144

145145
if(mb!=null&&hasRefType)
146146
{
147-
CheckRefTypes(mb,param);
147+
mb=CheckRefTypes(mb,param);
148148
}
149149

150150
// Do like in ClassManager.GetClassInfo
@@ -165,7 +165,7 @@ MethodBase CheckRefTypes(MethodBase mb, ParameterHelper[] ph)
165165
// void MyFn (ref int a)
166166
// to:
167167
// void MyFn (out int a)
168-
// will still find thefucntion correctly as, `in`, `out` and `ref`
168+
// will still find thefunction correctly as, `in`, `out` and `ref`
169169
// are all represented as a reference type. Query the method we got
170170
// and validate the parameters
171171
if(ph.Length!=0)

‎src/runtime/arrayobject.cs‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public static IntPtr tp_new(IntPtr tpRaw, IntPtr args, IntPtr kw)
3434
{
3535
returnExceptions.RaiseTypeError(self.type.DeletedMessage);
3636
}
37+
TypearrType=self.type.Value;
3738

3839
long[]dimensions=newlong[Runtime.PyTuple_Size(args)];
3940
if(dimensions.Length==0)
@@ -42,7 +43,7 @@ public static IntPtr tp_new(IntPtr tpRaw, IntPtr args, IntPtr kw)
4243
}
4344
if(dimensions.Length!=1)
4445
{
45-
returnCreateMultidimensional(self.type.Value.GetElementType(),dimensions,
46+
returnCreateMultidimensional(arrType.GetElementType(),dimensions,
4647
shapeTuple:newBorrowedReference(args),
4748
pyType:tp)
4849
.DangerousMoveToPointerOrNull();
@@ -60,14 +61,14 @@ public static IntPtr tp_new(IntPtr tpRaw, IntPtr args, IntPtr kw)
6061
}
6162
else
6263
{
63-
returnNewInstance(self.type.Value.GetElementType(),tp,dimensions)
64+
returnNewInstance(arrType.GetElementType(),tp,dimensions)
6465
.DangerousMoveToPointerOrNull();
6566
}
6667
}
6768
objectresult;
6869

6970
// this implements casting to Array[T]
70-
if(!Converter.ToManaged(op,self.type.Value,outresult,true))
71+
if(!Converter.ToManaged(op,arrType,outresult,true))
7172
{
7273
returnIntPtr.Zero;
7374
}

‎src/runtime/constructorbinder.cs‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,10 @@ internal object InvokeRaw(IntPtr inst, IntPtr args, IntPtr kw, MethodBase info)
5656
returnExceptions.RaiseTypeError(_containingType.DeletedMessage);
5757
}
5858
objectresult;
59+
Typetp=_containingType.Value;
5960

60-
if(_containingType.Value.IsValueType&&!_containingType.Value.IsPrimitive&&
61-
!_containingType.Value.IsEnum&&_containingType.Value!=typeof(decimal)&&
61+
if(tp.IsValueType&&!tp.IsPrimitive&&
62+
!tp.IsEnum&&tp!=typeof(decimal)&&
6263
Runtime.PyTuple_Size(args)==0)
6364
{
6465
// If you are trying to construct an instance of a struct by
@@ -68,7 +69,7 @@ internal object InvokeRaw(IntPtr inst, IntPtr args, IntPtr kw, MethodBase info)
6869
// Activator.CreateInstance().
6970
try
7071
{
71-
result=Activator.CreateInstance(_containingType.Value);
72+
result=Activator.CreateInstance(tp);
7273
}
7374
catch(Exceptione)
7475
{

‎src/runtime/constructorbinding.cs‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ public static IntPtr mp_subscript(IntPtr op, IntPtr key)
9696
{
9797
returnExceptions.RaiseTypeError(self.type.DeletedMessage);
9898
}
99+
Typetp=self.type.Value;
99100

100101
Type[]types=Runtime.PythonArgsToTypeArray(key);
101102
if(types==null)
@@ -104,12 +105,12 @@ public static IntPtr mp_subscript(IntPtr op, IntPtr key)
104105
}
105106
//MethodBase[] methBaseArray = self.ctorBinder.GetMethods();
106107
//MethodBase ci = MatchSignature(methBaseArray, types);
107-
ConstructorInfoci=self.type.Value.GetConstructor(types);
108+
ConstructorInfoci=tp.GetConstructor(types);
108109
if(ci==null)
109110
{
110111
returnExceptions.RaiseTypeError("No match found for constructor signature");
111112
}
112-
varboundCtor=newBoundContructor(self.type.Value,self.pyTypeHndl,self.ctorBinder,ci);
113+
varboundCtor=newBoundContructor(tp,self.pyTypeHndl,self.ctorBinder,ci);
113114

114115
returnboundCtor.pyHandle;
115116
}
@@ -126,6 +127,11 @@ public static IntPtr tp_repr(IntPtr ob)
126127
returnself.repr;
127128
}
128129
MethodBase[]methods=self.ctorBinder.GetMethods();
130+
131+
if(!self.type.Valid)
132+
{
133+
returnExceptions.RaiseTypeError(self.type.DeletedMessage);
134+
}
129135
stringname=self.type.Value.FullName;
130136
vardoc="";
131137
foreach(MethodBasetinmethods)

‎src/runtime/converter.cs‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,13 @@ internal static bool ToManagedValue(IntPtr value, Type obType,
344344
}
345345
if(mtisClassBase)
346346
{
347-
result=((ClassBase)mt).type.Value;
347+
varcb=(ClassBase)mt;
348+
if(!cb.type.Valid)
349+
{
350+
Exceptions.SetError(Exceptions.TypeError,cb.type.DeletedMessage);
351+
returnfalse;
352+
}
353+
result=cb.type.Value;
348354
returntrue;
349355
}
350356
// shouldn't happen

‎src/runtime/delegateobject.cs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public static IntPtr tp_new(IntPtr tp, IntPtr args, IntPtr kw)
5656
{
5757
returnExceptions.RaiseTypeError(self.type.DeletedMessage);
5858
}
59+
Typetype=self.type.Value;
5960

6061
if(Runtime.PyTuple_Size(args)!=1)
6162
{
@@ -69,7 +70,7 @@ public static IntPtr tp_new(IntPtr tp, IntPtr args, IntPtr kw)
6970
returnExceptions.RaiseTypeError("argument must be callable");
7071
}
7172

72-
Delegated=PythonEngine.DelegateManager.GetDelegate(self.type.Value,method);
73+
Delegated=PythonEngine.DelegateManager.GetDelegate(type,method);
7374
returnCLRObject.GetInstHandle(d,self.pyHandle);
7475
}
7576

‎src/runtime/methodbinding.cs‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,14 @@ public static IntPtr tp_call(IntPtr ob, IntPtr args, IntPtr kw)
114114
// for example this method in the tests: string Overloaded<T>(int arg1, int arg2, string arg3)
115115
if(self.info.Valid)
116116
{
117-
if(self.info.Value.IsGenericMethod)
117+
varinfo=self.info.Value;
118+
if(info.IsGenericMethod)
118119
{
119120
varlen=Runtime.PyTuple_Size(args);//FIXME: Never used
120121
Type[]sigTp=Runtime.PythonArgsToTypeArray(args,true);
121122
if(sigTp!=null)
122123
{
123-
Type[]genericTp=self.info.Value.GetGenericArguments();
124+
Type[]genericTp=info.GetGenericArguments();
124125
MethodInfobetterMatch=MethodBinder.MatchSignatureAndParameters(self.m.info,genericTp,sigTp);
125126
if(betterMatch!=null)
126127
{

‎src/runtime/moduleobject.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ protected override void OnSave(InterDomainContext context)
346346
{
347347
Runtime.PyDict_DelItemString(dict,pair.Key);
348348
pair.Value.DecrRefCount();
349-
if(Exceptions.ExceptionMatches(Exceptions.KeyError))
349+
if(Exceptions.ExceptionMatches(Exceptions.KeyError))
350350
{
351351
// Trying to remove a key that's not in the dictionary
352352
// raises an error. We don't care about it.

‎src/runtime/propertyobject.cs‎

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ public static IntPtr tp_descr_get(IntPtr ds, IntPtr ob, IntPtr tp)
3636
{
3737
returnExceptions.RaiseTypeError(self.info.DeletedMessage);
3838
}
39-
MethodInfogetter=self.getter.Value;
39+
varinfo=self.info.Value;
40+
MethodInfogetter=self.getter.UnsafeValue;
4041
objectresult;
4142

4243

@@ -56,8 +57,8 @@ public static IntPtr tp_descr_get(IntPtr ds, IntPtr ob, IntPtr tp)
5657

5758
try
5859
{
59-
result=self.info.Value.GetValue(null,null);
60-
returnConverter.ToPython(result,self.info.Value.PropertyType);
60+
result=info.GetValue(null,null);
61+
returnConverter.ToPython(result,info.PropertyType);
6162
}
6263
catch(Exceptione)
6364
{
@@ -73,8 +74,8 @@ public static IntPtr tp_descr_get(IntPtr ds, IntPtr ob, IntPtr tp)
7374

7475
try
7576
{
76-
result=self.info.Value.GetValue(co.inst,null);
77-
returnConverter.ToPython(result,self.info.Value.PropertyType);
77+
result=info.GetValue(co.inst,null);
78+
returnConverter.ToPython(result,info.PropertyType);
7879
}
7980
catch(Exceptione)
8081
{
@@ -101,8 +102,9 @@ public static IntPtr tp_descr_get(IntPtr ds, IntPtr ob, IntPtr tp)
101102
Exceptions.RaiseTypeError(self.info.DeletedMessage);
102103
return-1;
103104
}
105+
varinfo=self.info.Value;
104106

105-
MethodInfosetter=self.setter.Value;
107+
MethodInfosetter=self.setter.UnsafeValue;
106108
objectnewval;
107109

108110
if(val==IntPtr.Zero)
@@ -118,7 +120,7 @@ public static IntPtr tp_descr_get(IntPtr ds, IntPtr ob, IntPtr tp)
118120
}
119121

120122

121-
if(!Converter.ToManaged(val,self.info.Value.PropertyType,outnewval,true))
123+
if(!Converter.ToManaged(val,info.PropertyType,outnewval,true))
122124
{
123125
return-1;
124126
}
@@ -144,11 +146,11 @@ public static IntPtr tp_descr_get(IntPtr ds, IntPtr ob, IntPtr tp)
144146
Exceptions.RaiseTypeError("invalid target");
145147
return-1;
146148
}
147-
self.info.Value.SetValue(co.inst,newval,null);
149+
info.SetValue(co.inst,newval,null);
148150
}
149151
else
150152
{
151-
self.info.Value.SetValue(null,newval,null);
153+
info.SetValue(null,newval,null);
152154
}
153155
return0;
154156
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp