8000 Domain reload test cases fixes by BadSingleton · Pull Request #1287 · pythonnet/pythonnet · GitHub
[go: up one dir, main page]

Skip to content

Domain reload test cases fixes #1287

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
fc7da1d
Adds test cases for member changes during a domain reload
BadSingleton Nov 9, 2020
72fafdd
!fixup add the project to the solution files
BadSingleton Nov 9, 2020
20861b2
Add more test cases
BadSingleton Nov 18, 2020
2253ef3
Merge remote-tracking branch 'upstream/master' into domain-reload-tes…
BadSingleton Nov 18, 2020
635edac
Make the tests run as netcoreapp
BadSingleton Nov 19, 2020
0ee931e
Remove stray colon
BadSingleton Nov 19, 2020
3dad96e
Rework the serialization of reflected types
BadSingleton Nov 19, 2020
90a81f3
Call PyType_Modified after modifying the type
BadSingleton Nov 20, 2020
10276f1
Some code review changes
BadSingleton Nov 20, 2020
4d0e2ce
fixup! Some code review changes
BadSingleton Nov 23, 2020
02fa245
Remove hungarian notation from Maybe* types
BadSingleton Nov 23, 2020
91c881c
Check the type of the exception before ignoring it
BadSingleton Nov 23, 2020
284e8e1
Check for validity, don't throw
BadSingleton Nov 23, 2020
fe96781
Refactor the member binding logic of ClassManager
BadSingleton Nov 23, 2020
6ff9e0b
Include info about why deserialization failed in Maybe*
BadSingleton Nov 23, 2020
4d2d05b
improve deserialization resolution of ref, out and in parameters
BadSingleton Nov 24, 2020
5f061bc
Clean up the project and solution files
BadSingleton Nov 26, 2020
3adc559
Merge branch 'master' into domain-reload-test-cases
BadSingleton Nov 26, 2020
e8543cf
Rework the serialization of reflected types
BadSingleton Nov 19, 2020
61b0d8c
Call PyType_Modified after modifying the type
BadSingleton Nov 20, 2020
c8bacf3
Some code review changes
BadSingleton Nov 20, 2020
cde5c23
fixup! Some code review changes
BadSingleton Nov 23, 2020
a956773
Remove hungarian notation from Maybe* types
BadSingleton Nov 23, 2020
ee3b391
Check the type of the exception before ignoring it
BadSingleton Nov 23, 2020
9b4d5f9
Check for validity, don't throw
BadSingleton Nov 23, 2020
a2f3294
Refactor the member binding logic of ClassManager
BadSingleton Nov 23, 2020
46dcb9d
Include info about why deserialization failed in Maybe*
BadSingleton Nov 23, 2020
10116bb
improve deserialization resolution of ref, out and in parameters
BadSingleton Nov 24, 2020
102054e
!fixup leftover error from the rebase
BadSingleton Nov 26, 2020
329de5d
Add fixes and test for nested classes
BadSingleton Nov 27, 2020
f97262b
Code review fixes
BadSingleton Dec 2, 2020
ceb3fab
Merge branch 'master' into domain-reload-test-cases-fixes
BadSingleton Dec 2, 2020
2d6ae4c
fixup! Merge branch 'master' into domain-reload-test-cases-fixes
BadSingleton Dec 2, 2020
16a39a6
fixup! Code review fixes
BadSingleton Dec 2, 2020
ace340d
Fix build failures on non-windows
BadSingleton Dec 8, 2020
78a8088
fixup! Fix build failures on non-windows
BadSingleton Dec 8, 2020
3232f79
Merge remote-tracking branch 'origin/domain-reload-test-cases-fixes' …
BadSingleton Dec 8, 2020
87287a5
Merge branch 'master' into domain-reload-test-cases-fixes
BadSingleton Dec 8, 2020
44b4800
Merge branch 'master' into domain-reload-test-cases-fixes
BadSingleton Dec 10, 2020
79516f1
Code review fixes
BadSingleton Dec 10, 2020
421f665
Merge remote-tracking branch 'upstream/master' into domain-reload-tes…
BadSingleton Dec 10, 2020
5e4c976
(WIP) rework project structure
BadSingleton Dec 11, 2020
9d1991a
Merge remote-tracking branch 'upstream/master' into domain-reload-tes…
BadSingleton Dec 14, 2020
bcf0cd6
Rework the projects file structure
BadSingleton Dec 14, 2020
73e5a6b
Check teh return value of PyDict_DelItemString
BadSingleton Dec 14, 2020
510a7ae
netstandard.dll is a Facade Library
BadSingleton Dec 16, 2020
21eb14c
Remove TestClassReference
BadSingleton Dec 17, 2020
59e81e2
Test runner docs fixes
BadSingleton Dec 17, 2020
1383b5a
Skip the domain reload tests on macos
BadSingleton Dec 17, 2020
fbc06ef
fixup! Skip the domain reload tests on macos
BadSingleton Dec 17, 2020
b3e86da
Update ISSUE_TEMPLATE.md
filmor Dec 17, 2020
0b027c6
refactoring in CreateSubType
lostmsu Dec 17, 2020
b4533c4
allocate space for GCHandle in instances of CLR Metatype (which are t…
lostmsu Dec 18, 2020
0a3f044
classderived: handle tp_dealloc called after tp_clear
lostmsu Dec 18, 2020
639236a
a few extra assertions
lostmsu Dec 18, 2020
3069285
fixed crash in finalizer of CLR types defined in Python, that survive…
lostmsu Dec 18, 2020
5c14aad
Merge branch 'master' into domain-reload-test-cases-fixes
BadSingleton Dec 18, 2020
00c19d5
Merge branch 'master' into domain-reload-test-cases-fixes
BadSingleton Jan 4, 2021
833e836
Fix break introduced by merge
BadSingleton Jan 4, 2021
62ae107
Code review fixes
BadSingleton Jan 4, 2021
eedbae5
Merge remote-tracking branch 'upstream/master' into domain-reload-tes…
BadSingleton Jan 5, 2021
73f39bc
Add the PID of the test runner
BadSingleton Jan 6, 2021
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
Code review fixes
  • Loading branch information
BadSingleton committed Dec 10, 2020
commit 79516f1984ae310d412c62cf6cb4c01655ea7c49
30 changes: 11 additions & 19 deletions src/domain_tests/TestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,22 @@ namespace Python.DomainReloadTests
/// 3. This class at runtime creates a directory that has both C# and
/// python code, and compiles the C#.
/// 4. This class then runs the C# code.
///
/// But wait there's more indirection. The C# code that's run -- known as
/// the test runner --
/// This class compiles a DLL that contains the class which code will change
/// and a runner executable that will run Python code referencing the class.
/// Each test case:
///
/// But there's a bit more indirection. This class compiles a DLL that
/// contains code that will change.
/// Then, the test case:
/// * Compiles some code, loads it into a domain, runs python that refers to it.
/// * Unload the domain.
/// * Compile a new piece of code, load it into a domain, run a new piece of python that accesses the code.
/// * Unload the domain, re-runs the domain to make sure domain reload happens correctly.
/// * Compile a new piece of code, load it into a new domain, run a new piece of
/// Python code to test the objects after they've been deleted or modified in C#.
/// * Unload the domain. Reload the domain, run the same python again.
///
/// This class gets built into an executable which takes one argument:
/// which test case to run. That's because pytest assumes we'll run
/// everything in one process, but we really want a clean process on each
/// test case to test the init/reload/teardown parts of the domain reload
/// code.
/// test case to test the init/reload/teardown parts of the domain reload.
/// </summary>
///
class TestRunner
{
const string TestAssemblyName = "DomainTests";
Expand Down Expand Up @@ -347,12 +347,6 @@ assert called is True
called = False
Cls.Call()
assert called is False
#try:
# assert 2 == Cls.Before
#except TypeError:
# print('Caught expected exception')
#else:
# raise AssertionError('Failed to throw exception')
",
},

Expand Down Expand Up @@ -398,7 +392,6 @@ def before_reload():
def after_reload():
try:
TestNamespace.Cls(2)
sys.my_cls.Member()
except AttributeError:
print('Caught expected exception')
else:
Expand Down Expand Up @@ -845,7 +838,7 @@ raise AssertionError('failed to raise')
# foo should have changed
assert foo.num == 7
assert bar.num == 7
# Pythonnet also returns a new object with `ref`-quialified parameters
# Pythonnet also returns a new object with `ref`-qualified parameters
assert foo is not bar
",
},
Expand Down Expand Up @@ -1029,7 +1022,6 @@ static string CreateCaseRunnerAssembly(string verb, string shutdownMode = "Shutd
}
static string CreateAssembly(string name, string code, bool exe = false)
{
// Console.WriteLine(code);
// Never return or hold the Assembly instance. This will cause
// the assembly to be loaded into the current domain and this
// interferes with the tests. The Domain can execute fine from a
Expand Down
6 changes: 3 additions & 3 deletions src/runtime/StateSerialization/MaybeMethodBase.cs
8000
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ internal MaybeMethodBase(SerializationInfo serializationInfo, StreamingContext c
deserializationException = null;
try
{
// Retrive the reflected type of the method;
// Retrieve the reflected type of the method;
var typeName = serializationInfo.GetString(SerializationType);
var tp = Type.GetType(typeName);
if (tp == null)
Expand Down Expand Up @@ -144,7 +144,7 @@ internal MaybeMethodBase(SerializationInfo serializationInfo, StreamingContext c

if (mb != null && hasRefType)
{
CheckRefTypes(mb, param);
mb = CheckRefTypes(mb, param);
}

// Do like in ClassManager.GetClassInfo
Expand All @@ -165,7 +165,7 @@ MethodBase CheckRefTypes(MethodBase mb, ParameterHelper[] ph)
// void MyFn (ref int a)
// to:
// void MyFn (out int a)
// will still find the fucntion correctly as, `in`, `out` and `ref`
// will still find the function correctly as, `in`, `out` and `ref`
// are all represented as a reference type. Query the method we got
// and validate the parameters
if (ph.Length != 0)
Expand Down
7 changes: 4 additions & 3 deletions src/runtime/arrayobject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public static IntPtr tp_new(IntPtr tpRaw, IntPtr args, IntPtr kw)
{
return Exceptions.RaiseTypeError(self.type.DeletedMessage);
}
Type arrType = self.type.Value;

long[] dimensions = new long[Runtime.PyTuple_Size(args)];
if (dimensions.Length == 0)
Expand All @@ -42,7 +43,7 @@ public static IntPtr tp_new(IntPtr tpRaw, IntPtr args, IntPtr kw)
}
if (dimensions.Length != 1)
{
return CreateMultidimensional(self.type.Value.GetElementType(), dimensions,
return CreateMultidimensional(arrType.GetElementType(), dimensions,
shapeTuple: new BorrowedReference(args),
pyType: tp)
.DangerousMoveToPointerOrNull();
Expand All @@ -60,14 +61,14 @@ public static IntPtr tp_new(IntPtr tpRaw, IntPtr args, IntPtr kw)
}
else
{
return NewInstance(self.type.Value.GetElementType(), tp, dimensions)
return NewInstance(arrType.GetElementType(), tp, dimensions)
.DangerousMoveToPointerOrNull();
}
}
object result;

// this implements casting to Array[T]
if (!Converter.ToManaged(op, self.type.Value, out result, true))
if (!Converter.ToManaged(op, arrType, out result, true))
{
return IntPtr.Zero;
}
Expand Down
7 changes: 4 additions & 3 deletions src/runtime/constructorbinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,10 @@ internal object InvokeRaw(IntPtr inst, IntPtr args, IntPtr kw, MethodBase info)
return Exceptions.RaiseTypeError(_containingType.DeletedMessage);
}
object result;
Type tp = _containingType.Value;

if (_containingType.Value.IsValueType && !_containingType.Value.IsPrimitive &&
!_containingType.Value.IsEnum && _containingType.Value != typeof(decimal) &&
if (tp.IsValueType && !tp.IsPrimitive &&
!tp.IsEnum && tp != typeof(decimal) &&
Runtime.PyTuple_Size(args) == 0)
{
// If you are trying to construct an instance of a struct by
Expand All @@ -68,7 +69,7 @@ internal object InvokeRaw(IntPtr inst, IntPtr args, IntPtr kw, MethodBase info)
// Activator.CreateInstance().
try
{
result = Activator.CreateInstance(_containingType.Value);
result = Activator.CreateInstance(tp);
}
catch (Exception e)
{
Expand Down
10 changes: 8 additions & 2 deletions src/runtime/constructorbinding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public static IntPtr mp_subscript(IntPtr op, IntPtr key)
{
return Exceptions.RaiseTypeError(self.type.DeletedMessage);
}
Type tp = self.type.Value;

Type[] types = Runtime.PythonArgsToTypeArray(key);
if (types == null)
Expand All @@ -104,12 +105,12 @@ public static IntPtr mp_subscript(IntPtr op, IntPtr key)
}
//MethodBase[] methBaseArray = self.ctorBinder.GetMethods();
//MethodBase ci = MatchSignature(methBaseArray, types);
ConstructorInfo ci = self.type.Value.GetConstructor(types);
ConstructorInfo ci = tp.GetConstructor(types);
if (ci == null)
{
return Exceptions.RaiseTypeError("No match found for constructor signature");
}
var boundCtor = new BoundContructor(self.type.Value, self.pyTypeHndl, self.ctorBinder, ci);
var boundCtor = new BoundContructor(tp, self.pyTypeHndl, self.ctorBinder, ci);

return boundCtor.pyHandle;
}
Expand All @@ -126,6 +127,11 @@ public static IntPtr tp_repr(IntPtr ob)
return self.repr;
}
MethodBase[] methods = self.ctorBinder.GetMethods();

if (!self.type.Valid)
{
return Exceptions.RaiseTypeError(self.type.DeletedMessage);
}
string name = self.type.Value.FullName;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's invalid then probably print something like (missing {self.type.Name}) -- makes it possible to debug.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one was missing it's check.

var doc = "";
foreach (MethodBase t in methods)
Expand Down
8 changes: 7 additions & 1 deletion src/runtime/converter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,13 @@ internal static bool ToManagedValue(IntPtr value, Type obType,
}
if (mt is ClassBase)
{
result = ((ClassBase)mt).type.Value;
var cb = (ClassBase)mt;
if (!cb.type.Valid)
{
Exceptions.SetError(Exceptions.TypeError, cb.type.DeletedMessage);
return false;
}
result = cb.type.Value;
return true;
}
// shouldn't happen
Expand Down
3 changes: 2 additions & 1 deletion src/runtime/delegateobject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public static IntPtr tp_new(IntPtr tp, IntPtr args, IntPtr kw)
{
return Exceptions.RaiseTypeError(self.type.DeletedMessage);
}
Type type = self.type.Value;

if (Runtime.PyTuple_Size(args) != 1)
{
Expand All @@ -69,7 +70,7 @@ public static IntPtr tp_new(IntPtr tp, IntPtr args, IntPtr kw)
return Exceptions.RaiseTypeError("argument must be callable");
}

Delegate d = PythonEngine.DelegateManager.GetDelegate(self.type.Value, method);
Delegate d = PythonEngine.DelegateManager.GetDelegate(type, method);
return CLRObject.GetInstHandle(d, self.pyHandle);
}

Expand Down
5 changes: 3 additions & 2 deletions src/runtime/methodbinding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,14 @@ public static IntPtr tp_call(IntPtr ob, IntPtr args, IntPtr kw)
// for example this method in the tests: string Overloaded<T>(int arg1, int arg2, string arg3)
if (self.info.Valid)
{
if (self.info.Value.IsGenericMethod)
var info = self.info.Value;
if (info.IsGenericMethod)
{
var len = Runtime.PyTuple_Size(args); //FIXME: Never used
Type[] sigTp = Runtime.PythonArgsToTypeArray(args, true);
if (sigTp != null)
{
Type[] genericTp = self.info.Value.GetGenericArguments();
Type[] genericTp = info.GetGenericArguments();
MethodInfo betterMatch = MethodBinder.MatchSignatureAndParameters(self.m.info, genericTp, sigTp);
if (betterMatch != null)
{
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/moduleobject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ protected override void OnSave(InterDomainContext context)
{
Runtime.PyDict_DelItemString(dict, pair.Key);
pair.Value.DecrRefCount();
if (Exceptions.ExceptionMatches(Exceptions.KeyError))
if (Exceptions.ExceptionMatches(Exceptions.KeyError))
{
// Trying to remove a key that's not in the dictionary
// raises an error. We don't care about it.
Expand Down
20 changes: 11 additions & 9 deletions src/runtime/propertyobject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ public static IntPtr tp_descr_get(IntPtr ds, IntPtr ob, IntPtr tp)
{
return Exceptions.RaiseTypeError(self.info.DeletedMessage);
}
MethodInfo getter = self.getter.Value;
var info = self.info.Value;
MethodInfo getter = self.getter.UnsafeValue;
object result;


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

try
{
result = self.info.Value.GetValue(null, null);
return Converter.ToPython(result, self.info.Value.PropertyType);
result = info.GetValue(null, null);
return Converter.ToPython(result, info.PropertyType);
}
catch (Exception e)
{
Expand All @@ -73,8 +74,8 @@ public static IntPtr tp_descr_get(IntPtr ds, IntPtr ob, IntPtr tp)

try
{
result = self.info.Value.GetValue(co.inst, null);
return Converter.ToPython(result, self.info.Value.PropertyType);
result = info.GetValue(co.inst, null);
return Converter.ToPython(result, info.PropertyType);
}
catch (Exception e)
{
Expand All @@ -101,8 +102,9 @@ public static IntPtr tp_descr_get(IntPtr ds, IntPtr ob, IntPtr tp)
Exceptions.RaiseTypeError(self.info.DeletedMessage);
return -1;
}
var info = self.info.Value;

MethodInfo setter = self.setter.Value;
MethodInfo setter = self.setter.UnsafeValue;
object newval;

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


if (!Converter.ToManaged(val, self.info.Value.PropertyType, out newval, true))
if (!Converter.ToManaged(val, info.PropertyType, out newval, true))
{
return -1;
}
Expand All @@ -144,11 +146,11 @@ public static IntPtr tp_descr_get(IntPtr ds, IntPtr ob, IntPtr tp)
Exceptions.RaiseTypeError("invalid target");
return -1;
}
self.info.Value.SetValue(co.inst, newval, null);
info.SetValue(co.inst, newval, null);
}
else
{
self.info.Value.SetValue(null, newval, null);
info.SetValue(null, newval, null);
}
return 0;
}
Expand Down
0