problem with filelib:fold_files/5

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

problem with filelib:fold_files/5

Bengt Kleberg-4
greetings,

the following crash has me baffled. does anybody see what kind of
mistake i am making to create this crash?

i am using SunOS 5.8 and
Erlang (THREADS,HIPE) (BEAM) emulator version 5.3.6.3


1> Fun = fun( Cfile, Acc ) ->
                io:fwrite( "Cfile: ~s~n", [Cfile] ),
                io:fwrite( "Acc: ~w~n", [Acc] ),
                [Cfile|Acc]
        end,
Regexp = regexp:sh_to_awk( "*" ),
filelib:fold_files( "tmp", Regexp, false, Fun, [] ).

Cfile: tmp/a.c
Acc: []
Cfile: tmp/subtmp.beam
Acc: [[116,109,112,47,97,46,99]]
Cfile: tmp/inc.hrl
Acc:
[[116,109,112,47,115,117,98,116,109,112,46,98,101,97,109],[116,109,112,47,97,46,99]]
Cfile: tmp/subtmp.erl
Acc:
[[116,109,112,47,105,110,99,46,104,114,108],[116,109,112,47,115,117,98,116,109,112,46,98,101,97,109],[116,109,112,47,97,46,99]]
Cfile: tmp/cnh2
Acc:
[[116,109,112,47,115,117,98,116,109,112,46,101,114,108],[116,109,112,47,105,110,99,46,104,114,108],[116,109,112,47,115,117,98,116,109,112,46,98,101,97,109],[116,109,112,47,97,46,99]]

=ERROR REPORT==== 9-Sep-2004::11:20:56 ===
Error in process <0.31.0> with exit value:
{function_clause,[{filelib,fold_files,[[],"tmp",{concat,{concat,bos,{kclosure,{comp_class,"\n"}}},eos},false,#Fun<erl_eval.12.41869059>,["tmp/cnh2","tmp/subtmp.erl","tmp/inc.hrl","tmp/subtmp.beam","tmp/a.c"]]},{erl_eval,do_apply,5},{shell,eval_loop,2}]}

** exited: {function_clause,[{filelib,fold_files,
                                       [[],
                                        "tmp",
                                        {concat,
                                            {concat,
                                                bos,
 
{kclosure,{comp_class,"\n"}}},
                                            eos},
                                        false,
                                        #Fun<erl_eval.12.41869059>,
                                        ["tmp/cnh2",
                                         "tmp/subtmp.erl",
                                         "tmp/inc.hrl",
                                         "tmp/subtmp.beam",
                                         "tmp/a.c"]]},
                              {erl_eval,do_apply,5},
                              {shell,eval_loop,2}]} **


Reply | Threaded
Open this post in threaded view
|

problem with filelib:fold_files/5

Tobias Lindahl-3
Hi Bengt!

I recently discovered this bug in filelib.erl by using Dialyzer but I did
not get around to reporting it. The problem is that filelib:fold_files/6
do not have a leaf-case for when the list of files ends. It seems that you
are the first person ever to use the function ;)

Tobias


On Thu, 9 Sep 2004, Bengt Kleberg wrote:

> greetings,
>
> the following crash has me baffled. does anybody see what kind of
> mistake i am making to create this crash?
>
> i am using SunOS 5.8 and
> Erlang (THREADS,HIPE) (BEAM) emulator version 5.3.6.3
>
>
> 1> Fun = fun( Cfile, Acc ) ->
> io:fwrite( "Cfile: ~s~n", [Cfile] ),
> io:fwrite( "Acc: ~w~n", [Acc] ),
>        [Cfile|Acc]
> end,
> Regexp = regexp:sh_to_awk( "*" ),
> filelib:fold_files( "tmp", Regexp, false, Fun, [] ).
>
> Cfile: tmp/a.c
> Acc: []
> Cfile: tmp/subtmp.beam
> Acc: [[116,109,112,47,97,46,99]]
> Cfile: tmp/inc.hrl
> Acc:
> [[116,109,112,47,115,117,98,116,109,112,46,98,101,97,109],[116,109,112,47,97,46,99]]
> Cfile: tmp/subtmp.erl
> Acc:
> [[116,109,112,47,105,110,99,46,104,114,108],[116,109,112,47,115,117,98,116,109,112,46,98,101,97,109],[116,109,112,47,97,46,99]]
> Cfile: tmp/cnh2
> Acc:
> [[116,109,112,47,115,117,98,116,109,112,46,101,114,108],[116,109,112,47,105,110,99,46,104,114,108],[116,109,112,47,115,117,98,116,109,112,46,98,101,97,109],[116,109,112,47,97,46,99]]
>
> =ERROR REPORT==== 9-Sep-2004::11:20:56 ===
> Error in process <0.31.0> with exit value:
> {function_clause,[{filelib,fold_files,[[],"tmp",{concat,{concat,bos,{kclosure,{comp_class,"\n"}}},eos},false,#Fun<erl_eval.12.41869059>,["tmp/cnh2","tmp/subtmp.erl","tmp/inc.hrl","tmp/subtmp.beam","tmp/a.c"]]},{erl_eval,do_apply,5},{shell,eval_loop,2}]}
>
> ** exited: {function_clause,[{filelib,fold_files,
>                                        [[],
>                                         "tmp",
>                                         {concat,
>                                             {concat,
>                                                 bos,
>
> {kclosure,{comp_class,"\n"}}},
>                                             eos},
>                                         false,
>                                         #Fun<erl_eval.12.41869059>,
>                                         ["tmp/cnh2",
>                                          "tmp/subtmp.erl",
>                                          "tmp/inc.hrl",
>                                          "tmp/subtmp.beam",
>                                          "tmp/a.c"]]},
>                               {erl_eval,do_apply,5},
>                               {shell,eval_loop,2}]} **
>


Reply | Threaded
Open this post in threaded view
|

problem with filelib:fold_files/5

Bengt Kleberg-4
Tobias Lindahl wrote:
> Hi Bengt!
>
> I recently discovered this bug in filelib.erl by using Dialyzer but I did
> not get around to reporting it. The problem is that filelib:fold_files/6

i hope it is considered reported now.


bengt


Reply | Threaded
Open this post in threaded view
|

problem with filelib:fold_files/5

Chris Pressey
In reply to this post by Tobias Lindahl-3
On Thu, 9 Sep 2004 11:48:59 +0200 (MEST)
Tobias Lindahl <tobias.lindahl> wrote:

> Hi Bengt!
>
> I recently discovered this bug in filelib.erl by using Dialyzer but I did
> not get around to reporting it. The problem is that filelib:fold_files/6
> do not have a leaf-case for when the list of files ends. It seems that you
> are the first person ever to use the function ;)
>
> Tobias

Not at all, Dominic Williams reported this bug in February:

http://www.erlang.org/ml-archive/erlang-questions/200402/msg00029.html

and I reported it a year ago:

http://www.erlang.org/ml-archive/erlang-questions/200309/msg00198.html

-Chris


Reply | Threaded
Open this post in threaded view
|

problem with filelib:fold_files/5

Raimo Niskanen-3
In reply to this post by Bengt Kleberg-4
Found. It will be fixed in R10B.

--

/ Raimo Niskanen, Erlang/OTP, Ericsson AB


Reply | Threaded
Open this post in threaded view
|

problem with filelib:fold_files/5

Dominic Williams
In reply to this post by Chris Pressey

Le 9 sept. 04, ? 17:09, Chris Pressey a ?crit :

> Not at all, Dominic Williams reported this bug in February:
>
> http://www.erlang.org/ml-archive/erlang-questions/200402/msg00029.html
>
> and I reported it a year ago:
>
> http://www.erlang.org/ml-archive/erlang-questions/200309/msg00198.html

Indeed.

Here's a patch (there are actually two distinct bugs):

46c46
< ????? {ok, _} ->
---
 > ????? {ok, #file_info{type=regular}} ->
87c87,89
<???? end.
---
 >???? end;
 > fold_files([],_,_,_,_,Acc) ->
 >???? Acc.

Cheers,

Dominic Williams
http://www.dominicwilliams.net
----

Dominic Williams
http://www.dominicwilliams.net
----



Reply | Threaded
Open this post in threaded view
|

problem with filelib:fold_files/5

Raimo Niskanen-3
That seems to correct the wrong bug, that is, the fix on line 46.

The documentation for filelib:is_file/1 says that it should return 'true'
iff the file is 'regular' or 'directory', so the test for 'directory' is
missing in your fix.

Later, however, in filelib:fold_files/6, is_file/1 is used as if it
was defined according to your fix, so fold_files/6 also has to be
rewritten according to the documented behaviour of is_file/1. I dare
not change that strange but documented behaviour.

To the next release (or maybe now) I will probably add is_regular/1 to
filelib.

I think the fix on lines 87 to 89 is correct.



erlang-list (Dominic Williams) writes:

> Le 9 sept. 04, ? 17:09, Chris Pressey a ?crit :
>
> > Not at all, Dominic Williams reported this bug in February:
> >
> > http://www.erlang.org/ml-archive/erlang-questions/200402/msg00029.html
> >
> > and I reported it a year ago:
> >
> > http://www.erlang.org/ml-archive/erlang-questions/200309/msg00198.html
>
> Indeed.
>
> Here's a patch (there are actually two distinct bugs):
>
> 46c46
> < ????? {ok, _} ->
> ---
>  > ????? {ok, #file_info{type=regular}} ->
> 87c87,89
> <???? end.
> ---
>  >???? end;
>  > fold_files([],_,_,_,_,Acc) ->
>  >???? Acc.
>
> Cheers,
>
> Dominic Williams
> http://www.dominicwilliams.net
> ----
>
> Dominic Williams
> http://www.dominicwilliams.net
> ----
>

--

/ Raimo Niskanen, Erlang/OTP, Ericsson AB