| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 80b19e6 commit f8db1b8
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -291,8 +291,8 @@ internal static void ScanAssembly(Assembly assembly) { | |||
| 291 | 291 | Type[] types = assembly.GetTypes(); | |
| 292 | 292 | for (int i = 0; i < types.Length; i++) { | |
| 293 | 293 | Type t = types[i]; | |
| 294 | - string ns = t.Namespace; | ||
| 295 | - if ((ns != null) && (!namespaces.ContainsKey(ns))) { | ||
| 294 | + string ns = t.Namespace ?? ""; | ||
| 295 | + if (!namespaces.ContainsKey(ns)) { | ||
| 296 | 296 | string[] names = ns.Split('.'); | |
| 297 | 297 | string s = ""; | |
| 298 | 298 | for (int n = 0; n < names.Length; n++) { | |
@@ -367,7 +367,7 @@ public static List<string> GetNames(string nsname) { | |||
| 367 | 367 | Type[] types = a.GetTypes(); | |
| 368 | 368 | for (int i = 0; i < types.Length; i++) { | |
| 369 | 369 | Type t = types[i]; | |
| 370 | - if (t.Namespace == nsname) { | ||
| 370 | + if ((t.Namespace ?? "") == nsname) { | ||
| 371 | 371 | names.Add(t.Name); | |
| 372 | 372 | } | |
| 373 | 373 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -92,9 +92,44 @@ internal static void Shutdown() { | |||
| 92 | 92 | //=================================================================== | |
| 93 | 93 | // Return the clr python module (new reference) | |
| 94 | 94 | //=================================================================== | |
| 95 | - public static IntPtr GetCLRModule() { | ||
| 95 | + public static IntPtr GetCLRModule(IntPtr? fromList=null) { | ||
| 96 | 96 | root.InitializePreload(); | |
| 97 | 97 | #if (PYTHON32 || PYTHON33 || PYTHON34) | |
| 98 | + // update the module dictionary with the contents of the root dictionary | ||
| 99 | + root.LoadNames(); | ||
| 100 | + IntPtr py_mod_dict = Runtime.PyModule_GetDict(py_clr_module); | ||
| 101 | + IntPtr clr_dict = Runtime._PyObject_GetDictPtr(root.pyHandle); // PyObject** | ||
| 102 | + clr_dict = (IntPtr)Marshal.PtrToStructure(clr_dict, typeof(IntPtr)); | ||
| 103 | + Runtime.PyDict_Update(py_mod_dict, clr_dict); | ||
| 104 | + | ||
| 105 | + // find any items from the fromlist and get them from the root if they're not | ||
| 106 | + // aleady in the module dictionary | ||
| 107 | + if (fromList != null && fromList != IntPtr.Zero) { | ||
| 108 | + if (Runtime.PyTuple_Check(fromList.GetValueOrDefault())) | ||
| 109 | + { | ||
| 110 | + Runtime.Incref(py_mod_dict); | ||
| 111 | + PyDict mod_dict = new PyDict(py_mod_dict); | ||
| 112 | + | ||
| 113 | + Runtime.Incref(fromList.GetValueOrDefault()); | ||
| 114 | + PyTuple from = new PyTuple(fromList.GetValueOrDefault()); | ||
| 115 | + foreach (PyObject item in from) { | ||
| 116 | + if (mod_dict.HasKey(item)) | ||
| 117 | + continue; | ||
| 118 | + | ||
| 119 | + string s = item.AsManagedObject(typeof(string)) as string; | ||
| 120 | + if (null == s) | ||
| 121 | + continue; | ||
| 122 | + | ||
| 123 | + ManagedType attr = root.GetAttribute(s, true); | ||
| 124 | + if (null == attr) | ||
| 125 | + continue; | ||
| 126 | + | ||
| 127 | + Runtime.Incref(attr.pyHandle); | ||
| 128 | + mod_dict.SetItem(s, new PyObject(attr.pyHandle)); | ||
| 129 | + } | ||
| 130 | + } | ||
| 131 | + } | ||
| 132 | + | ||
| 98 | 133 | Runtime.Incref(py_clr_module); | |
| 99 | 134 | return py_clr_module; | |
| 100 | 135 | #else | |
@@ -145,12 +180,12 @@ public static IntPtr __import__(IntPtr self, IntPtr args, IntPtr kw) { | |||
| 145 | 180 | // do the Incref()ed return here, since we've already found | |
| 146 | 181 | // the module. | |
| 147 | 182 | if (mod_name == "clr") { | |
| 148 | - return GetCLRModule(); | ||
| 183 | + return GetCLRModule(fromList); | ||
| 149 | 184 | } | |
| 150 | 185 | if (mod_name == "CLR") { | |
| 151 | 186 | Exceptions.deprecation("The CLR module is deprecated. " + | |
| 152 | 187 | "Please use 'clr'."); | |
| 153 | - return GetCLRModule(); | ||
| 188 | + return GetCLRModule(fromList); | ||
| 154 | 189 | } | |
| 155 | 190 | string realname = mod_name; | |
| 156 | 191 | if (mod_name.StartsWith("CLR.")) { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments