Hi!
When trying to save a file in a linux-x86_64 environment, an application returns an error. I've noticed that the error appears when the file exceeds the maximum value of a longint. Looking at the assembler window of Lazarus I've assumed that the error was related to the procedure TStream.WriteBuffer(const Buffer; Count: Longint); that is found in rtl/objpas/classes/streams.inc.
Because the situation appears to be simmilar I've modified both TStream.WriteBuffer(const Buffer; Count: Longint) and TStream.ReadBuffer(var Buffer; Count: Longint);
from
procedure TStream.ReadBuffer(var Buffer; Count: Longint);
Var
r,t : longint;
begin
t:=0;
repeat
r:=Read(PByte(@Buffer)[t],Count-t);
inc(t,r);
until (t=Count) or (r<=0);
if (t<Count) then
Raise EReadError.Create(SReadError);
end;
procedure TStream.WriteBuffer(const Buffer; Count: Longint);
var
r,t : Longint;
begin
T:=0;
Repeat
r:=Write(PByte(@Buffer)[t],Count-t);
inc(t,r);
Until (t=count) or (r<=0);
if (t<Count) then
Raise EWriteError.Create(SWriteError);
end;
to
procedure TStream.ReadBuffer(var Buffer; Count: NativeInt);
Var
r,t : NativeInt;
begin
t:=0;
repeat
r:=Count-t;
if r>maxlongint then r:=maxlongint;
r:=Read(PByte(@Buffer)[t],r);
inc(t,r);
until (t=Count) or (r<=0);
if (t<Count) then
Raise EReadError.Create(SReadError);
end;
procedure TStream.WriteBuffer(const Buffer; Count: NativeInt);
var
r,t : NativeInt;
begin
T:=0;
Repeat
r:=Count-t;
if r>maxlongint then r:=maxlongint;
r:=Write(PByte(@Buffer)[t],r);
inc(t,r);
Until (t=count) or (r<=0);
if (t<Count) then
Raise EWriteError.Create(SWriteError);
end;
I've built fpc clean and after that I've rebuilt Lazarus clean but the application returned the same error when trying to write files with a size greater than the maximum value of a longint. I've looked at the assembler window of Lazarus again and to my surprise I've seen a "CLASSES$_$TSTREAM_$__$$_WRITEBUFFER$formal$LONGINT" line followed by the same assembly code. It's like I haven't changed anything in the streams.inc file.
What am I doing wrong, how comes that the assembly code remained the same? Remember that it's a x86_64 target. I'm using relatively new fpc and Lazarus sources and the error in the application appears at a TFilestream.WriteBuffer routine. Could it be that an optimized assembly procedure is used instead of a generic pascal-written procedure!? By the way, I think there is or was a bug report related to this situation, the new interface of the bug tracking system is...new to me
.