[erlang-questions] Port is NULL verification in the start callback of a linked-in driver

Zhemzhitsky Sergey <>
Mon Sep 3 11:15:34 CEST 2012


Hello Sverker,

Thanks a lot for help!

Regards,
Sergey Zhemzhitsky

-----Original Message-----
From: Sverker Eriksson [mailto:] 
Sent: Monday, September 03, 2012 12:52 PM
To: Zhemzhitsky Sergey
Cc: Erlang Questions
Subject: Re: [erlang-questions] Port is NULL verification in the start callback of a linked-in driver

ErlDrvPort is an opaque type. 
Comparing it to NULL is not only unnecessary but wrong.

/Sverker, Erlang/OTP


Zhemzhitsky Sergey wrote:
> Hi erlangers,
>
>  
>
> I'm wondering whether it’s necessary to check that port is not NULL in 
> the start callback of the driver:
>
> ErlDrvData (*start)(ErlDrvPort port, char *command);
>
>  
>
> I’m asking because there are some samples that do such a verification, i.e.
>
> https://github.com/dlfen/erlang-db-driver/blob/master/c_src/base/Async
> Drv.cpp#L29
>
> https://github.com/norton/lets/blob/master/c_src/lets_drv.cc#L251
>
> and a lot of port drivers that do not.
>
>  
>
> As I understand (according to the otp sources) port parameter is only 
> a number of the port in the erts_port array
> (https://github.com/erlang/otp/blob/maint/erts/emulator/beam/io.c#L60) 
> and 0
> (zero) is a valid value for it.
>
>  
>
> So I have two questions:
>
>  
>
> 1.       Is it necessary to check that the port parameter in the start callback 
> of the driver is not NULL (not 0) and why?
>
> 2.       If 0 (zero) is a legal value for the port parameter in the start 
> callback of the driver, why there are drivers which require that 
> parameter to be not NULL (or this is a kind of a bug)?
>
>  
>
>  
>
> Best Regards,
>
> Sergey
>
>  
>
> _______________________________________________________
>
>  
>
> The information contained in this message may be privileged and conf 
> idential and protected from disclosure. If you are not the original 
> intended recipient, you are hereby notified that any review, 
> retransmission, dissemination, or other use of, or taking of any 
> action in reliance upon, this information is prohibited. If you have 
> received this communication in error, please notify the sender immediately by replying to this message and delete it from your computer.
> Thank you for your cooperation. Troika Dialog, Russia.
>
> If you need assistance please contact our Contact Center (+7495) 258 
> 0500 or go to www.troika.ru/eng/Contacts/system.wbp
>
>  
>
>   





More information about the erlang-questions mailing list