Skip to content

Commit da8947e

Browse files
committed
Fix #436
1 parent 02a783d commit da8947e

1 file changed

Lines changed: 46 additions & 46 deletions

File tree

Source/WrapDelphi.pas

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,7 +1048,11 @@ function RttiCall(ParentAddress: pointer; DelphiWrapper: TPyDelphiWrapper;
10481048
AParentAddrIsClass: Boolean = false): PPyObject; overload; forward;
10491049

10501050
function RttiCall(ParentAddress: pointer; DelphiWrapper: TPyDelphiWrapper;
1051-
Method: TRttiMethod; ob1, ob2: PPyObject; const Args: TArray<TValue>;
1051+
Method: TRttiMethod; ob1, ob2: PPyObject;
1052+
AParentAddrIsClass: Boolean = false): PPyObject; overload; forward;
1053+
1054+
function RttiCall(ParentAddress: pointer; DelphiWrapper: TPyDelphiWrapper;
1055+
Method: TRttiMethod; const Args: TArray<TValue>;
10521056
const VarParamIndices: TArray<Integer>;
10531057
AParentAddrIsClass: Boolean = false): PPyObject; overload; forward;
10541058

@@ -1466,7 +1470,7 @@ function TPyIndexedProperty.MpSubscript(obj: PPyObject) : PPyObject;
14661470
PyArgs := FPyWrapper.Engine.MakePyTuple([obj]);
14671471

14681472
Result := RttiCall(PascalObject, FPyWrapper, FProperty.ReadMethod,
1469-
PyArgs, nil, [], []);
1473+
PyArgs, nil);
14701474

14711475
if not FPyWrapper.Engine.PyTuple_Check(obj) then
14721476
FPyWrapper.Engine.Py_DECREF(PyArgs); // release created tuple
@@ -1515,7 +1519,7 @@ function TPyIndexedProperty.MpAssSubscript(obj1, obj2: PPyObject) : Integer;
15151519
PyArgs := Engine.MakePyTuple([obj1, obj2]);
15161520

15171521
TempPy := RttiCall(PascalObject, FPyWrapper, FProperty.WriteMethod,
1518-
PyArgs, nil, [], []);
1522+
PyArgs, nil);
15191523

15201524
Engine.Py_DECREF(PyArgs); // release created tuple
15211525

@@ -2643,68 +2647,64 @@ function RttiCall(ParentAddress: pointer; DelphiWrapper: TPyDelphiWrapper;
26432647
end;
26442648

26452649
var
2646-
Args: TArray<TValue>;
2647-
VarParamIndices: TArray<Integer>;
2648-
ArgCount: Integer;
2649-
meth: TRttiMethod;
2650+
LArgs: TArray<TValue>;
2651+
LVarParamIndices: TArray<Integer>;
2652+
LArgCount: Integer;
2653+
Method: TRttiMethod;
26502654
ErrMsg : string;
26512655

26522656
begin
26532657
Result := nil;
26542658

2655-
ArgCount := DelphiWrapper.Engine.PyTuple_Size(ob1);
2656-
SetLength(Args, ArgCount);
2659+
LArgCount := DelphiWrapper.Engine.PyTuple_Size(ob1);
2660+
SetLength(LArgs, LArgCount);
26572661

2658-
meth := FindMethod(MethName, ParentRtti, ob1, Args, VarParamIndices, ErrMsg);
2662+
Method := FindMethod(MethName, ParentRtti, ob1, LArgs, LVarParamIndices, ErrMsg);
26592663

2660-
if not Assigned(meth) then begin
2664+
if not Assigned(Method) then begin
26612665
InvalidArguments(MethName, ErrMsg);
26622666
Exit;
26632667
end;
26642668

2665-
Result := RttiCall(ParentAddress, DelphiWrapper, meth, ob1, ob2, Args,
2666-
VarParamIndices, AParentAddrIsClass);
2669+
Result := RttiCall(ParentAddress, DelphiWrapper, Method, LArgs,
2670+
LVarParamIndices, AParentAddrIsClass);
26672671
end;
26682672

2669-
// This overload can be called either directly or from the overload above.
2670-
// When it is called from above Args are already setup and validated
2671-
// When it is called directly Args = []
26722673
function RttiCall(ParentAddress: pointer; DelphiWrapper: TPyDelphiWrapper;
2673-
Method: TRttiMethod; ob1, ob2: PPyObject; const Args: TArray<TValue>;
2674-
const VarParamIndices: TArray<Integer>;
2674+
Method: TRttiMethod; ob1, ob2: PPyObject;
26752675
AParentAddrIsClass: Boolean = false): PPyObject;
26762676
var
2677-
ArgCount: Integer;
26782677
LArgs: TArray<TValue>;
26792678
LVarParamIndices: TArray<Integer>;
2680-
Addr: TValue;
2681-
ReturnValue: TValue;
2682-
ErrMsg: string;
2683-
TempPy: PPyObject;
2684-
Index, Pos: Integer;
26852679
begin
2686-
Result := nil;
2680+
Result := nil;
2681+
26872682
// Ignore keyword arguments ob2
26882683
// ob1 is a tuple with zero or more elements
2689-
2690-
ArgCount := DelphiWrapper.Engine.PyTuple_Size(ob1);
2691-
if Length(Args) = ArgCount then
2684+
SetLength(LArgs, DelphiWrapper.Engine.PyTuple_Size(ob1));
2685+
if not PyArgsToValues(ob1, Method, LArgs, LVarParamIndices) then
26922686
begin
2693-
// already validated
2694-
LArgs := Args;
2695-
LVarParamIndices := VarParamIndices;
2696-
end
2697-
else
2698-
begin
2699-
SetLength(LArgs, ArgCount);
2700-
2701-
if not PyArgsToValues(ob1, Method, LArgs, LVarParamIndices) then
2702-
begin
2703-
InvalidArguments(Method.Name, rs_IncompatibleArguments);
2704-
Exit;
2705-
end;
2687+
InvalidArguments(Method.Name, rs_IncompatibleArguments);
2688+
Exit;
27062689
end;
27072690

2691+
Result := RttiCall(ParentAddress, DelphiWrapper, Method, LArgs,
2692+
LVarParamIndices, AParentAddrIsClass);
2693+
end;
2694+
2695+
2696+
function RttiCall(ParentAddress: pointer; DelphiWrapper: TPyDelphiWrapper;
2697+
Method: TRttiMethod; const Args: TArray<TValue>;
2698+
const VarParamIndices: TArray<Integer>;
2699+
AParentAddrIsClass: Boolean = false): PPyObject;
2700+
var
2701+
Addr: TValue;
2702+
ReturnValue: TValue;
2703+
ErrMsg: string;
2704+
TempPy: PPyObject;
2705+
Index, Pos: Integer;
2706+
begin
2707+
// Args and VarParamIndices are already setup and validated
27082708
try
27092709
if Method.Parent is TRttiInstanceType then
27102710
if Method.IsClassMethod or Method.IsStatic then
@@ -2719,7 +2719,7 @@ function RttiCall(ParentAddress: pointer; DelphiWrapper: TPyDelphiWrapper;
27192719
else
27202720
Addr := TValue.From(ParentAddress);
27212721

2722-
ReturnValue := Method.Invoke(Addr, LArgs);
2722+
ReturnValue := Method.Invoke(Addr, Args);
27232723

27242724
{ Deal with var/out arguments
27252725
e.g.
@@ -2740,7 +2740,7 @@ function RttiCall(ParentAddress: pointer; DelphiWrapper: TPyDelphiWrapper;
27402740
if Length(VarParamIndices) = 0 then
27412741
Result := TValueToPyObject(ReturnValue, DelphiWrapper, ErrMsg)
27422742
else if (Method.ReturnType = nil) and (Length(VarParamIndices) = 1) then
2743-
Result := TValueToPyObject(LArgs[VarParamIndices[0]], DelphiWrapper, ErrMsg)
2743+
Result := TValueToPyObject(Args[VarParamIndices[0]], DelphiWrapper, ErrMsg)
27442744
else
27452745
begin
27462746
// we return a tuple - start with the return value
@@ -2766,7 +2766,7 @@ function RttiCall(ParentAddress: pointer; DelphiWrapper: TPyDelphiWrapper;
27662766
if Result <> nil then
27672767
for Index in VarParamIndices do
27682768
begin
2769-
TempPy := TValueToPyObject(LArgs[Index], DelphiWrapper, ErrMsg);
2769+
TempPy := TValueToPyObject(Args[Index], DelphiWrapper, ErrMsg);
27702770
if TempPy = nil then
27712771
begin
27722772
DelphiWrapper.Engine.Py_DECREF(Result);
@@ -4046,7 +4046,7 @@ function TPyDelphiObject.MpSubscript(obj: PPyObject) : PPyObject;
40464046
PyArgs := PyDelphiWrapper.Engine.MakePyTuple([obj]);
40474047

40484048
Result := RttiCall(DelphiObject, PyDelphiWrapper, Prop.ReadMethod,
4049-
PyArgs, nil, [], []);
4049+
PyArgs, nil);
40504050

40514051
if not PyDelphiWrapper.Engine.PyTuple_Check(obj) then
40524052
PyDelphiWrapper.Engine.Py_DECREF(PyArgs); // release created tuple
@@ -4091,7 +4091,7 @@ function TPyDelphiObject.MpAssSubscript(obj1, obj2: PPyObject) : Integer;
40914091
PyArgs := Engine.MakePyTuple([obj1, obj2]);
40924092

40934093
TempPy := RttiCall(DelphiObject, PyDelphiWrapper, Prop.WriteMethod,
4094-
PyArgs, nil, [], []);
4094+
PyArgs, nil);
40954095

40964096
Engine.Py_DECREF(PyArgs); // release created tuple
40974097

0 commit comments

Comments
 (0)