[Kamailio-Devel] why setting int val to pvar also sets str val?

Daniel-Constantin Mierla miconda at gmail.com
Wed Sep 3 10:16:29 CEST 2008


Hello,

On 09/03/08 09:22, Juha Heinanen wrote:
> i started to wonder how it is possible that acc module succeeds to log
> an int pvar value as a string without doing any conversion.  a look at
> pvar.c revealed this:
>
> /**
>  * convert signed int to pv_value_t
>  */
> int pv_get_sintval(struct sip_msg *msg, pv_param_t *param,
> 		pv_value_t *res, int sival)
> {
> 	int l = 0;
> 	char *ch = NULL;
>
> 	if(res==NULL)
> 		return -1;
>
> 	ch = int2str(sival, &l);
> 	res->rs.s = ch;
> 	res->rs.len = l;
>
> 	res->ri = sival;
> 	res->flags = PV_VAL_STR|PV_VAL_INT|PV_TYPE_INT;
> 	return 0;
> }
>
> question: why is cpu cycles wasted in int2str conversion for every int
> valued pvar?  would it be better to do the conversion in the application
> IF it needs str version of int val?
it was there from beginning, as the PVs were moved out of the xlog 
module where everything was needed as string. The penalty is low, at 
some point each PV callback function had a parameter for flags intended 
to use it for such purpose, convert to str only if expressly asked. It 
was removed to move that at application level, but here comes code 
review for each PV.

Cheers,
Daniel

-- 
Daniel-Constantin Mierla
http://www.asipto.com




More information about the Devel mailing list