Skip to content

Call PyErr_NormalizeException for exceptions #1265

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 17 commits into from
Dec 21, 2020
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
Localize call to PyErr_NormalizeException to the Format method.
  • Loading branch information
slide committed Oct 15, 2020
commit 9b3d14b9996d72717e11db1d960c4fc3b51a5445
18 changes: 11 additions & 7 deletions src/runtime/pythonexception.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public PythonException()
{
IntPtr gs = PythonEngine.AcquireLock();
Runtime.PyErr_Fetch(out _pyType, out _pyValue, out _pyTB);
Runtime.PyErr_NormalizeException(ref _pyType, ref _pyValue, ref _pyTB);
if (_pyType != IntPtr.Zero && _pyValue != IntPtr.Zero)
{
string type;
Expand Down Expand Up @@ -159,12 +158,17 @@ public string Format()
{
if (_pyTB != IntPtr.Zero && _pyType != IntPtr.Zero && _pyValue != IntPtr.Zero)
{
Runtime.XIncref(_pyType);
Runtime.XIncref(_pyValue);
Runtime.XIncref(_pyTB);
using (PyObject pyType = new PyObject(_pyType))
using (PyObject pyValue = new PyObject(_pyValue))
using (PyObject pyTB = new PyObject(_pyTB))
IntPtr tb = _pyTB;
IntPtr type = _pyType;
IntPtr value = _pyValue;
Runtime.PyErr_NormalizeException(ref type, ref value, ref tb);

Runtime.XIncref(type);
Runtime.XIncref(value);
Runtime.XIncref(tb);
using (PyObject pyType = new PyObject(type))
using (PyObject pyValue = new PyObject(value))
using (PyObject pyTB = new PyObject(tb))
using (PyObject tb_mod = PythonEngine.ImportModule("traceback"))
{
var buffer = new StringBuilder();
Expand Down