10000 Improve Python <-> .NET exception integration by lostmsu · Pull Request #1134 · pythonnet/pythonnet · GitHub
[go: up one dir, main page]

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
turned on CLR exception marshaling
  • Loading branch information
lostmsu committed May 13, 2020
commit 0d941c576bc676c718bac189d228aa261018c307
3 changes: 1 addition & 2 deletions src/runtime/delegatemanager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,7 @@ public object TrueDispatch(ArrayList args)

if (op == IntPtr.Zero)
{
var e = new PythonException();
throw e;
throw PythonException.ThrowLastAsClrException();
}

if (rtype == typeof(void))
Expand Down
4 changes: 2 additions & 2 deletions src/runtime/exceptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ internal static void ErrorCheck(IntPtr pointer)
{
if (pointer == IntPtr.Zero)
{
throw new PythonException();
throw PythonException.ThrowLastAsClrException();
}
}

Expand All @@ -208,7 +208,7 @@ internal static void ErrorOccurredCheck(IntPtr pointer)
{
if (pointer == IntPtr.Zero || ErrorOccurred())
{
throw new PythonException();
throw PythonException.ThrowLastAsClrException();
}
}

Expand Down
12 changes: 6 additions & 6 deletions src/runtime/pydict.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public PyDict()
obj = Runtime.PyDict_New();
if (obj == IntPtr.Zero)
{
throw new PythonException();
throw PythonException.ThrowLastAsClrException();
}
}

Expand Down Expand Up @@ -108,7 +108,7 @@ public PyObject Keys()
IntPtr items = Runtime.PyDict_Keys(obj);
if (items == IntPtr.Zero)
{
throw new PythonException();
throw PythonException.ThrowLastAsClrException();
}
return new PyObject(items);
}
Expand All @@ -125,7 +125,7 @@ public PyObject Values()
IntPtr items = Runtime.PyDict_Values(obj);
if (items == IntPtr.Zero)
{
throw new PythonException();
throw PythonException.ThrowLastAsClrException();
}
return new PyObject(items);
}
Expand All @@ -144,7 +144,7 @@ public PyObject Items()
{
if (items.IsNull())
{
throw new PythonException();
throw PythonException.ThrowLastAsClrException();
}

return items.MoveToPyObject();
Expand All @@ -167,7 +167,7 @@ public PyDict Copy()
IntPtr op = Runtime.PyDict_Copy(obj);
if (op == IntPtr.Zero)
{
throw new PythonException();
throw PythonException.ThrowLastAsClrException();
}
return new PyDict(op);
}
Expand All @@ -184,7 +184,7 @@ public void Update(PyObject other)
int result = Runtime.PyDict_Update(obj, other.obj);
if (result < 0)
{
throw new PythonException();
throw PythonException.ThrowLastAsClrException();
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/runtime/pyiter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public PyIter(PyObject iterable)
obj = Runtime.PyObject_GetIter(iterable.obj);
if (obj == IntPtr.Zero)
{
throw new PythonException();
throw PythonException.ThrowLastAsClrException();
}
}

Expand Down
14 changes: 7 additions & 7 deletions src/runtime/pylist.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public PyList()
obj = Runtime.PyList_New(0);
if (obj == IntPtr.Zero)
{
throw new PythonException();
throw PythonException.ThrowLastAsClrException();
}
}

Expand All @@ -75,7 +75,7 @@ public PyList(PyObject[] items)
int r = Runtime.PyList_SetItem(obj, i, ptr);
if (r < 0)
{
throw new PythonException();
throw PythonException.ThrowLastAsClrException();
}
}
}
Expand Down Expand Up @@ -106,7 +106,7 @@ public static PyList AsList(PyObject value)
IntPtr op = Runtime.PySequence_List(value.obj);
if (op == IntPtr.Zero)
{
throw new PythonException();
throw PythonException.ThrowLastAsClrException();
}
return new PyList(op);
}
Expand All @@ -123,7 +123,7 @@ public void Append(PyObject item)
int r = Runtime.PyList_Append(this.Reference, item.obj);
if (r < 0)
{
throw new PythonException();
throw PythonException.ThrowLastAsClrException();
}
}

Expand All @@ -138,7 +138,7 @@ public void Insert(int index, PyObject item)
int r = Runtime.PyList_Insert(this.Reference, index, item.obj);
if (r < 0)
{
throw new PythonException();
throw PythonException.ThrowLastAsClrException();
}
}

Expand All @@ -154,7 +154,7 @@ public void Reverse()
int r = Runtime.PyList_Reverse(this.Reference);
if (r < 0)
{
throw new PythonException();
throw PythonException.ThrowLastAsClrException();
}
}

Expand All @@ -170,7 +170,7 @@ public void Sort()
int r = Runtime.PyList_Sort(this.Reference);
if (r < 0)
{
throw new PythonException();
throw PythonException.ThrowLastAsClrException();
}
}
}
Expand Down
36 changes: 18 additions & 18 deletions src/runtime/pyobject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ public PyObject GetAttr(string name)
IntPtr op = Runtime.PyObject_GetAttrString(obj, name);
if (op == IntPtr.Zero)
{
throw new PythonException();
throw PythonException.ThrowLastAsClrException();
}
return new PyObject(op);
}
Expand Down Expand Up @@ -353,7 +353,7 @@ public PyObject GetAttr(PyObject name)
IntPtr op = Runtime.PyObject_GetAttr(obj, name.obj);
if (op == IntPtr.Zero)
{
throw new PythonException();
throw PythonException.ThrowLastAsClrException();
}
return new PyObject(op);
}
Expand Down Expand Up @@ -396,7 +396,7 @@ public void SetAttr(string name, PyObject value)
int r = Runtime.PyObject_SetAttrString(obj, name, value.obj);
if (r < 0)
{
throw new PythonException();
throw PythonException.ThrowLastAsClrException();
}
}

Expand All @@ -417,7 +417,7 @@ public void SetAttr(PyObject name, PyObject value)
int r = Runtime.PyObject_SetAttr(obj, name.obj, value.obj);
if (r < 0)
{
throw new PythonException();
throw PythonException.ThrowLastAsClrException();
}
}

Expand All @@ -436,7 +436,7 @@ public void DelAttr(string name)
int r = Runtime.PyObject_SetAttrString(obj, name, IntPtr.Zero);
if (r < 0)
{
throw new PythonException();
throw PythonException.ThrowLastAsClrException();
}
}

Expand All @@ -456,7 +456,7 @@ public void DelAttr(PyObject name)
int r = Runtime.PyObject_SetAttr(obj, name.obj, IntPtr.Zero);
if (r < 0)
{
throw new PythonException();
throw PythonException.ThrowLastAsClrException();
}
}

Expand All @@ -476,7 +476,7 @@ public virtual PyObject GetItem(PyObject key)
IntPtr op = Runtime.PyObject_GetItem(obj, key.obj);
if (op == IntPtr.Zero)
{
throw new PythonException();
throw PythonException.ThrowLastAsClrException();
}
return new PyObject(op);
}
Expand Down Expand Up @@ -534,7 +534,7 @@ public virtual void SetItem(PyObject key, PyObject value)
int r = Runtime.PyObject_SetItem(obj, key.obj, value.obj);
if (r < 0)
{
throw new PythonException();
throw PythonException.ThrowLastAsClrException();
}
}

Expand Down Expand Up @@ -593,7 +593,7 @@ public virtual void DelItem(PyObject key)
int r = Runtime.PyObject_DelItem(obj, key.obj);
if (r < 0)
{
throw new PythonException();
throw PythonException.ThrowLastAsClrException();
}
}

Expand Down Expand Up @@ -708,7 +708,7 @@ public PyObject GetIterator()
IntPtr r = Runtime.PyObject_GetIter(obj);
if (r == IntPtr.Zero)
{
throw new PythonException();
throw PythonException.ThrowLastAsClrException();
}
return new PyObject(r);
}
Expand Down Expand Up @@ -744,7 +744,7 @@ public PyObject Invoke(params PyObject[] args)
t.Dispose();
if (r == IntPtr.Zero)
{
throw new PythonException();
throw PythonException.ThrowLastAsClrException();
}
return new PyObject(r);
}
Expand All @@ -764,7 +764,7 @@ public PyObject Invoke(PyTuple args)
IntPtr r = Runtime.PyObject_Call(obj, args.obj, IntPtr.Zero);
if (r == IntPtr.Zero)
{
throw new PythonException();
throw PythonException.ThrowLastAsClrException();
}
return new PyObject(r);
}
Expand All @@ -787,7 +787,7 @@ public PyObject Invoke(PyObject[] args, PyDict kw)
t.Dispose();
if (r == IntPtr.Zero)
{
throw new PythonException();
throw PythonException.ThrowLastAsClrException();
}
return new PyObject(r);
}
Expand All @@ -807,7 +807,7 @@ public PyObject Invoke(PyTuple args, PyDict kw)
IntPtr r = Runtime.PyObject_Call(obj, args.obj, kw?.obj ?? IntPtr.Zero);
if (r == IntPtr.Zero)
{
throw new PythonException();
throw PythonException.ThrowLastAsClrException();
}
return new PyObject(r);
}
Expand Down Expand Up @@ -1028,7 +1028,7 @@ public PyList Dir()
IntPtr r = Runtime.PyObject_Dir(obj);
if (r == IntPtr.Zero)
{
throw new PythonException();
throw PythonException.ThrowLastAsClrException();
}
return new PyList(r);
}
Expand Down Expand Up @@ -1086,7 +1086,7 @@ public override bool Equals(object o)
int r = Runtime.PyObject_Compare(obj, ((PyObject)o).obj);
if (Exceptions.ErrorOccurred())
{
throw new PythonException();
throw PythonException.ThrowLastAsClrException();
}
return r == 0;
}
Expand Down Expand Up @@ -1127,7 +1127,7 @@ public override bool TrySetMember(SetMemberBinder binder, object value)
int r = Runtime.PyObject_SetAttrString(obj, binder.Name, ptr);
if (r < 0)
{
throw new PythonException();
throw PythonException.ThrowLastAsClrException();
}
Runtime.XDecref(ptr);
return true;
Expand Down Expand Up @@ -1199,7 +1199,7 @@ private static void AddArgument(IntPtr argtuple, int i, object target)

if (Runtime.PyTuple_SetItem(argtuple, i, ptr) < 0)
{
throw new PythonException();
throw PythonException.ThrowLastAsClrException();
}
}

Expand Down
16 changes: 8 additions & 8 deletions src/runtime/pyscope.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public void ImportAll(PyScope scope)
int result = Runtime.PyDict_Update(variables, scope.variables);
if (result < 0)
{
throw new PythonException();
throw PythonException.ThrowLastAsClrException();
}
}

Expand All @@ -206,7 +206,7 @@ public void ImportAll(PyObject module)
int result = Runtime.PyDict_Update(variables, module_dict);
if (result < 0)
{
throw new PythonException();
throw PythonException.ThrowLastAsClrException();
}
}

Expand All @@ -221,7 +221,7 @@ public void ImportAll(PyDict dict)
int result = Runtime.PyDict_Update(variables, dict.obj);
if (result < 0)
{
throw new PythonException();
throw PythonException.ThrowLastAsClrException();
}
}

Expand Down Expand Up @@ -333,7 +333,7 @@ private void Exec(string code, IntPtr _globals, IntPtr _locals)
Runtime.CheckExceptionOccurred();
if (!reference.IsNone())
{
throw new PythonException();
throw PythonException.ThrowLastAsClrException();
}
}
finally
Expand Down Expand Up @@ -364,7 +364,7 @@ private void Set(string name, IntPtr value)
int r = Runtime.PyObject_SetItem(variables, pyKey.obj, value);
if (r < 0)
{
throw new PythonException();
throw PythonException.ThrowLastAsClrException();
}
}
}
Expand All @@ -383,7 +383,7 @@ public void Remove(string name)
int r = Runtime.PyObject_DelItem(variables, pyKey.obj);
if (r < 0)
{
throw new PythonException();
throw PythonException.ThrowLastAsClrException();
}
}
}
Expand Down Expand Up @@ -438,7 +438,7 @@ public bool TryGet(string name, out PyObject value)
IntPtr op = Runtime.PyObject_GetItem(variables, pyKey.obj);
if (op == IntPtr.Zero)
{
throw new PythonException();
throw PythonException.ThrowLastAsClrException();
}
if (op == Runtime.PyNone)
{
Expand Down Expand Up @@ -577,7 +577,7 @@ internal PyScope NewScope(string name)
var module = Runtime.PyModule_New(name);
if (module == IntPtr.Zero)
{
throw new PythonException();
throw PythonException.ThrowLastAsClrException();
}
return new PyScope(module, this);
}
Expand Down
Loading
0