Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
7ed0c7a
WIP
lostmsu Oct 24, 2021
d6a853f
avoid generating and handling useless SerializationException when May…
lostmsu Oct 28, 2021
b0c25c1
finalizer does not attempt to finalize objects when runtime is shut down
lostmsu Oct 28, 2021
5ca474a
PyType Dict and MRO properties to assist debugging
lostmsu Oct 28, 2021
48078b3
WIP 2
lostmsu Oct 28, 2021
a624dd8
fixed PyObject disposal crashing when runtime is still finalizing
lostmsu Oct 29, 2021
e7ab071
arrays: use 64 bit indexing, and avoid first chance .NET exceptions o…
lostmsu Oct 29, 2021
cbe1dd2
refactored conditional ClassBase slot initialization
lostmsu Oct 29, 2021
d5f1c48
removed DisposePythonWrappersForClrTypes
lostmsu Oct 29, 2021
74d87c5
simplified outdated condition in ClassBase.tp_clear
lostmsu Oct 29, 2021
82d6c33
sprinkled a few DebuggerHidden to make debugging easier
lostmsu Oct 29, 2021
eeebcd7
fixed derived classes not inheriting slots correctly
lostmsu Oct 29, 2021
8ee8d3d
remove unused TypeManager._slotImpls
lostmsu Oct 29, 2021
1a4ada7
fixed TestRuntime not building in Release mode
lostmsu Oct 30, 2021
a610aa3
can't really clear managed references to Python objects from ManagedT…
lostmsu Oct 30, 2021
03f32cb
PythonException is serializable
lostmsu Oct 30, 2021
b1c9f5b
EventObject no longer used for static events. EventBinding is constru…
lostmsu Oct 30, 2021
cb4bb9a
use a special class to stub .NET types that no longer exist after a d…
lostmsu Nov 2, 2021
652f946
make EventHandlerCollection serializable
lostmsu Nov 2, 2021
84db670
fixed MaybeMemberInfo always failing for properties
lostmsu Nov 2, 2021
56fafe3
fixed construct_removed_class domain reload test case
lostmsu Nov 2, 2021
d33dcdd
domain reload test runner can run test by index
lostmsu Nov 2, 2021
b737e10
minor docs change
lostmsu Nov 2, 2021
d3e4fba
assert check in GetUnmanagedBaseType for null base
lostmsu Nov 2, 2021
e003e12
PythonEngine .Exec and .Eval no longer work with raw pointers
lostmsu Nov 9, 2021
d0a6f44
a few annotation to ease debugging
lostmsu Nov 9, 2021
e31f7ba
ensure Python types continue to exist when registered decoders for th…
lostmsu Nov 9, 2021
48c0dfc
GC-related WIP
lostmsu Nov 9, 2021
cb58147
merge latest changes from upstream
lostmsu Nov 23, 2021
2fdbf0e
added TraceAlloc solution configuration
lostmsu Nov 24, 2021
a8ef06c
fixed sending PyObject across domain boundary
lostmsu Nov 24, 2021
7167229
fixed accidental premature disposal of Runtime.PyNone
lostmsu Nov 24, 2021
ab11fa2
made freeing GCHandles more robust
lostmsu Nov 24, 2021
7a4daeb
removed bad assert in generated constructor for derived classes
lostmsu Nov 24, 2021
e422367
fixed __pyobj__ access
lostmsu Nov 24, 2021
a74ea86
minor
lostmsu Nov 24, 2021
0325a8c
fixed Python derived types trying to double-free GCHandle when collec…
lostmsu Nov 24, 2021
85fab3b
reinstate collection assert on shutdown from Python
lostmsu Nov 24, 2021
932fce2
fixed crash when Python derived class instances survive past early sh…
lostmsu Nov 24, 2021
c2e207a
delay nulling GC handles of reflected instances until the last moment…
lostmsu Nov 24, 2021
c8f0f09
fixed assert in XDecref in case _Py_IsFinalizing is not present
lostmsu Nov 24, 2021
e269cf0
when initialized from Python, reset slots implemented in CLR: CLR mig…
lostmsu Nov 25, 2021
d7d5cb7
fixed minor warnings
lostmsu Nov 25, 2021
d6edace
fixed line endings in intern_.cs
lostmsu Nov 25, 2021
a86994f
use NonCopyableAnalyzer 0.7.0-m05
lostmsu Nov 25, 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
Next Next commit
WIP
  • Loading branch information
lostmsu committed Oct 30, 2021
commit 7ed0c7aa260f7043163e49a8fb5e58fd2fcf897c
2 changes: 1 addition & 1 deletion src/runtime/DefaultBaseTypeProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ static BorrowedReference GetBaseType(Type type)
return Exceptions.Exception;

return type.BaseType is not null
? ClassManager.GetClass(type.BaseType).ObjectReference
? ClassManager.GetClass(type.BaseType)
: Runtime.PyBaseObjectType;
}

Expand Down
30 changes: 15 additions & 15 deletions src/runtime/ManagedTypes.cd
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<Class Name="Python.Runtime.ClassBase" Collapsed="true">
<Position X="15" Y="1.75" Width="1.5" />
<TypeIdentifier>
<HashCode>FAAAAgAIAAAEDAAAAAAAAEACIACJAAIAAAAAAAIAAAQ=</HashCode>
<HashCode>VAAAAgAIAAAEDAAAAAAAAEACIACLAAIAAAAAAAIAoBU=</HashCode>
<FileName>classbase.cs</FileName>
</TypeIdentifier>
</Class>
Expand All @@ -17,7 +17,7 @@
<Class Name="Python.Runtime.ArrayObject" Collapsed="true">
<Position X="10.5" Y="3.25" Width="1.5" />
<TypeIdentifier>
<HashCode>AAAAAAAAABAAAAAAAAAAACAAIAAJAAAAIAAAAACAAAI=</HashCode>
<HashCode>AAQAgAAAABAQAAAAAAAARGAAMgAJAAAAJAACACSABAI=</HashCode>
<FileName>arrayobject.cs</FileName>
</TypeIdentifier>
</Class>
Expand All @@ -31,28 +31,28 @@
<Class Name="Python.Runtime.BoundContructor" Collapsed="true">
<Position X="29.5" Y="4.5" Width="1.5" />
<TypeIdentifier>
<HashCode>AAAACAAAAAAABABAAAAACAAAABAJAEAAAAAAAAIAAAA=</HashCode>
<HashCode>AAAACAAAAAAAAABAAAAACAAAABAJAAAAAAAAAAJAAAA=</HashCode>
<FileName>constructorbinding.cs</FileName>
</TypeIdentifier>
</Class>
<Class Name="Python.Runtime.CLRObject" Collapsed="true">
<Position X="18.25" Y="1.75" Width="1.5" />
<TypeIdentifier>
<HashCode>EAAAAAAAAAAAAAAAAAACAAACBIAAAAJAAAAAAAAAAAA=</HashCode>
<HashCode>AAAAAAAAAAAAAAAAAAACAAACAIAAAAIAAAAAAAAAABA=</HashCode>
<FileName>clrobject.cs</FileName>
</TypeIdentifier>
</Class>
<Class Name="Python.Runtime.CLRModule" Collapsed="true">
<Position X="25" Y="4.75" Width="1.5" />
<TypeIdentifier>
<HashCode>AAAAAEAgIAQABAAAAABAAAAAIAIAAAAAAhAQAAAAKBA=</HashCode>
<HashCode>AAAAAEIgIAQABAAAAABAAAAAIAIAAAAgAhAQAAAAKBA=</HashCode>
<FileName>moduleobject.cs</FileName>
</TypeIdentifier>
</Class>
<Class Name="Python.Runtime.ConstructorBinding" Collapsed="true">
<Position X="29.5" Y="3.25" Width="1.5" />
<TypeIdentifier>
<HashCode>AAAACAAAAAAABAAAAAAACAAAABAJAEAAAAAAAAIAEAA=</HashCode>
<HashCode>AAAACAAAAAAAAAAAAAAACAAAABAJAAAAAAAAAAJAEAA=</HashCode>
<FileName>constructorbinding.cs</FileName>
</TypeIdentifier>
</Class>
Expand All @@ -74,14 +74,14 @@
</Path>
</InheritanceLine>
<TypeIdentifier>
<HashCode>AAAAAAAAAAAADAAAIAAAEABAAAAAAAACAAAAAAIAAAQ=</HashCode>
<HashCode>AAAAAAAAAAAACAAAIAAAEABAAAAAAAACAAAAAAJAAAA=</HashCode>
<FileName>eventbinding.cs</FileName>
</TypeIdentifier>
</Class>
<Class Name="Python.Runtime.EventObject" Collapsed="true">
<Position X="22.75" Y="3.25" Width="1.5" />
<TypeIdentifier>
<HashCode>AAACAAAAAAAAAAAAAAIAAIAAAAAEAAAAQABAAAIBEAQ=</HashCode>
<HashCode>AAACAAAAAAAAAAAAAAIAAIAAAAAEAAAAQABAAAJBEAA=</HashCode>
<FileName>eventobject.cs</FileName>
</TypeIdentifier>
</Class>
Expand All @@ -95,7 +95,7 @@
<Class Name="Python.Runtime.ExtensionType" Collapsed="true">
<Position X="27.5" Y="1.75" Width="1.5" />
<TypeIdentifier>
<HashCode>AAAAAAAAAAAAAAAAAAAAAAACAAAAAEEBAAAAAAABAAQ=</HashCode>
<HashCode>AAAAAAAAAAAABAAAAAAAAAgCAAAAAEEBAAAAAABAABQ=</HashCode>
<FileName>extensiontype.cs</FileName>
</TypeIdentifier>
</Class>
Expand All @@ -116,14 +116,14 @@
<Class Name="Python.Runtime.ManagedType" Collapsed="true">
<Position X="25" Y="0.5" Width="1.5" />
<TypeIdentifier>
<HashCode>UCBBgoBAIUgAAAEAACAAsAACAgAIABIAQYAAACIYIBA=</HashCode>
<HashCode>UCBBgIAAAUgAAAAAASAAMACCAAAIABIAAZAAAAIYABA=</HashCode>
<FileName>managedtype.cs</FileName>
</TypeIdentifier>
</Class>
<Class Name="Python.Runtime.MetaType" Collapsed="true">
<Position X="20.5" Y="1.75" Width="1.5" />
<TypeIdentifier>
<HashCode>AQAAAAAICBAAAQBAAAABAAIAAgABAAABAAAAUBCAAAQ=</HashCode>
<HashCode>AQAAAAAICBAAAQBAAAABAAIAAgABAAABAAAAUBCAABQ=</HashCode>
<FileName>metatype.cs</FileName>
</TypeIdentifier>
</Class>
Expand All @@ -138,14 +138,14 @@
</Path>
</InheritanceLine>
<TypeIdentifier>
<HashCode>EAAAAAAAAIAADABAIAAAAAAAAAgBAAAAUgAAAAIAAAQ=</HashCode>
<HashCode>AAAAAAAAAIAACABAIAAAAAAAAAABAAAAUgAAAAJAAAE=</HashCode>
<FileName>methodbinding.cs</FileName>
</TypeIdentifier>
</Class>
<Class Name="Python.Runtime.MethodObject" Collapsed="true">
<Position X="33.75" Y="3.25" Width="1.5" />
<TypeIdentifier>
<HashCode>FIADAAAAAAAIBAAAIAAIAAAIAAgFAAAAUAAgAAIAEAQ=</HashCode>
<HashCode>BIADAAAAAAAIAAAAIAAIAAAIAAAFAAAAUAAgAAJAFAA=</HashCode>
<FileName>methodobject.cs</FileName>
</TypeIdentifier>
</Class>
Expand All @@ -159,7 +159,7 @@
<Class Name="Python.Runtime.ModuleObject" Collapsed="true">
<Position X="25" Y="3.25" Width="1.5" />
<TypeIdentifier>
<HashCode>ECCCCkAAAAAABAAAAAABAAACAAAIAIIAEAAAAAIACAQ=</HashCode>
<HashCode>ECCCCkAAgAAAAAAAAAABAAgCAABIAAIBEAAAAAJACAA=</HashCode>
<FileName>moduleobject.cs</FileName>
</TypeIdentifier>
</Class>
Expand Down Expand Up @@ -188,7 +188,7 @@
</Path>
</InheritanceLine>
<TypeIdentifier>
<HashCode>AAAAAAAAAAAAAAAAIAAAAAAAAAABAAAAAgAAAAIAAAQ=</HashCode>
<HashCode>AAAAAAAAAAAAAAAAIAAAAAAAAAABAAAAAgAAAAJAAAA=</HashCode>
<FileName>overload.cs</FileName>
</TypeIdentifier>
</Class>
Expand Down
20 changes: 20 additions & 0 deletions src/runtime/StateSerialization/CLRMappedItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System.Collections.Generic;

namespace Python.Runtime;

public class CLRMappedItem
{
public object Instance { get; private set; }
public List<PyObject> PyRefs { get; set; } = new List<PyObject>();
public bool Stored { get; set; }

public CLRMappedItem(object instance)
{
Instance = instance;
}

internal void AddRef(PyObject pyRef)
{
this.PyRefs.Add(pyRef);
}
}
21 changes: 21 additions & 0 deletions src/runtime/StateSerialization/CLRWrapperCollection.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System.Collections.ObjectModel;

namespace Python.Runtime;

public class CLRWrapperCollection : KeyedCollection<object, CLRMappedItem>
{
public bool TryGetValue(object key, out CLRMappedItem value)
{
if (Dictionary == null)
{
value = null;
return false;
}
return Dictionary.TryGetValue(key, out value);
}

protected override object GetKeyForItem(CLRMappedItem item)
{
return item.Instance;
}
}
2 changes: 1 addition & 1 deletion src/runtime/StateSerialization/ClassManagerState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ namespace Python.Runtime.StateSerialization;
internal class ClassManagerState
{
public Dictionary<PyType, InterDomainContext> Contexts { get; set; }
public Dictionary<MaybeType, ClassBase> Cache { get; set; }
public Dictionary<MaybeType, PyType> Cache { get; set; }
}
9 changes: 9 additions & 0 deletions src/runtime/StateSerialization/ICLRObjectStorer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System.Collections.Generic;

namespace Python.Runtime;

public interface ICLRObjectStorer
{
ICollection<CLRMappedItem> Store(CLRWrapperCollection wrappers, RuntimeDataStorage storage);
CLRWrapperCollection Restore(RuntimeDataStorage storage);
}
4 changes: 2 additions & 2 deletions src/runtime/StateSerialization/SharedObjectsState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ namespace Python.Runtime.StateSerialization;
[Serializable]
internal class SharedObjectsState
{
public List<CLRObject> InternalStores { get; set; }
public List<ManagedType> Extensions { get; set; }
public Dictionary<PyObject, CLRObject> InternalStores { get; set; }
public Dictionary<PyObject, ExtensionType> Extensions { get; set; }
public RuntimeDataStorage Wrappers { get; set; }
public Dictionary<PyObject, InterDomainContext> Contexts { get; set; }
}
2 changes: 1 addition & 1 deletion src/runtime/arrayobject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Python.Runtime
/// to support natural array usage (indexing) from Python.
/// </summary>
[Serializable]
internal class ArrayObject : ClassBase
internal sealed class ArrayObject : ClassBase
{
internal ArrayObject(Type tp) : base(tp)
{
Expand Down
49 changes: 20 additions & 29 deletions src/runtime/classbase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;

namespace Python.Runtime
{
Expand All @@ -24,12 +25,6 @@ internal class ClassBase : ManagedType
internal readonly Dictionary<int, MethodObject> richcompare = new();
internal MaybeType type;

internal new PyType pyHandle
{
get => (PyType)base.pyHandle;
set => base.pyHandle = value;
}

internal ClassBase(Type tp)
{
if (tp is null) throw new ArgumentNullException(nameof(type));
Expand Down Expand Up @@ -83,8 +78,8 @@ public virtual NewReference type_subscript(BorrowedReference idx)
{
return Exceptions.RaiseTypeError(e.Message);
}
ManagedType c = ClassManager.GetClass(t);
return new NewReference(c.ObjectReference);
var c = ClassManager.GetClass(t);
return new NewReference(c);
}

return Exceptions.RaiseTypeError($"{type.Value.Namespace}.{type.Name} does not accept {types.Length} generic parameters");
Expand Down Expand Up @@ -254,7 +249,7 @@ public static NewReference tp_iter(BorrowedReference ob)
}
}

return new NewReference(new Iterator(o, elemType).ObjectReference);
return new Iterator(o, elemType).Alloc();
}


Expand Down Expand Up @@ -339,11 +334,16 @@ public static NewReference tp_repr(BorrowedReference ob)
/// </summary>
public static void tp_dealloc(NewReference lastRef)
{
ManagedType self = GetManagedObject(lastRef.Borrow())!;
var self = (CLRObject)GetManagedObject(lastRef.Borrow())!;
GCHandle gcHandle = GetGCHandle(lastRef.Borrow());
tp_clear(lastRef.Borrow());
Runtime.PyObject_GC_UnTrack(lastRef.Borrow());
Runtime.PyObject_GC_Del(lastRef.Steal());
self?.FreeGCHandle();

bool deleted = CLRObject.reflectedObjects.Remove(lastRef.DangerousGetAddress());
Debug.Assert(deleted);

gcHandle.Free();
}

public static int tp_clear(BorrowedReference ob)
Expand Down Expand Up @@ -399,26 +399,17 @@ static unsafe int BaseUnmanagedClear(BorrowedReference ob)
return clear(ob);
}

protected override void OnSave(InterDomainContext context)
protected override void OnSave(BorrowedReference ob, InterDomainContext context)
{
base.OnSave(context);
if (!this.IsClrMetaTypeInstance())
{
BorrowedReference dict = GetObjectDict(ObjectReference);
context.Storage.AddValue("dict", PyObject.FromNullableReference(dict));
}
base.OnSave(ob, context);
context.Storage.AddValue("impl", this);
}

protected override void OnLoad(InterDomainContext context)
protected override void OnLoad(BorrowedReference ob, InterDomainContext context)
{
base.OnLoad(context);
if (!this.IsClrMetaTypeInstance())
{
var dict = context.Storage.GetValue<PyObject>("dict");
SetObjectDict(ObjectReference, dict.NewReferenceOrNull().StealNullable());
}
gcHandle = AllocGCHandle();
SetGCHandle(ObjectReference, gcHandle);
base.OnLoad(ob, context);
var gcHandle = GCHandle.Alloc(this);
SetGCHandle(ob, gcHandle);
}


Expand Down Expand Up @@ -539,14 +530,14 @@ static IEnumerable<MethodInfo> GetCallImplementations(Type type)
=> type.GetMethods(BindingFlags.Public | BindingFlags.Instance)
.Where(m => m.Name == "__call__");

public virtual void InitializeSlots(SlotsHolder slotsHolder)
public virtual void InitializeSlots(BorrowedReference pyType, SlotsHolder slotsHolder)
{
if (!this.type.Valid) return;

if (GetCallImplementations(this.type.Value).Any()
&& !slotsHolder.IsHolding(TypeOffset.tp_call))
{
TypeManager.InitializeSlot(ObjectReference, TypeOffset.tp_call, new Interop.BBB_N(tp_call_impl), slotsHolder);
TypeManager.InitializeSlot(pyType, TypeOffset.tp_call, new Interop.BBB_N(tp_call_impl), slotsHolder);
}
}
}
Expand Down
Loading