Should erl_ddll:load/2 return 'ok' when loading a permanent driver?

Alexey Romanov alexey.v.romanov@REDACTED
Mon Dec 6 17:13:41 CET 2010

The documentation says:

> If more than one process tries to load an already loaded driver withe the same Path, or if the same process tries to load it several times, the function will return ok. The emulator will keep track of the load/2 calls, so that a corresponding number of unload/2 calls will have to be done from the same process before the driver will actually get unloaded. It is therefore safe for an application to load a driver that is shared between processes or applications when needed.

However, if a _permanent_ driver is already loaded, this doesn't
happen; instead {error, permanent} is returned. If trying to use the
function as documented, I shouldn't even pattern match on it in this

    case erl_ddll:load(PrivDir, atom_to_list(?DRIVER_NAME)) of
      ok ->
        Port = open_port({spawn, create_port_cmd(DbFile)}, [binary]),
        {ok, #state{port = Port, ops = Options}};
      {error, permanent} -> %% already loaded!
        Port = open_port({spawn, create_port_cmd(DbFile)}, [binary]),
        {ok, #state{port = Port, ops = Options}};
      {error, Error} ->
        Msg = io_lib:format("Error loading ~p: ~s",
                            [?DRIVER_NAME, erl_ddll:format_error(Error)]),
        {stop, lists:flatten(Msg)}


> On failure, the return value is {error,ErrorDesc}, where ErrorDesc is an opaque term to be translated into human readable form by the format_error/1 function.

What is the correct thing to do here? The driver can't be made
non-permanent because of

Should either documentation or behavior of OTP be changed?

Yours, Alexey Romanov

More information about the erlang-questions mailing list