Skip to content

SIGSEGV, when using extended Rtti

Summary

SIGSEGV, when using extended Rtti

System Information

  • Operating system: Linux
  • Processor architecture: x86-64 (9e8f09b9)
  • Compiler version: trunk
  • Device: Computer

Steps to reproduce

program Project1;

{$mode DELPHI}

uses
  SysUtils, Rtti;

type
  TCurrencyHandler = procedure (Sender: TObject; Cur: Currency) of object;

procedure DoTest;
var
  Context: TRttiContext;
  Ty: TRttiType;
  P: TRttiParameter;
begin
  Context := TRttiContext.Create();
  try
    Ty := Context.GetType(TypeInfo(TCurrencyHandler));
    for P in (Ty as TRttiMethodType).GetParameters() do
      WriteLn(P.Name, ': ', P.ParamType.Name);
  finally
    Context.Free;
  end;
end;

begin
  DoTest;
end.

Possible fixes

The reason is that in some cases you forget to pass FUsePublishedOnly to "child" TRttiObject and TRttiContext objects. As a result, the objects end up in different pools and some of them are destroyed. In the example above:
Ty.FUsePublishedOnly = True
P.FUsePublishedOnly = False, but it is placed in GRttiPool[True]
P.ParamType is placed in GRttiPool[True] and is destroyed on exit from TRttiMethodTypeParameter.GetParamType

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information