<html>
<head>
<meta content="text/html; charset=windows-1252"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
Hi Luis,<br>
<br>
you should not care about the script interpreter inside your C code.
It does freeing of pv value, if needed (the interpreter executes
pv_value_destroy() when needed).<br>
<br>
The flags PV_VAL_PKG or PV_VAL_SHM must be set only (when needed) by
a pv or transformation implementation. It is not necessary to use
them if you call the ->setf() function from a pv, because that
setf function will copy the value to its own structure.<br>
<br>
Cheers,<br>
Daniel<br>
<br>
<div class="moz-cite-prefix">On 05/01/15 13:25, Luis Azedo wrote:<br>
</div>
<blockquote
cite="mid:6FFC6465A51B5B4C80DD111E16112FD1C4067B@mbx022-w1-ca-4.exch022.domain.local"
type="cite">
<meta http-equiv="Content-Type" content="text/html;
charset=windows-1252">
<div style="direction: ltr;font-family: Tahoma;color:
#000000;font-size: 10pt;">Hi Daniel,
<div><br>
</div>
<div>if i understand it correctly, it is safe to call
pv_value_destroy after assigning the $var(..) in module code.</div>
<div><br>
</div>
<div>i still have doubt on when and how to free the result of a
transform returned value.</div>
<div><br>
</div>
<div>
<div><span style="font-size: 10pt;">in script</span></div>
<div>
<div>if( $(myPvar{my.mytransform,transformParameter})
=="test value") {</div>
<div> $var(x) =
$(myPvar{my.mytransform,transformParameter});</div>
<div>}</div>
<div><br>
</div>
<div>in module i assign the returned value of transform
with <span style="font-size: 10pt;">dst_val->flags =
PV_VAL_STR | PV_VAL_PKG;</span></div>
<div><span style="font-size: 10pt;">since this line "</span><span
style="font-size: 10pt;">if(
$(myPvar{my.mytransform,transformParameter}) =="test
value") {" is allocating memory, will it be freed by
script with </span><span style="font-size: 10pt;">pv_value_destroy</span><span
style="font-size: 10pt;"> ?</span></div>
<div><span style="font-size: 10pt;">this line "</span><span
style="font-size: 10pt;">$var(x) =
$(myPvar{my.mytransform,transformParameter});" assigns
the returned value to a variable, will the script free
the right side of the expression ? will it use </span><span
style="font-size: 10pt;">pv_value_destroy</span><span
style="font-size: 10pt;"> ?</span></div>
<div><span style="font-size: 10pt;"><br>
</span></div>
<div><span style="font-size: 10pt;"><br>
</span></div>
<div><span style="font-size: 10pt;">Thanks</span></div>
<div style="font-size: 10pt;"><br>
</div>
</div>
<div><br>
</div>
<div style="font-family: Times New Roman; color: #000000;
font-size: 16px">
<hr tabindex="-1">
<div id="divRpF132983" style="direction: ltr;"><font
color="#000000" face="Tahoma" size="2"><b>From:</b>
sr-dev [<a class="moz-txt-link-abbreviated" href="mailto:sr-dev-bounces@lists.sip-router.org">sr-dev-bounces@lists.sip-router.org</a>] on behalf
of Daniel-Constantin Mierla [<a class="moz-txt-link-abbreviated" href="mailto:miconda@gmail.com">miconda@gmail.com</a>]<br>
<b>Sent:</b> Monday, January 05, 2015 3:59 AM<br>
<b>To:</b> Kamailio (SER) - Development Mailing List<br>
<b>Subject:</b> Re: [sr-dev] need help understanding
pv_value_destroy<br>
</font><br>
</div>
<div>Hello,<br>
<br>
if you assign to a $var(...), it makes a deep copy in pkg
memory. It is up to you to handle further the content of
dst_val and free it properly.<br>
<br>
If you set the PV_VAL_PKG (value must be in a pkg_malloc()
pointer) or PV_VAL_SHM (value must be in a shm_malloc()
pointer) for dst_val, then you can call pv_value_destroy()
to get it freed. But it is not necessary, if you free it
in the code yourself.<br>
<br>
Cheers,<br>
Daniel<br>
<br>
<div class="moz-cite-prefix">On 04/01/15 12:36, Luis Azedo
wrote:<br>
</div>
<blockquote type="cite">
<style type="text/css" id="owaParaStyle"></style>
<div style="direction:ltr; font-family:Tahoma;
color:#000000; font-size:10pt">Hi Daniel,
<div><br>
</div>
<div>can you help on this ?</div>
<div><br>
<div style="font-family:Times New Roman;
color:#000000; font-size:16px">
<hr tabindex="-1">
<div id="divRpF641763" style="direction:ltr"><font
color="#000000" face="Tahoma" size="2"><b>From:</b>
sr-dev [<a moz-do-not-send="true"
class="moz-txt-link-abbreviated"
href="mailto:sr-dev-bounces@lists.sip-router.org"
target="_blank">sr-dev-bounces@lists.sip-router.org</a>]
on behalf of Luis Azedo [<a
moz-do-not-send="true"
class="moz-txt-link-abbreviated"
href="mailto:luis@2600hz.com"
target="_blank">luis@2600hz.com</a>]<br>
<b>Sent:</b> Wednesday, December 31, 2014 4:19
AM<br>
<b>To:</b> <a moz-do-not-send="true"
class="moz-txt-link-abbreviated"
href="mailto:sr-dev@lists.sip-router.org"
target="_blank">
sr-dev@lists.sip-router.org</a><br>
<b>Subject:</b> [sr-dev] need help
understanding pv_value_destroy<br>
</font><br>
</div>
<div>
<div style="direction:ltr; font-family:Tahoma;
color:#000000; font-size:10pt">
<div>Hi,</div>
<div><br>
</div>
in some function that return a value with
PV_VAL_PKG or PV_VAL_SHM, the allocated memory
is supposed to be freed by core ?
<div><br>
</div>
<div>
<div>script example</div>
<div><br>
</div>
<div>my_function("some
param","$var(result)");</div>
<div><span style="font-size:10pt"><br>
</span></div>
<div><span style="font-size:10pt">in code
=> </span></div>
<div>dst_val->flags = PV_VAL_STR |
PV_VAL_PKG;</div>
<div><span style="font-size:10pt">dst_pv->setf(msg,
&dst_pv->pvp, (int)EQ_T,
&dst_val);</span></div>
<div><br>
</div>
<div>when $var(result) is freed, will it
free the allocated string ?</div>
<div><br>
</div>
<div><br>
</div>
<div>if(
$(myPvar{my.mytransform,transformParameter})
== $null) {</div>
<div> $var(x) = <span style="font-size:10pt">$(myPvar{my.mytransform,transformParameter});</span></div>
<div>}</div>
<div>
<div><span style="font-size:10pt"><br>
</span></div>
<div><span style="font-size:10pt">in code
=> </span></div>
<div>dst_val->flags = PV_VAL_STR |
PV_VAL_PKG;</div>
<div><br>
</div>
</div>
<div>will the memory allocated <span
style="font-size:10pt">be freed</span><span
style="font-size:10pt"> in the
comparison line ?</span></div>
<div><span style="font-size:10pt">will</span><span
style="font-size:10pt"> </span><span
style="font-size:10pt">the memory
allocated </span><span
style="font-size:10pt">be freed</span><span
style="font-size:10pt"> when $var(x) is
freed ?</span></div>
<div><span style="font-size:10pt"><br>
</span></div>
<div><span style="font-size:10pt">thank you</span></div>
<div><span style="font-size:10pt"><br>
</span></div>
</div>
</div>
</div>
</div>
</div>
</div>
<br>
<fieldset class="mimeAttachmentHeader" target="_blank"></fieldset>
<br>
<pre>_______________________________________________
sr-dev mailing list
<a moz-do-not-send="true" class="moz-txt-link-abbreviated" href="mailto:sr-dev@lists.sip-router.org" target="_blank">sr-dev@lists.sip-router.org</a>
<a moz-do-not-send="true" class="moz-txt-link-freetext" href="http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev" target="_blank">http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev</a>
</pre>
</blockquote>
<br>
<pre class="moz-signature" cols="72">--
Daniel-Constantin Mierla
<a moz-do-not-send="true" class="moz-txt-link-freetext" href="http://twitter.com/#%21/miconda" target="_blank">http://twitter.com/#!/miconda</a> - <a moz-do-not-send="true" class="moz-txt-link-freetext" href="http://www.linkedin.com/in/miconda" target="_blank">http://www.linkedin.com/in/miconda</a></pre>
</div>
</div>
</div>
</div>
</blockquote>
<br>
<pre class="moz-signature" cols="72">--
Daniel-Constantin Mierla
<a class="moz-txt-link-freetext" href="http://twitter.com/#!/miconda">http://twitter.com/#!/miconda</a> - <a class="moz-txt-link-freetext" href="http://www.linkedin.com/in/miconda">http://www.linkedin.com/in/miconda</a></pre>
</body>
</html>