* rework low level callback API

git-svn-id: trunk@40697 -
This commit is contained in:
svenbarth 2018-12-29 19:21:09 +00:00
parent feff0c673f
commit 9a23613b9d
2 changed files with 16 additions and 26 deletions

View File

@ -500,7 +500,6 @@ const
Invoke: @FFIInvoke; Invoke: @FFIInvoke;
CreateCallbackProc: Nil; CreateCallbackProc: Nil;
CreateCallbackMethod: Nil; CreateCallbackMethod: Nil;
FreeCallback: Nil
); );
var var

View File

@ -47,7 +47,12 @@ type
TRttiProperty = class; TRttiProperty = class;
TRttiInstanceType = class; TRttiInstanceType = class;
TFunctionCallCallback = Pointer; TFunctionCallCallback = class
protected
function GetCodeAddress: CodePointer; virtual; abstract;
public
property CodeAddress: CodePointer read GetCodeAddress;
end;
TFunctionCallFlag = ( TFunctionCallFlag = (
fcfStatic fcfStatic
@ -451,15 +456,14 @@ type
end; end;
TFunctionCallParameterArray = specialize TArray<TFunctionCallParameter>; TFunctionCallParameterArray = specialize TArray<TFunctionCallParameter>;
TFunctionCallProc = procedure(const aArgs: TValueArray; out aResult: TValue; aContext: Pointer); TFunctionCallProc = procedure(const aArgs: specialize TArray<Pointer>; aResult: Pointer; aContext: Pointer);
TFunctionCallMethod = procedure(const aArgs: TValueArray; out aResult: TValue; aContext: Pointer) of object; TFunctionCallMethod = procedure(const aArgs: specialize TArray<Pointer>; aResult: Pointer; aContext: Pointer) of object;
TFunctionCallManager = record TFunctionCallManager = record
Invoke: procedure(CodeAddress: CodePointer; const Args: TFunctionCallParameterArray; CallingConvention: TCallConv; Invoke: procedure(CodeAddress: CodePointer; const Args: TFunctionCallParameterArray; CallingConvention: TCallConv;
ResultType: PTypeInfo; ResultValue: Pointer; Flags: TFunctionCallFlags); ResultType: PTypeInfo; ResultValue: Pointer; Flags: TFunctionCallFlags);
CreateCallbackProc: function(aHandler: TFunctionCallProc; aCallConv: TCallConv; aArgs: array of PTypeInfo; aResultType: PTypeInfo; aFlags: TFunctionCallFlags; aContext: Pointer): TFunctionCallCallback; CreateCallbackProc: function(aHandler: TFunctionCallProc; aCallConv: TCallConv; aArgs: array of TFunctionCallParameterInfo; aResultType: PTypeInfo; aFlags: TFunctionCallFlags; aContext: Pointer): TFunctionCallCallback;
CreateCallbackMethod: function(aHandler: TFunctionCallMethod; aCallConv: TCallConv; aArgs: array of PTypeInfo; aResultType: PTypeInfo; aFlags: TFunctionCallFlags; aContext: Pointer): TFunctionCallCallback; CreateCallbackMethod: function(aHandler: TFunctionCallMethod; aCallConv: TCallConv; aArgs: array of TFunctionCallParameterInfo; aResultType: PTypeInfo; aFlags: TFunctionCallFlags; aContext: Pointer): TFunctionCallCallback;
FreeCallback: procedure(aCallback: TFunctionCallCallback; aCallConv: TCallConv);
end; end;
TFunctionCallManagerArray = array[TCallConv] of TFunctionCallManager; TFunctionCallManagerArray = array[TCallConv] of TFunctionCallManager;
@ -480,9 +484,8 @@ procedure GetFunctionCallManagers(out aFuncCallMgrs: TFunctionCallManagerArray);
function Invoke(aCodeAddress: CodePointer; const aArgs: TValueArray; aCallConv: TCallConv; function Invoke(aCodeAddress: CodePointer; const aArgs: TValueArray; aCallConv: TCallConv;
aResultType: PTypeInfo; aIsStatic: Boolean; aIsConstructor: Boolean): TValue; aResultType: PTypeInfo; aIsStatic: Boolean; aIsConstructor: Boolean): TValue;
function CreateCallbackProc(aHandler: TFunctionCallProc; aCallConv: TCallConv; aArgs: array of PTypeInfo; aResultType: PTypeInfo; aFlags: TFunctionCallFlags; aContext: Pointer): TFunctionCallCallback; function CreateCallbackProc(aHandler: TFunctionCallProc; aCallConv: TCallConv; aArgs: array of TFunctionCallParameterInfo; aResultType: PTypeInfo; aFlags: TFunctionCallFlags; aContext: Pointer): TFunctionCallCallback;
function CreateCallbackMethod(aHandler: TFunctionCallMethod; aCallConv: TCallConv; aArgs: array of PTypeInfo; aResultType: PTypeInfo; aFlags: TFunctionCallFlags; aContext: Pointer): TFunctionCallCallback; function CreateCallbackMethod(aHandler: TFunctionCallMethod; aCallConv: TCallConv; aArgs: array of TFunctionCallParameterInfo; aResultType: PTypeInfo; aFlags: TFunctionCallFlags; aContext: Pointer): TFunctionCallCallback;
procedure FreeCallback(aCallback: TFunctionCallCallback; aCallConv: TCallConv);
function IsManaged(TypeInfo: PTypeInfo): boolean; function IsManaged(TypeInfo: PTypeInfo): boolean;
@ -670,29 +673,23 @@ begin
raise ENotImplemented.Create(SErrInvokeNotImplemented); raise ENotImplemented.Create(SErrInvokeNotImplemented);
end; end;
function NoCreateCallbackProc(aFunc: TFunctionCallProc; aCallConv: TCallConv; aArgs: array of PTypeInfo; aResultType: PTypeInfo; aFlags: TFunctionCallFlags; aContext: Pointer): TFunctionCallCallback; function NoCreateCallbackProc(aFunc: TFunctionCallProc; aCallConv: TCallConv; aArgs: array of TFunctionCallParameterInfo; aResultType: PTypeInfo; aFlags: TFunctionCallFlags; aContext: Pointer): TFunctionCallCallback;
begin begin
Result := Nil; Result := Nil;
raise ENotImplemented.Create(SErrCallbackNotImplented); raise ENotImplemented.Create(SErrCallbackNotImplented);
end; end;
function NoCreateCallbackMethod(aFunc: TFunctionCallMethod; aCallConv: TCallConv; aArgs: array of PTypeInfo; aResultType: PTypeInfo; aFlags: TFunctionCallFlags; aContext: Pointer): TFunctionCallCallback; function NoCreateCallbackMethod(aFunc: TFunctionCallMethod; aCallConv: TCallConv; aArgs: array of TFunctionCallParameterInfo; aResultType: PTypeInfo; aFlags: TFunctionCallFlags; aContext: Pointer): TFunctionCallCallback;
begin begin
Result := Nil; Result := Nil;
raise ENotImplemented.Create(SErrCallbackNotImplented); raise ENotImplemented.Create(SErrCallbackNotImplented);
end; end;
procedure NoFreeCallback(aCallback: TFunctionCallCallback; aCallConv: TCallConv);
begin
raise ENotImplemented.Create(SErrCallbackNotImplented);
end;
const const
NoFunctionCallManager: TFunctionCallManager = ( NoFunctionCallManager: TFunctionCallManager = (
Invoke: @NoInvoke; Invoke: @NoInvoke;
CreateCallbackProc: @NoCreateCallbackProc; CreateCallbackProc: @NoCreateCallbackProc;
CreateCallbackMethod: @NoCreateCallbackMethod; CreateCallbackMethod: @NoCreateCallbackMethod;
FreeCallback: @NoFreeCallback
); );
procedure SetFunctionCallManager(aCallConv: TCallConv; constref aFuncCallMgr: TFunctionCallManager; procedure SetFunctionCallManager(aCallConv: TCallConv; constref aFuncCallMgr: TFunctionCallManager;
@ -931,7 +928,7 @@ begin
mgr.Invoke(aCodeAddress, args, aCallConv, restype, resptr, flags); mgr.Invoke(aCodeAddress, args, aCallConv, restype, resptr, flags);
end; end;
function CreateCallbackProc(aHandler: TFunctionCallProc; aCallConv: TCallConv; aArgs: array of PTypeInfo; aResultType: PTypeInfo; aFlags: TFunctionCallFlags; aContext: Pointer): TFunctionCallCallback; function CreateCallbackProc(aHandler: TFunctionCallProc; aCallConv: TCallConv; aArgs: array of TFunctionCallParameterInfo; aResultType: PTypeInfo; aFlags: TFunctionCallFlags; aContext: Pointer): TFunctionCallCallback;
begin begin
if not Assigned(FuncCallMgr[aCallConv].CreateCallbackProc) then if not Assigned(FuncCallMgr[aCallConv].CreateCallbackProc) then
raise ENotImplemented.Create(SErrCallbackNotImplented); raise ENotImplemented.Create(SErrCallbackNotImplented);
@ -942,7 +939,7 @@ begin
Result := FuncCallMgr[aCallConv].CreateCallbackProc(aHandler, aCallConv, aArgs, aResultType, aFlags, aContext); Result := FuncCallMgr[aCallConv].CreateCallbackProc(aHandler, aCallConv, aArgs, aResultType, aFlags, aContext);
end; end;
function CreateCallbackMethod(aHandler: TFunctionCallMethod; aCallConv: TCallConv; aArgs: array of PTypeInfo; aResultType: PTypeInfo; aFlags: TFunctionCallFlags; aContext: Pointer): TFunctionCallCallback; function CreateCallbackMethod(aHandler: TFunctionCallMethod; aCallConv: TCallConv; aArgs: array of TFunctionCallParameterInfo; aResultType: PTypeInfo; aFlags: TFunctionCallFlags; aContext: Pointer): TFunctionCallCallback;
begin begin
if not Assigned(FuncCallMgr[aCallConv].CreateCallbackMethod) then if not Assigned(FuncCallMgr[aCallConv].CreateCallbackMethod) then
raise ENotImplemented.Create(SErrCallbackNotImplented); raise ENotImplemented.Create(SErrCallbackNotImplented);
@ -953,12 +950,6 @@ begin
Result := FuncCallMgr[aCallConv].CreateCallbackMethod(aHandler, aCallConv, aArgs, aResultType, aFlags, aContext); Result := FuncCallMgr[aCallConv].CreateCallbackMethod(aHandler, aCallConv, aArgs, aResultType, aFlags, aContext);
end; end;
procedure FreeCallback(aCallback: TFunctionCallCallback; aCallConv: TCallConv);
begin
if Assigned(FuncCallMgr[aCallConv].FreeCallback) then
FuncCallMgr[aCallConv].FreeCallback(aCallback, aCallConv);
end;
function IsManaged(TypeInfo: PTypeInfo): boolean; function IsManaged(TypeInfo: PTypeInfo): boolean;
begin begin
if Assigned(TypeInfo) then if Assigned(TypeInfo) then