I thought the whole point of the va_start, va_end, va_arg and va_copy macros was to make variadic functions portable. (At least that's what it done said on that there inter-web thingy.) It's really sad if it doesn't actually work that way. :-)<br>
<br>I ran it for a little while with if(1), and it seemed to work fine, but that was with a very mundane scenario.<br><br><br><div class="gmail_quote">On Mon, Dec 13, 2010 at 9:30 AM, Anthony Minessale <span dir="ltr"><<a href="mailto:anthony.minessale@gmail.com">anthony.minessale@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">va_copy is not portable either =D welcome to C<br>
<br>
I think this code has evolved to the point at which i don't think its<br>
even possible for this to happen anyway.<br>
I am going to try running it without the test at all.<br>
<br>
commit dfecc914876b164ce64c53c4f048aa38ed65d9c5<br>
Author: Anthony Minessale <<a href="mailto:anthm@freeswitch.org">anthm@freeswitch.org</a>><br>
Date: Mon Dec 13 11:20:12 2010 -0600<br>
<div><div></div><div class="h5"><br>
<br>
On Mon, Dec 13, 2010 at 1:10 AM, Tom C <<a href="mailto:mel0torme@gmail.com">mel0torme@gmail.com</a>> wrote:<br>
> I was attempting to build FreeSwitch on a Dockstar running Debian Squeeze,<br>
> and ran into the sofia.c logger() compile problem as described here:<br>
> <a href="http://jira.freeswitch.org/browse/FS-802" target="_blank">http://jira.freeswitch.org/browse/FS-802</a><br>
><br>
> The offered solution was to downgrade GCC, but being a Linux newbie, I<br>
> didn't know how to do that. So I decided to figure out what the problem<br>
> really is.<br>
><br>
> After learning waaaay too much about va_list, I see that the logger()<br>
> function in sofia.c assumes that va_list will always be a pointer. But on<br>
> different platforms, va_list can be an array or a struct. On the Dockstar<br>
> (with Debian Squeeze and GCC 4.4), va_list is apparently a struct.<br>
><br>
> I made the following modifications to logger() to make it truly portable,<br>
> and it compiles and runs fine on my DockStar, my Debian Lenny x86. (My<br>
> Windows build is having bigger problems.) But I'm no C guru, so someone<br>
> needs to thoroughly examine my code before anyone else takes it as gospel.<br>
> Am I actually checking what needs to be checked with the va_arg() macro?<br>
> Changing it to if(1) worked too, after all.<br>
><br>
><br>
> ORIGINAL logger() in sofia.c, to make it easy to see what I changed.<br>
> static void logger(void *logarg, char const *fmt, va_list ap)<br>
> {<br>
> /* gcc 4.4 gets mad at us for testing if (ap) so let's try to work around<br>
> it....*/<br>
> void *ap_ptr = (void *) (intptr_t) ap; //Error now occurs here, because ap<br>
> is a struct.<br>
> if (!fmt) return;<br>
> if (ap_ptr) { //Error used to occur here, before attempted fix above.<br>
> switch_log_vprintf(SWITCH_CHANNEL_LOG_CLEAN,<br>
> mod_sofia_globals.tracelevel, fmt, ap);<br>
> } else {<br>
> switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, mod_sofia_globals.tracelevel,<br>
> "%s", fmt);<br>
> }<br>
> }<br>
><br>
><br>
> My MODIFIED logger() function, additions and changes labelled with DOCKSTAR:<br>
><br>
> static<br>
><br>
> void logger(void *logarg, char const *fmt, va_list ap)<br>
> {<br>
> va_list temp_ap; //DOCKSTAR: Added line (replacing previous ap_ptr cast).<br>
><br>
> if (!fmt) return;<br>
><br>
> va_copy(temp_ap, ap); //DOCKSTAR: Added Line. Make copy of "ap" so va_arg()<br>
> macro doesn't move pointer.<br>
><br>
> if (va_arg(temp_ap, int)) { //DOCKSTAR: Modified, get first argument from<br>
> ap, check non-null.<br>
> switch_log_vprintf(SWITCH_CHANNEL_LOG_CLEAN,<br>
> mod_sofia_globals.tracelevel, fmt, ap);<br>
> } else {<br>
> switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN,<br>
> mod_sofia_globals.tracelevel, "%s", fmt);<br>
> }<br>
><br>
> va_end(temp_ap); //DOCKSTAR: Added line. Release our copy of "ap".<br>
> }<br>
><br>
</div></div><div class="im">> _______________________________________________<br>
> FreeSWITCH-users mailing list<br>
> <a href="mailto:FreeSWITCH-users@lists.freeswitch.org">FreeSWITCH-users@lists.freeswitch.org</a><br>
> <a href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/listinfo/freeswitch-users</a><br>
> UNSUBSCRIBE:<a href="http://lists.freeswitch.org/mailman/options/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/options/freeswitch-users</a><br>
> <a href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a><br>
><br>
><br>
<br>
<br>
<br>
</div>--<br>
Anthony Minessale II<br>
<br>
FreeSWITCH <a href="http://www.freeswitch.org/" target="_blank">http://www.freeswitch.org/</a><br>
ClueCon <a href="http://www.cluecon.com/" target="_blank">http://www.cluecon.com/</a><br>
Twitter: <a href="http://twitter.com/FreeSWITCH_wire" target="_blank">http://twitter.com/FreeSWITCH_wire</a><br>
<br>
AIM: anthm<br>
<a href="mailto:MSN%3Aanthony_minessale@hotmail.com">MSN:anthony_minessale@hotmail.com</a><br>
GTALK/JABBER/<a href="mailto:PAYPAL%3Aanthony.minessale@gmail.com">PAYPAL:anthony.minessale@gmail.com</a><br>
IRC: <a href="http://irc.freenode.net" target="_blank">irc.freenode.net</a> #freeswitch<br>
<br>
FreeSWITCH Developer Conference<br>
<a href="mailto:sip%3A888@conference.freeswitch.org">sip:888@conference.freeswitch.org</a><br>
<a href="mailto:googletalk%3Aconf%2B888@conference.freeswitch.org">googletalk:conf+888@conference.freeswitch.org</a><br>
pstn:+19193869900<br>
<div><div></div><div class="h5"><br>
_______________________________________________<br>
FreeSWITCH-users mailing list<br>
<a href="mailto:FreeSWITCH-users@lists.freeswitch.org">FreeSWITCH-users@lists.freeswitch.org</a><br>
<a href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/listinfo/freeswitch-users</a><br>
UNSUBSCRIBE:<a href="http://lists.freeswitch.org/mailman/options/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/options/freeswitch-users</a><br>
<a href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a><br>
</div></div></blockquote></div><br>