Преглед изворни кода

Merged revisions 2627,2639,2764,2950,3027-3028,3050 via svnmerge from
http://[email protected]/svn/fpc/trunk

........
r2627 | florian | 2006-02-19 15:37:03 +0100 (Sun, 19 Feb 2006) | 2 lines

+ ansistring benchmark added

........
r2639 | peter | 2006-02-20 07:53:12 +0100 (Mon, 20 Feb 2006) | 2 lines

* remove Windows use

........
r2764 | peter | 2006-03-05 19:58:55 +0100 (Sun, 05 Mar 2006) | 2 lines

* nested for loop with same counter

........
r2950 | jonas | 2006-03-17 23:35:04 +0100 (Fri, 17 Mar 2006) | 2 lines

* fixed bug in sprintf of extended

........
r3027 | jonas | 2006-03-24 23:51:55 +0100 (Fri, 24 Mar 2006) | 2 lines

* fixed test (mainly for little endian systems)

........
r3028 | jonas | 2006-03-24 23:57:50 +0100 (Fri, 24 Mar 2006) | 2 lines

+ added

........
r3050 | peter | 2006-03-27 09:20:35 +0200 (Mon, 27 Mar 2006) | 2 lines

* remove svn:executable

........

git-svn-id: branches/fixes_2_0@3088 -

peter пре 19 година
родитељ
комит
c519a6c55a
7 измењених фајлова са 393 додато и 2 уклоњено
  1. 4 1
      .gitattributes
  2. 334 0
      tests/bench/ansibench.pp
  3. 14 0
      tests/tbf/tb0179.pp
  4. 1 1
      tests/test/cg/tprintf.pp
  5. 40 0
      tests/webtbs/tw4632.pp
  6. 0 0
      tests/webtbs/tw4700.pp
  7. 0 0
      tests/webtbs/tw4763.pp

+ 4 - 1
.gitattributes

@@ -4343,6 +4343,7 @@ rtl/x86_64/x86_64.inc svneol=native#text/plain
 tests/MPWMake -text
 tests/Makefile svneol=native#text/plain
 tests/Makefile.fpc svneol=native#text/plain
+tests/bench/ansibench.pp -text
 tests/bench/dmisc.pas svneol=native#text/plain
 tests/bench/drystone.pas svneol=native#text/plain
 tests/bench/pi.c -text
@@ -4579,6 +4580,7 @@ tests/tbf/tb0175.pp svneol=native#text/plain
 tests/tbf/tb0176.pp svneol=native#text/plain
 tests/tbf/tb0177.pp svneol=native#text/plain
 tests/tbf/tb0178.pp svneol=native#text/plain
+tests/tbf/tb0179.pp svneol=native#text/plain
 tests/tbf/ub0115.pp svneol=native#text/plain
 tests/tbf/ub0149.pp svneol=native#text/plain
 tests/tbf/ub0158a.pp svneol=native#text/plain
@@ -6444,8 +6446,9 @@ tests/webtbs/tw4635.pp svneol=native#text/plain
 tests/webtbs/tw4640.pp svneol=native#text/plain
 tests/webtbs/tw4669.pp svneol=native#text/plain
 tests/webtbs/tw4675.pp svneol=native#text/plain
+tests/webtbs/tw4678.pp -text
 tests/webtbs/tw4700.pp svneol=native#text/plain
-tests/webtbs/tw4707.pp -text
+tests/webtbs/tw4704.pp -text
 tests/webtbs/tw4763.pp svneol=native#text/plain
 tests/webtbs/tw4768.pp -text
 tests/webtbs/tw4778.pp svneol=native#text/plain

+ 334 - 0
tests/bench/ansibench.pp

@@ -0,0 +1,334 @@
+program Bench2;
+{$APPTYPE CONSOLE}
+{$Mode Objfpc}
+{$H+}
+
+uses
+   sysutils;
+
+const
+ cTimes = 999999;
+   Number1: array [0..19] of string = (
+   'zero', 'one', 'two', 'three', 'four', 'five',
+   'six', 'seven', 'eight', 'nine', 'ten', 'eleven',
+   'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen',
+   'seventeen', 'eighteen', 'nineteen');
+    Number9: array [0..9] of string = (
+   '', ' one', ' two', ' three', ' four', ' five',
+   ' six', ' seven', ' eight', ' nine');
+
+   Number10: array [0..9] of string = (
+   'zero', 'ten', 'twenty', 'thirty', 'fourty', 'fifty',
+   'sixty', 'seventy', 'eighty', 'ninety');
+
+
+    function GetTickCount : Cardinal;
+      var
+         h,m,s,s1000 : word;
+      begin
+         decodetime(time,h,m,s,s1000);
+         result:=h*3600000+m*60000+s*1000+s1000;
+      end;
+
+
+var
+   StartTick: Cardinal;
+
+procedure StartLog(const Text: string; Count: Integer);
+begin
+   if Count > 0 then
+       write(Text, ': ', Count, ' ... ')
+   else
+       write(Text, ' ... ');
+   StartTick:= GetTickCount;
+end;
+
+procedure EndLog(const Text: string);
+begin
+   writeln(Text, ' done in ', (GetTickCount - StartTick) / 1000.0: 0: 3, ' sec');
+end;
+
+type
+ TFastStringRec = record
+   l: Cardinal;
+   s: string;
+ end;
+
+procedure FS_Clear(var AFS: TFastStringRec); inline;
+begin
+ AFS.L:= 0;
+ AFS.S:= '';
+end;
+
+procedure FS_Assign(var AFS: TFastStringRec; const s: string); inline;
+begin
+ AFS.l:= Length(s);
+ SetLength(AFS.s, (AFS.l and not 63) + 64);
+ if AFS.l > 0 then
+   Move(s[1], AFS.s[1], AFS.l);
+end;
+
+procedure FS_Append(var AFS: TFastStringRec; const s: string); overload;
+inline;
+var
+ L, ls: Cardinal;
+begin
+ ls:= Length(s);
+ if ls > 0 then begin
+   L:= AFS.l;
+   AFS.l:= L + ls;
+   SetLength(AFS.s, (AFS.l and not 63) + 64);
+   Move(s[1], AFS.s[1 + L], ls);
+ end;
+end;
+
+procedure FS_Append(var AFS, S: TFastStringRec); overload; inline;
+var
+ L: Cardinal;
+begin
+ if S.L > 0 then begin
+   L:= AFS.l;
+   AFS.l:= L + S.L;
+   SetLength(AFS.s, (AFS.l and not 63) + 64);
+   Move(S.S[1], AFS.S[1 + L], S.L);
+ end;
+end;
+
+function FS_ToStr(var AFS: TFastStringRec): string; inline;
+begin
+ if AFS.L >  0 then begin
+   SetLength(Result, AFS.L);
+   Move(AFS.S[1], Result[1], AFS.L);
+ end else
+   Result:= '';
+end;
+
+procedure NumberToText_V1(out s: string; n: Integer);
+
+ procedure TensToText(var s: TFastStringRec; dig: Integer);
+ var
+   x: Integer;
+ begin
+     if dig > 0 then begin
+         if dig >= 20 then begin
+           x:= dig mod 10;
+           FS_Assign(s, Number10[dig div 10]);
+             if x <> 0 then
+              FS_Append(s, Number9[x]);
+         end else begin
+             FS_Assign(s, Number1[dig]);
+         end;
+     end else
+       FS_Clear(s);
+ end;
+
+ procedure HundredsToText(var s: TFastStringRec; dig: Integer);
+ var
+     h, t: Integer;
+     s1: TFastStringRec;
+ begin
+   if dig > 0 then begin
+       t:= dig mod 100;
+       h:= dig div 100;
+       if h > 0 then begin
+       TensToText(s, h);
+         if t > 0 then begin
+           FS_Append(s, ' houndred ');
+         TensToText(s1, t);
+         FS_Append(s, s1);
+         end else
+           FS_Append(s, ' houndred');
+       end else
+         TensToText(s, t);
+     end else
+       FS_Clear(s);
+ end;
+
+var
+   dig, h: Integer;
+   s0, s1: TFastStringRec;
+begin
+   if n > 0 then begin
+       dig:= n div 1000;
+       h:= n mod 1000;
+       if dig > 0 then begin
+         HundredsToText(s0, dig);
+         if h > 0 then begin
+       FS_Append(s0, ' thousand ');
+             HundredsToText(s1, h);
+       FS_Append(s0, s1);
+         end else
+           FS_Append(s0, ' thousand');
+       end else
+         HundredsToText(s0, h);
+       s:= FS_ToStr(s0);
+   end else
+       s:= Number1[0];
+end;
+
+
+procedure NumberToText_V2(out s: string; n: Integer);
+
+ procedure TensToText(out s: string; dig: Integer);
+ var
+   x: Integer;
+ begin
+     if dig > 0 then begin
+         if dig >= 20 then begin
+           x:= dig mod 10;
+             if x <> 0 then begin
+                 s:= Number10[dig div 10] + Number9[x]
+             end else
+               s:= Number10[dig div 10];
+         end else begin
+             s:= Number1[dig];
+         end;
+     end else
+       s:= '';
+ end;
+
+ procedure HundredsToText(out s: string; dig: Integer);
+ var
+     h, t: Integer;
+     s1: string;
+ begin
+   if dig > 0 then begin
+       t:= dig mod 100;
+       h:= dig div 100;
+       if h > 0 then begin
+       TensToText(s, h);
+         if t > 0 then begin
+           s:= s + ' houndred ';
+         TensToText(s1, t);
+         s:= s + s1;
+         end else
+           s:= s + ' houndred';
+       end else
+         TensToText(s, t);
+     end else
+       s:= '';
+ end;
+
+var
+   dig, h: Integer;
+   s1: string;
+begin
+   if n > 0 then begin
+       dig:= n div 1000;
+       h:= n mod 1000;
+       if dig > 0 then begin
+         HundredsToText(s, dig);
+         if h > 0 then begin
+       s:= s + ' thousand ';
+             HundredsToText(s1, h);
+       s:= s + s1;
+         end else
+           s:= s + ' thousand';
+       end else
+         HundredsToText(s, h);
+   end else
+       s:= Number1[0];
+end;
+
+function NumberToText_V3(n: Integer): string;
+
+   function TensToText(dig: Integer): string;
+ var
+   x: Integer;
+ begin
+     if dig > 0 then begin
+         if dig >= 20 then begin
+           x:= dig mod 10;
+             if x <> 0 then begin
+                 Result:= Number10[dig div 10] + Number9[x]
+             end else
+               Result:= Number10[dig div 10];
+         end else begin
+             Result:= Number1[dig];
+         end;
+     end else
+       Result:= '';
+ end;
+
+   function HundredsToText(dig: Integer): string;
+ var
+     h, t: Integer;
+ begin
+   if dig > 0 then begin
+       t:= dig mod 100;
+       h:= dig div 100;
+       if h > 0 then begin
+         if t > 0 then
+           Result:= TensToText(h) + ' houndred ' + TensToText(t)
+         else
+           Result:= TensToText(h) + ' houndred';
+       end else
+         Result:= TensToText(t);
+     end else
+       Result:= '';
+ end;
+
+var
+   dig, h: Integer;
+begin
+   if n > 0 then begin
+       dig:= n div 1000;
+       h:= n mod 1000;
+       if dig > 0 then begin
+         if h > 0 then
+       Result:= HundredsToText(dig) + ' thousand ' + HundredsToText(h)
+         else
+           Result:= HundredsToText(dig) + ' thousand';
+       end else
+         Result:= HundredsToText(h);
+   end else
+       Result:= Number1[0];
+end;
+
+procedure Test1;
+var
+   i: Integer;
+   s: string;
+begin
+   StartLog('Test 1', cTimes + 1);
+   for i:= 0 to cTimes do begin
+     NumberToText_V1(s, i);
+   end;
+   EndLog('');
+end;
+
+procedure Test2;
+var
+   i: Integer;
+   s: string;
+begin
+   StartLog('Test 2', cTimes + 1);
+   for i:= 0 to cTimes do begin
+     NumberToText_V2(s, i);
+   end;
+   EndLog('');
+end;
+
+procedure Test3;
+var
+   i: Integer;
+   s: string;
+begin
+   StartLog('Test 3', cTimes + 1);
+   for i:= 0 to cTimes do begin
+     s:= NumberToText_V3(i);
+   end;
+   EndLog('');
+end;
+
+procedure Benchmark;
+begin
+   Test1;
+   Test2;
+   Test3;
+end;
+
+begin
+   Benchmark;
+end.
+

+ 14 - 0
tests/tbf/tb0179.pp

@@ -0,0 +1,14 @@
+{ %fail }
+
+var
+  i : integer;
+begin
+  if i=2 then
+    begin
+      for i:=1 to 10 do
+      { The next line should be forbidden }
+        for i:=1 to 9 do
+          writeln(i);
+    end;
+end.
+

+ 1 - 1
tests/test/cg/tprintf.pp

@@ -92,7 +92,7 @@ begin
     end;
 
   printf('Text containing long double: %f'+lineending,[e]);
-  sprintf(p,'Text containing long double: %f'+lineending,[e]);
+  sprintf(p,'Text containing long double: %Lf'+lineending,[e]);
   if strpos(p,'long double: 74.7')=nil then
     begin
       writeln('The output of sprintf for long double is wrong:',p);

+ 40 - 0
tests/webtbs/tw4632.pp

@@ -0,0 +1,40 @@
+{ %OPT=-Sd }
+
+{ Source provided for Free Pascal Bug Report 4678 }
+{ Submitted by "Phil H." on  2006-01-09 }
+{ e-mail: [email protected] }
+program TestVarBug2;
+
+uses
+  Variants;
+
+type
+  TMyClass = class
+  private
+    function GetValue(AnInt : Integer) : Variant;
+  public
+    property Value[AnInt : Integer] : Variant read GetValue;
+  end;
+  
+function TMyClass.GetValue(AnInt : Integer) : Variant;
+begin
+  if AnInt < 0 then
+    Result := Null
+  else
+    Result := AnInt;
+end;
+
+var
+  AClass : TMyClass;  
+  VarVal : Variant;
+begin
+  AClass := TMyClass.Create;
+
+   // This statement throws an exception with FPC.
+   // Should assign Null to VarVal as per Delphi rule:
+   // "any operation on a Null variant produces a Null variant".
+  VarVal := AClass.Value[5] + AClass.Value[-1] + 1;
+
+end.
+
+

+ 0 - 0
tests/webtbs/tw4700.pp → tests/webtbs/tw4700.pp


+ 0 - 0
tests/webtbs/tw4763.pp