Skip to content

Fix exception pickling #286

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Nov 10, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/runtime/clrobject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ internal CLRObject(Object ob, IntPtr tp) : base()
this.pyHandle = py;
this.gcHandle = gc;
inst = ob;

// Fix the BaseException args slot if wrapping a CLR exception
Exceptions.SetArgs(py);
}


Expand Down
45 changes: 1 addition & 44 deletions src/runtime/converter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,20 +156,7 @@ internal static IntPtr ToPython(Object value, Type type)
switch (tc)
{
case TypeCode.Object:
result = CLRObject.GetInstHandle(value, type);

// XXX - hack to make sure we convert new-style class based
// managed exception instances to wrappers ;(
if (Runtime.wrap_exceptions)
{
Exception e = value as Exception;
if (e != null)
{
return Exceptions.GetExceptionInstanceWrapper(result);
}
}

return result;
return CLRObject.GetInstHandle(value, type);

case TypeCode.String:
return Runtime.PyUnicode_FromString((string)value);
Expand Down Expand Up @@ -283,36 +270,6 @@ internal static bool ToManagedValue(IntPtr value, Type obType,
ManagedType mt = ManagedType.GetManagedObject(value);
result = null;

// XXX - hack to support objects wrapped in old-style classes
// (such as exception objects).
if (Runtime.wrap_exceptions)
{
if (mt == null)
{
if (Runtime.PyObject_IsInstance(
value, Exceptions.Exception
) > 0)
{
IntPtr p = Runtime.PyObject_GetAttrString(value, "_inner");
if (p != IntPtr.Zero)
{
// This is safe because we know that the __dict__ of
// value holds a reference to _inner.
value = p;
Runtime.XDecref(p);
mt = ManagedType.GetManagedObject(value);
}
}
IntPtr c = Exceptions.UnwrapExceptionClass(value);
if ((c != IntPtr.Zero) && (c != value))
{
value = c;
Runtime.XDecref(c);
mt = ManagedType.GetManagedObject(value);
}
}
}

if (mt != null)
{
if (mt is CLRObject)
Expand Down
Loading