|
@@ -1,43 +1,66 @@
|
|
-{ Source provided for Free Pascal Bug Report 14019 }
|
|
|
|
-{ Submitted by "hennymcc" on 2009-06-21 }
|
|
|
|
|
|
+{ %opt=-gh }
|
|
|
|
|
|
-program tw14019;
|
|
|
|
|
|
+program RefCountBug;
|
|
|
|
|
|
-{$mode objfpc}
|
|
|
|
|
|
+{$ifdef fpc}
|
|
|
|
+ //{$mode objfpc}{$H+}
|
|
|
|
+ {$mode delphi}
|
|
|
|
+{$endif}
|
|
|
|
+
|
|
|
|
+{$ifdef mswindows}
|
|
|
|
+ {$apptype console}
|
|
|
|
+{$endif}
|
|
|
|
+
|
|
|
|
+uses
|
|
|
|
+ Classes,
|
|
|
|
+ SysUtils;
|
|
|
|
|
|
type
|
|
type
|
|
ITest = interface
|
|
ITest = interface
|
|
function SomeMethod(): ITest;
|
|
function SomeMethod(): ITest;
|
|
- function GetValue(): Integer;
|
|
|
|
|
|
+ function GetValue(): AnsiString;
|
|
end;
|
|
end;
|
|
|
|
|
|
TTest = class(TInterfacedObject, ITest)
|
|
TTest = class(TInterfacedObject, ITest)
|
|
|
|
+ private
|
|
|
|
+ fValue: AnsiString;
|
|
public
|
|
public
|
|
- procedure FreeInstance; override;
|
|
|
|
|
|
+ constructor Create(Value: AnsiString);
|
|
|
|
+ destructor Destroy(); override;
|
|
function SomeMethod(): ITest;
|
|
function SomeMethod(): ITest;
|
|
- function GetValue(): Integer;
|
|
|
|
|
|
+ function GetValue(): AnsiString;
|
|
end;
|
|
end;
|
|
|
|
|
|
-procedure TTest.FreeInstance;
|
|
|
|
|
|
+constructor TTest.Create(Value: AnsiString);
|
|
|
|
+begin
|
|
|
|
+ inherited Create();
|
|
|
|
+ fValue := Value;
|
|
|
|
+ Writeln('TTest.Create('+Value+')');
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+destructor TTest.Destroy();
|
|
begin
|
|
begin
|
|
- FillChar(Pointer(Self)^, InstanceSize, 0);
|
|
|
|
- inherited FreeInstance;
|
|
|
|
|
|
+ Writeln('TTest.Destroy('+fValue+')');
|
|
|
|
+ inherited;
|
|
end;
|
|
end;
|
|
|
|
|
|
function TTest.SomeMethod(): ITest;
|
|
function TTest.SomeMethod(): ITest;
|
|
begin
|
|
begin
|
|
- Result := TTest.Create();
|
|
|
|
|
|
+ if (FRefCount <> 1) then
|
|
|
|
+ halt(1);
|
|
|
|
+ Writeln('SomeMethod: ' + fValue, ' ', FRefCount);
|
|
|
|
+ Result := TTest.Create(fValue + ',MethodCall');
|
|
end;
|
|
end;
|
|
|
|
|
|
-function TTest.GetValue(): Integer;
|
|
|
|
|
|
+function TTest.GetValue(): AnsiString;
|
|
begin
|
|
begin
|
|
- Result := 0;
|
|
|
|
|
|
+ Result := fValue;
|
|
end;
|
|
end;
|
|
|
|
|
|
var
|
|
var
|
|
t: ITest;
|
|
t: ITest;
|
|
begin
|
|
begin
|
|
- t := TTest.Create();
|
|
|
|
- t.SomeMethod().SomeMethod().GetValue();
|
|
|
|
|
|
+ HaltOnNotReleased := true;
|
|
|
|
+ t := TTest.Create('Create');
|
|
|
|
+ Writeln('Result: ' + t.SomeMethod().SomeMethod().GetValue);
|
|
end.
|
|
end.
|
|
-
|
|
|