Skip to content
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
refactoring in CreateSubType
  • Loading branch information
lostmsu authored and BadSingleton committed Dec 18, 2020
commit 0b027c63ef0b4f3db69b8720335e76fad154ce02
4 changes: 3 additions & 1 deletion src/runtime/converter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,9 @@ internal static bool ToManaged(IntPtr value, Type type,
return Converter.ToManagedValue(value, type, out result, setError);
}


internal static bool ToManagedValue(BorrowedReference value, Type obType,
out object result, bool setError)
=> ToManagedValue(value.DangerousGetAddress(), obType, out result, setError);
internal static bool ToManagedValue(IntPtr value, Type obType,
out object result, bool setError)
{
Expand Down
2 changes: 2 additions & 0 deletions src/runtime/runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1642,6 +1642,8 @@ internal static bool PyDict_Check(IntPtr ob)
/// </summary>
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern IntPtr PyDict_GetItem(IntPtr pointer, IntPtr key);
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern BorrowedReference PyDict_GetItemWithError(BorrowedReference pointer, BorrowedReference key);

/// <summary>
/// Return value: Borrowed reference.
Expand Down
51 changes: 21 additions & 30 deletions src/runtime/typemanager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Runtime.InteropServices;
using System.Diagnostics;
using Python.Runtime.Slots;
using static Python.Runtime.PythonException;

namespace Python.Runtime
{
Expand Down Expand Up @@ -313,6 +314,7 @@ internal static IntPtr CreateType(ManagedType impl, Type clrType)

internal static IntPtr CreateSubType(IntPtr py_name, IntPtr py_base_type, IntPtr py_dict)
{
var dictRef = new BorrowedReference(py_dict);
// Utility to create a subtype of a managed type with the ability for the
// a python subtype able to override the managed implementation
string name = Runtime.GetManagedString(py_name);
Expand All @@ -322,40 +324,29 @@ internal static IntPtr CreateSubType(IntPtr py_name, IntPtr py_base_type, IntPtr
object assembly = null;
object namespaceStr = null;

var disposeList = new List<PyObject>();
try
using (var assemblyKey = new PyString("__assembly__"))
{
var assemblyKey = new PyObject(Converter.ToPython("__assembly__", typeof(string)));
disposeList.Add(assemblyKey);
if (0 != Runtime.PyMapping_HasKey(py_dict, assemblyKey.Handle))
var assemblyPtr = Runtime.PyDict_GetItemWithError(dictRef, assemblyKey.Reference);
if (assemblyPtr.IsNull)
{
var pyAssembly = new PyObject(Runtime.PyDict_GetItem(py_dict, assemblyKey.Handle));
Runtime.XIncref(pyAssembly.Handle);
disposeList.Add(pyAssembly);
if (!Converter.ToManagedValue(pyAssembly.Handle, typeof(string), out assembly, false))
{
throw new InvalidCastException("Couldn't convert __assembly__ value to string");
}
if (Exceptions.ErrorOccurred()) return IntPtr.Zero;
}
else if (!Converter.ToManagedValue(assemblyPtr, typeof(string), out assembly, false))
{
return Exceptions.RaiseTypeError("Couldn't convert __assembly__ value to string");
}

var namespaceKey = new PyObject(Converter.ToPythonImplicit("__namespace__"));
disposeList.Add(namespaceKey);
if (0 != Runtime.PyMapping_HasKey(py_dict, namespaceKey.Handle))
using (var namespaceKey = new PyString("__namespace__"))
{
var pyNamespace = new PyObject(Runtime.PyDict_GetItem(py_dict, namespaceKey.Handle));
Runtime.XIncref(pyNamespace.Handle);
disposeList.Add(pyNamespace);
if (!Converter.ToManagedValue(pyNamespace.Handle, typeof(string), out namespaceStr, false))
var pyNamespace = Runtime.PyDict_GetItemWithError(dictRef, namespaceKey.Reference);
if (pyNamespace.IsNull)
{
throw new InvalidCastException("Couldn't convert __namespace__ value to string");
if (Exceptions.ErrorOccurred()) return IntPtr.Zero;
}
else if (!Converter.ToManagedValue(pyNamespace, typeof(string), out namespaceStr, false))
{
return Exceptions.RaiseTypeError("Couldn't convert __namespace__ value to string");
}
}
}
finally
{
foreach (PyObject o in disposeList)
{
o.Dispose();
}
}

Expand All @@ -381,14 +372,14 @@ internal static IntPtr CreateSubType(IntPtr py_name, IntPtr py_base_type, IntPtr
// by default the class dict will have all the C# methods in it, but as this is a
// derived class we want the python overrides in there instead if they exist.
IntPtr cls_dict = Marshal.ReadIntPtr(py_type, TypeOffset.tp_dict);
Runtime.PyDict_Update(cls_dict, py_dict);
ThrowIfIsNotZero(Runtime.PyDict_Update(cls_dict, py_dict));
Runtime.XIncref(py_type);
// Update the __classcell__ if it exists
var cell = new BorrowedReference(Runtime.PyDict_GetItemString(cls_dict, "__classcell__"));
if (!cell.IsNull)
{
Runtime.PyCell_Set(cell, py_type);
Runtime.PyDict_DelItemString(cls_dict, "__classcell__");
ThrowIfIsNotZero(Runtime.PyCell_Set(cell, py_type));
ThrowIfIsNotZero(Runtime.PyDict_DelItemString(cls_dict, "__classcell__"));
}

return py_type;
Expand Down