Bug
Joe Armstrong (AL/EAB)
joe.armstrong@REDACTED
Wed Dec 29 09:45:42 CET 2004
I have found an interesting bug - to illustrate it here are two modules bug.erl and bug1.erl
If you compile bug.erl and evaluate bug:module_info() you'll see what gets exported from bug.erl - so
far so good.
Now compile and run bug1.erl - bug1.erl calls bug:c() but there is no routine called c/0 in bug.erl
Then evauate bug:module_info() again - look at the exports - bug.erl now mysteriously exports c/0.
So calling a routine which does not exist has the side effect of corrupting the module_info() data in
an already loaded module - ooops :-)
Happy New Year
/Joe
Here's a fun bug:
--- bug.erl
-module(bug).
-export([a/0]).
a() ->
1.
---- bug1.erl
-module(bug1).
-export([b/0]).
b() ->
bug:c().
----------------------------
Compile bug and llook at what is exported
Eshell V5.4 (abort with ^G)
1> c(bug).
{ok,bug}
2> bug:module_info().
[{exports,[{a,0},{module_info,0},{module_info,1}]},
{imports,[]},
{attributes,[{vsn,[275716032013154121462940958450039619938]}]},
{compile,[{options,[]},
{version,"4.3"},
{time,{2004,12,23,18,35,59}},
{source,"/home/joe/blogger/src/styles/bug.erl"}]}]
Compile and run bug1
3> c(bug1).
{ok,bug1}
4> bug1:b().
** exited: {undef,[{bug,c,[]},
{erl_eval,do_apply,5},
{shell,exprs,6},
{shell,eval_loop,3}]} **
Now look at what is exported from module bug
5> bug:module_info().
[{exports,[{c,0},{a,0},{module_info,0},{module_info,1}]},
*****
{imports,[]},
{attributes,[{vsn,[275716032013154121462940958450039619938]}]},
{compile,[{options,[]},
{version,"4.3"},
{time,{2004,12,23,18,35,59}},
{source,"/home/joe/blogger/src/styles/bug.erl"}]}]
c/0 now appears to be exported from bug !!!
Happy Christmas
/Joe
More information about the erlang-questions
mailing list