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. :-)
I ran it for a little while with if(1), and it seemed to work fine, but that was with a very mundane scenario.
va_copy is not portable either =D welcome to C
I think this code has evolved to the point at which i don't think its
even possible for this to happen anyway.
I am going to try running it without the test at all.
commit dfecc914876b164ce64c53c4f048aa38ed65d9c5
Author: Anthony Minessale <anthm@freeswitch.org>
Date: Mon Dec 13 11:20:12 2010 -0600
On Mon, Dec 13, 2010 at 1:10 AM, Tom C <mel0torme@gmail.com> wrote:
> I was attempting to build FreeSwitch on a Dockstar running Debian Squeeze,
> and ran into the sofia.c logger() compile problem as described here:
> http://jira.freeswitch.org/browse/FS-802
>
> 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.
>
> 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.
>
> 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.
>
>
> ORIGINAL logger() in sofia.c, to make it easy to see what I changed.
> static void logger(void *logarg, char const *fmt, va_list ap)
> {
> /* gcc 4.4 gets mad at us for testing if (ap) so let's try to work around
> it....*/
> void *ap_ptr = (void *) (intptr_t) ap; //Error now occurs here, because ap
> is a struct.
> if (!fmt) return;
> if (ap_ptr) { //Error used to occur here, before attempted fix above.
> switch_log_vprintf(SWITCH_CHANNEL_LOG_CLEAN,
> mod_sofia_globals.tracelevel, fmt, ap);
> } else {
> switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, mod_sofia_globals.tracelevel,
> "%s", fmt);
> }
> }
>
>
> My MODIFIED logger() function, additions and changes labelled with DOCKSTAR:
>
> static
>
> void logger(void *logarg, char const *fmt, va_list ap)
> {
> va_list temp_ap; //DOCKSTAR: Added line (replacing previous ap_ptr cast).
>
> if (!fmt) return;
>
> va_copy(temp_ap, ap); //DOCKSTAR: Added Line. Make copy of "ap" so va_arg()
> macro doesn't move pointer.
>
> if (va_arg(temp_ap, int)) { //DOCKSTAR: Modified, get first argument from
> ap, check non-null.
> switch_log_vprintf(SWITCH_CHANNEL_LOG_CLEAN,
> mod_sofia_globals.tracelevel, fmt, ap);
> } else {
> switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN,
> mod_sofia_globals.tracelevel, "%s", fmt);
> }
>
> va_end(temp_ap); //DOCKSTAR: Added line. Release our copy of "ap".
> }
>
> _______________________________________________--
> FreeSWITCH-users mailing list
> FreeSWITCH-users@lists.freeswitch.org
> http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
> UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
> http://www.freeswitch.org
>
>
Anthony Minessale II
FreeSWITCH http://www.freeswitch.org/
ClueCon http://www.cluecon.com/
Twitter: http://twitter.com/FreeSWITCH_wire
AIM: anthm
MSN:anthony_minessale@hotmail.com
GTALK/JABBER/PAYPAL:anthony.minessale@gmail.com
IRC: irc.freenode.net #freeswitch
FreeSWITCH Developer Conference
sip:888@conference.freeswitch.org
googletalk:conf+888@conference.freeswitch.org
pstn:+19193869900
_______________________________________________
FreeSWITCH-users mailing list
FreeSWITCH-users@lists.freeswitch.org
http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
http://www.freeswitch.org