many packages __FUNCTION__ problems



hello,

oki as manny of you know development goes on, so is gcc 3.0.3 going on
and a lot of gnome related packages unfortunately causes an error
when used with -Werror on __FUNCTION__ since it is marked as depracted
in gcc 3.0.3 because of c99. also the glib solution is no real solution.
to make sure that people with most recent compiler can use your package
and for the sake of future consistence look at this patch that i applied
here.

what does this patch do:

a) it adds some sumbroutines to configure.in which checks in this row:

   do we have funct (yes/no)
     if yes, export variable
     if no
       do we have pretty function (yes/no)
         if yes, export variable
         if no
           do we have function (yes/no)
             if yes, export variable
             if no (should'nt happen)

b) adds the declaraions to acconfig.h
c) your_source_that_contains_function.c

   added three different ifdefs so we always get the right code.

i added pretty_function because i belive that pretty function outputs
more information than function. i know that on other unix systems a lot
of compilers doesn't support __FUNCTION__ but __func__ so if this works
then i bet you can offer your packages to a more wide userbase.

you need less than 5 minutes to figure out what my patch does and how to
apply it to your own package. by doing this you make sure that a lot of
people won't get any errors.

i welcome comments, suggestions, corrections and feedback. i may also be
wrong with this (i doubt it). but it's worth to pay attention to this
and take care to solve this issue correctly.

attached example is done for gdm2 cvs (gnome1) and should only be an
example. i already send some patches to some other project but since
they are too many of them, so i can't handle all patches on my own.

-- 
Name....: Ali Akcaagac
Status..: Student Of Computer & Economic Science
E-Mail..: mailto:ali akcaagac stud fh-wilhelmshaven de
WWW.....: http://www.fh-wilhelmshaven.de/~akcaagaa
diff -ruN gdm2-cvs/acconfig.h gdm2/acconfig.h
--- gdm2-cvs/acconfig.h	Mon Jan 28 21:14:53 2002
+++ gdm2/acconfig.h	Mon Jan 28 21:14:52 2002
@@ -15,6 +15,9 @@
 #undef HAVE_SETENV
 #undef HAVE_UNSETENV
 #undef HAVE_CLEARENV
+#undef HAVE_FUNC
+#undef HAVE_PRETTY_FUNCTION
+#undef HAVE_FUNCTION
 #undef EXPANDED_DATADIR
 #undef EXPANDED_PIXMAPDIR
 #undef EXPANDED_BINDIR
diff -ruN gdm2-cvs/configure.in gdm2/configure.in
--- gdm2-cvs/configure.in	Mon Jan 28 21:14:53 2002
+++ gdm2/configure.in	Mon Jan 28 21:14:52 2002
@@ -331,6 +331,39 @@
 AC_SUBST(PIXBUF_LIBS)
 AC_SUBST(GDK_PIXBUF_REQUIRED)
 
+dnl
+dnl Check for functions
+dnl
+AC_MSG_CHECKING(whether $GCC implements __func__)
+AC_CACHE_VAL(have_func,
+[AC_TRY_LINK([#include <stdio.h>],[printf("%s", __func__);],
+have_func=yes,
+have_func=no)])
+AC_MSG_RESULT($have_func)
+if test "$have_func" = yes; then
+	AC_DEFINE(HAVE_FUNC)
+else
+	AC_MSG_CHECKING(whether $GCC implements __PRETTY_FUNCTION__)
+	AC_CACHE_VAL(have_pretty_function,
+	[AC_TRY_LINK([#include <stdio.h>],[printf("%s", __PRETTY_FUNCTION__);],
+	have_pretty_function=yes,
+	have_pretty_function=no)])
+	AC_MSG_RESULT($have_pretty_function)
+	if test "$have_pretty_function" = yes; then
+		AC_DEFINE(HAVE_PRETTY_FUNCTION)
+	else
+		AC_MSG_CHECKING(whether $GCC implements __FUNCTION__)
+		AC_CACHE_VAL(have_function,
+		[AC_TRY_LINK([#include <stdio.h>],[printf("%s", __FUNCTION__);],
+		have_function=yes,
+		have_function=no)])
+		AC_MSG_RESULT($have_function)
+		if test "$have_function" = yes; then
+			AC_DEFINE(HAVE_FUNCTION)
+		fi
+	fi
+fi
+
 #
 # Configuration file foo, we need to get expanded versions of a bunch of things
 # if you actually know how to code shell then fix this :-) 
diff -ruN gdm2-cvs/gui/gdmwm.c gdm2/gui/gdmwm.c
--- gdm2-cvs/gui/gdmwm.c	Mon Jan 28 21:14:54 2002
+++ gdm2/gui/gdmwm.c	Mon Jan 28 21:14:53 2002
@@ -191,6 +191,16 @@
 	return gdk_error_trap_pop ();
 }
 
+#ifdef HAVE_FUNC
+#define FUNCTION __func__
+#elif HAVE_PRETTY_FUNCTION
+#define FUNCTION __PRETTY_FUNCTION__
+#elif HAVE_FUNCTION
+#define FUNCTION __FUNCTION__
+#else
+#define FUNCTION ""
+#endif
+
 /* stolen from gwmh */
 static gpointer
 get_typed_property_data (Display *xdisplay,
@@ -235,13 +245,13 @@
     }
   if (!abort && bytes_after_return)
     {
-      g_warning (G_GNUC_PRETTY_FUNCTION "(): Eeek, property has more than %u bytes, stored on harddisk?",
+      g_warning (FUNCTION "(): Eeek, property has more than %u bytes, stored on harddisk?",
 		 prop_buffer_lengh);
       abort++;
     }
   if (!abort && expected_format && expected_format != format_returned)
     {
-      g_warning (G_GNUC_PRETTY_FUNCTION "(): Expected format (%u) unmatched (%d), programmer was drunk?",
+      g_warning (FUNCTION "(): Expected format (%u) unmatched (%d), programmer was drunk?",
 		 expected_format, format_returned);
       abort++;
     }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]