From ecd6b0b9a494a33a402cdddf16448727172f7f71 Mon Sep 17 00:00:00 2001 From: Chun-wei Fan Date: Wed, 23 Dec 2020 11:24:34 +0800 Subject: [PATCH 1/2] gtk/gtkscrolledwindow.c: Declare variables at top-of-block This way, the code can be built on C89-esque compilers. --- gtk/gtkscrolledwindow.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gtk/gtkscrolledwindow.c b/gtk/gtkscrolledwindow.c index 0f4193b14b..408c09265d 100644 --- a/gtk/gtkscrolledwindow.c +++ b/gtk/gtkscrolledwindow.c @@ -3754,10 +3754,11 @@ kinetic_scroll_stop_notify (GtkScrolledWindow *scrolled_window) static void gtk_scrolled_window_accumulate_velocity (GtkKineticScrolling **scrolling, double elapsed, double *velocity) { + double last_velocity; + if (!*scrolling) return; - double last_velocity; gtk_kinetic_scrolling_tick (*scrolling, elapsed, NULL, &last_velocity); if (((*velocity >= 0) == (last_velocity >= 0)) && (fabs (*velocity) >= fabs (last_velocity) * VELOCITY_ACCUMULATION_FLOOR)) From 91343251b98f752e1b4e6cef1e4305e085cbc289 Mon Sep 17 00:00:00 2001 From: Chun-wei Fan Date: Wed, 23 Dec 2020 11:28:10 +0800 Subject: [PATCH 2/2] 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.meson | 3 +++ config.h.win32.in | 5 +++++ configure.ac | 2 +- gtk/fallback-c89.c | 8 ++++++++ gtk/gtkscrolledwindow.c | 2 +- meson.build | 1 + 6 files changed, 19 insertions(+), 2 deletions(-) diff --git a/config.h.meson b/config.h.meson index 2af55473fc..eb347ae538 100644 --- a/config.h.meson +++ b/config.h.meson @@ -44,6 +44,9 @@ /* Define to 1 if you have the `flockfile' function. */ #mesondefine HAVE_FLOCKFILE +/* Define to 1 if you have the `fmin' function. */ +#mesondefine HAVE_FMIN + /* Define to 1 if you have the header file. */ #mesondefine HAVE_FTW_H diff --git a/config.h.win32.in b/config.h.win32.in index 62fe46149c..d0546db297 100644 --- a/config.h.win32.in +++ b/config.h.win32.in @@ -52,6 +52,11 @@ /* Define to 1 if you have the `flockfile' function. */ #undef HAVE_FLOCKFILE +/* Define to 1 if you have the `fmin' function. */ +#if !defined (_MSC_VER) || (_MSC_VER >= 1800) +# define HAVE_FMIN 1 +#endif + /* Define to 1 if you have the header file. */ /* #undef HAVE_FTW_H */ diff --git a/configure.ac b/configure.ac index 51467bb6cc..acafa2f603 100644 --- a/configure.ac +++ b/configure.ac @@ -843,7 +843,7 @@ AC_TYPE_UID_T # Check for round(), rint(), isnan() and isinf() # Check for log2(), exp2(), nearbyint() and trunc() AC_CHECK_LIB(m,round,,) -AC_CHECK_FUNCS(round rint nearbyint sincos exp2 log2 trunc) +AC_CHECK_FUNCS(round rint nearbyint sincos exp2 log2 trunc fmin) AC_CHECK_DECLS([isnan, isinf], [], [], [[#include ]]) AC_MSG_CHECKING(whether to build dynamic modules) diff --git a/gtk/fallback-c89.c b/gtk/fallback-c89.c index 737983c049..1bfa3fb3b3 100644 --- a/gtk/fallback-c89.c +++ b/gtk/fallback-c89.c @@ -126,3 +126,11 @@ isnan (double x) return _isnan (x); } #endif + +#ifndef HAVE_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 +#include "fallback-c89.c" /** * SECTION:gtkscrolledwindow diff --git a/meson.build b/meson.build index b2eaa33a88..405c5a511c 100644 --- a/meson.build +++ b/meson.build @@ -252,6 +252,7 @@ check_functions = [ 'sincos', 'trunc', 'localtime_r', + 'fmin', ] foreach func : check_functions