Browse Source

"SizeInt" inside the compiler references the "size of an int" on the Host platform. What we want for writing size information in PPUs for Generics is "ASizeInt" which is the "size of an int" of the target platform. This fixes Mantis #20947.

* pscanner.pas: change SizeInt to ASizeInt for tokenreadsizeint and tokenwritesizeint and change necessary other locations for record- and replaytokenbuffers
+ Added a test in the hope that some test-platforms do cross platform (e.g. win32 => win64) compilation.

git-svn-id: trunk@21651 -
svenbarth 13 years ago
parent
commit
e0b41141d2
3 changed files with 44 additions and 20 deletions
  1. 1 0
      .gitattributes
  2. 22 20
      compiler/scanner.pas
  3. 21 0
      tests/webtbs/tw20947.pp

+ 1 - 0
.gitattributes

@@ -12582,6 +12582,7 @@ tests/webtbs/tw20874b.pp svneol=native#text/pascal
 tests/webtbs/tw20889.pp svneol=native#text/pascal
 tests/webtbs/tw20889.pp svneol=native#text/pascal
 tests/webtbs/tw20909.pp svneol=native#text/pascal
 tests/webtbs/tw20909.pp svneol=native#text/pascal
 tests/webtbs/tw20940.pp svneol=native#text/pascal
 tests/webtbs/tw20940.pp svneol=native#text/pascal
+tests/webtbs/tw20947.pp svneol=native#text/pascal
 tests/webtbs/tw20962.pp svneol=native#text/plain
 tests/webtbs/tw20962.pp svneol=native#text/plain
 tests/webtbs/tw20995a.pp svneol=native#text/pascal
 tests/webtbs/tw20995a.pp svneol=native#text/pascal
 tests/webtbs/tw20995b.pp svneol=native#text/pascal
 tests/webtbs/tw20995b.pp svneol=native#text/pascal

+ 22 - 20
compiler/scanner.pas

@@ -174,16 +174,16 @@ interface
           procedure stoprecordtokens;
           procedure stoprecordtokens;
           procedure replaytoken;
           procedure replaytoken;
           procedure startreplaytokens(buf:tdynamicarray; achange_endian : boolean);
           procedure startreplaytokens(buf:tdynamicarray; achange_endian : boolean);
-          { bit length sizeint is target depend }
-          procedure tokenwritesizeint(val : sizeint);
+          { bit length asizeint is target depend }
+          procedure tokenwritesizeint(val : asizeint);
           procedure tokenwritelongint(val : longint);
           procedure tokenwritelongint(val : longint);
           procedure tokenwritelongword(val : longword);
           procedure tokenwritelongword(val : longword);
           procedure tokenwriteword(val : word);
           procedure tokenwriteword(val : word);
           procedure tokenwriteshortint(val : shortint);
           procedure tokenwriteshortint(val : shortint);
           procedure tokenwriteset(var b;size : longint);
           procedure tokenwriteset(var b;size : longint);
           procedure tokenwriteenum(var b;size : longint);
           procedure tokenwriteenum(var b;size : longint);
-          function  tokenreadsizeint : sizeint;
-          procedure tokenwritesettings(var asettings : tsettings; var size : sizeint);
+          function  tokenreadsizeint : asizeint;
+          procedure tokenwritesettings(var asettings : tsettings; var size : asizeint);
           { longword/longint are 32 bits on all targets }
           { longword/longint are 32 bits on all targets }
           { word/smallint are 16-bits on all targest }
           { word/smallint are 16-bits on all targest }
           function  tokenreadlongword : longword;
           function  tokenreadlongword : longword;
@@ -197,7 +197,7 @@ interface
           procedure tokenreadset(var b;size : longint);
           procedure tokenreadset(var b;size : longint);
           function  tokenreadenum(size : longint) : longword;
           function  tokenreadenum(size : longint) : longword;
 
 
-          procedure tokenreadsettings(var asettings : tsettings; expected_size : longint);
+          procedure tokenreadsettings(var asettings : tsettings; expected_size : asizeint);
           procedure readchar;
           procedure readchar;
           procedure readstring;
           procedure readstring;
           procedure readnumber;
           procedure readnumber;
@@ -2184,9 +2184,9 @@ In case not, the value returned can be arbitrary.
         recordtokenbuf.write(b,1);
         recordtokenbuf.write(b,1);
       end;
       end;
 
 
-    procedure tscannerfile.tokenwritesizeint(val : sizeint);
+    procedure tscannerfile.tokenwritesizeint(val : asizeint);
       begin
       begin
-        recordtokenbuf.write(val,sizeof(sizeint));
+        recordtokenbuf.write(val,sizeof(asizeint));
       end;
       end;
 
 
     procedure tscannerfile.tokenwritelongint(val : longint);
     procedure tscannerfile.tokenwritelongint(val : longint);
@@ -2209,11 +2209,11 @@ In case not, the value returned can be arbitrary.
         recordtokenbuf.write(val,sizeof(longword));
         recordtokenbuf.write(val,sizeof(longword));
       end;
       end;
 
 
-    function tscannerfile.tokenreadsizeint : sizeint;
+    function tscannerfile.tokenreadsizeint : asizeint;
       var
       var
-        val : sizeint;
+        val : asizeint;
       begin
       begin
-        replaytokenbuf.read(val,sizeof(sizeint));
+        replaytokenbuf.read(val,sizeof(asizeint));
         if tokenbuf_change_endian then
         if tokenbuf_change_endian then
           val:=swapendian(val);
           val:=swapendian(val);
         result:=val;
         result:=val;
@@ -2306,7 +2306,7 @@ In case not, the value returned can be arbitrary.
    end;
    end;
 
 
 
 
-    procedure tscannerfile.tokenreadsettings(var asettings : tsettings; expected_size : longint);
+    procedure tscannerfile.tokenreadsettings(var asettings : tsettings; expected_size : asizeint);
 
 
     {    This procedure
     {    This procedure
        needs to be changed whenever
        needs to be changed whenever
@@ -2374,7 +2374,7 @@ In case not, the value returned can be arbitrary.
          end;
          end;
      end;
      end;
 
 
-    procedure tscannerfile.tokenwritesettings(var asettings : tsettings; var size : sizeint);
+    procedure tscannerfile.tokenwritesettings(var asettings : tsettings; var size : asizeint);
 
 
     {    This procedure
     {    This procedure
        needs to be changed whenever
        needs to be changed whenever
@@ -2450,7 +2450,8 @@ In case not, the value returned can be arbitrary.
       var
       var
         t : ttoken;
         t : ttoken;
         s : tspecialgenerictoken;
         s : tspecialgenerictoken;
-        len,val,msgnb,copy_size : sizeint;
+        len,msgnb,copy_size : asizeint;
+        val : longint;
         b : byte;
         b : byte;
         pmsg : pmessagestaterecord;
         pmsg : pmessagestaterecord;
       begin
       begin
@@ -2482,7 +2483,7 @@ In case not, the value returned can be arbitrary.
             pmsg:=current_settings.pmessage;
             pmsg:=current_settings.pmessage;
             while assigned(pmsg) do
             while assigned(pmsg) do
               begin
               begin
-                if msgnb=high(sizeint) then
+                if msgnb=high(asizeint) then
                   { Too many messages }
                   { Too many messages }
                   internalerror(2011090401);
                   internalerror(2011090401);
                 inc(msgnb);
                 inc(msgnb);
@@ -2492,11 +2493,12 @@ In case not, the value returned can be arbitrary.
             pmsg:=current_settings.pmessage;
             pmsg:=current_settings.pmessage;
             while assigned(pmsg) do
             while assigned(pmsg) do
               begin
               begin
-                { What about endianess here? }
+                { What about endianess here?}
+                { SB: this is handled by tokenreadlongint }
                 val:=pmsg^.value;
                 val:=pmsg^.value;
-                tokenwritesizeint(val);
+                tokenwritelongint(val);
                 val:=ord(pmsg^.state);
                 val:=ord(pmsg^.state);
-                tokenwritesizeint(val);
+                tokenwritelongint(val);
                 pmsg:=pmsg^.next;
                 pmsg:=pmsg^.next;
               end;
               end;
             last_message:=current_settings.pmessage;
             last_message:=current_settings.pmessage;
@@ -2613,7 +2615,7 @@ In case not, the value returned can be arbitrary.
 
 
     procedure tscannerfile.replaytoken;
     procedure tscannerfile.replaytoken;
       var
       var
-        wlen,mesgnb,copy_size : sizeint;
+        wlen,mesgnb,copy_size : asizeint;
         specialtoken : tspecialgenerictoken;
         specialtoken : tspecialgenerictoken;
         i : byte;
         i : byte;
         pmsg,prevmsg : pmessagestaterecord;
         pmsg,prevmsg : pmessagestaterecord;
@@ -2717,8 +2719,8 @@ In case not, the value returned can be arbitrary.
                               end
                               end
                             else
                             else
                               prevmsg^.next:=pmsg;
                               prevmsg^.next:=pmsg;
-                            replaytokenbuf.read(pmsg^.value,sizeof(longint));
-                            replaytokenbuf.read(pmsg^.state,sizeof(tmsgstate));
+                            pmsg^.value:=tokenreadlongint;
+                            pmsg^.state:=tmsgstate(tokenreadlongint);
                             pmsg^.next:=nil;
                             pmsg^.next:=nil;
                             prevmsg:=pmsg;
                             prevmsg:=pmsg;
                           end;
                           end;

+ 21 - 0
tests/webtbs/tw20947.pp

@@ -0,0 +1,21 @@
+{ the important part of this test is a cross compilation which a change in the
+  size of the bitness, e.g. from Win32 to Win64 where the unit "fgl" was
+  compiled with the 32-to-64-bit cross compiler and this program itself is
+  compiled with the native 64-bit compiler }
+
+program tw20947;
+
+uses
+  fgl;
+
+type
+  TTestList = specialize TFPGList<Byte>;
+
+Var
+  Test : TTestList;
+begin
+  Test := TTestList.Create;
+  Test.Add(2);
+  WriteLn(Test[0]);  // This should output 2 to console
+  Test.Free;
+end.