◐ Shell
reader mode source ↗
Skip to content
Merged
Hide file tree
Changes from all commits
File filter
Conversations
Jump to
Diff view
Apply and reload
Show whitespace
Diff view
Apply and reload
1 change: 1 addition & 0 deletions src/runtime/InteropConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public static InteropConfiguration MakeDefault()
{
DefaultBaseTypeProvider.Instance,
new CollectionMixinsProvider(new Lazy<PyObject>(() => Py.Import("clr._extras.collections"))),
},
};
}
Expand Down
18 changes: 18 additions & 0 deletions src/runtime/Mixins/dlr.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
2 changes: 1 addition & 1 deletion src/runtime/PythonEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ static void LoadSubmodule(BorrowedReference targetModuleDict, string fullName, s

static void LoadMixins(BorrowedReference targetModuleDict)
{
foreach (string nested in new[] { "collections" })
{
LoadSubmodule(targetModuleDict,
fullName: "clr._extras." + nested,
Expand Down
192 changes: 192 additions & 0 deletions src/runtime/TypeManager.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Diagnostics;
using Python.Runtime.Native;
using Python.Runtime.StateSerialization;

Expand Down Expand Up @@ -37,10 +40,190 @@ internal class TypeManager
"tp_clear",
};

internal static void Initialize()
{
Debug.Assert(cache.Count == 0, "Cache should be empty",
"Some errors may occurred on last shutdown");
using (var plainType = SlotHelper.CreateObjectType())
{
subtype_traverse = Util.ReadIntPtr(plainType.Borrow(), TypeOffset.tp_traverse);
Expand All @@ -64,6 +247,8 @@ internal static void RemoveTypes()
}
}

foreach (var type in cache.Values)
{
type.Dispose();
Expand Down Expand Up @@ -313,6 +498,13 @@ internal static void InitializeClass(PyType type, ClassBase impl, Type clrType)
throw PythonException.ThrowLastAsClrException();
}

var dict = Util.ReadRef(type, TypeOffset.tp_dict);
string mn = clrType.Namespace ?? "";
using (var mod = Runtime.PyString_FromString(mn))
Expand Down
37 changes: 37 additions & 0 deletions src/runtime/Types/ClassDerived.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
Expand Down Expand Up @@ -232,6 +233,13 @@ internal static Type CreateDerivedType(string name,
continue;
}

// skip if this property has already been overridden
if ((method.Name.StartsWith("get_") || method.Name.StartsWith("set_"))
&& pyProperties.Contains(method.Name.Substring(4)))
Expand Down Expand Up @@ -300,6 +308,35 @@ internal static Type CreateDerivedType(string name,
return type;
}

/// <summary>
/// Add a constructor override that calls the python ctor after calling the base type constructor.
/// </summary>
Expand Down
Loading
Loading
Toggle all file notes Toggle all file annotations