spec of erlang:open_port/2

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

spec of erlang:open_port/2

Salikhov Dinislam
Hello.


erlang:open_port/2 has following spec (not related parts are omitted):
    -spec open_port(PortName, PortSettings) -> port() when
        PortName :: {spawn, Command :: string() | binary()} | ...

, so Command can be either string() or binary().

On the other hand, the name of a driver is extracted as follows (erts/emulator/beam/erl_bif_port.c):
    if ((name_buf = erts_convert_filename_to_encoding(name, NULL, 0, ERTS_ALC_T_TMP,0,1, encoding, NULL, 0))

The argument 1, before encoding, is an allow_atom flag, so there is no runtime error when Command being an atom is passed (of course, if the driver exists).

Is there a rationale for such limits of Command's type?
For me, it seems logical if Command would have type driver:
    driver() = iolist() | atom()


Dinislam Salikhov

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions