| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent bdbea6a commit 5d9d65d
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -98,6 +98,21 @@ public static IntPtr __import__(IntPtr self, IntPtr args, IntPtr kw) { | |||
| 98 | 98 | } | |
| 99 | 99 | ||
| 100 | 100 | string mod_name = Runtime.GetManagedString(py_mod_name); | |
| 101 | + // Check these BEFORE the built-in import runs; may as well | ||
| 102 | + // do the Incref()ed return here, since we've already found | ||
| 103 | + // the module. | ||
| 104 | + if (mod_name == "clr") { | ||
| 105 | + root.InitializePreload(); | ||
| 106 | + Runtime.Incref(root.pyHandle); | ||
| 107 | + return root.pyHandle; | ||
| 108 | + } | ||
| 109 | + if (mod_name == "CLR") { | ||
| 110 | + Exceptions.deprecation("The CLR module is deprecated. " + | ||
| 111 | + "Please use 'clr'."); | ||
| 112 | + root.InitializePreload(); | ||
| 113 | + Runtime.Incref(root.pyHandle); | ||
| 114 | + return root.pyHandle; | ||
| 115 | + } | ||
| 101 | 116 | // 2010-08-15: Always seemed smart to let python try first... | |
| 102 | 117 | // This shaves off a few tenths of a second on test_module.py | |
| 103 | 118 | // and works around a quirk where 'sys' is found by the | |
@@ -107,23 +122,16 @@ public static IntPtr __import__(IntPtr self, IntPtr args, IntPtr kw) { | |||
| 107 | 122 | // little sense to me. | |
| 108 | 123 | IntPtr res = Runtime.PyObject_Call(py_import, args, kw); | |
| 109 | 124 | if (res != IntPtr.Zero) { | |
| 125 | + // There was no error. | ||
| 110 | 126 | return res; | |
| 111 | 127 | } | |
| 112 | - Exceptions.Clear(); | ||
| 113 | - | ||
| 114 | - if (mod_name == "CLR") { | ||
| 115 | - Exceptions.deprecation("The CLR module is deprecated. " + | ||
| 116 | - "Please use 'clr'."); | ||
| 117 | - root.InitializePreload(); | ||
| 118 | - Runtime.Incref(root.pyHandle); | ||
| 119 | - return root.pyHandle; | ||
| 120 | - } | ||
| 121 | - | ||
| 122 | - if (mod_name == "clr") { | ||
| 123 | - root.InitializePreload(); | ||
| 124 | - Runtime.Incref(root.pyHandle); | ||
| 125 | - return root.pyHandle; | ||
| 128 | + // There was an error | ||
| 129 | + if (!Exceptions.ExceptionMatches(Exceptions.ImportError)) { | ||
| 130 | + // and it was NOT an ImportError; bail out here. | ||
| 131 | + return IntPtr.Zero; | ||
| 126 | 132 | } | |
| 133 | + // Otherwise, just clear the it. | ||
| 134 | + Exceptions.Clear(); | ||
| 127 | 135 | ||
| 128 | 136 | string realname = mod_name; | |
| 129 | 137 | if (mod_name.StartsWith("CLR.")) { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments