mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-09-13 12:49:20 +02:00
* removed explicit refcounting checks and replaced with memory leak check
git-svn-id: trunk@8388 -
This commit is contained in:
parent
48980ccbe8
commit
f70894607f
@ -1,4 +1,5 @@
|
|||||||
{ %version=1.1 }
|
{ %version=1.1 }
|
||||||
|
{ %opt=-gh }
|
||||||
|
|
||||||
{ Source provided for Free Pascal Bug Report 2911 }
|
{ Source provided for Free Pascal Bug Report 2911 }
|
||||||
{ Submitted by "Chris Hilder" on 2004-01-19 }
|
{ Submitted by "Chris Hilder" on 2004-01-19 }
|
||||||
@ -20,53 +21,21 @@ var
|
|||||||
twostring : string;
|
twostring : string;
|
||||||
ARecordWithStrings : RecordWithStrings;
|
ARecordWithStrings : RecordWithStrings;
|
||||||
|
|
||||||
procedure RefCount(const s : string;expect:longint);
|
|
||||||
type
|
|
||||||
PLongint = ^Longint;
|
|
||||||
var
|
|
||||||
P : psizeint;
|
|
||||||
rc : longint;
|
|
||||||
begin
|
|
||||||
P := psizeint(s);
|
|
||||||
rc:=0;
|
|
||||||
if (p = nil)
|
|
||||||
then writeln('Nil string.')
|
|
||||||
else
|
|
||||||
{$ifdef fpc}
|
|
||||||
{$if defined(ver1_0) or defined(ver1_9_4)}
|
|
||||||
rc:=(p-1)^;
|
|
||||||
{$else}
|
|
||||||
rc:=psizeint(pchar(p)-sizeof(sizeint)*2)^;
|
|
||||||
{$endif}
|
|
||||||
{$else}
|
|
||||||
rc:=psizeint(pchar(p)-sizeof(sizeint)*2)^;
|
|
||||||
{$endif}
|
|
||||||
writeln('Ref count is ',rc,' expected ',expect);
|
|
||||||
if rc<>expect then
|
|
||||||
halt(1);
|
|
||||||
end;
|
|
||||||
|
|
||||||
function FunctionResultIsRecord(a : RecordWithStrings) : RecordWithStrings;
|
function FunctionResultIsRecord(a : RecordWithStrings) : RecordWithStrings;
|
||||||
begin
|
begin
|
||||||
result := a;
|
result := a;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
|
HaltOnNotReleased := true;
|
||||||
onestring := 'one';
|
onestring := 'one';
|
||||||
twostring := 'two';
|
twostring := 'two';
|
||||||
ARecordWithStrings.one := onestring + twostring;
|
ARecordWithStrings.one := onestring + twostring;
|
||||||
twostring := onestring + twostring;
|
twostring := onestring + twostring;
|
||||||
RefCount(ARecordWithStrings.one,1);
|
|
||||||
{ Here we allocate a temp so refcount will be 2 }
|
|
||||||
ARecordWithStrings := FunctionResultIsRecord(ARecordWithStrings);
|
ARecordWithStrings := FunctionResultIsRecord(ARecordWithStrings);
|
||||||
twostring := onestring + twostring;
|
twostring := onestring + twostring;
|
||||||
RefCount(ARecordWithStrings.one,2);
|
|
||||||
{ Temp is reused, refcount should stay 2 }
|
|
||||||
ARecordWithStrings := FunctionResultIsRecord(ARecordWithStrings);
|
ARecordWithStrings := FunctionResultIsRecord(ARecordWithStrings);
|
||||||
twostring := onestring + twostring;
|
twostring := onestring + twostring;
|
||||||
RefCount(ARecordWithStrings.one,2);
|
|
||||||
{ Temp is reused, refcount should stay 2 }
|
|
||||||
ARecordWithStrings := FunctionResultIsRecord(ARecordWithStrings);
|
ARecordWithStrings := FunctionResultIsRecord(ARecordWithStrings);
|
||||||
twostring := onestring + twostring;
|
twostring := onestring + twostring;
|
||||||
RefCount(ARecordWithStrings.one,2);
|
|
||||||
end.
|
end.
|
||||||
|
Loading…
Reference in New Issue
Block a user