[gdk-pixbuf] Builds: Add a fallback-c89.c for pre-C99 compilers



commit ad0ca78ae40da45fe699743917d588c21ec89f39
Author: Chun-wei Fan <fanchunwei src gnome org>
Date:   Fri Feb 17 18:36:53 2017 +0800

    Builds: Add a fallback-c89.c for pre-C99 compilers
    
    Some supported compilers lack some C99 math functions that are beginning
    to be used in the code, so this adds a fallback implementation for them,
    namely round() and lrint(), where the fallbacks are used if they are not
    found during configure.
    
    For Visual Studio builds, config.h.win32.in is updated to reflect the
    situation on various Visual Studio versions as Visual Studio builds
    do not use autotools.

 config.h.win32.in          |   10 +++++++++
 configure.ac               |    3 ++
 gdk-pixbuf/Makefile.am     |    3 +-
 gdk-pixbuf/fallback-c89.c  |   49 ++++++++++++++++++++++++++++++++++++++++++++
 gdk-pixbuf/io-jpeg.c       |    1 +
 gdk-pixbuf/io-png.c        |    3 +-
 gdk-pixbuf/io-tiff.c       |    1 +
 gdk-pixbuf/pixops/pixops.c |    1 +
 8 files changed, 68 insertions(+), 3 deletions(-)
---
diff --git a/config.h.win32.in b/config.h.win32.in
index 9a8640b..1aaa149 100644
--- a/config.h.win32.in
+++ b/config.h.win32.in
@@ -41,12 +41,22 @@
 /*#define HAVE_INTTYPES_H*/
 #endif
 
+/* Define to 1 if lrint() is available */
+#if !defined (_MSC_VER) || (_MSC_VER >= 1800)
+#define HAVE_LRINT 1
+#endif
+
 /* Define to 1 if you have the <memory.h> header file. */
 #define HAVE_MEMORY_H 1
 
 /* Define to 1 is libjpeg supports progressive JPEG */
 #define HAVE_PROGRESSIVE_JPEG 1
 
+/* Define to 1 if round() is available */
+#if !defined (_MSC_VER) || (_MSC_VER >= 1800)
+#define HAVE_ROUND 1
+#endif
+
 /* Define to 1 if sigsetjmp is available */
 /*#undef HAVE_SIGSETJMP*/
 
diff --git a/configure.ac b/configure.ac
index 491a9b5..5bab061 100644
--- a/configure.ac
+++ b/configure.ac
@@ -424,6 +424,9 @@ AC_CHECK_FUNCS(setrlimit)
 saved_cflags="$CFLAGS"
 saved_ldflags="$LDFLAGS"
 
+AC_CHECK_LIB(m,round,)
+AC_CHECK_LIB(m,lrint,)
+AC_CHECK_FUNCS(round lrint)
 
 # Checks for header files.
 AC_HEADER_STDC
diff --git a/gdk-pixbuf/Makefile.am b/gdk-pixbuf/Makefile.am
index a318985..691cb78 100644
--- a/gdk-pixbuf/Makefile.am
+++ b/gdk-pixbuf/Makefile.am
@@ -595,7 +595,8 @@ EXTRA_DIST =                                        \
        gdk-pixbuf-enum-types.c.template        \
        gdk-pixbuf-enum-types.h.template        \
        gen-color-table.pl                      \
-       gdiplus.def
+       gdiplus.def                             \
+       fallback-c89.c
 
 # ---------- MSVC Items ------------------
 
diff --git a/gdk-pixbuf/fallback-c89.c b/gdk-pixbuf/fallback-c89.c
new file mode 100755
index 0000000..f2078ff
--- /dev/null
+++ b/gdk-pixbuf/fallback-c89.c
@@ -0,0 +1,49 @@
+/* GTK - The GIMP Toolkit
+ * Copyright (C) 2011 Chun-wei Fan <fanc999 yahoo com tw>
+ *
+ * Author: Chun-wei Fan <fanc999 yahoo com tw>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <math.h>
+ 
+/* Workaround for round() for non-GCC/non-C99 compilers */
+#ifndef HAVE_ROUND
+static inline double
+round (double x)
+{
+  if (x >= 0)
+    return floor (x + 0.5);
+  else
+    return ceil (x - 0.5);
+}
+#endif
+
+/* Workaround for lrint() for non-GCC/non-C99 compilers */
+#ifndef HAVE_LRINT
+static inline long
+lrint (double x)
+{
+  if (ceil (x + 0.5) == floor (x + 0.5))
+    {
+      if (x < 1 && x > -1)
+        return 0;
+
+      return (int) ceil (x) % 2 == 0 ? ceil (x) : floor (x);
+    }
+  else
+    return x >= 0 ? floor (x + 0.5) : ceil (x - 0.5);
+}
+#endif
\ No newline at end of file
diff --git a/gdk-pixbuf/io-jpeg.c b/gdk-pixbuf/io-jpeg.c
index 96f993f..92ec36b 100644
--- a/gdk-pixbuf/io-jpeg.c
+++ b/gdk-pixbuf/io-jpeg.c
@@ -35,6 +35,7 @@
 #include <math.h>
 
 #include "gdk-pixbuf-private.h"
+#include "fallback-c89.c"
 
 #ifndef HAVE_SIGSETJMP
 #define sigjmp_buf jmp_buf
diff --git a/gdk-pixbuf/io-png.c b/gdk-pixbuf/io-png.c
index a9fc1f6..759e78a 100644
--- a/gdk-pixbuf/io-png.c
+++ b/gdk-pixbuf/io-png.c
@@ -28,8 +28,7 @@
 #include <png.h>
 #include <math.h>
 #include "gdk-pixbuf-private.h"
-
-
+#include "fallback-c89.c"
 
 static gboolean
 setup_png_transformations(png_structp png_read_ptr, png_infop png_info_ptr,
diff --git a/gdk-pixbuf/io-tiff.c b/gdk-pixbuf/io-tiff.c
index 62f2531..4d10ef0 100644
--- a/gdk-pixbuf/io-tiff.c
+++ b/gdk-pixbuf/io-tiff.c
@@ -36,6 +36,7 @@
 #include <tiffio.h>
 #include <errno.h>
 #include "gdk-pixbuf-private.h"
+#include "fallback-c89.c"
 
 #ifdef G_OS_WIN32
 #include <fcntl.h>
diff --git a/gdk-pixbuf/pixops/pixops.c b/gdk-pixbuf/pixops/pixops.c
index dc1b461..f91f0e3 100644
--- a/gdk-pixbuf/pixops/pixops.c
+++ b/gdk-pixbuf/pixops/pixops.c
@@ -21,6 +21,7 @@
 #include <math.h>
 #include <glib.h>
 
+#include "../fallback-c89.c"
 #include "pixops.h"
 #include "pixops-internal.h"
 


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