~ubuntu-branches/debian/lenny/fpc/lenny

« back to all changes in this revision

Viewing changes to fpcsrc/tests/webtbs/tw2911.pp

  • Committer: Bazaar Package Importer
  • Author(s): Mazen Neifer, Torsten Werner, Mazen Neifer
  • Date: 2008-05-17 17:12:11 UTC
  • mfrom: (3.1.9 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080517171211-9qi33xhd9evfa0kg
Tags: 2.2.0-dfsg1-9
[ Torsten Werner ]
* Add Mazen Neifer to Uploaders field.

[ Mazen Neifer ]
* Moved FPC sources into a version dependent directory from /usr/share/fpcsrc
  to /usr/share/fpcsrc/${FPCVERSION}. This allow installing more than on FPC
  release.
* Fixed far call issue in compiler preventing building huge binearies.
  (closes: #477743)
* Updated building dependencies, recomennded and suggested packages.
* Moved fppkg to fp-utils as it is just a helper tool and is not required by
  compiler.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
{ %version=1.1 }
 
2
 
 
3
{ Source provided for Free Pascal Bug Report 2911 }
 
4
{ Submitted by "Chris Hilder" on  2004-01-19 }
 
5
{ e-mail: cj.hilder@astronomyinyourhands.com }
 
6
program bug_demo;
 
7
 
 
8
{$ifdef fpc}{$Mode objfpc}{$endif}
 
9
{$LONGSTRINGS ON}
 
10
 
 
11
type
 
12
        RecordWithStrings =
 
13
                record
 
14
                        one,
 
15
                        two : string;
 
16
                end;
 
17
 
 
18
var
 
19
        onestring,
 
20
        twostring : string;
 
21
        ARecordWithStrings : RecordWithStrings;
 
22
 
 
23
procedure RefCount(const s : string;expect:longint);
 
24
type
 
25
        PLongint = ^Longint;
 
26
var
 
27
        P : psizeint;
 
28
        rc : longint;
 
29
begin
 
30
        P := psizeint(s);
 
31
        rc:=0;
 
32
        if (p = nil)
 
33
        then writeln('Nil string.')
 
34
        else
 
35
{$ifdef  fpc}
 
36
  {$if defined(ver1_0) or defined(ver1_9_4)}
 
37
         rc:=(p-1)^;
 
38
  {$else}
 
39
         rc:=psizeint(pchar(p)-sizeof(sizeint)*2)^;
 
40
  {$endif}
 
41
{$else}
 
42
         rc:=psizeint(pchar(p)-sizeof(sizeint)*2)^;
 
43
{$endif}
 
44
  writeln('Ref count is ',rc,' expected ',expect);
 
45
  if rc<>expect then
 
46
    halt(1);
 
47
end;
 
48
 
 
49
function FunctionResultIsRecord(a : RecordWithStrings) : RecordWithStrings;
 
50
begin
 
51
        result := a;
 
52
end;
 
53
 
 
54
begin
 
55
        onestring := 'one';
 
56
        twostring := 'two';
 
57
        ARecordWithStrings.one := onestring + twostring;
 
58
        twostring := onestring + twostring;
 
59
        RefCount(ARecordWithStrings.one,1);
 
60
        { Here we allocate a temp so refcount will be 2 }
 
61
        ARecordWithStrings := FunctionResultIsRecord(ARecordWithStrings);
 
62
        twostring := onestring + twostring;
 
63
        RefCount(ARecordWithStrings.one,2);
 
64
        { Temp is reused, refcount should stay 2 }
 
65
        ARecordWithStrings := FunctionResultIsRecord(ARecordWithStrings);
 
66
        twostring := onestring + twostring;
 
67
        RefCount(ARecordWithStrings.one,2);
 
68
        { Temp is reused, refcount should stay 2 }
 
69
        ARecordWithStrings := FunctionResultIsRecord(ARecordWithStrings);
 
70
        twostring := onestring + twostring;
 
71
        RefCount(ARecordWithStrings.one,2);
 
72
end.