Skip to content

Improve Python <-> .NET exception integration #1134

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 42 commits into from
Jun 1, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
663df73
reworked PythonException to simplify memory management, and enable .N…
lostmsu May 5, 2020
d45c39a
allows codecs to encode and decode thrown exceptions
lostmsu Feb 25, 2020
0d941c5
turned on CLR exception marshaling
lostmsu May 5, 2020
02cd234
revert to C# 7.3
lostmsu May 5, 2020
defb200
fixed Restore when not all exception fields are set
lostmsu May 5, 2020
945dc85
cleaned PythonException code up a bit
lostmsu May 5, 2020
3d95e60
remove unused overloads of FromPyErr
lostmsu May 5, 2020
d667998
capture exception on Exceptions.SetError, restore in ThrowLastAsClrEx…
lostmsu May 5, 2020
bec8b7d
fixed failure in ExceptionEncoded test case caused by ExceptionDispat…
lostmsu May 5, 2020
0961c94
added tests for __cause__/InnerException #893 #1098
lostmsu May 6, 2020
2cd8627
introduced StolenReference type
lostmsu May 14, 2020
e4c1b9b
prevent undebuggable StackOverflowException during exception interop
lostmsu May 29, 2020
81cd197
Merge branch 'master' into PR/ExceptionsImprovement
lostmsu Jun 22, 2020
3c0b737
README: added summary of new exception handling features
lostmsu Jun 22, 2020
257a765
merge latest master
lostmsu Apr 9, 2021
c0fe430
reworked `PythonException`:
lostmsu Apr 9, 2021
e58411d
rum embedding tests before Python tests
lostmsu Apr 9, 2021
00653dc
PythonException.StackTrace is GIL-safe
lostmsu Apr 9, 2021
3433201
separate .Steal() and .StealNullable()
lostmsu Apr 11, 2021
95cc52f
can't test exception type when runtime is down
lostmsu Apr 11, 2021
63ad42c
PythonException: dispose intermediate values used in stack trace gene…
lostmsu Apr 11, 2021
faec7fc
Point users to Message property of PythonException
lostmsu Apr 11, 2021
dfc70f6
minor change in PythonEngine.With
lostmsu Apr 11, 2021
d976acf
simplified code of PythonException and added a lot more checks
lostmsu Apr 11, 2021
146ebf3
fixed type of reference in PyException_SetCause
lostmsu Apr 11, 2021
272687b
minor fixes to Converter.ToArray:
lostmsu Apr 11, 2021
2cd3f61
added a few debug checks to Exceptions.SetError
lostmsu Apr 11, 2021
e79f041
method binding failure now supports non-Python exception causes
lostmsu Apr 11, 2021
d068f36
XDecref now checks, that refcount is positive in debug builds
lostmsu Apr 11, 2021
4877fe7
fixed __cause__ on overload bind failure and array conversion
lostmsu Apr 11, 2021
ed594c1
cache PythonException message
lostmsu Apr 11, 2021
e5bce06
minor code cleanup
lostmsu Apr 11, 2021
6819e7b
improved handling of dict offset in object instances
lostmsu Apr 11, 2021
6679d1c
added a few debug checks
lostmsu Apr 11, 2021
67bd1c2
merge latest master
lostmsu May 15, 2021
2e57b04
+ class diagram for ManagedType and subclasses
lostmsu May 23, 2021
539ce81
added OverloadMapper to ManagedTypes class diagram
lostmsu May 23, 2021
25e3864
refactored tp_dealloc in ExtensionType and descendants
lostmsu May 23, 2021
5bca333
refactored tp_clear in ExtensionType and descendants into a virtual C…
lostmsu May 23, 2021
7271d88
all Dealloc overrides simply duplicate Clear, so just call both from …
lostmsu May 23, 2021
4f3f648
fixup! merge latest master
SDEII May 29, 2021
c500a39
fixup! reworked `PythonException`:
lostmsu May 29, 2021
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
method binding failure now supports non-Python exception causes
  • Loading branch information
lostmsu committed Apr 11, 2021
commit e79f041f3a72e1855e8b0239ccadf954f58d9fec
8 changes: 4 additions & 4 deletions src/runtime/methodbinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -341,13 +341,13 @@ public MatchedMethod(int kwargsMatched, int defaultsNeeded, object[] margs, int

private readonly struct MismatchedMethod
{
public MismatchedMethod(PythonException exception, MethodBase mb)
public MismatchedMethod(Exception exception, MethodBase mb)
{
Exception = exception;
Method = mb;
}

public PythonException Exception { get; }
public Exception Exception { get; }
public MethodBase Method { get; }
}

Expand Down Expand Up @@ -438,8 +438,8 @@ internal Binding Bind(IntPtr inst, IntPtr args, IntPtr kw, MethodBase info, Meth
outs: out outs);
if (margs == null)
{
mismatchedMethods.Add(new MismatchedMethod(PythonException.FetchCurrentRaw(), mi));
Exceptions.Clear();
var mismatchCause = PythonException.FetchCurrent();
mismatchedMethods.Add(new MismatchedMethod(mismatchCause, mi));
continue;
}
if (isOperator)
Expand Down
4 changes: 4 additions & 0 deletions src/runtime/pythonexception.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ internal static PythonException FetchCurrentRaw()
}
}

internal static Exception FetchCurrent()
=> FetchCurrentOrNull(out _)
?? throw new InvalidOperationException("No exception is set");

private static ExceptionDispatchInfo? TryGetDispatchInfo(BorrowedReference exception)
{
if (exception.IsNull) return null;
Expand Down