Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
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
11 changes: 9 additions & 2 deletions 11 src/runtime/Util.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Python.Runtime
{
internal class Util
internal static class Util
{
internal static Int64 ReadCLong(IntPtr tp, int offset)
{
Expand All @@ -29,5 +29,12 @@ internal static void WriteCLong(IntPtr type, int offset, Int64 flags)
Marshal.WriteInt64(type, offset, flags);
}
}

/// <summary>
/// Null-coalesce: if <paramref name="primary"/> parameter is not
/// <see cref="IntPtr.Zero"/>, return it. Otherwise return <paramref name="fallback"/>.
/// </summary>
internal static IntPtr Coalesce(this IntPtr primary, IntPtr fallback)
=> primary == IntPtr.Zero ? fallback : primary;
}
}
}
9 changes: 6 additions & 3 deletions 9 src/runtime/pythonengine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -758,11 +758,14 @@ public static void With(PyObject obj, Action<dynamic> Body)
catch (PythonException e)
{
ex = e;
type = ex.PyType;
val = ex.PyValue;
traceBack = ex.PyTB;
type = ex.PyType.Coalesce(type);
val = ex.PyValue.Coalesce(val);
traceBack = ex.PyTB.Coalesce(traceBack);
}

Runtime.XIncref(type);
Runtime.XIncref(val);
Runtime.XIncref(traceBack);
var exitResult = obj.InvokeMethod("__exit__", new PyObject(type), new PyObject(val), new PyObject(traceBack));

if (ex != null && !exitResult.IsTrue()) throw ex;
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.