[erlang-patches] exporting a new function in prim_file.erl

Filipe David Manana fdmanana@REDACTED
Wed Apr 21 18:43:41 CEST 2010


Ups, misspelled it.
I do have it in an exports declaration (copy paste from my prim_file.erl) :

%%% Interface towards a single file's contents. Uses ?FD_DRV.

%% Generic file contents operations
-export([open/2, close/1, my_func/1, sync/1, position/2, truncate/1,
     write/2, pwrite/2, pwrite/3, read/2, read_line/1, pread/2, pread/3,
copy/3]).

This is why I am finding it very weird.

In the shell:

5> lists:member("/opt/dev-otp/lib/erlang/lib/kernel-2.13.5/ebin",
code:get_path()).
true
6> code:which(prim_file).
preloaded
7> prim_file:
altname/1             altname/2             close/1
copy/3                del_dir/1             del_dir/2
delete/1              delete/2              get_cwd/0
get_cwd/1             get_cwd/2             ipread_s32bu_p32bu/3
list_dir/1            list_dir/2            make_dir/1
make_dir/2            make_link/2           make_link/3
make_symlink/2        make_symlink/3        module_info/0
module_info/1         open/1                open/2
open/3                open_int/4            open_mode/1
open_mode/4           position/2            pread/2
pread/3               pwrite/2              pwrite/3
read/2                read_file/1           read_file/2
read_file_info/1      read_file_info/2      read_line/1
read_link/1           read_link/2           read_link_info/1
read_link_info/2      rename/2              rename/3
set_cwd/1             set_cwd/2             start/0
stop/1                sync/1                truncate/1
write/2               write_file/2          write_file_info/2
write_file_info/3
7>

Are preloaded modules different from regular modules?

On Wed, Apr 21, 2010 at 5:26 PM, Robert Virding <rvirding@REDACTED> wrote:

> Hi Filipe,
>
> On 21 April 2010 18:18, Filipe David Manana <fdmanana@REDACTED> wrote:
> > Hello,
> >
> > I'm trying to add a new function to prim_file.erl that will be called by
> > file_io_server.erl. Therefore I export it in the first export macro.
> >
> > This new function happens to have exactly the same interface (arity and
> arg
> > type, return values) as prim_file:sync/1, so I copied the sync function
> > clause, renamed it, and added the corresponding export.
> >
> > After building and installing OTP, I get an error when calling
> > file:my_func/1:
> >
> > =ERROR REPORT==== 21-Apr-2010::16:30:53 ===
> > Error in process <0.35.0> with exit value:
> >
> {undef,[{prim_file,my_func[{file_descriptor,prim_file,{#Port<0.500>,7}}]},{file_io_server,file_request,2},{file_io_server,server_loop,1}]}
> >
> > file:my_func/1 just calls file_io_server:my_func/1 wich in turn calls
> > prim_file:my_func/1.
> >
> > It seems that prim_file is not exporting  my_func. Yet I have an explicit
> > "-define([... sync/1 my_func/1 ...])."
>
> This, -define, is used to define macros, not for exporting functions
> from a module. It should be:
>
> -export(([... sync/1 my_func/1 ...]).
>
> There is an export declaration already which exports the old
> functions. It is perfectly ok to have many export declaration, I use
> that to cluster various "classes" of exported functions.
>
> Robert
>



-- 
Filipe David Manana,
fdmanana@REDACTED

"Reasonable men adapt themselves to the world.
Unreasonable men adapt the world to themselves.
That's why all progress depends on unreasonable men."


More information about the erlang-patches mailing list