[Freeswitch-users] DockStar compile failure, with possible fix
Tom C
mel0torme at gmail.com
Mon Dec 13 10:10:07 MSK 2010
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".
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.freeswitch.org/pipermail/freeswitch-users/attachments/20101212/1d5f7fe8/attachment.html
More information about the FreeSWITCH-users
mailing list