@@ -1339,7 +1339,7 @@ TPythonInterface=class(TDynamicDll)
1339
1339
PyErr_BadInternalCall: procedure; cdecl;
1340
1340
PyErr_CheckSignals: function: integer; cdecl;
1341
1341
PyErr_Clear: procedure; cdecl;
1342
- PyErr_Fetch: procedure( errtype, errvalue, errtraceback: PPPyObject ); cdecl;
1342
+ PyErr_Fetch: procedure(out errtype, errvalue, errtraceback: PPyObject ); cdecl;
1343
1343
PyErr_NoMemory: function: PPyObject; cdecl;
1344
1344
PyErr_Occurred: function: PPyObject; cdecl;
1345
1345
PyErr_Print: procedure; cdecl;
@@ -1703,7 +1703,8 @@ TPythonTraceback = class
1703
1703
destructor Destroy; override;
1704
1704
1705
1705
procedure Clear ;
1706
- procedure Refresh ;
1706
+ procedure Refresh (pytraceback: PPyObject = nil );
1707
+ procedure AddItem (const Context, FileName: string; LineNo: Integer);
1707
1708
1708
1709
property ItemCount : Integer read GetItemCount;
1709
1710
property Items[ idx : Integer ] : TTracebackItem read GetItem;
@@ -3771,6 +3772,18 @@ destructor TPythonTraceback.Destroy;
3771
3772
inherited ;
3772
3773
end ;
3773
3774
3775
+ procedure TPythonTraceback.AddItem (const Context, FileName: string;
3776
+ LineNo: Integer);
3777
+ var
3778
+ Item: TTracebackItem;
3779
+ begin
3780
+ Item := TTracebackItem.Create;
3781
+ Item.Context := Context;
3782
+ Item.FileName := FileName;
3783
+ Item.LineNo := LineNo;
3784
+ FItems.Add(Item);
3785
+ end ;
3786
+
3774
3787
procedure TPythonTraceback.Clear ;
3775
3788
var
3776
3789
i : Integer;
@@ -5653,14 +5666,32 @@ procedure TPythonEngine.ListToSet( List : PPyObject; data : Pointer; size : Inte
5653
5666
end ;
5654
5667
5655
5668
procedure TPythonEngine.CheckError (ACatchStopEx : Boolean = False);
5669
+ procedure ProcessSystemExit ;
5670
+ var
5671
+ errtype, errvalue, errtraceback: PPyObject;
5672
+ SErrValue: string;
5673
+ begin
5674
+ PyErr_Fetch(errtype, errvalue, errtraceback);
5675
+ Traceback.Refresh(errtraceback);
5676
+ SErrValue := PyObjectAsString(errvalue);
5677
+ PyErr_Clear;
5678
+ raise EPySystemExit.CreateResFmt(@SPyExcSystemError, [SErrValue]);
5679
+ end ;
5680
+
5681
+ var
5682
+ PyException: PPyObject;
5656
5683
begin
5657
- if PyErr_Occurred <> nil then
5684
+ PyException := PyErr_Occurred;
5685
+ if PyException <> nil then
5658
5686
begin
5659
- if ACatchStopEx and (PyErr_GivenExceptionMatches(PyErr_Occurred , PyExc_StopIteration^) <> 0 ) then
5687
+ if ACatchStopEx and (PyErr_GivenExceptionMatches(PyException , PyExc_StopIteration^) <> 0 ) then
5660
5688
begin
5661
5689
PyErr_Clear;
5662
- raise EPyStopIteration.Create( ' Stop iteration ' );
5690
+ raise EPyStopIteration.CreateRes(@SPyExcStopIteration );
5663
5691
end
5692
+ else if PyErr_GivenExceptionMatches(PyException, PyExc_SystemExit^) <> 0 then
5693
+ // Special treatment for SystemExit. Calling PyErr_Print would terminate the process
5694
+ ProcessSystemExit
5664
5695
else
5665
5696
begin
5666
5697
PyErr_Print;
0 commit comments