| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -31,7 +31,6 @@ internal class AssemblyManager { | |||
| 31 | 31 | static Dictionary<string, int> probed; | |
| 32 | 32 | static List<Assembly> assemblies; | |
| 33 | 33 | static List<string> pypath; | |
| 34 | - static int last; | ||
| 35 | 34 | ||
| 36 | 35 | private AssemblyManager() {} | |
| 37 | 36 | ||
@@ -271,7 +270,7 @@ static void ScanAssembly(Assembly assembly) { | |||
| 271 | 270 | } | |
| 272 | 271 | ||
| 273 | 272 | if (t.IsGenericTypeDefinition) { | |
| 274 | - GenericManager.Register(t); | ||
| 273 | + GenericUtil.Register(t); | ||
| 275 | 274 | // Dictionary<string, string> map = null; | |
| 276 | 275 | // generics.TryGetValue(t.Namespace, out map); | |
| 277 | 276 | // if (map == null) { | |
@@ -323,7 +322,7 @@ public static List<string> GetNames(string nsname) { | |||
| 323 | 322 | Dictionary<string, int> seen = new Dictionary<string, int>(); | |
| 324 | 323 | List<string> names = new List<string>(8); | |
| 325 | 324 | ||
| 326 | - List<string> g = GenericManager.GetGenericBaseNames(nsname); | ||
| 325 | + List<string> g = GenericUtil.GetGenericBaseNames(nsname); | ||
| 327 | 326 | if (g != null) { | |
| 328 | 327 | foreach (string n in g) { | |
| 329 | 328 | names.Add(n); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -28,7 +28,6 @@ internal class ClassBase : ManagedType { | |||
| 28 | 28 | ||
| 29 | 29 | internal bool is_exception; | |
| 30 | 30 | internal Indexer indexer; | |
| 31 | - internal Type[] generics; | ||
| 32 | 31 | internal Type type; | |
| 33 | 32 | ||
| 34 | 33 | internal ClassBase(Type tp) : base() { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -75,7 +75,7 @@ public override IntPtr type_subscript(IntPtr idx) { | |||
| 75 | 75 | } | |
| 76 | 76 | else { | |
| 77 | 77 | foreach (Type t in | |
| 78 | - GenericManager.GenericsForType(this.type)) { | ||
| 78 | + GenericUtil.GenericsForType(this.type)) { | ||
| 79 | 79 | if (t.GetGenericArguments().Length == types.Length) { | |
| 80 | 80 | target = t; | |
| 81 | 81 | break; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,138 @@ | |||
| 1 | + // ========================================================================== | ||
| 2 | + // This software is subject to the provisions of the Zope Public License, | ||
| 3 | + // Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution. | ||
| 4 | + // THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED | ||
| 5 | + // WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
| 6 | + // WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS | ||
| 7 | + // FOR A PARTICULAR PURPOSE. | ||
| 8 | + // ========================================================================== | ||
| 9 | + | ||
| 10 | + using System; | ||
| 11 | + using System.Runtime.InteropServices; | ||
| 12 | + using System.Collections.Generic; | ||
| 13 | + using System.Collections; | ||
| 14 | + using System.Reflection; | ||
| 15 | + using System.Security; | ||
| 16 | + | ||
| 17 | + namespace Python.Runtime { | ||
| 18 | + | ||
| 19 | + /// <summary> | ||
| 20 | + /// This class is responsible for efficiently maintaining the bits | ||
| 21 | + /// of information we need to support aliases with 'nice names'. | ||
| 22 | + /// </summary> | ||
| 23 | + | ||
| 24 | + internal class GenericUtil { | ||
| 25 | + | ||
| 26 | + static Dictionary<string, Dictionary<string, List<string>>> mapping; | ||
| 27 | + | ||
| 28 | + private GenericUtil() {} | ||
| 29 | + | ||
| 30 | + static GenericUtil() { | ||
| 31 | + mapping = new | ||
| 32 | + Dictionary<string, Dictionary<string, List<string>>>(); | ||
| 33 | + } | ||
| 34 | + | ||
| 35 | + //==================================================================== | ||
| 36 | + // Register a generic type that appears in a given namespace. | ||
| 37 | + //==================================================================== | ||
| 38 | + | ||
| 39 | + internal static void Register(Type t) { | ||
| 40 | + Dictionary<string, List<string>> nsmap = null; | ||
| 41 | + mapping.TryGetValue(t.Namespace, out nsmap); | ||
| 42 | + if (nsmap == null) { | ||
| 43 | + nsmap = new Dictionary<string, List<string>>(); | ||
| 44 | + mapping[t.Namespace] = nsmap; | ||
| 45 | + } | ||
| 46 | + string basename = t.Name; | ||
| 47 | + int tick = basename.IndexOf("`"); | ||
| 48 | + if (tick > -1) { | ||
| 49 | + basename = basename.Substring(0, tick); | ||
| 50 | + } | ||
| 51 | + List<string> gnames = null; | ||
| 52 | + nsmap.TryGetValue(basename, out gnames); | ||
| 53 | + if (gnames == null) { | ||
| 54 | + gnames = new List<string>(); | ||
| 55 | + nsmap[basename] = gnames; | ||
| 56 | + } | ||
| 57 | + gnames.Add(t.Name); | ||
| 58 | + } | ||
| 59 | + | ||
| 60 | + //==================================================================== | ||
| 61 | + // xxx | ||
| 62 | + //==================================================================== | ||
| 63 | + | ||
| 64 | + public static List<string> GetGenericBaseNames(string ns) { | ||
| 65 | + Dictionary<string, List<string>> nsmap = null; | ||
| 66 | + mapping.TryGetValue(ns, out nsmap); | ||
| 67 | + if (nsmap == null) { | ||
| 68 | + return null; | ||
| 69 | + } | ||
| 70 | + List<string> names = new List<string>(); | ||
| 71 | + foreach (string key in nsmap.Keys) { | ||
| 72 | + names.Add(key); | ||
| 73 | + } | ||
| 74 | + return names; | ||
| 75 | + } | ||
| 76 | + | ||
| 77 | + //==================================================================== | ||
| 78 | + // xxx | ||
| 79 | + //==================================================================== | ||
| 80 | + | ||
| 81 | + public static List<Type> GenericsForType(Type t) { | ||
| 82 | + Dictionary<string, List<string>> nsmap = null; | ||
| 83 | + mapping.TryGetValue(t.Namespace, out nsmap); | ||
| 84 | + if (nsmap == null) { | ||
| 85 | + return null; | ||
| 86 | + } | ||
| 87 | + | ||
| 88 | + string basename = t.Name; | ||
| 89 | + int tick = basename.IndexOf("`"); | ||
| 90 | + if (tick > -1) { | ||
| 91 | + basename = basename.Substring(0, tick); | ||
| 92 | + } | ||
| 93 | + | ||
| 94 | + List<string> names = null; | ||
| 95 | + nsmap.TryGetValue(basename, out names); | ||
| 96 | + if (names == null) { | ||
| 97 | + return null; | ||
| 98 | + } | ||
| 99 | + | ||
| 100 | + List<Type> result = new List<Type>(); | ||
| 101 | + foreach (string name in names) { | ||
| 102 | + string qname = t.Namespace + "." + name; | ||
| 103 | + Type o = AssemblyManager.LookupType(qname); | ||
| 104 | + if (o != null) { | ||
| 105 | + result.Add(o); | ||
| 106 | + } | ||
| 107 | + } | ||
| 108 | + | ||
| 109 | + return result; | ||
| 110 | + } | ||
| 111 | + | ||
| 112 | + //==================================================================== | ||
| 113 | + // xxx | ||
| 114 | + //==================================================================== | ||
| 115 | + | ||
| 116 | + public static string GenericNameForBaseName(string ns, string name) { | ||
| 117 | + Dictionary<string, List<string>> nsmap = null; | ||
| 118 | + mapping.TryGetValue(ns, out nsmap); | ||
| 119 | + if (nsmap == null) { | ||
| 120 | + return null; | ||
| 121 | + } | ||
| 122 | + List<string> gnames = null; | ||
| 123 | + nsmap.TryGetValue(name, out gnames); | ||
| 124 | + if (gnames == null) { | ||
| 125 | + return null; | ||
| 126 | + } | ||
| 127 | + if (gnames.Count > 0) { | ||
| 128 | + return gnames[0]; | ||
| 129 | + } | ||
| 130 | + return null; | ||
| 131 | + } | ||
| 132 | + | ||
| 133 | + | ||
| 134 | + } | ||
| 135 | + | ||
| 136 | + | ||
| 137 | + | ||
| 138 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -136,7 +136,7 @@ public ManagedType GetAttribute(string name, bool guess) { | |||
| 136 | 136 | // enough to complicate the implementation for now. | |
| 137 | 137 | ||
| 138 | 138 | if (guess) { | |
| 139 | - string gname = GenericManager.GenericNameForBaseName( | ||
| 139 | + string gname = GenericUtil.GenericNameForBaseName( | ||
| 140 | 140 | _namespace, name); | |
| 141 | 141 | if (gname != null) { | |
| 142 | 142 | ManagedType o = GetAttribute(gname, false); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,80 @@ | |||
| 1 | + // ========================================================================== | ||
| 2 | + // This software is subject to the provisions of the Zope Public License, | ||
| 3 | + // Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution. | ||
| 4 | + // THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED | ||
| 5 | + // WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
| 6 | + // WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS | ||
| 7 | + // FOR A PARTICULAR PURPOSE. | ||
| 8 | + // ========================================================================== | ||
| 9 | + | ||
| 10 | + //============================================================================ | ||
| 11 | + // This file implements the deprecated CLR extension module. | ||
| 12 | + //============================================================================ | ||
| 13 | + | ||
| 14 | + .assembly extern mscorlib | ||
| 15 | + { | ||
| 16 | + .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) | ||
| 17 | + .ver 1:0:5000:0 | ||
| 18 | + } | ||
| 19 | + .assembly extern Python.Runtime | ||
| 20 | + { | ||
| 21 | + .ver 1:0:0:0 | ||
| 22 | + } | ||
| 23 | + .assembly CLR | ||
| 24 | + { | ||
| 25 | + // --- The following custom attribute is added automatically, do not uncomment ------- | ||
| 26 | + // .custom instance void [mscorlib]System.Diagnostics.DebuggableAttribute::.ctor(bool, | ||
| 27 | + // bool) = ( 01 00 00 01 00 00 ) | ||
| 28 | + .hash algorithm 0x00008004 | ||
| 29 | + .ver 0:0:0:0 | ||
| 30 | + } | ||
| 31 | + | ||
| 32 | + .module CLR.dll | ||
| 33 | + // MVID: {01BEB897-1638-4D9D-B01C-3638714A76B4} | ||
| 34 | + .imagebase 0x00400000 | ||
| 35 | + .subsystem 0x00000003 | ||
| 36 | + .file alignment 512 | ||
| 37 | + .corflags 0x00000002 | ||
| 38 | + | ||
| 39 | + .vtfixup [1] int32 fromunmanaged at VT_01 | ||
| 40 | + .data VT_01 = int32(0) | ||
| 41 | + | ||
| 42 | + | ||
| 43 | + .class public auto ansi beforefieldinit CLRModule | ||
| 44 | + extends [mscorlib]System.Object | ||
| 45 | + { | ||
| 46 | + } // end of class CLRModule | ||
| 47 | + | ||
| 48 | + | ||
| 49 | + | ||
| 50 | + .class public auto ansi beforefieldinit CLRModule | ||
| 51 | + extends [mscorlib]System.Object | ||
| 52 | + { | ||
| 53 | + .method public hidebysig static void | ||
| 54 | + modopt([mscorlib]System.Runtime.CompilerServices.CallConvCdecl) | ||
| 55 | + initCLR() cil managed | ||
| 56 | + { | ||
| 57 | + .vtentry 1:1 | ||
| 58 | + .export [1] as initCLR | ||
| 59 | + | ||
| 60 | + // Code size 8 (0x8) | ||
| 61 | + .maxstack 0 | ||
| 62 | + IL_0000: call void [Python.Runtime]Python.Runtime.PythonEngine::InitExt() | ||
| 63 | + IL_0005: br.s IL_0007 | ||
| 64 | + | ||
| 65 | + IL_0007: ret | ||
| 66 | + } // end of method CLRModule::initCLR | ||
| 67 | + | ||
| 68 | + .method public hidebysig specialname rtspecialname | ||
| 69 | + instance void .ctor() cil managed | ||
| 70 | + { | ||
| 71 | + // Code size 7 (0x7) | ||
| 72 | + .maxstack 1 | ||
| 73 | + IL_0000: ldarg.0 | ||
| 74 | + IL_0001: call instance void [mscorlib]System.Object::.ctor() | ||
| 75 | + IL_0006: ret | ||
| 76 | + } // end of method CLRModule::.ctor | ||
| 77 | + | ||
| 78 | + } // end of class CLRModule | ||
| 79 | + | ||
| 80 | + | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,72 @@ | |||
| 1 | + // ========================================================================== | ||
| 2 | + // This software is subject to the provisions of the Zope Public License, | ||
| 3 | + // Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution. | ||
| 4 | + // THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED | ||
| 5 | + // WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
| 6 | + // WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS | ||
| 7 | + // FOR A PARTICULAR PURPOSE. | ||
| 8 | + // ========================================================================== | ||
| 9 | + | ||
| 10 | + using System; | ||
| 11 | + using System.Reflection; | ||
| 12 | + | ||
| 13 | + namespace Python.Runtime { | ||
| 14 | + | ||
| 15 | + //======================================================================== | ||
| 16 | + // Implements the __overloads__ attribute of method objects. This object | ||
| 17 | + // supports the [] syntax to explicitly select an overload by signature. | ||
| 18 | + //======================================================================== | ||
| 19 | + | ||
| 20 | + internal class OverloadMapper : ExtensionType { | ||
| 21 | + | ||
| 22 | + MethodObject m; | ||
| 23 | + IntPtr target; | ||
| 24 | + | ||
| 25 | + public OverloadMapper(MethodObject m, IntPtr target) : base() { | ||
| 26 | + Runtime.Incref(target); | ||
| 27 | + this.target = target; | ||
| 28 | + this.m = m; | ||
| 29 | + } | ||
| 30 | + | ||
| 31 | + //==================================================================== | ||
| 32 | + // Implement explicit overload selection using subscript syntax ([]). | ||
| 33 | + //==================================================================== | ||
| 34 | + | ||
| 35 | + public static IntPtr mp_subscript(IntPtr tp, IntPtr idx) { | ||
| 36 | + OverloadMapper self = (OverloadMapper)GetManagedObject(tp); | ||
| 37 | + | ||
| 38 | + // Note: if the type provides a non-generic method with N args | ||
| 39 | + // and a generic method that takes N params, then we always | ||
| 40 | + // prefer the non-generic version in doing overload selection. | ||
| 41 | + | ||
| 42 | + Type[] types = Runtime.PythonArgsToTypeArray(idx); | ||
| 43 | + if (types == null) { | ||
| 44 | + return Exceptions.RaiseTypeError("type(s) expected"); | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + MethodInfo mi = MethodBinder.MatchSignature(self.m.info, types); | ||
| 48 | + if (mi == null) { | ||
| 49 | + string e = "No match found for signature"; | ||
| 50 | + return Exceptions.RaiseTypeError(e); | ||
| 51 | + } | ||
| 52 | + | ||
| 53 | + MethodBinding mb = new MethodBinding(self.m, self.target); | ||
| 54 | + mb.info = mi; | ||
| 55 | + Runtime.Incref(mb.pyHandle); | ||
| 56 | + return mb.pyHandle; | ||
| 57 | + } | ||
| 58 | + | ||
| 59 | + //==================================================================== | ||
| 60 | + // OverloadMapper dealloc implementation. | ||
| 61 | + //==================================================================== | ||
| 62 | + | ||
| 63 | + public static new void tp_dealloc(IntPtr ob) { | ||
| 64 | + OverloadMapper self = (OverloadMapper)GetManagedObject(ob); | ||
| 65 | + Runtime.Decref(self.target); | ||
| 66 | + ExtensionType.FinalizeObject(self); | ||
| 67 | + } | ||
| 68 | + | ||
| 69 | + } | ||
| 70 | + | ||
| 71 | + | ||
| 72 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments