d-mozulyov / Tiny.Library

General purpose low level library for Delphi 7-XE10, FreePascal and C++Builder
MIT License
79 stars 17 forks source link

AV with certain method signature #8

Open sglienke opened 2 years ago

sglienke commented 2 years ago

I experience an exception (tried in Delphi 10.1 and 11) with the following code on Win64:

program TinyInvokeBug64bit;

{$APPTYPE CONSOLE}

uses
  System.SysUtils,
  Tiny.Rtti,
  Tiny.Invoke;

type
  TEventArgs = record i: Integer; s: string; v: Variant; end;
  TEventWithStackParams = procedure(const Value1: Int64; const Value2: Single;
    const Value3: Double; const Value4: Extended; const Value5: TEventArgs) of object;

  TTest = class
    procedure Handle(const Value1: Int64; const Value2: Single;
      const Value3: Double; const Value4: Extended; const Value5: TEventArgs);
  end;

procedure TTest.Handle(const Value1: Int64; const Value2: Single;
  const Value3: Double; const Value4: Extended; const Value5: TEventArgs);
begin
  Assert(Value1 = 42);
  Assert(Value2 = 43);
  Assert(Value3 = 44);
  Assert(Value4 = 45);
  Assert(Value5.i = 46);
  Assert(Value5.s = '47');
  Assert(value5.v = 48);
end;

procedure Main;
var
  sig: TRttiSignature;
  args: TEventArgs;
  dump: TRttiInvokeDump;
begin
  args.i := 46;
  args.s := '47';
  args.v := 48;
  sig.Init(TypeInfo(TEventWithStackParams));
  sig.Invoke(dump, @TTest.Handle, nil, [42, 43, 44, 45, TValue.From(args)]);
end;
begin
  Main;
end.

It looks like it happens inside the UniversalInvokeFunc that gets called from TRttiInvokeBuffer.Invoke