erl_driver documentation

Ulf Wiger (AL/EAB) ulf.wiger@REDACTED
Wed Apr 12 12:53:36 CEST 2006


Is there some errata concerning the erl_driver 
documentation? I'm trying to acquaint myself with
the port_call() function and driver_output_term()
functions. The first bug I noticed was that the 
type ErlDriverTerm should rather be ErlDrvTermData.

Also, the example for driver_output_term():

    ErlDriverBinary* bin = ...
    ErlDriverPort port = ...
    ErlDriverTerm spec[] = {
        ERL_DRV_ATOM, driver_mk_atom("tcp"),
        ERL_DRV_PORT, driver_mk_port(port),
            ERL_DRV_INT, 100,
            ERL_DRV_BINARY, bin, 50, 0,
            ERL_DRV_LIST, 2,
        ERL_DRV_TUPLE, 3,
    };
    driver_output_term(port, spec, sizeof(spec) / sizeof(spec[0]));

has a few things wrong with it, as far as I can tell.
But my C programming is rusty to say the least, and 
I'm having to spend significant time comparing the 
manual with the sources and trying to figure out if
they are consistent, or if it's just me.

I noted that inet_drv.c has a different way of 
building the term array:

    ErlDrvTermData spec[6];
    int i = 0;

    i = LOAD_ATOM(spec, i, am_tcp_closed);
    i = LOAD_PORT(spec, i, desc->inet.dport);
    i = LOAD_TUPLE(spec, i, 2);
    ASSERT(i <= 6);
    return driver_output_term(desc->inet.port, spec, i);

(based on some local macros, e.g.

    #define LOAD_ATOM(vec, i, atom) \
      (((vec)[(i)] = ERL_DRV_ATOM), \
      ((vec)[(i)+1] = (atom)), \
      (i+2))
)

Btw, some of the comments in erl_driver.h are also
out of sync with the actual source. Just one example
is the ErlDriverBinary (also shown above), which is 
really named ErlDrvBinary, but referred to in erl_driver.h
(line 346) as ErlDriverBinary, and the ErlDriverTerm type
above (which is really ErlDrvTermData) is referred to in
the comments of erl_driver.h (line 327) as ErlDrvTerm.

BR,
/Ulf W



More information about the erlang-questions mailing list