Browse Source

* use the first element of the filrec._private array to track eof for typed files in iso mode (this will not hurt as iso mode does not specify the _private field), resolves #32938

git-svn-id: trunk@37915 -
florian 7 years ago
parent
commit
273045c295
4 changed files with 45 additions and 3 deletions
  1. 1 0
      .gitattributes
  2. 1 3
      rtl/inc/iso7185.pp
  3. 8 0
      rtl/inc/typefile.inc
  4. 35 0
      tests/webtbs/tw32938.pp

+ 1 - 0
.gitattributes

@@ -15932,6 +15932,7 @@ tests/webtbs/tw3281.pp svneol=native#text/plain
 tests/webtbs/tw32821.pp svneol=native#text/pascal
 tests/webtbs/tw32821.pp svneol=native#text/pascal
 tests/webtbs/tw3286.pp svneol=native#text/plain
 tests/webtbs/tw3286.pp svneol=native#text/plain
 tests/webtbs/tw3292.pp svneol=native#text/plain
 tests/webtbs/tw3292.pp svneol=native#text/plain
+tests/webtbs/tw32938.pp svneol=native#text/pascal
 tests/webtbs/tw3294a.pp svneol=native#text/plain
 tests/webtbs/tw3294a.pp svneol=native#text/plain
 tests/webtbs/tw3298.pp svneol=native#text/plain
 tests/webtbs/tw3298.pp svneol=native#text/plain
 tests/webtbs/tw3301.pp svneol=native#text/plain
 tests/webtbs/tw3301.pp svneol=native#text/plain

+ 1 - 3
rtl/inc/iso7185.pp

@@ -204,10 +204,8 @@ unit iso7185;
 
 
 
 
     Function Eof(var f:TypedFile): Boolean;[IOCheck];
     Function Eof(var f:TypedFile): Boolean;[IOCheck];
-      Type
-        UnTypedFile = File;
       Begin
       Begin
-        Eof:=System.Eof(UnTypedFile(f));
+        Eof:=FileRec(f)._private[1]=1;
       End;
       End;
 
 
 begin
 begin

+ 8 - 0
rtl/inc/typefile.inc

@@ -102,6 +102,9 @@ Begin
   if FileRec(f).mode=0 then
   if FileRec(f).mode=0 then
     DoAssign(f);
     DoAssign(f);
 
 
+  { use _private[1] to track eof }
+  FileRec(f)._private[1]:=0;
+
   Reset(UnTypedFile(f),Size);
   Reset(UnTypedFile(f),Size);
   BlockRead(UntypedFile(f),(pbyte(@f)+sizeof(FileRec))^,1);
   BlockRead(UntypedFile(f),(pbyte(@f)+sizeof(FileRec))^,1);
 End;
 End;
@@ -129,6 +132,9 @@ Begin
   if FileRec(f).mode=0 then
   if FileRec(f).mode=0 then
     Assign(f,FileName);
     Assign(f,FileName);
 
 
+  { use _private[1] to track eof }
+  FileRec(f)._private[1]:=0;
+
   Reset(UnTypedFile(f),Size);
   Reset(UnTypedFile(f),Size);
   BlockRead(UntypedFile(f),(pbyte(@f)+sizeof(FileRec))^,1);
   BlockRead(UntypedFile(f),(pbyte(@f)+sizeof(FileRec))^,1);
 End;
 End;
@@ -183,6 +189,8 @@ Begin
   move((pbyte(@f)+sizeof(TypedFile))^,Buf,TypeSize);
   move((pbyte(@f)+sizeof(TypedFile))^,Buf,TypeSize);
   if not(eof(f)) then
   if not(eof(f)) then
     BlockRead(f,(pbyte(@f)+sizeof(FileRec))^,1)
     BlockRead(f,(pbyte(@f)+sizeof(FileRec))^,1)
+  else
+    FileRec(f)._private[1]:=1;
 End;
 End;
 
 
 
 

+ 35 - 0
tests/webtbs/tw32938.pp

@@ -0,0 +1,35 @@
+{$mode iso}
+program test(output);
+
+label 99;
+
+type byte = 0..255;
+
+var f: file of byte;
+    b: byte;
+    i: integer;
+
+begin
+
+   rewrite(f);
+   for b := 1 to 10 do write(f, b);
+   reset(f);
+   for i := 1 to 10 do begin
+
+      if eof(f) then begin
+
+         writeln('End of file');
+         goto 99
+
+      end;
+      read(f, b);
+      write(b:1, ' ')
+
+   end;
+   99:
+   if b<>10 then
+     halt(1);
+   write;
+   writeln('ok');
+end.
+