mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-16 04:59:25 +02:00
The TStream.ReadBuffer and TStream.WriteBuffer methods have changed the Count parameter type to NativeInt.
Changed the implementation of ReadBuffer, WriteBuffer so that the size of the blocks when calling Read and Write does not exceed High(Longint). Notes: - Thanks to this change, for example, a file larger than 2GB can be loaded into TMemoryStream. - The fact that the Count parameter has the NativeInt type is compatible with the latest versions of Delphi.
This commit is contained in:
parent
fbc65314b9
commit
e27ea76b88
@ -999,7 +999,7 @@ type
|
||||
function ReadData(var Buffer: TExtended80Rec): NativeInt; overload;
|
||||
function ReadData(var Buffer: TExtended80Rec; Count: NativeInt): NativeInt; overload;
|
||||
{$ENDIF}
|
||||
procedure ReadBuffer(var Buffer; Count: Longint);
|
||||
procedure ReadBuffer(var Buffer; Count: NativeInt);
|
||||
procedure ReadBuffer(var Buffer: TBytes; Count: NativeInt); overload;
|
||||
procedure ReadBuffer(var Buffer: TBytes; Offset, Count: NativeInt); overload;
|
||||
|
||||
@ -1035,7 +1035,7 @@ type
|
||||
procedure ReadBufferData(var Buffer: TExtended80Rec); overload;
|
||||
procedure ReadBufferData(var Buffer: TExtended80Rec; Count: NativeInt); overload;
|
||||
{$ENDIF}
|
||||
procedure WriteBuffer(const Buffer; Count: Longint);
|
||||
procedure WriteBuffer(const Buffer; Count: NativeInt);
|
||||
procedure WriteBuffer(const Buffer: TBytes; Count: NativeInt); overload;
|
||||
procedure WriteBuffer(const Buffer: TBytes; Offset, Count: NativeInt); overload;
|
||||
|
||||
|
@ -404,19 +404,19 @@ begin
|
||||
end;
|
||||
{$ENDIF}
|
||||
|
||||
procedure TStream.ReadBuffer(var Buffer; Count: Longint);
|
||||
|
||||
Var
|
||||
r,t : longint;
|
||||
|
||||
procedure TStream.ReadBuffer(var Buffer; Count: NativeInt);
|
||||
var
|
||||
r,t: NativeInt;
|
||||
begin
|
||||
t:=0;
|
||||
repeat
|
||||
r:=Read(PByte(@Buffer)[t],Count-t);
|
||||
r:=Count-t;
|
||||
if r>High(Longint) then r:=High(Longint);
|
||||
r:=Read(PByte(@Buffer)[t],r);
|
||||
inc(t,r);
|
||||
until (t=Count) or (r<=0);
|
||||
if (t<Count) then
|
||||
Raise EReadError.Create(SReadError);
|
||||
raise EReadError.Create(SReadError);
|
||||
end;
|
||||
|
||||
procedure TStream.ReadBuffer(var Buffer: TBytes; Count: NativeInt);
|
||||
@ -581,20 +581,20 @@ begin
|
||||
end;
|
||||
{$ENDIF}
|
||||
|
||||
procedure TStream.WriteBuffer(const Buffer; Count: Longint);
|
||||
|
||||
procedure TStream.WriteBuffer(const Buffer; Count: NativeInt);
|
||||
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;
|
||||
w,t: NativeInt;
|
||||
begin
|
||||
t:=0;
|
||||
repeat
|
||||
w:=Count-t;
|
||||
if w>High(Longint) then w:=High(Longint);
|
||||
w:=Write(PByte(@Buffer)[t],w);
|
||||
inc(t,w);
|
||||
until (t=count) or (w<=0);
|
||||
if (t<Count) then
|
||||
raise EWriteError.Create(SWriteError);
|
||||
end;
|
||||
|
||||
procedure TStream.WriteBuffer(const Buffer: TBytes; Count: NativeInt);
|
||||
begin
|
||||
|
Loading…
Reference in New Issue
Block a user