[Freeswitch-users] DockStar compile failure, with possible fix

Anthony Minessale anthony.minessale at gmail.com
Mon Dec 13 20:30:42 MSK 2010


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 at freeswitch.org>
Date:   Mon Dec 13 11:20:12 2010 -0600


On Mon, Dec 13, 2010 at 1:10 AM, Tom C <mel0torme at 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 at 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 at hotmail.com
GTALK/JABBER/PAYPAL:anthony.minessale at gmail.com
IRC: irc.freenode.net #freeswitch

FreeSWITCH Developer Conference
sip:888 at conference.freeswitch.org
googletalk:conf+888 at conference.freeswitch.org
pstn:+19193869900



More information about the FreeSWITCH-users mailing list