<div>I was attempting to build FreeSwitch on a Dockstar running Debian Squeeze, and ran into the sofia.c logger() compile problem as described here: <a href="http://jira.freeswitch.org/browse/FS-802">http://jira.freeswitch.org/browse/FS-802</a></div>
<div> </div>
<div>The offered solution was to downgrade GCC, but being a Linux newbie, I didn't know how to do that. So I decided to figure out what the problem really is.</div>
<div> </div>
<div>After learning waaaay too much about va_list, I see that the logger() function in sofia.c assumes that va_list will always be a pointer. But on different platforms, va_list can be an array or a struct. On the Dockstar (with Debian Squeeze and GCC 4.4), va_list is apparently a struct.</div>
<div> </div>
<div>I made the following modifications to logger() to make it truly portable, and it compiles and runs fine on my DockStar, my Debian Lenny x86. (My Windows build is having bigger problems.) But I'm no C guru, so someone needs to thoroughly examine my code before anyone else takes it as gospel. Am I actually checking what needs to be checked with the va_arg() macro? Changing it to if(1) worked too, after all.</div>
<div> </div>
<div> </div>
<div>ORIGINAL logger() in sofia.c, to make it easy to see what I changed.<br><font color="#0000ff" size="2" face="Courier New"><font color="#0000ff" size="2" face="Courier New"><font color="#0000ff" size="2" face="Courier New">static</font></font></font><font size="2" face="Courier New"><font size="2" face="Courier New"> </font></font><font color="#0000ff" size="2" face="Courier New"><font color="#0000ff" size="2" face="Courier New"><font color="#0000ff" size="2" face="Courier New">void</font></font></font><font size="2" face="Courier New"><font size="2" face="Courier New"> logger(</font></font><font color="#0000ff" size="2" face="Courier New"><font color="#0000ff" size="2" face="Courier New"><font color="#0000ff" size="2" face="Courier New">void</font></font></font><font size="2" face="Courier New"><font size="2" face="Courier New"> *logarg, </font></font><font color="#0000ff" size="2" face="Courier New"><font color="#0000ff" size="2" face="Courier New"><font color="#0000ff" size="2" face="Courier New">char</font></font></font><font size="2" face="Courier New"><font size="2" face="Courier New"> </font></font><font color="#0000ff" size="2" face="Courier New"><font color="#0000ff" size="2" face="Courier New"><font color="#0000ff" size="2" face="Courier New">const</font></font></font><font size="2" face="Courier New"><font size="2" face="Courier New"> *fmt, va_list ap)<br>
</font></font><font size="2" face="Courier New"><font size="2" face="Courier New">{<br></font></font><font color="#008000" size="2" face="Courier New"><font color="#008000" size="2" face="Courier New"><font color="#008000" size="2" face="Courier New">/* gcc 4.4 gets mad at us for testing if (ap) so let's try to work around it....*/<br>
</font></font></font><font color="#0000ff" size="2" face="Courier New"><font color="#0000ff" size="2" face="Courier New"><font color="#0000ff" size="2" face="Courier New">void</font></font></font><font size="2" face="Courier New"><font size="2" face="Courier New"> *ap_ptr = (</font></font><font color="#0000ff" size="2" face="Courier New"><font color="#0000ff" size="2" face="Courier New"><font color="#0000ff" size="2" face="Courier New">void</font></font></font><font size="2" face="Courier New"><font size="2" face="Courier New"> *) (intptr_t) ap; <font color="#009900">//Error now occurs here, because ap is a struct.<br>
</font></font></font><font color="#0000ff" size="2" face="Courier New"><font color="#0000ff" size="2" face="Courier New"><font color="#0000ff" size="2" face="Courier New">if</font></font></font><font size="2" face="Courier New"><font size="2" face="Courier New"> (!fmt) </font></font><font color="#0000ff" size="2" face="Courier New"><font color="#0000ff" size="2" face="Courier New"><font color="#0000ff" size="2" face="Courier New">return</font></font></font><font size="2" face="Courier New"><font size="2" face="Courier New">;<br>
</font></font><font color="#0000ff" size="2" face="Courier New"><font color="#0000ff" size="2" face="Courier New"><font color="#0000ff" size="2" face="Courier New">if</font></font></font><font size="2" face="Courier New"><font size="2" face="Courier New"> (ap_ptr) { </font></font><font color="#009900">//Error used to occur here, before attempted fix above.</font><font size="2" face="Courier New"><font size="2" face="Courier New"><br>
switch_log_vprintf(SWITCH_CHANNEL_LOG_CLEAN, mod_sofia_globals.tracelevel, fmt, ap);<br>} </font></font><font color="#0000ff" size="2" face="Courier New"><font color="#0000ff" size="2" face="Courier New"><font color="#0000ff" size="2" face="Courier New">else</font></font></font><font size="2" face="Courier New"><font size="2" face="Courier New"> {<br>
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, mod_sofia_globals.tracelevel, </font></font><font color="#a31515" size="2" face="Courier New"><font color="#a31515" size="2" face="Courier New"><font color="#a31515" size="2" face="Courier New">"%s"</font></font></font><font size="2" face="Courier New"><font size="2" face="Courier New">, fmt);<br>
}<br>}</font></font></div>
<div><font size="2" face="Courier New"><font size="2" face="Courier New"></font></font> </div>
<div><font face="Courier New"></font> </div>
<div>My MODIFIED logger() function, additions and changes labelled with DOCKSTAR:<br><font color="#0000ff" size="2" face="Courier New"><font color="#0000ff" size="2" face="Courier New"><font color="#0000ff" size="2" face="Courier New">
<p>static</p></font></font></font><font size="2" face="Courier New"><font size="2" face="Courier New"> </font></font><font color="#0000ff" size="2" face="Courier New"><font color="#0000ff" size="2" face="Courier New"><font color="#0000ff" size="2" face="Courier New">void</font></font></font><font size="2" face="Courier New"><font size="2" face="Courier New"> logger(</font></font><font color="#0000ff" size="2" face="Courier New"><font color="#0000ff" size="2" face="Courier New"><font color="#0000ff" size="2" face="Courier New">void</font></font></font><font size="2" face="Courier New"><font size="2" face="Courier New"> *logarg, </font></font><font color="#0000ff" size="2" face="Courier New"><font color="#0000ff" size="2" face="Courier New"><font color="#0000ff" size="2" face="Courier New">char</font></font></font><font size="2" face="Courier New"><font size="2" face="Courier New"> </font></font><font color="#0000ff" size="2" face="Courier New"><font color="#0000ff" size="2" face="Courier New"><font color="#0000ff" size="2" face="Courier New">const</font></font></font><font size="2" face="Courier New"><font size="2" face="Courier New"> *fmt, va_list ap)<br>
{<br>va_list temp_ap; <font color="#009900"> //DOCKSTAR: Added line (replacing previous ap_ptr cast).</font></font></font>
<p><font color="#0000ff" size="2" face="Courier New"><font color="#0000ff" size="2" face="Courier New"><font color="#0000ff" size="2" face="Courier New">if</font></font></font><font size="2" face="Courier New"><font size="2" face="Courier New"> (!fmt) </font></font><font color="#0000ff" size="2" face="Courier New"><font color="#0000ff" size="2" face="Courier New"><font color="#0000ff" size="2" face="Courier New">return</font></font></font><font size="2" face="Courier New"><font size="2" face="Courier New">;</font></font></p>
<p><font size="2" face="Courier New"><font size="2" face="Courier New">va_copy(temp_ap, ap); <font color="#009900">//DOCKSTAR: Added Line. Make copy of "ap" so va_arg() macro doesn't move pointer.</font></font></font></p>
<p><font color="#0000ff" size="2" face="Courier New"><font color="#0000ff" size="2" face="Courier New"><font color="#0000ff" size="2" face="Courier New">if</font></font></font><font size="2" face="Courier New"><font size="2" face="Courier New"> (va_arg(temp_ap, int)) { <font color="#009900">//DOCKSTAR: Modified, get first argument from ap, check non-null.<br>
</font> switch_log_vprintf(SWITCH_CHANNEL_LOG_CLEAN, mod_sofia_globals.tracelevel, fmt, ap);<br>} </font></font><font color="#0000ff" size="2" face="Courier New"><font color="#0000ff" size="2" face="Courier New"><font color="#0000ff" size="2" face="Courier New">else</font></font></font><font size="2" face="Courier New"><font size="2" face="Courier New"> {<br>
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, mod_sofia_globals.tracelevel, </font></font><font color="#a31515" size="2" face="Courier New"><font color="#a31515" size="2" face="Courier New"><font color="#a31515" size="2" face="Courier New">"%s"</font></font></font><font size="2" face="Courier New"><font size="2" face="Courier New">, fmt);<br>
}</font></font></p>
<p><font face="Courier New">va_end(temp_ap); <font color="#009900">//DOCKSTAR: Added line. Release our copy of "ap".<br></font></font><font size="2" face="Courier New"><font size="2" face="Courier New">}</font></font></p>
</div>