GNOME Bugzilla – Bug 504176
"#define IN_HEADER defined" irritates SunCC-12
Last modified: 2010-08-26 04:05:49 UTC
This idiom #define IN_HEADER defined irritates SunCC/SunStudio 12, which complains thusly: "galias.h", line 12: warning: non-portable use of "defined" operator in macro "galias.h", line 124: warning: non-portable use of "defined" operator in macro "galias.h", line 193: warning: non-portable use of "defined" operator in macro "galias.h", line 209: warning: non-portable use of "defined" operator in macro and so on --- glib/galias.h.orig 2007-11-24 16:31:35.000000000 +0000 +++ glib/galias.h @@ -7,7 +7,7 @@ #ifdef G_HAVE_GNUC_VISIBILITY #define IN_FILE(x) 1 -#define IN_HEADER defined +#define IN_HEADER(x) (x##___X != ___X) #if IN_HEADER(__G_ARRAY_H__) #if IN_FILE(__G_ARRAY_C__) --- glib/galiasdef.c.orig 2007-11-24 16:31:35.000000000 +0000 +++ glib/galiasdef.c @@ -7,7 +7,7 @@ #ifdef G_HAVE_GNUC_VISIBILITY #undef IN_FILE -#define IN_FILE defined +#define IN_FILE(x) (x##___X != ___X) #undef IN_HEADER #define IN_HEADER(x) 1 --- gobject/gobjectaliasdef.c.orig 2007-11-24 16:31:41.000000000 +0000 +++ gobject/gobjectaliasdef.c @@ -7,7 +7,7 @@ #ifdef G_HAVE_GNUC_VISIBILITY #undef IN_FILE -#define IN_FILE defined +#define IN_FILE(x) (x##___X != ___X) #undef IN_HEADER #define IN_HEADER(x) 1 --- gobject/gobjectalias.h.orig 2007-11-24 16:31:41.000000000 +0000 +++ gobject/gobjectalias.h @@ -7,7 +7,7 @@ #ifdef G_HAVE_GNUC_VISIBILITY #define IN_FILE(x) 1 -#define IN_HEADER defined +#define IN_HEADER(x) (x##___X != ___X) #if IN_HEADER(__G_BOXED_H__) #if IN_FILE(__G_BOXED_C__)
Looks fine to me if it works with gcc. Please provide a patch against the make...alias.pl scripts, the files you patch are generated.
Unless I miss something, that change doesn't seem to work for gcc: #define FOO_C #undef IN_FILE #define IN_FILE(x) (x##___X != ___X) #if IN_FILE(FOO_C) #warning in file foo.c #else #warning NOT in file foo.c #endif #if IN_FILE(BAR_C) #warning in file bar.c #else #warning NOT in file bar.c #endif #undef IN_FILE #define IN_FILE defined #if IN_FILE(FOO_C) #warning in file foo.c #else #warning NOT in file foo.c #endif #if IN_FILE(BAR_C) #warning in file bar.c #else #warning NOT in file bar.c #endif Gives: /tmp/504176.c:9:2: Warnung: #warning NOT in file foo.c /tmp/504176.c:15:2: Warnung: #warning NOT in file bar.c /tmp/504176.c:22:2: Warnung: #warning in file foo.c /tmp/504176.c:30:2: Warnung: #warning NOT in file bar.c Instead of: /tmp/504176.c:9:2: Warnung: #warning in file foo.c /tmp/504176.c:15:2: Warnung: #warning NOT in file bar.c /tmp/504176.c:22:2: Warnung: #warning in file foo.c /tmp/504176.c:30:2: Warnung: #warning NOT in file bar.c When passed to gcc.
A pattern that seems to work is this: Instead of just: #define FOO_C the folliwng must be used in the code files: #define FOO_C 1 The check would look like this: #undef IN_FILE #define IN_FILE(x) ((x) != 0) This uses the fact, that pre-processors seem to treat undefined symbols as 0. Next question: Why does each and every glib and gtk sub-library has its on makeXXXalias.pl script? Shouldn't one single script be used, and details like symbol prefixes being read from command line, or some configuration file?
Created attachment 155825 [details] [review] part 1 Here is part 1 of the proposed changes.
Created attachment 155826 [details] [review] part 2 Now to change all the "#define FOO" to "#define FOO 1" This was tested on UnixWare 7.1.4 w/ native compiler, Solaris 8 w/ gcc 3.4.6 and Solaris 10 w/ Sun Studio 12.
I should have mentioned this was using 2.23.5 code.
Created attachment 155894 [details] [review] part2a I found a duplicate #define __G_UTILS_C__ 1 in glib/gutils.c that need fixing too. Apply this patch in addition to the other 2.
galias.h is no more, so this problem should be solved.