DockStar compile failure, with possible fix
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". }
If you want, please take a look at posts on this http://freeswitch-users.2379917.n2.nabble.com/Failed-to-compile-sofia-c-for-... thread . ----- don't and stop are the ONLY two 4-letter words considered offensive to men, but not when used together. -- View this message in context: http://freeswitch-users.2379917.n2.nabble.com/DockStar-compile-failure-with-... Sent from the freeswitch-users mailing list archive at Nabble.com.
Yes, I saw that thread when I was researching the problem. Since parameters are passed in different ways on different platforms, it makes sense for va_list to be a different memory structure on different platforms. So it really is not a compiler bug. It is a portability issue in FreeSwitch that va_list is assumed to be a char * in this one location. Is there something more I should do, to re-open the issue and submit my suggested fix? On Mon, Dec 13, 2010 at 6:12 AM, mazilo <Nabble@slickdeals.endjunk.com>wrote:
If you want, please take a look at posts on this
http://freeswitch-users.2379917.n2.nabble.com/Failed-to-compile-sofia-c-for-... thread .
----- don't and stop are the ONLY two 4-letter words considered offensive to men, but not when used together. -- View this message in context: http://freeswitch-users.2379917.n2.nabble.com/DockStar-compile-failure-with-... Sent from the freeswitch-users mailing list archive at Nabble.com.
_______________________________________________ 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
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
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. On Mon, Dec 13, 2010 at 9:30 AM, Anthony Minessale < anthony.minessale@gmail.com> wrote:
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 <MSN%3Aanthony_minessale@hotmail.com> GTALK/JABBER/PAYPAL:anthony.minessale@gmail.com<PAYPAL%3Aanthony.minessale@gmail.com> IRC: irc.freenode.net #freeswitch
FreeSWITCH Developer Conference sip:888@conference.freeswitch.org <sip%3A888@conference.freeswitch.org> googletalk:conf+888@conference.freeswitch.org<googletalk%3Aconf%2B888@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
indeed, http://www.delorie.com/gnu/docs/glibc/libc_675.html In either case I think we now can function without the code at all. On Mon, Dec 13, 2010 at 1:26 PM, Tom C <mel0torme@gmail.com> wrote:
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.
On Mon, Dec 13, 2010 at 9:30 AM, Anthony Minessale <anthony.minessale@gmail.com> wrote:
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
_______________________________________________ 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
participants (3)
-
Anthony Minessale
-
mazilo
-
Tom C