[gtk/324.c89] gtk/fallback-c89.c: Add fallback for fmin()




commit 0398e5aa5fb03729573cd835fb39860fd52a2a5b
Author: Chun-wei Fan <fanchunwei src gnome org>
Date:   Wed Dec 23 11:28:10 2020 +0800

    gtk/fallback-c89.c: Add fallback for fmin()
    
    fmin() is a function that is introduced with C99/C++11, so check for the
    presence of it and provide a simple implementation for it if it does not
    exist.
    
    Also update the config.h.win32.in template accordingly, since this
    function is provided on Visual Studio 2013 or later.

 config.h.win32.in       | 5 +++++
 configure.ac            | 2 +-
 gtk/fallback-c89.c      | 8 ++++++++
 gtk/gtkscrolledwindow.c | 2 +-
 meson.build             | 1 +
 5 files changed, 16 insertions(+), 2 deletions(-)
---
diff --git a/config.h.win32.in b/config.h.win32.in
index 62fe46149c..71e2186333 100644
--- a/config.h.win32.in
+++ b/config.h.win32.in
@@ -29,6 +29,11 @@
 /* Define to 1 if you have the `dcgettext' function. */
 #define HAVE_DCGETTEXT 1
 
+/* Define to 1 if you have the declaration of `fmin', and to 0 if you don't. */
+#if !defined (_MSC_VER) || (_MSC_VER >= 1800)
+# define HAVE_DECL_FMIN 1
+#endif
+
 /* Define to 1 if you have the declaration of `isinf', and to 0 if you don't.
    */
 #if !defined (_MSC_VER) || (_MSC_VER >= 1800)
diff --git a/configure.ac b/configure.ac
index 51467bb6cc..fb216bce9c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -844,7 +844,7 @@ AC_TYPE_UID_T
 # Check for log2(), exp2(), nearbyint() and trunc()
 AC_CHECK_LIB(m,round,,)
 AC_CHECK_FUNCS(round rint nearbyint sincos exp2 log2 trunc)
-AC_CHECK_DECLS([isnan, isinf], [], [], [[#include <math.h>]])
+AC_CHECK_DECLS([isnan, isinf, fmin], [], [], [[#include <math.h>]])
 
 AC_MSG_CHECKING(whether to build dynamic modules)
 
diff --git a/gtk/fallback-c89.c b/gtk/fallback-c89.c
index 737983c049..2e5a61159d 100644
--- a/gtk/fallback-c89.c
+++ b/gtk/fallback-c89.c
@@ -126,3 +126,11 @@ isnan (double x)
   return _isnan (x);
 }
 #endif
+
+#ifndef HAVE_DECL_FMIN
+static inline double
+fmin (double x, double y)
+{
+  return x < y ? x : y;
+}
+#endif
diff --git a/gtk/gtkscrolledwindow.c b/gtk/gtkscrolledwindow.c
index 408c09265d..bea7339f39 100644
--- a/gtk/gtkscrolledwindow.c
+++ b/gtk/gtkscrolledwindow.c
@@ -48,7 +48,7 @@
 #include "gtkprogresstrackerprivate.h"
 #include "gtksettingsprivate.h"
 
-#include <math.h>
+#include "fallback-c89.c"
 
 /**
  * SECTION:gtkscrolledwindow
diff --git a/meson.build b/meson.build
index b2eaa33a88..896b9791a5 100644
--- a/meson.build
+++ b/meson.build
@@ -262,6 +262,7 @@ endforeach
 
 cdata.set('HAVE_DECL_ISINF', cc.has_header_symbol('math.h', 'isinf') ? 1 : false)
 cdata.set('HAVE_DECL_ISNAN', cc.has_header_symbol('math.h', 'isnan') ? 1 : false)
+cdata.set('HAVE_DECL_FMIN', cc.has_header_symbol('math.h', 'fmin') ? 1 : false)
 
 # Disable deprecation checks for all libraries we depend on on stable branches.
 # This is so newer versions of those libraries don't cause more warnings with


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