[PATCH] RTTI.Invoke(): fix access violation when returning record
Original Reporter info from Mantis: silvioprog
-
Reporter name: silvioprog
Original Reporter info from Mantis: silvioprog
- Reporter name: silvioprog
Description:
Hi.
Consider the following example:
unit Unit1; {$mode objfpc}{$H+} interface uses Forms, StdCtrls; type TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); end; var Form1: TForm1; implementation {$R *.lfm} uses typinfo, rtti; type TR = record S: string; I: integer; end; function Test(P: TR): TR; begin WriteLn('F: ', P.S, ' - ', P.I); Result := P; end; procedure TForm1.Button1Click(Sender: TObject); var V, R: TValue; R1, R2: TR; begin R1.S := 'abc'; R1.I := 123; TValue.Make(@R1, TypeInfo(TR), V); R := Rtti.Invoke(@Test, [V], ccReg, TypeInfo(TR), True, False); R2 := TR(R.GetReferenceToRawData^); WriteLn('R: ', R2.S, ' - ', R2.I); end; end.
It raises an access violation solved, but the attached patch solves it.
Steps to reproduce:
Just create a new project on your Lazarus, put a new button (Button1) and replace the entire code by the attached one.
Additional information:
This new patch already applies the first one attached here: https://bugs.freepascal.org/view.php?id=34496
*** This patch is for Windows 64 ONLY! ***
Mantis conversion info:
- Mantis ID: 34509
- Platform: Win64
- Version: 3.3.1
- Fixed in revision: 40669 (#9eac2ea8)