Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Remove access to obsolete message attribute.
  • Loading branch information
filmor committed Nov 8, 2016
commit 1a46d0e9397f5e890010ea807e48769edaf14625
45 changes: 3 additions & 42 deletions src/runtime/exceptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,51 +55,12 @@ internal static Exception ToException(IntPtr ob)
{
message = e.Message;
}
if ((e.StackTrace != null) && (e.StackTrace != String.Empty))
if (!string.IsNullOrEmpty(e.StackTrace))
{
message = message + "\n" + e.StackTrace;
}
return Runtime.PyUnicode_FromString(message);
}

//====================================================================
// Exceptions __getattribute__ implementation.
// handles Python's args and message attributes
//====================================================================

public static IntPtr tp_getattro(IntPtr ob, IntPtr key)
{
if (!Runtime.PyString_Check(key))
{
Exceptions.SetError(Exceptions.TypeError, "string expected");
return IntPtr.Zero;
}

string name = Runtime.GetManagedString(key);
if (name == "args")
{
Exception e = ToException(ob);
IntPtr args;
if (e.Message != String.Empty)
{
args = Runtime.PyTuple_New(1);
IntPtr msg = Runtime.PyUnicode_FromString(e.Message);
Runtime.PyTuple_SetItem(args, 0, msg);
}
else
{
args = Runtime.PyTuple_New(0);
}
return args;
}

if (name == "message")
{
return ExceptionClassObject.tp_str(ob);
}

return Runtime.PyObject_GenericGetAttr(ob, key);
}
}

/// <summary>
Expand Down Expand Up @@ -190,10 +151,10 @@ internal static void SetArgs(IntPtr ob)
return;

IntPtr args;
if (e.Message != String.Empty)
if (!string.IsNullOrEmpty(e.Message))
{
args = Runtime.PyTuple_New(1);
IntPtr msg = Runtime.PyUnicode_FromString(e.Message);
var msg = Runtime.PyUnicode_FromString(e.Message);
Runtime.PyTuple_SetItem(args, 0, msg);
}
else
Expand Down