mchoccac / snes9x-gtk

Automatically exported from code.google.com/p/snes9x-gtk
0 stars 0 forks source link

"powerof2" macro in BSD <sys/param.h> conflicts with gtk_sound.h #8

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Fetch snes9x-1.51-src-gtk-delta-73.tar.bz2
2. Follow the instructions for "building from patch" at
http://www.snes9x.com/phpbb2/viewtopic.php?t=3703&start=0&postdays=0&postorder=a
sc&highlight=

What is the expected output? What do you see instead?
=> When I run "make", there is a syntax error before "int" at line 10 of
gtk_sound.h, included from gtk_config.cpp

What version of the product are you using? On what operating system?
=> This bug happens with delta-73. (I skipped delta-72, but I know that
delta-71 does not have this bug.) My operating system is a snapshot of
OpenBSD 4.5-current from May 2009.

Please provide any additional information below.

gtk_sound.h declares a "powerof2" function, but because of my bad luck,
something defined a "powerof2" macro, so cpp expanded the macro and ruined
the function declaration.

I traced the problem to the OpenBSD kernel header file <sys/param.h>, which
defines this "powerof2" macro:

#define powerof2(x)     ((((x)-1)&(x))==0)

GDK header files eventually include <glib/gmacros.h>, which attempts to
define NULL by including both <stddef.h> and <sys/param.h>. OpenBSD defines
NULL in both files, but also defines "powerof2" in <sys/param.h>.

The purpose of the "powerof2" macro in OpenBSD is different from the
purpose of the "powerof2" function in gtk_sound.cpp; the one in OpenBSD
tests if the argument is a power of 2, but the one in gtk_sound.cpp raises
2 to the argument.

To solve the conflict, I renamed "powerof2" to "base2exp":

--- gtk_sound.cpp.prev  Fri May 29 04:44:01 2009
+++ gtk_sound.cpp   Thu Jun 25 11:49:36 2009
@@ -43,7 +43,7 @@
 }

 int
-powerof2 (int num)
+base2exp (int num)
 {
     return (1 << num);
 }
--- gtk_sound.h.prev    Sun May 24 05:37:35 2009
+++ gtk_sound.h Thu Jun 25 11:49:19 2009
@@ -7,7 +7,7 @@
 void S9xSoundStop (void);

 int base2log (int num);
-int powerof2 (int num);
+int base2exp (int num);

 extern int playback_rates[8];
 extern int buffer_sizes[8];
--- gtk_sound_driver_oss.cpp.prev   Fri May 29 06:16:55 2009
+++ gtk_sound_driver_oss.cpp    Thu Jun 25 11:50:02 2009
@@ -140,7 +140,7 @@
      * of fragments to generate, second 16 are the respective power-of-two. */
     temp = (4 << 16) | ((base2log (so.buffer_size / 4)));

-    so.buffer_size = powerof2 (temp & 0xffff) * 4;
+    so.buffer_size = base2exp (temp & 0xffff) * 4;

     printf ("    --> (Buffer size: %d bytes, %dms latency)...",
             so.buffer_size,
--- gtk_sound_driver_sdl.cpp.prev   Fri May 29 07:01:57 2009
+++ gtk_sound_driver_sdl.cpp    Thu Jun 25 11:50:22 2009
@@ -87,7 +87,7 @@
     audiospec->channels = so.stereo ? 2 : 1;
     audiospec->format = so.sixteen_bit ? AUDIO_S16SYS : AUDIO_U8;
     audiospec->samples = gui_config->sound_buffer_size * audiospec->freq /
1000;
-    audiospec->samples = powerof2 (base2log (audiospec->samples));
+    audiospec->samples = base2exp (base2log (audiospec->samples));
     so.buffer_size = (audiospec->samples << (so.stereo ? 1 : 0)) <<
(so.sixteen_bit ? 1 : 0);
     audiospec->callback = sdl_audio_callback;
     audiospec->userdata = this;

This fixes the bug for me. With this fix, I was able to build, install and
run delta-73.

However, my build of delta-73 produced no sound (using either PortAudio or
SDL), except sometimes a ringing noise while opening the Preferences
window. I decided to downgrade from delta-73 to delta-71 so that I have sound.

Original issue reported on code.google.com by kern...@gmail.com on 25 Jun 2009 at 6:12

GoogleCodeExporter commented 9 years ago
Both of these issues should be fixed in SVN now.

Original comment by bear...@gmail.com on 3 Jul 2009 at 12:54