Re: babl portability patches, and a test failure

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

 



Hi,

attached is a patch for babl_log. I am not too happy with the outcome as
it will result in less informative log output on platforms that don't
support variadic macros. But I guess that's somewhat hard to avoid and
hopefully the most important platforms will support this feature. I'd
appreciate feedback on this patch.


Sven

Index: babl/babl-internal.h
===================================================================
--- babl/babl-internal.h	(revision 394)
+++ babl/babl-internal.h	(working copy)
@@ -122,7 +122,7 @@ int      babl_type_is_symmetric         
 /* FIXME: nasty,. including the symbol even in files where it is
  * not needed,. and a dummy function to use it in those cases
  */
-static BablDb *db=NULL;
+static BablDb *db = NULL;
 static void hack_hack (void)
 {
   if (db==NULL)
@@ -135,26 +135,27 @@ static void hack_hack (void)
 void babl_backtrack (void);
 
 static inline void
-real_babl_log (const char *file,
-               int         line,
-               const char *function,
-               const char *fmt, ...)
+real_babl_logv (const char *file,
+                int         line,
+                const char *function,
+                const char *fmt,
+                va_list     varg)
 {
-  Babl *extender = babl_extender();
-  va_list  varg;
-
-
-  if (extender != babl_extension_quiet_log())
+  if (file && function)
     {
-      if (babl_extender())
-        fprintf (stdout, "When loading %s:\n\t", babl_extender()->instance.name);
+      Babl *extender = babl_extender();
 
-      fprintf (stdout, "%s:%i %s()\n\t", file, line, function);
+      if (extender != babl_extension_quiet_log())
+        {
+          if (babl_extender())
+            fprintf (stdout, "When loading %s:\n\t",
+                     babl_extender()->instance.name);
+
+          fprintf (stdout, "%s:%i %s()\n\t", file, line, function);
+        }
     }
 
-  va_start (varg, fmt);
   vfprintf (stdout, fmt, varg);
-  va_end (varg);
 
   fprintf (stdout, "\n");
   fflush (NULL);
@@ -162,14 +163,67 @@ real_babl_log (const char *file,
   hack_hack ();
 }
 
-#define babl_log(args...)                               \
+static inline void
+real_babl_log (const char *file,
+               int         line,
+               const char *function,
+               const char *fmt,
+               ...)
+{
+  va_list varg;
+
+  va_start (varg, fmt);
+  real_babl_logv (file, line, function, fmt, varg);
+  va_end (varg);
+}
+
+#ifdef HAVE_ISO_C_VARARGS
+
+#define babl_log(...)                                       \
+  real_babl_log(__FILE__, __LINE__, __func__, __VA_ARGS__)
+
+#define babl_fatal(...) do{                                 \
+  real_babl_log(__FILE__, __LINE__, __func__, __VA_ARGS__); \
+  babl_die();}                                              \
+while(0)
+
+#elif if defined(HAVE_GNUC_VARARGS)
+
+#define babl_log(args...)                                   \
   real_babl_log(__FILE__, __LINE__, __func__, args)
 
-#define babl_fatal(args...) do{                         \
-  real_babl_log(__FILE__, __LINE__, __func__, args);\
-  babl_die();}                                          \
+#define babl_fatal(args...) do{                             \
+  real_babl_log(__FILE__, __LINE__, __func__, args);        \
+  babl_die();}                                              \
 while(0)
 
+#else   /* no varargs macros */
+
+static void
+babl_log (const char *fmt,
+          ...)
+{
+  va_list args;
+
+  va_start (args, fmt);
+  real_babl_logv (NULL, 0, NULL, fmt, args);
+  va_end (args);
+}
+
+static void
+babl_fatal (const char *fmt,
+            ...)
+{
+  va_list args;
+
+  va_start (args, fmt);
+  real_babl_logv (NULL, 0, NULL, fmt, args);
+  va_end (args);
+  babl_die();
+}
+
+#endif
+
 
 #define babl_assert(expr) do{                              \
   if(!(expr))                                              \
Index: configure.ac
===================================================================
--- configure.ac	(revision 393)
+++ configure.ac	(working copy)
@@ -132,12 +132,46 @@ BABL_DETECT_CFLAGS(extra_warnings, '-Wol
 CFLAGS="$CFLAGS $extra_warnings"
 
 
+######################################
+# Check for flavours of varargs macros
+######################################
+
+AC_MSG_CHECKING(for ISO C99 varargs macros in C)
+AC_TRY_COMPILE([],[
+int a(int p1, int p2, int p3);
+#define call_a(...) a(1,__VA_ARGS__)
+call_a(2,3);
+], have_iso_c_varargs=yes, have_iso_c_varargs=no)
+AC_MSG_RESULT($have_iso_c_varargs)
+if test "x$have_iso_c_varargs" = "xyes"; then
+  AC_DEFINE(HAVE_ISO_C_VARARGS, 1,
+            [Define to 1 if the compiler supports ISO C99 variadic macros])
+fi
+
+AC_MSG_CHECKING(for GNUC varargs macros)
+AC_TRY_COMPILE([],[
+int a(int p1, int p2, int p3);
+#define call_a(params...) a(1,params)
+call_a(2,3);
+], have_gnuc_varargs=yes, have_gnuc_varargs=no)
+AC_MSG_RESULT($g_have_gnuc_varargs)
+if test "x$have_gnuc_varargs" = "xyes"; then
+  AC_DEFINE(HAVE_GNUC_VARARGS, 1,
+            [Define to 1 if the compiler supports GNUC variadic macros])
+fi
+
+
+################################
+# Check availability of programs
+################################
+
 AC_PATH_PROG(INKSCAPE, inkscape, no)
 AM_CONDITIONAL(HAVE_INKSCAPE, test "x$INKSCAPE" != "xno")
 
 AC_PATH_PROG(W3M, w3m, no)
 AM_CONDITIONAL(HAVE_W3M, test "x$W3M" != "xno")
 
+
 ###########################
 # Check target architecture
 ###########################
_______________________________________________
Gegl-developer mailing list
Gegl-developer@xxxxxxxxxxxxxxxxxxxxxx
https://lists.XCF.Berkeley.EDU/mailman/listinfo/gegl-developer

[Index of Archives]     [Yosemite News]     [Yosemite Photos]     [gtk]     [GIMP Users]     [KDE]     [Gimp's Home]     [Gimp on Windows]     [Steve's Art]

  Powered by Linux