| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 46de53e commit f92a26b
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1836,12 +1836,6 @@ internal static void SetNoSiteFlag() | |||
| 1836 | 1836 | return *Delegates.Py_NoSiteFlag; | |
| 1837 | 1837 | }); | |
| 1838 | 1838 | } | |
| 1839 | - | ||
| 1840 | - internal static uint PyTuple_GetSize(BorrowedReference tuple) | ||
| 1841 | - { | ||
| 1842 | - IntPtr r = Delegates.PyTuple_Size(tuple); | ||
| 1843 | - return (uint)r.ToInt32(); | ||
| 1844 | - } | ||
| 1845 | 1839 | } | |
| 1846 | 1840 | ||
| 1847 | 1841 | internal class BadPythonDllException : MissingMethodException | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -374,7 +374,7 @@ static PyTuple GetBaseTypeTuple(Type clrType) | |||
| 374 | 374 | return new PyTuple(bases); | |
| 375 | 375 | } | |
| 376 | 376 | ||
| 377 | - internal static NewReference CreateSubType(BorrowedReference py_name, IList<ClassBase> py_base_type, IList<Type> interfaces, BorrowedReference dictRef) | ||
| 377 | + internal static NewReference CreateSubType(BorrowedReference py_name, ClassBase py_base_type, IList<Type> interfaces, BorrowedReference dictRef) | ||
| 378 | 378 | { | |
| 379 | 379 | // Utility to create a subtype of a managed type with the ability for the | |
| 380 | 380 | // a python subtype able to override the managed implementation | |
@@ -415,9 +415,7 @@ internal static NewReference CreateSubType(BorrowedReference py_name, IList<Clas | |||
| 415 | 415 | } | |
| 416 | 416 | ||
| 417 | 417 | // create the new managed type subclassing the base managed type | |
| 418 | - var baseClass = py_base_type.FirstOrDefault(); | ||
| 419 | - | ||
| 420 | - return ReflectedClrType.CreateSubclass(baseClass, interfaces, name, | ||
| 418 | + return ReflectedClrType.CreateSubclass(py_base_type, interfaces, name, | ||
| 421 | 419 | ns: (string?)namespaceStr, | |
| 422 | 420 | assembly: (string?)assembly, | |
| 423 | 421 | dict: dictRef); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -84,34 +84,37 @@ public static NewReference tp_new(BorrowedReference tp, BorrowedReference args, | |||
| 84 | 84 | ||
| 85 | 85 | // Extract interface types and base class types. | |
| 86 | 86 | var interfaces = new List<Type>(); | |
| 87 | - var baseType = new List<ClassBase>(); | ||
| 88 | 87 | ||
| 89 | - var cnt = Runtime.PyTuple_GetSize(bases); | ||
| 88 | + // More than one base type case be declared, but an exception will be thrown | ||
| 89 | + // if more than one is a class/not an interface. | ||
| 90 | + var baseTypes = new List<ClassBase>(); | ||
| 90 | 91 | ||
| 91 | - for (uint i = 0; i < cnt; i++) | ||
| 92 | + var baseClassCount = Runtime.PyTuple_Size(bases); | ||
| 93 | + | ||
| 94 | + for (nint i = 0; i < baseClassCount; i++) | ||
| 92 | 95 | { | |
| 93 | - var base_type2 = Runtime.PyTuple_GetItem(bases, (int)i); | ||
| 94 | - var cb2 = (ClassBase) GetManagedObject(base_type2); | ||
| 95 | - if (cb2 != null) | ||
| 96 | + var baseTypeIt = Runtime.PyTuple_GetItem(bases, (int)i); | ||
| 97 | + | ||
| 98 | + if (GetManagedObject(baseTypeIt) is ClassBase classBaseIt) | ||
| 96 | 99 | { | |
| 97 | - if (cb2.type.Valid && cb2.type.Value.IsInterface) | ||
| 98 | - interfaces.Add(cb2.type.Value); | ||
| 99 | - else baseType.Add(cb2); | ||
| 100 | + if (classBaseIt.type.Valid && classBaseIt.type.Value.IsInterface) | ||
| 101 | + interfaces.Add(classBaseIt.type.Value); | ||
| 102 | + else baseTypes.Add(classBaseIt); | ||
| 100 | 103 | } | |
| 101 | 104 | } | |
| 102 | 105 | // if the base type count is 0, there might still be interfaces to implement. | |
| 103 | - if (baseType.Count == 0) | ||
| 106 | + if (baseTypes.Count == 0) | ||
| 104 | 107 | { | |
| 105 | - baseType.Add(new ClassBase(typeof(object))); | ||
| 108 | + baseTypes.Add(new ClassBase(typeof(object))); | ||
| 106 | 109 | } | |
| 107 | 110 | ||
| 108 | 111 | // Multiple inheritance is not supported, unless the other types are interfaces | |
| 109 | - if (baseType.Count > 1) | ||
| 112 | + if (baseTypes.Count > 1) | ||
| 110 | 113 | { | |
| 111 | 114 | return Exceptions.RaiseTypeError("cannot use multiple inheritance with managed classes"); | |
| 112 | 115 | } | |
| 113 | 116 | ||
| 114 | - var cb = baseType[0]; | ||
| 117 | + var cb = baseTypes[0]; | ||
| 115 | 118 | try | |
| 116 | 119 | { | |
| 117 | 120 | if (!cb.CanSubclass()) | |
@@ -140,7 +143,7 @@ public static NewReference tp_new(BorrowedReference tp, BorrowedReference args, | |||
| 140 | 143 | using var clsDict = new PyDict(dict); | |
| 141 | 144 | if (clsDict.HasKey("__assembly__") || clsDict.HasKey("__namespace__")) | |
| 142 | 145 | { | |
| 143 | - return TypeManager.CreateSubType(name, baseType, interfaces, clsDict); | ||
| 146 | + return TypeManager.CreateSubType(name, baseTypes[0], interfaces, clsDict); | ||
| 144 | 147 | } | |
| 145 | 148 | } | |
| 146 | 149 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments