[erlang-questions] Init callback return value not checked for port driver

Julien Barbot julien@REDACTED
Tue Mar 6 21:10:53 CET 2007


Hello,

I'm currently working on an erlang port driver and I need some advice
on the behaviour of the init callback in the erl_drv_entry structure.
The version of erlang used is R11B-3.

The documentation says
(http://erlang.org/doc/doc-5.5.3/erts-5.5.3/doc/html/driver_entry.html):

"This is called directly after the driver has been loaded by
erl_ddll:load_driver/2. (Actually when the driver is added to the
driver list.) The driver should return 0, or if the driver can't
initialize, -1."

If I understand well, the driver is loaded then it is added to the
driver list and the init function is called (erts_add_driver_entry()
in erts/emulator/beam/io.c).

The problem is that the return code of this callback is not checked:
erts/emulator/beam/io.c:4498

 if (drv->init != NULL) {
    (*drv->init)();
 }

What is the good behaviour ?:
- The function should never fail, so the documentation is wrong,
- The function can fail, so the call of the init function is badly placed.

Maybe it could be a better idea to call this function before adding
the driver to the driver list ?

Here is a simple patch for the R11-B3 that does check the return code
before adding the driver to the list if this is what we want.

Regards,

-- 
Julien Barbot

-------------- next part --------------
A non-text attachment was scrubbed...
Name: init_check.patch
Type: text/x-patch
Size: 1288 bytes
Desc: not available
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20070306/cd605dbf/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 190 bytes
Desc: not available
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20070306/cd605dbf/attachment-0001.bin>


More information about the erlang-questions mailing list