why can not call erl_init() in drivers

View: New views
2 Messages — Rating Filter:   Alert me  

why can not call erl_init() in drivers

by 曹煦 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi
 
   I found the erl_interface lib can not be used when I was working on
some c-drivers for erlang, since there is no response when calling
erl_init().
   Instead, we can only use the ei lib. So, is there any articles or
references to introduce the reason?

________________________________________________________________
erlang-questions mailing list. See http://www.erlang.org/faq.html
erlang-questions (at) erlang.org


Re: why can not call erl_init() in drivers

by Per Hedeland :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

caox <caox@...> wrote:
>
>   I found the erl_interface lib can not be used when I was working on
>some c-drivers for erlang, since there is no response when calling
>erl_init().

This is probably because there is an erl_init() function in the emulator
itself (in erts/emulator/beam/erl_init.c) that does "something
completely different", and that's the one you end up calling. I happened
to notice that as I wanted to use erl_interface in a driver a while
back, never actually tried calling erl_init() though.:-)

In my case it never was a problem, because in the driver I actually
dynamically loaded a library (i.e. via dlopen()) that was built from
erl_interface and some other stuff, and so while the driver does call
the erl_init() in erl_interface, it does it via the pointer returned by
dlsym(), not a direct call - hence no collision possible (for erl_init()
or any other function that happens to have the same name as one in the
emulator).

There are probably other ways to avoid the issue, e.g. you could have
the 3 lines of code that erl_init() consist of in your driver instead -
or maybe it would work if you link your driver statically with
erl_interface.

--Per

________________________________________________________________
erlang-questions mailing list. See http://www.erlang.org/faq.html
erlang-questions (at) erlang.org