View Issue Details

IDProjectCategoryView StatusLast Update
0036147FPCRTLpublic2019-10-20 13:20
ReporterLuca OlivettiAssigned ToMichael Van Canneyt 
PrioritynormalSeverityminorReproducibilityalways
Status feedbackResolutionopen 
Product Version3.2.0Product Buildsvn revision 43147 (fixes_3_2) 
Target VersionFixed in Version 
Summary0036147: using readln on TMemoryStream opened with AssignStream return empty strings
DescriptionThe attached test program prints 3 lines but they are empty
---
---
---
If I remove the "stream.position:=0", or I use $H- (or line:shortstring) or I avoid the RStream procedure (i.e I put what it does in the main program) or I use fpc 3.0.4 it correctly prints

--- a
--- b
--- c
Additional InformationSee the mailing list thread starting here https://lists.freepascal.org/pipermail/fpc-pascal/2019-October/056925.html
TagsNo tags attached.
Fixed in Revision
FPCOldBugId
FPCTarget-
Attached Files
  • Project1.pas (478 bytes)
    program Project1;
    {$mode objfpc}
    {$H+}
    
    uses Classes, SysUtils, StreamIO;
    
    
    procedure RStream(s:TStream);
    var f:textfile;
        line:string;
    begin
      AssignStream(f,s);
      Reset(f);
      while not eof(f) do
      begin
        readln(f,line);
        writeln('--- ',line);
      end;
      Close(f);
    end;
    
    var
      stream: TStringStream;
    begin
      stream:=TStringStream.Create('a'#13#10'b'#13#10'c'#13#10);
      stream.position:=0;
      RStream(stream);
      stream.free;
      readln;
    end.
    
    
    Project1.pas (478 bytes)

Activities

Luca Olivetti

2019-10-08 13:31

reporter  

Project1.pas (478 bytes)
program Project1;
{$mode objfpc}
{$H+}

uses Classes, SysUtils, StreamIO;


procedure RStream(s:TStream);
var f:textfile;
    line:string;
begin
  AssignStream(f,s);
  Reset(f);
  while not eof(f) do
  begin
    readln(f,line);
    writeln('--- ',line);
  end;
  Close(f);
end;

var
  stream: TStringStream;
begin
  stream:=TStringStream.Create('a'#13#10'b'#13#10'c'#13#10);
  stream.position:=0;
  RStream(stream);
  stream.free;
  readln;
end.

Project1.pas (478 bytes)

Thaddy de Koning

2019-10-08 13:42

reporter   ~0118412

Last edited: 2019-10-08 13:44

View 4 revisions

{$mode objfpc}
{$H+}

uses Classes, SysUtils, StreamIO;


procedure RStream(s:TStream);
var f:textfile;
    line:string;
begin
  AssignStream(f,s);
  Reset(f);
  while not eof(f) do
  begin
    readln(f,line);
    writeln('--- ',line);
  end;
  Close(f);
end;

var
  stream: TStringStream;
begin
  stream:=TStringStream.Create('a'+LineEnding+'b'+LineEnding+'c'+LineEnding);
  stream.position:=0;
  RStream(stream);
  stream.free;
  readln;
end.

Works ok?

Note: You should have asked this on the forum. The bug tracker is not for programmer bugs....
Please ask to close this.

Bart Broersma

2019-10-08 14:01

reporter   ~0118416

@Thaddy: he did ask on ML.

Luca Olivetti

2019-10-08 15:16

reporter   ~0118419

Last edited: 2019-10-08 15:17

View 2 revisions

It works OK with fpc 3.0.4, it doesn't with 3.2 (as specified in the fields "Product version/product build"), so it's a regression, not a "programmer bug".

Thaddy de Koning

2019-10-08 16:45

reporter   ~0118420

It is not a regression. It is merely that 3.2.0+ are more strict. As per my example works in 3.0.4 3.2.0 and trunk of today.
See also the changes for 3.2.0

Luca Olivetti

2019-10-08 17:11

reporter   ~0118421

Last edited: 2019-10-08 17:13

View 4 revisions

What do you mean with "more strict"? Do you know that '# 13#10' and LineEnding (the only part you changed) is the same thing?
Anyway, even with LineEnding instead of '# 13#10' (note that I put a space between # and 13 just to avoid mantis transforming it into a link).

D:\streamio>d:\pp\bin\i386-win32\ppc386.exe project1.pas
Free Pascal Compiler version 3.2.0-beta [2019/10/07] for i386
Copyright (c) 1993-2018 by Florian Klaempfl and others
Target OS: Win32 for i386
Compiling project1.pas
Linking project1.exe
31 lines compiled, 0.9 sec, 150464 bytes code, 6564 bytes data

D:\streamio>project1
---
---
---

Thaddy de Koning

2019-10-08 17:15

reporter   ~0118422

You did not try my code did you?

Luca Olivetti

2019-10-08 17:41

reporter   ~0118423

Yes, the last message was with your code (which is exactly like mine but with # 13#10 changed for LineEnding)

Luca Olivetti

2019-10-08 18:38

reporter   ~0118424

The plot thickens: if I compile the same project in Linux/x86_64 it works as it should

luca@seis:~/Datos/streamio$ /usr/local/lib/fpc/3.2.0/ppcx64 Project1.pas
Free Pascal Compiler version 3.2.0-beta [2019/10/08] for x86_64
Copyright (c) 1993-2018 by Florian Klaempfl and others
Target OS: Linux for x86-64
Compiling Project1.pas
Linking Project1
31 lines compiled, 0.2 sec
luca@seis:~/Datos/streamio$ ./Project1
--- a
--- b
--- c

Bart Broersma

2019-10-08 18:39

reporter   ~0118425

@ThaddyExample program from Thaddy (note 0118412):
Output with fpc 3.0.4:
--- a
--- b
--- c

Output with fpc trunk (r42348):
---
---
---

And as Luca stated: if using shortstrings fpc trunk outputs the same as 3.0.4.

All tested on Win10 with 32-bit fpc.

Luca Olivetti

2019-10-08 18:43

reporter   ~0118426

And the same with Linux/i386

luca@seis:~/Datos/streamio$ /usr/local/lib/fpc/3.2.0/ppcross386 Project1.pas
Free Pascal Compiler version 3.2.0-beta [2019/10/08] for i386
Copyright (c) 1993-2018 by Florian Klaempfl and others
Target OS: Linux for i386
Compiling Project1.pas
Linking Project1
31 lines compiled, 0.2 sec
luca@seis:~/Datos/streamio$ ./Project1
--- a
--- b
--- c

Thaddy de Koning

2019-10-08 21:13

reporter   ~0118430

Last edited: 2019-10-08 21:15

View 2 revisions

I simply can't reproduce it on arm-linux-32 or x86_64-win64 or x86_64-linux64
Plot thickens indeed.
Did you really test..., I did, Bart did... Bart, on my machines the output is correct... I can't test Windows 32 intel though... May be an issue there
I like testing...

Michael Van Canneyt

2019-10-20 11:13

administrator   ~0118723

On what platform does it not work ?
I tried Linux, and the output is the same for all versions I tested: 3.0.4, 3.2.0-beta, 3.3.1 (trunk)

Bart Broersma

2019-10-20 13:20

reporter   ~0118724

At least it does not work on Win32.
It does work on Win64 though.

Issue History

Date Modified Username Field Change
2019-10-08 13:31 Luca Olivetti New Issue
2019-10-08 13:31 Luca Olivetti File Added: Project1.pas
2019-10-08 13:42 Thaddy de Koning Note Added: 0118412
2019-10-08 13:43 Thaddy de Koning Note Edited: 0118412 View Revisions
2019-10-08 13:43 Thaddy de Koning Note Edited: 0118412 View Revisions
2019-10-08 13:44 Thaddy de Koning Note Edited: 0118412 View Revisions
2019-10-08 14:01 Bart Broersma Note Added: 0118416
2019-10-08 15:16 Luca Olivetti Note Added: 0118419
2019-10-08 15:17 Luca Olivetti Note Edited: 0118419 View Revisions
2019-10-08 16:45 Thaddy de Koning Note Added: 0118420
2019-10-08 17:11 Luca Olivetti Note Added: 0118421
2019-10-08 17:12 Luca Olivetti Note Edited: 0118421 View Revisions
2019-10-08 17:12 Luca Olivetti Note Edited: 0118421 View Revisions
2019-10-08 17:13 Luca Olivetti Note Edited: 0118421 View Revisions
2019-10-08 17:15 Thaddy de Koning Note Added: 0118422
2019-10-08 17:41 Luca Olivetti Note Added: 0118423
2019-10-08 18:38 Luca Olivetti Note Added: 0118424
2019-10-08 18:39 Bart Broersma Note Added: 0118425
2019-10-08 18:43 Luca Olivetti Note Added: 0118426
2019-10-08 21:13 Thaddy de Koning Note Added: 0118430
2019-10-08 21:15 Thaddy de Koning Note Edited: 0118430 View Revisions
2019-10-20 11:06 Michael Van Canneyt Assigned To => Michael Van Canneyt
2019-10-20 11:06 Michael Van Canneyt Status new => assigned
2019-10-20 11:13 Michael Van Canneyt Status assigned => feedback
2019-10-20 11:13 Michael Van Canneyt FPCTarget => -
2019-10-20 11:13 Michael Van Canneyt Note Added: 0118723
2019-10-20 13:20 Bart Broersma Note Added: 0118724