| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -21,11 +21,6 @@ This document follows the conventions laid out in [Keep a CHANGELOG][]. | |||
| 21 | 21 | details about the cause of the failure | |
| 22 | 22 | - `clr.AddReference` no longer adds ".dll" implicitly | |
| 23 | 23 | - `PyIter(PyObject)` constructor replaced with static `PyIter.GetIter(PyObject)` method | |
| 24 | - - BREAKING: Return values from .NET methods that return an interface are now automatically | ||
| 25 | - wrapped in that interface. This is a breaking change for users that rely on being | ||
| 26 | - able to access members that are part of the implementation class, but not the | ||
| 27 | - interface. Use the new __implementation__ or __raw_implementation__ properties to | ||
| 28 | - if you need to "downcast" to the implementation class. | ||
| 29 | 24 | - BREAKING: Parameters marked with `ParameterAttributes.Out` are no longer returned in addition | |
| 30 | 25 | to the regular method return value (unless they are passed with `ref` or `out` keyword). | |
| 31 | 26 | - BREAKING: Drop support for the long-deprecated CLR.* prefix. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -137,13 +137,8 @@ static NewReference NewInstance(Type elementType, BorrowedReference arrayPyType, | |||
| 137 | 137 | public new static IntPtr mp_subscript(IntPtr ob, IntPtr idx) | |
| 138 | 138 | { | |
| 139 | 139 | var obj = (CLRObject)GetManagedObject(ob); | |
| 140 | - var arrObj = (ArrayObject)GetManagedObjectType(ob); | ||
| 141 | - if (!arrObj.type.Valid) | ||
| 142 | - { | ||
| 143 | - return Exceptions.RaiseTypeError(arrObj.type.DeletedMessage); | ||
| 144 | - } | ||
| 145 | 140 | var items = obj.inst as Array; | |
| 146 | - Type itemType = arrObj.type.Value.GetElementType(); | ||
| 141 | + Type itemType = obj.inst.GetType().GetElementType(); | ||
| 147 | 142 | int rank = items.Rank; | |
| 148 | 143 | int index; | |
| 149 | 144 | object value; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -207,21 +207,6 @@ internal static IntPtr ToPython(object value, Type type) | |||
| 207 | 207 | } | |
| 208 | 208 | } | |
| 209 | 209 | ||
| 210 | - if (type.IsInterface) | ||
| 211 | - { | ||
| 212 | - var ifaceObj = (InterfaceObject)ClassManager.GetClass(type); | ||
| 213 | - return ifaceObj.WrapObject(value); | ||
| 214 | - } | ||
| 215 | - | ||
| 216 | - // We need to special case interface array handling to ensure we | ||
| 217 | - // produce the correct type. Value may be an array of some concrete | ||
| 218 | - // type (FooImpl[]), but we want access to go via the interface type | ||
| 219 | - // (IFoo[]). | ||
| 220 | - if (type.IsArray && type.GetElementType().IsInterface) | ||
| 221 | - { | ||
| 222 | - return CLRObject.GetInstHandle(value, type); | ||
| 223 | - } | ||
| 224 | - | ||
| 225 | 210 | // it the type is a python subclass of a managed type then return the | |
| 226 | 211 | // underlying python object rather than construct a new wrapper object. | |
| 227 | 212 | var pyderived = value as IPythonDerivedType; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -76,43 +76,7 @@ public static IntPtr tp_new(IntPtr tp, IntPtr args, IntPtr kw) | |||
| 76 | 76 | return IntPtr.Zero; | |
| 77 | 77 | } | |
| 78 | 78 | ||
| 79 | - return self.WrapObject(obj); | ||
| 80 | - } | ||
| 81 | - | ||
| 82 | - /// <summary> | ||
| 83 | - /// Wrap the given object in an interface object, so that only methods | ||
| 84 | - /// of the interface are available. | ||
| 85 | - /// </summary> | ||
| 86 | - public IntPtr WrapObject(object impl) | ||
| 87 | - { | ||
| 88 | - var objPtr = CLRObject.GetInstHandle(impl, pyHandle); | ||
| 89 | - return objPtr; | ||
| 90 | - } | ||
| 91 | - | ||
| 92 | - /// <summary> | ||
| 93 | - /// Expose the wrapped implementation through attributes in both | ||
| 94 | - /// converted/encoded (__implementation__) and raw (__raw_implementation__) form. | ||
| 95 | - /// </summary> | ||
| 96 | - public static IntPtr tp_getattro(IntPtr ob, IntPtr key) | ||
| 97 | - { | ||
| 98 | - var clrObj = (CLRObject)GetManagedObject(ob); | ||
| 99 | - | ||
| 100 | - if (!Runtime.PyString_Check(key)) | ||
| 101 | - { | ||
| 102 | - return Exceptions.RaiseTypeError("string expected"); | ||
| 103 | - } | ||
| 104 | - | ||
| 105 | - string name = Runtime.GetManagedString(key); | ||
| 106 | - if (name == "__implementation__") | ||
| 107 | - { | ||
| 108 | - return Converter.ToPython(clrObj.inst); | ||
| 109 | - } | ||
| 110 | - else if (name == "__raw_implementation__") | ||
| 111 | - { | ||
| 112 | - return CLRObject.GetInstHandle(clrObj.inst); | ||
| 113 | - } | ||
| 114 | - | ||
| 115 | - return Runtime.PyObject_GenericGetAttr(ob, key); | ||
| 79 | + return CLRObject.GetInstHandle(obj, self.pyHandle); | ||
| 116 | 80 | } | |
| 117 | 81 | } | |
| 118 | 82 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -109,25 +109,6 @@ internal static ManagedType GetManagedObject(IntPtr ob) | |||
| 109 | 109 | return null; | |
| 110 | 110 | } | |
| 111 | 111 | ||
| 112 | - /// <summary> | ||
| 113 | - /// Given a Python object, return the associated managed object type or null. | ||
| 114 | - /// </summary> | ||
| 115 | - internal static ManagedType GetManagedObjectType(IntPtr ob) | ||
| 116 | - { | ||
| 117 | - if (ob != IntPtr.Zero) | ||
| 118 | - { | ||
| 119 | - IntPtr tp = Runtime.PyObject_TYPE(ob); | ||
| 120 | - var flags = Util.ReadCLong(tp, TypeOffset.tp_flags); | ||
| 121 | - if ((flags & TypeFlags.Managed) != 0) | ||
| 122 | - { | ||
| 123 | - tp = Marshal.ReadIntPtr(tp, TypeOffset.magic()); | ||
| 124 | - var gc = (GCHandle)tp; | ||
| 125 | - return (ManagedType)gc.Target; | ||
| 126 | - } | ||
| 127 | - } | ||
| 128 | - return null; | ||
| 129 | - } | ||
| 130 | - | ||
| 131 | 112 | ||
| 132 | 113 | internal static ManagedType GetManagedObjectErr(IntPtr ob) | |
| 133 | 114 | { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -251,8 +251,10 @@ internal static IntPtr CreateType(ManagedType impl, Type clrType) | |||
| 251 | 251 | InitializeSlot(type, TypeOffset.mp_length, mp_length_slot.Method, slotsHolder); | |
| 252 | 252 | } | |
| 253 | 253 | ||
| 254 | - if (!typeof(IEnumerable).IsAssignableFrom(clrType) && | ||
| 255 | - !typeof(IEnumerator).IsAssignableFrom(clrType)) | ||
| 254 | + // we want to do this after the slot stuff above in case the class itself implements a slot method | ||
| 255 | + InitializeSlots(type, impl.GetType()); | ||
| 256 | + | ||
| 257 | + if (!clrType.GetInterfaces().Any(ifc => ifc == typeof(IEnumerable) || ifc == typeof(IEnumerator))) | ||
| 256 | 258 | { | |
| 257 | 259 | // The tp_iter slot should only be set for enumerable types. | |
| 258 | 260 | Marshal.WriteIntPtr(type, TypeOffset.tp_iter, IntPtr.Zero); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -11,6 +11,7 @@ internal interface IInternalInterface | |||
| 11 | 11 | { | |
| 12 | 12 | } | |
| 13 | 13 | ||
| 14 | + | ||
| 14 | 15 | public interface ISayHello1 | |
| 15 | 16 | { | |
| 16 | 17 | string SayHello(); | |
@@ -42,27 +43,6 @@ string ISayHello2.SayHello() | |||
| 42 | 43 | return "hello 2"; | |
| 43 | 44 | } | |
| 44 | 45 | ||
| 45 | - public ISayHello1 GetISayHello1() | ||
| 46 | - { | ||
| 47 | - return this; | ||
| 48 | - } | ||
| 49 | - | ||
| 50 | - public void GetISayHello2(out ISayHello2 hello2) | ||
| 51 | - { | ||
| 52 | - hello2 = this; | ||
| 53 | - } | ||
| 54 | - | ||
| 55 | - public ISayHello1 GetNoSayHello(out ISayHello2 hello2) | ||
| 56 | - { | ||
| 57 | - hello2 = null; | ||
| 58 | - return null; | ||
| 59 | - } | ||
| 60 | - | ||
| 61 | - public ISayHello1 [] GetISayHello1Array() | ||
| 62 | - { | ||
| 63 | - return new[] { this }; | ||
| 64 | - } | ||
| 65 | - | ||
| 66 | 46 | public interface IPublic | |
| 67 | 47 | { | |
| 68 | 48 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -89,24 +89,13 @@ public static string test_bar(IInterfaceTest x, string s, int i) | |||
| 89 | 89 | } | |
| 90 | 90 | ||
| 91 | 91 | // test instances can be constructed in managed code | |
| 92 | - public static SubClassTest create_instance(Type t) | ||
| 93 | - { | ||
| 94 | - return (SubClassTest)t.GetConstructor(new Type[] { }).Invoke(new object[] { }); | ||
| 95 | - } | ||
| 96 | - | ||
| 97 | - public static IInterfaceTest create_instance_interface(Type t) | ||
| 92 | + public static IInterfaceTest create_instance(Type t) | ||
| 98 | 93 | { | |
| 99 | 94 | return (IInterfaceTest)t.GetConstructor(new Type[] { }).Invoke(new object[] { }); | |
| 100 | 95 | } | |
| 101 | 96 | ||
| 102 | - // test instances pass through managed code unchanged ... | ||
| 103 | - public static SubClassTest pass_through(SubClassTest s) | ||
| 104 | - { | ||
| 105 | - return s; | ||
| 106 | - } | ||
| 107 | - | ||
| 108 | - // ... but the return type is an interface type, objects get wrapped | ||
| 109 | - public static IInterfaceTest pass_through_interface(IInterfaceTest s) | ||
| 97 | + // test instances pass through managed code unchanged | ||
| 98 | + public static IInterfaceTest pass_through(IInterfaceTest s) | ||
| 110 | 99 | { | |
| 111 | 100 | return s; | |
| 112 | 101 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1334,10 +1334,9 @@ def test_special_array_creation(): | |||
| 1334 | 1334 | assert value[1].__class__ == inst.__class__ | |
| 1335 | 1335 | assert value.Length == 2 | |
| 1336 | 1336 | ||
| 1337 | - iface_class = ISayHello1(inst).__class__ | ||
| 1338 | 1337 | value = Array[ISayHello1]([inst, inst]) | |
| 1339 | - assert value[0].__class__ == iface_class | ||
| 1340 | - assert value[1].__class__ == iface_class | ||
| 1338 | + assert value[0].__class__ == inst.__class__ | ||
| 1339 | + assert value[1].__class__ == inst.__class__ | ||
| 1341 | 1340 | assert value.Length == 2 | |
| 1342 | 1341 | ||
| 1343 | 1342 | inst = System.Exception("badness") | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -318,6 +318,7 @@ def test_generic_method_type_handling(): | |||
| 318 | 318 | assert_generic_method_by_type(ShortEnum, ShortEnum.Zero) | |
| 319 | 319 | assert_generic_method_by_type(System.Object, InterfaceTest()) | |
| 320 | 320 | assert_generic_method_by_type(InterfaceTest, InterfaceTest(), 1) | |
| 321 | + assert_generic_method_by_type(ISayHello1, InterfaceTest(), 1) | ||
| 321 | 322 | ||
| 322 | 323 | ||
| 323 | 324 | def test_correct_overload_selection(): | |
@@ -546,11 +547,10 @@ def test_method_overload_selection_with_generic_types(): | |||
| 546 | 547 | value = MethodTest.Overloaded.__overloads__[vtype](input_) | |
| 547 | 548 | assert value.value.__class__ == inst.__class__ | |
| 548 | 549 | ||
| 549 | - iface_class = ISayHello1(inst).__class__ | ||
| 550 | 550 | vtype = GenericWrapper[ISayHello1] | |
| 551 | 551 | input_ = vtype(inst) | |
| 552 | 552 | value = MethodTest.Overloaded.__overloads__[vtype](input_) | |
| 553 | - assert value.value.__class__ == iface_class | ||
| 553 | + assert value.value.__class__ == inst.__class__ | ||
| 554 | 554 | ||
| 555 | 555 | vtype = System.Array[GenericWrapper[int]] | |
| 556 | 556 | input_ = vtype([GenericWrapper[int](0), GenericWrapper[int](1)]) | |
@@ -725,12 +725,11 @@ def test_overload_selection_with_arrays_of_generic_types(): | |||
| 725 | 725 | assert value[0].value.__class__ == inst.__class__ | |
| 726 | 726 | assert value.Length == 2 | |
| 727 | 727 | ||
| 728 | - iface_class = ISayHello1(inst).__class__ | ||
| 729 | 728 | gtype = GenericWrapper[ISayHello1] | |
| 730 | 729 | vtype = System.Array[gtype] | |
| 731 | 730 | input_ = vtype([gtype(inst), gtype(inst)]) | |
| 732 | 731 | value = MethodTest.Overloaded.__overloads__[vtype](input_) | |
| 733 | - assert value[0].value.__class__ == iface_class | ||
| 732 | + assert value[0].value.__class__ == inst.__class__ | ||
| 734 | 733 | assert value.Length == 2 | |
| 735 | 734 | ||
| 736 | 735 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments