After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 504176 - "#define IN_HEADER defined" irritates SunCC-12
"#define IN_HEADER defined" irritates SunCC-12
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: general
2.14.x
Other Solaris
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2007-12-18 04:17 UTC by john heasley
Modified: 2010-08-26 04:05 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
part 1 (1.98 KB, patch)
2010-03-11 04:49 UTC, Tim Rice
none Details | Review
part 2 (93.02 KB, patch)
2010-03-11 04:53 UTC, Tim Rice
none Details | Review
part2a (460 bytes, patch)
2010-03-11 20:57 UTC, Tim Rice
none Details | Review

Description john heasley 2007-12-18 04:17:19 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__)
Comment 1 Matthias Clasen 2007-12-22 18:30:24 UTC
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.
Comment 2 Mathias Hasselmann (IRC: tbf) 2007-12-24 13:24:19 UTC
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.
Comment 3 Mathias Hasselmann (IRC: tbf) 2007-12-24 14:38:23 UTC
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?
Comment 4 Tim Rice 2010-03-11 04:49:56 UTC
Created attachment 155825 [details] [review]
part 1

Here is part 1 of the proposed changes.
Comment 5 Tim Rice 2010-03-11 04:53:22 UTC
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.
Comment 6 Tim Rice 2010-03-11 04:57:02 UTC
I should have mentioned this was using 2.23.5 code.
Comment 7 Tim Rice 2010-03-11 20:57:29 UTC
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.
Comment 8 Matthias Clasen 2010-08-26 04:05:49 UTC
galias.h is no more, so this problem should be solved.