Skip to content

Commit

Permalink
Implement EnableMemoryLeakReportingUsesQualifiedClassName in function…
Browse files Browse the repository at this point in the history
… AppendClassNameToBuffer
  • Loading branch information
jeroenuw committed Mar 20, 2019
1 parent bed3021 commit c1f3247
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
37 changes: 36 additions & 1 deletion FastMM4.pas
Original file line number Diff line number Diff line change
Expand Up @@ -3585,18 +3585,53 @@ function AppendStringToBuffer(const ASource, ADestination: PAnsiChar; ACount: Ca
Result := Pointer(PByte(ADestination) + ACount);
end;

{$ifdef EnableMemoryLeakReportingUsesQualifiedClassName}
type
PClassData = ^TClassData;
TClassData = record
ClassType: TClass;
ParentInfo: Pointer;
PropCount: SmallInt;
UnitName: ShortString;
end;
{$endif EnableMemoryLeakReportingUsesQualifiedClassName}

{Appends the name of the class to the destination buffer and returns the new
destination position}
function AppendClassNameToBuffer(AClass: TClass; ADestination: PAnsiChar): PAnsiChar;
var
{$ifdef EnableMemoryLeakReportingUsesQualifiedClassName}
FirstUnitNameChar: AnsiChar;
LClassInfo: Pointer;
UnitName: PShortString;
{$endif EnableMemoryLeakReportingUsesQualifiedClassName}
LPClassName: PShortString;
begin
{Get a pointer to the class name}
if AClass <> nil then
begin
Result := ADestination;
{$ifdef EnableMemoryLeakReportingUsesQualifiedClassName}
// based on TObject.UnitScope
LClassInfo := AClass.ClassInfo;
if LClassInfo <> nil then // prepend the UnitName
begin
UnitName := @PClassData(PByte(LClassInfo) + 2 + PByte(PByte(LClassInfo) + 1)^).UnitName;
FirstUnitNameChar := UnitName^[1];
if FirstUnitNameChar <> '@' then
Result := AppendStringToBuffer(@FirstUnitNameChar, Result, Length(UnitName^))
else // Pos does no memory allocations, so it is safe to use
begin // Skip the '@', then copy until the ':' - never seen this happen in Delphi, but might be a C++ thing
Result := AppendStringToBuffer(@UnitName^[2], Result, Pos(ShortString(':'), UnitName^) - 2)
;
end;
// dot between unit name and class name:
Result := AppendStringToBuffer('.', Result, Length('.'));
end;
{$endif EnableMemoryLeakReportingUsesQualifiedClassName}
LPClassName := PShortString(PPointer(PByte(AClass) + vmtClassName)^);
{Append the class name}
Result := AppendStringToBuffer(@LPClassName^[1], ADestination, Length(LPClassName^));
Result := AppendStringToBuffer(@LPClassName^[1], Result, Length(LPClassName^));
end
else
begin
Expand Down
7 changes: 7 additions & 0 deletions FastMM4Options.inc
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,13 @@ Set the default options for FastMM here.
message.}
{.$define HideMemoryLeakHintMessage}

{Set this option to use QualifiedClassName equivalent instead of ClassName
equivalent during memory leak reporting.
This is useful for duplicate class names (like EConversionError, which is in
units Data.DBXJSONReflect, REST.JsonReflect and System.ConvUtils,
or TClipboard being in Vcl.Clibprd and WinAPI.ApplicationModel.DataTransfer }
{$define EnableMemoryLeakReportingUsesQualifiedClassName}

{--------------------------Instruction Set Options----------------------------}

{Set this option to enable the use of MMX instructions. Disabling this option
Expand Down

0 comments on commit c1f3247

Please sign in to comment.