| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent c11c50a commit 3fccfd5
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -225,6 +225,12 @@ internal static bool ToManagedValue(IntPtr value, Type obType, | |||
| 225 | 225 | mt = ManagedType.GetManagedObject(value); | |
| 226 | 226 | } | |
| 227 | 227 | } | |
| 228 | + IntPtr c = Exceptions.UnwrapExceptionClass(value); | ||
| 229 | + if ((c != IntPtr.Zero) && (c != value)) { | ||
| 230 | + value = c; | ||
| 231 | + Runtime.Decref(c); | ||
| 232 | + mt = ManagedType.GetManagedObject(value); | ||
| 233 | + } | ||
| 228 | 234 | } | |
| 229 | 235 | } | |
| 230 | 236 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -192,6 +192,23 @@ internal static IntPtr GetExceptionInstanceWrapper(IntPtr real) { | |||
| 192 | 192 | return op; | |
| 193 | 193 | } | |
| 194 | 194 | ||
| 195 | + internal static IntPtr UnwrapExceptionClass(IntPtr op) { | ||
| 196 | + // In some cases its necessary to recognize an exception *class*, | ||
| 197 | + // and obtain the inner (wrapped) exception class. This method | ||
| 198 | + // returns the inner class if found, or a null pointer. | ||
| 199 | + | ||
| 200 | + IntPtr d = Runtime.PyObject_GetAttrString(op, "__dict__"); | ||
| 201 | + if (d == IntPtr.Zero) { | ||
| 202 | + Exceptions.Clear(); | ||
| 203 | + return IntPtr.Zero; | ||
| 204 | + } | ||
| 205 | + IntPtr c = Runtime.PyDict_GetItemString(d, "_class"); | ||
| 206 | + Runtime.Decref(d); | ||
| 207 | + if (c == IntPtr.Zero) { | ||
| 208 | + Exceptions.Clear(); | ||
| 209 | + } | ||
| 210 | + return c; | ||
| 211 | + } | ||
| 195 | 212 | ||
| 196 | 213 | ||
| 197 | 214 | /// <summary> | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -47,18 +47,17 @@ internal static ManagedType GetManagedObject(IntPtr ob) { | |||
| 47 | 47 | return (ManagedType)gc.Target; | |
| 48 | 48 | } | |
| 49 | 49 | ||
| 50 | - | ||
| 51 | - // // Hmm - check to see if its a wrapped exception? | ||
| 52 | - // if (Runtime.wrap_exceptions) { | ||
| 53 | - // IntPtr p = Runtime.PyObject_GetAttrString(ob, "_inner"); | ||
| 54 | - // if (p != IntPtr.Zero) { | ||
| 55 | - // ManagedType m = GetManagedObject(p); | ||
| 56 | - // Runtime.Decref(p); | ||
| 57 | - // if (m != null) | ||
| 58 | - // return m; | ||
| 59 | - // } | ||
| 60 | - // } | ||
| 61 | - | ||
| 50 | + // In certain situations, we need to recognize a wrapped | ||
| 51 | + // exception class and be willing to unwrap the class :( | ||
| 52 | + | ||
| 53 | + if (Runtime.wrap_exceptions) { | ||
| 54 | + IntPtr e = Exceptions.UnwrapExceptionClass(ob); | ||
| 55 | + if ((e != IntPtr.Zero) && (e != ob)) { | ||
| 56 | + ManagedType m = GetManagedObject(e); | ||
| 57 | + Runtime.Decref(e); | ||
| 58 | + return m; | ||
| 59 | + } | ||
| 60 | + } | ||
| 62 | 61 | } | |
| 63 | 62 | return null; | |
| 64 | 63 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments