Prechádzať zdrojové kódy

Merged revisions 9105,9218-9220 via svnmerge from
svn+ssh://[email protected]/FPC/svn/fpc/trunk

........
r9105 | florian | 2007-11-03 16:51:11 +0100 (Sat, 03 Nov 2007) | 2 lines

* fix Index*Word for CPUs requiring proper alignment

........
r9218 | florian | 2007-11-12 20:57:47 +0100 (Mon, 12 Nov 2007) | 2 lines

+ simple CompareByte0 test

........
r9219 | florian | 2007-11-12 21:01:57 +0100 (Mon, 12 Nov 2007) | 2 lines

* fixed CompareChar0, resolves #10151

........
r9220 | jonas | 2007-11-12 22:25:27 +0100 (Mon, 12 Nov 2007) | 3 lines

* fixed test (comparechar0 is defined as returning values <, =, > 0, not
just -1, 0, 1)

........

git-svn-id: branches/fixes_2_2@9456 -

Jonas Maebe 18 rokov pred
rodič
commit
47e447b16a
3 zmenil súbory, kde vykonal 74 pridanie a 25 odobranie
  1. 1 0
      .gitattributes
  2. 50 25
      rtl/inc/generic.inc
  3. 23 0
      tests/test/tcmp0.pp

+ 1 - 0
.gitattributes

@@ -7058,6 +7058,7 @@ tests/test/tclass7.pp svneol=native#text/plain
 tests/test/tclass8.pp svneol=native#text/plain
 tests/test/tclrprop.pp svneol=native#text/plain
 tests/test/tcmp.pp svneol=native#text/plain
+tests/test/tcmp0.pp svneol=native#text/plain
 tests/test/tendian1.pp svneol=native#text/plain
 tests/test/tenum1.pp svneol=native#text/plain
 tests/test/tenum2.pp svneol=native#text/plain

+ 50 - 25
rtl/inc/generic.inc

@@ -285,15 +285,28 @@ begin
     pend:=pword(high(PtrUInt)-sizeof(word))
   else
     pend:=psrc+len;
-  while psrc<pend do
-    begin
-      if psrc^=b then
-        begin
-          result:=psrc-pword(@buf);
-          exit;
-        end;
-      inc(psrc);
-    end;
+{$ifdef FPC_REQUIRES_PROPER_ALIGNMENT}
+  if (ptruint(psrc) mod 2)<>0 then
+    while psrc<pend do
+      begin
+        if unaligned(psrc^)=b then
+          begin
+            result:=psrc-pword(@buf);
+            exit;
+          end;
+        inc(psrc);
+      end
+  else
+{$endif FPC_REQUIRES_PROPER_ALIGNMENT}
+    while psrc<pend do
+      begin
+        if psrc^=b then
+          begin
+            result:=psrc-pword(@buf);
+            exit;
+          end;
+        inc(psrc);
+      end;
   result:=-1;
 end;
 {$endif not FPC_SYSTEM_HAS_INDEXWORD}
@@ -313,15 +326,28 @@ begin
     pend:=pdword(high(PtrUInt)-sizeof(dword))
   else
     pend:=psrc+len;
-  while psrc<pend do
-    begin
-      if psrc^=b then
-        begin
-          result:=psrc-pdword(@buf);
-          exit;
-        end;
-      inc(psrc);
-    end;
+{$ifdef FPC_REQUIRES_PROPER_ALIGNMENT}
+  if (ptruint(psrc) mod 4)<>0 then
+    while psrc<pend do
+      begin
+        if unaligned(psrc^)=b then
+          begin
+            result:=psrc-pdword(@buf);
+            exit;
+          end;
+        inc(psrc);
+      end
+  else
+{$endif FPC_REQUIRES_PROPER_ALIGNMENT}
+    while psrc<pend do
+      begin
+        if psrc^=b then
+          begin
+            result:=psrc-pdword(@buf);
+            exit;
+          end;
+        inc(psrc);
+      end;
   result:=-1;
 end;
 {$endif not FPC_SYSTEM_HAS_INDEXDWORD}
@@ -617,13 +643,12 @@ begin
   while psrc<pend do
     begin
       b:=(ptrint(psrc^)-ptrint(pdest^));
-      if (b<>0) or (psrc^=0) or (pdest^=0) then
-        begin
-          if b<0 then
-            exit(-1)
-          else
-            exit(1);
-        end;
+      if b<0 then
+        exit(-1)
+      else if b>0 then
+        exit(1);
+      if (psrc^=0) or (pdest^=0) then
+        exit(0);
       inc(pdest);
       inc(psrc);
     end;

+ 23 - 0
tests/test/tcmp0.pp

@@ -0,0 +1,23 @@
+program comparechar0bug;
+
+var str1 : pchar = 'test';
+    str2 : pchar = 'test';
+    str3 : pchar = 'testa';
+    str4 : pchar = 'asdf';
+    res : longint;
+begin
+  res:=CompareChar0(str1[0],str2[0],maxint);
+  if res<>0 then
+    halt(1);
+  res:=CompareChar0(str1[0],str3[0],maxint);
+  if res>=0 then
+    halt(1);
+  res:=CompareChar0(str4[0],str1[0],maxint);
+  if res>=0 then
+    halt(1);
+  res:=CompareChar0(str1[0],str4[0],maxint);
+  if res<=0 then
+    halt(1);
+
+  writeln('ok');
+end.