commit fix for noticing wrapped exception types
This commit is contained in:
Родитель
c11c50a32c
Коммит
3fccfd5afc
|
@ -225,6 +225,12 @@ namespace Python.Runtime {
|
|||
mt = ManagedType.GetManagedObject(value);
|
||||
}
|
||||
}
|
||||
IntPtr c = Exceptions.UnwrapExceptionClass(value);
|
||||
if ((c != IntPtr.Zero) && (c != value)) {
|
||||
value = c;
|
||||
Runtime.Decref(c);
|
||||
mt = ManagedType.GetManagedObject(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -192,6 +192,23 @@ namespace Python.Runtime {
|
|||
return op;
|
||||
}
|
||||
|
||||
internal static IntPtr UnwrapExceptionClass(IntPtr op) {
|
||||
// In some cases its necessary to recognize an exception *class*,
|
||||
// and obtain the inner (wrapped) exception class. This method
|
||||
// returns the inner class if found, or a null pointer.
|
||||
|
||||
IntPtr d = Runtime.PyObject_GetAttrString(op, "__dict__");
|
||||
if (d == IntPtr.Zero) {
|
||||
Exceptions.Clear();
|
||||
return IntPtr.Zero;
|
||||
}
|
||||
IntPtr c = Runtime.PyDict_GetItemString(d, "_class");
|
||||
Runtime.Decref(d);
|
||||
if (c == IntPtr.Zero) {
|
||||
Exceptions.Clear();
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -47,18 +47,17 @@ namespace Python.Runtime {
|
|||
return (ManagedType)gc.Target;
|
||||
}
|
||||
|
||||
// In certain situations, we need to recognize a wrapped
|
||||
// exception class and be willing to unwrap the class :(
|
||||
|
||||
// // Hmm - check to see if its a wrapped exception?
|
||||
// if (Runtime.wrap_exceptions) {
|
||||
// IntPtr p = Runtime.PyObject_GetAttrString(ob, "_inner");
|
||||
// if (p != IntPtr.Zero) {
|
||||
// ManagedType m = GetManagedObject(p);
|
||||
// Runtime.Decref(p);
|
||||
// if (m != null)
|
||||
// return m;
|
||||
// }
|
||||
// }
|
||||
|
||||
if (Runtime.wrap_exceptions) {
|
||||
IntPtr e = Exceptions.UnwrapExceptionClass(ob);
|
||||
if ((e != IntPtr.Zero) && (e != ob)) {
|
||||
ManagedType m = GetManagedObject(e);
|
||||
Runtime.Decref(e);
|
||||
return m;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче