BUG: in io:fread/3: doesn't return eof

Raimo Niskanen raimo@REDACTED
Tue Oct 14 11:17:28 CEST 2003


I do not doubt that you have discovered that the behaviour has changed 
between R9B-1 and R9C-0, I just wanted your help to pinpoint the bug. 
Something like:

-------------------
This shows the bug:
Erlang (BEAM) emulator version 5.3 [hipe] [threads:0]

Eshell V5.3  (abort with ^G)
1> file:write_file("kasta.txt","1 2.0 3.0 4 5.0\n").
ok
2> {ok,Io} = file:open("kasta.txt", [read]).
{ok,<0.32.0>}
3> io:fread(Io, 'adhoc> ', "~d~f~f~d~f").
{ok,[1,2.00000,3.00000,4,5.00000]}
4> io:fread(Io, 'adhoc> ', "~d~f~f~d~f").
{error,{fread,format}}

compared to R9B-1 that returns 'eof' from command 4>
-------------------



I cracked it anyway, but if I had a small example like above I might 
have cracked it yesterday.

Here is a "diff -c" that fixes the bug:

*** lib/stdlib/src/io_lib_fread.erl@@/OTP_R9C   Mon Jul  7 13:59:36 2003
--- lib/stdlib/src/io_lib_fread.erl     Tue Oct 14 08:45:12 2003
***************
*** 53,59 ****
         {more,RestFormat,N,Inputs} ->
             case More of
                 eof ->
!                   {done,fread_error(format),eof};
                 _ ->
                     %% Don't forget to count the newline.
                     {more,{More,RestFormat,N+1,Inputs}}
--- 53,59 ----
         {more,RestFormat,N,Inputs} ->
             case More of
                 eof ->
!                   {done,eof,eof};
                 _ ->
                     %% Don't forget to count the newline.
                     {more,{More,RestFormat,N+1,Inputs}}

It will be fixed in R9C-1.

-- 
/ Raimo Niskanen, Erlang/OTP, Ericsson AB



david wallin wrote:
> 
> On Monday, October 13, 2003, at 08:23 AM, Raimo Niskanen wrote:
> 
>> Erlang (BEAM) emulator version 5.3 [hipe] [threads:0]
>>
>> Eshell V5.3  (abort with ^G)
>> 1> io:fread('adhoc> ', "~d~f~f~d~f").
>> adhoc> 1 2.0 3.0 4 5.0
>> {ok,[1,2.00000,3.00000,4,5.00000]}
>> 2>
>>
> 
> I have a file with alot of entries like that, and the function below is 
> supposed to be called until all of them are read, i.e, it should return 
> the eof from io:fread/3. The behaviour of 'io:fread/3' has clearly 
> changed between R9B-1 and R9C-0.
> 
> --david.
> 
> 
>> Works fine. Please give more info about from where you read input and 
>> how you expect the end of file in the input to appear.
>>
>> -- 
>> / Raimo Niskanen, Erlang/OTP, Ericsson AB
>>
>>
>> david wallin wrote:
>>
>>> Subject says it all really. With release R9C-0 io:fread/3 doesn't 
>>> return 'eof' but an error.
>>> The following function worked fine with R9B-1 but now I get an 
>>> '{error, Error}' instead of 'eof'.
>>> get_best_fitness(Io) ->
>>>     case io:fread(Io, 'adhoc> ', "~d~f~f~d~f") of
>>>     {ok, [Generation, BestFitness, AvgFitness, ValidSol, Entropy]} ->
>>>         {Generation, BestFitness} ;
>>>     {error, Error} ->
>>>         io:format("~p.get_best_fitness: unexpected format '~p'\n", 
>>> [?MODULE, Error]),
>>>         error ;
>>>     eof -> eof
>>>     end.
>>> cheers,
>>> --david.
> 
> 




More information about the erlang-questions mailing list