[erlang-questions] spec of erlang:open_port/2

Salikhov Dinislam Dinislam.Salikhov@REDACTED
Fri Oct 5 16:52:34 CEST 2018


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20181005/92a84c5a/attachment.htm>


More information about the erlang-questions mailing list