[erlang-bugs] code:load_abs/1 fails for packaged modules

cyril Romain c.romain@REDACTED
Sun Dec 28 23:42:13 CET 2008


Hi,

_StepToReproduce_:
Let's assume you have /home/me/project/src/test/mymodule.erl and 
'-module(test.mymodule)' defined in mymodule.erl.
And the corresponding beam file: /home/me/project/ebin/test/mymodule.beam.
Run Erlang from the project directory with 'erl -pa ebin'.
Now in Erlang code:load_abs("/home/me/project/ebin/test/mymodule") fails 
with the following error report:

_ErrorReport_:
=ERROR REPORT==== 28-Dec-2008::22:12:10 ===
beam/beam_load.c(1035): Error loading module mymodule:
  module name in object code is test.mymodule

=ERROR REPORT==== 28-Dec-2008::22:12:10 ===
Loading of /home/cyril/ebin/test/mymodule.beam failed: badfile
{error,badfile}

_Problem_:
In kernel-2.12.5/src/code_server.erl in load_abs/3 the try_load_module/4 
call can fail if Mod0 is [] and if the module is a packaged module (i.e. 
a module within a namespace).
It is worth noting that code:load_abs/2 succeed though. Indeed 
code:load_abs("/home/me/project/ebin/test/mymodule", test.mymodule) 
returns {module,'test.mymodule'}.

Unfortunately I'm in a case where I only know the file name and not the 
module name. FYI, I'm trying to fix dialyzer to support packaged module. 
Dialyzer assumes the module name is the filename:basename, which is 
wrong for packaged modules. And dialyzer cannot guess the module name 
without loading the beam file, hence the  load_abs/1 call.

_Workaround_:
Although I could make the application loading the /path/to/mymodule.beam 
by successive call to code:load_abs("/path/to/mymodule", mymodule), then 
code:load_abs("/path/to/mymodule", to.mymodule), etc. until success, I 
think Erlang should support packages module (at least because packaged 
modules were officially introduced in OTP/Erlang).
I could also give up using packaged module, so that I can use dialyzer 
and don't have to fix the Erlang tools I want to use that do not support 
packaged module. But if packaged module are the way to go and unless 
packaged module is considered a bad or wrongly implemented or 
about-to-be-removed thing, I'll try to use them.

_FixSuggestions_:
I think in code_server.erl the load_abs/3 function should be fix so that it:
  - Successively calls try_load_module with mymodule, to.mymodule, 
path.to.mymodule, stopping on sucess. Not so elegant though...
  - Calls try_load_module with mymodule (it actually does). But if the 
module name in object code does match mymodule, try_load_module with the 
module name found in object code. So that there is at most 2 calls of 
try_load_module. Problem: the object code (and the module name) is read 
by a C function (in beam_load.c) and it seems not straightforward to let 
Erlang know about the module name read in that object code.
  - Reading the file once, and use the module name defined within; 
avoiding multiple call to try_load_module. Better solution, but is it 
possible ?

Best regards,

  Cyril




More information about the erlang-bugs mailing list