1From 2c767bb260a25b415e8c9c4b3ea37280b2127cec Mon Sep 17 00:00:00 2001 2From: japm48 <japm48@users.noreply.github.com> 3Date: Fri, 10 Apr 2020 23:35:30 +0200 4Subject: [PATCH] boost: remove deprecated math/common_factor.hpp 5 6Remove deprecation warning and prefer using std::{lcm,gcd} to Boost. 7Fixes #2712. 8 9[Retrieved from: 10https://github.com/gnuradio/gnuradio/commit/2c767bb260a25b415e8c9c4b3ea37280b2127cec] 11Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com> 12--- 13 .../include/gnuradio/CMakeLists.txt | 1 + 14 .../include/gnuradio/integer_math.h | 35 +++++++++++++++++++ 15 gnuradio-runtime/lib/buffer.cc | 19 ++-------- 16 gr-digital/lib/symbol_sync_cc_impl.cc | 4 +-- 17 gr-digital/lib/symbol_sync_ff_impl.cc | 4 +-- 18 5 files changed, 43 insertions(+), 20 deletions(-) 19 create mode 100644 gnuradio-runtime/include/gnuradio/integer_math.h 20 21diff --git a/gnuradio-runtime/include/gnuradio/CMakeLists.txt b/gnuradio-runtime/include/gnuradio/CMakeLists.txt 22index 8d718e87b5b..056af5d6f48 100644 23--- a/gnuradio-runtime/include/gnuradio/CMakeLists.txt 24+++ b/gnuradio-runtime/include/gnuradio/CMakeLists.txt 25@@ -31,6 +31,7 @@ install(FILES 26 gr_complex.h 27 hier_block2.h 28 high_res_timer.h 29+ integer_math.h 30 io_signature.h 31 logger.h 32 math.h 33diff --git a/gnuradio-runtime/include/gnuradio/integer_math.h b/gnuradio-runtime/include/gnuradio/integer_math.h 34new file mode 100644 35index 00000000000..15141049fa4 36--- /dev/null 37+++ b/gnuradio-runtime/include/gnuradio/integer_math.h 38@@ -0,0 +1,35 @@ 39+/* -*- c++ -*- */ 40+/* 41+ * Copyright 2020 Free Software Foundation, Inc. 42+ * 43+ * This file is part of GNU Radio 44+ * 45+ * SPDX-License-Identifier: GPL-3.0-or-later 46+ * 47+ */ 48+#ifndef INCLUDED_GR_INTEGER_MATH_H 49+#define INCLUDED_GR_INTEGER_MATH_H 50+ 51+#if (__cplusplus >= 201703L) 52+ 53+// Prefer C++17 goodness. 54+#include <numeric> 55+#define GR_GCD std::gcd 56+#define GR_LCM std::lcm 57+ 58+#elif (BOOST_VERSION >= 105800) 59+ 60+// Fallback: newer boost API (introduced in Boost 1.58.0). 61+#include <boost/integer/common_factor_rt.hpp> 62+#define GR_GCD boost::integer::gcd 63+#define GR_LCM boost::integer::lcm 64+ 65+#else 66+ 67+// Last resort: old deprecated boost API. 68+#include <boost/math/common_factor_rt.hpp> 69+#define GR_GCD boost::math::gcd 70+#define GR_LCM boost::math::lcm 71+ 72+#endif /* __cplusplus >= 201703L */ 73+#endif /* INCLUDED_GR_INTEGER_MATH_H */ 74diff --git a/gnuradio-runtime/lib/buffer.cc b/gnuradio-runtime/lib/buffer.cc 75index 720c72c4ee8..46d704542b1 100644 76--- a/gnuradio-runtime/lib/buffer.cc 77+++ b/gnuradio-runtime/lib/buffer.cc 78@@ -13,22 +13,13 @@ 79 #endif 80 #include "vmcircbuf.h" 81 #include <gnuradio/buffer.h> 82+#include <gnuradio/integer_math.h> 83 #include <gnuradio/math.h> 84 #include <assert.h> 85 #include <algorithm> 86 #include <iostream> 87 #include <stdexcept> 88 89-// the following header is deprecated as of Boost 1.66.0, and the 90-// other API was introduced in Boost 1.58.0. Since we still support 91-// Boost back to 1.54.0, use the older API if pre-1.5.80 and otherwise 92-// use the newer API. 93-#if (BOOST_VERSION < 105800) 94-#include <boost/math/common_factor_rt.hpp> 95-#else 96-#include <boost/integer/common_factor_rt.hpp> 97-#endif 98- 99 namespace gr { 100 101 static long s_buffer_count = 0; // counts for debugging storage mgmt 102@@ -68,13 +59,9 @@ static long s_buffer_reader_count = 0; 103 * 104 * type_size * nitems == k * page_size 105 */ 106-static long minimum_buffer_items(long type_size, long page_size) 107+static inline long minimum_buffer_items(long type_size, long page_size) 108 { 109-#if (BOOST_VERSION < 105800) 110- return page_size / boost::math::gcd(type_size, page_size); 111-#else 112- return page_size / boost::integer::gcd(type_size, page_size); 113-#endif 114+ return page_size / GR_GCD(type_size, page_size); 115 } 116 117 118diff --git a/gr-digital/lib/symbol_sync_cc_impl.cc b/gr-digital/lib/symbol_sync_cc_impl.cc 119index 55f85e7c6a7..55f162dc727 100644 120--- a/gr-digital/lib/symbol_sync_cc_impl.cc 121+++ b/gr-digital/lib/symbol_sync_cc_impl.cc 122@@ -13,9 +13,9 @@ 123 #endif 124 125 #include "symbol_sync_cc_impl.h" 126+#include <gnuradio/integer_math.h> 127 #include <gnuradio/io_signature.h> 128 #include <gnuradio/math.h> 129-#include <boost/math/common_factor.hpp> 130 #include <stdexcept> 131 132 namespace gr { 133@@ -95,7 +95,7 @@ symbol_sync_cc_impl::symbol_sync_cc_impl(enum ted_type detector_type, 134 throw std::runtime_error("unable to create interpolating_resampler_ccf"); 135 136 // Block Internal Clocks 137- d_interps_per_symbol_n = boost::math::lcm(d_ted->inputs_per_symbol(), d_osps_n); 138+ d_interps_per_symbol_n = GR_LCM(d_ted->inputs_per_symbol(), d_osps_n); 139 d_interps_per_ted_input_n = d_interps_per_symbol_n / d_ted->inputs_per_symbol(); 140 d_interps_per_output_sample_n = d_interps_per_symbol_n / d_osps_n; 141 142diff --git a/gr-digital/lib/symbol_sync_ff_impl.cc b/gr-digital/lib/symbol_sync_ff_impl.cc 143index d0ec32ab192..1172c1b4f8a 100644 144--- a/gr-digital/lib/symbol_sync_ff_impl.cc 145+++ b/gr-digital/lib/symbol_sync_ff_impl.cc 146@@ -13,9 +13,9 @@ 147 #endif 148 149 #include "symbol_sync_ff_impl.h" 150+#include <gnuradio/integer_math.h> 151 #include <gnuradio/io_signature.h> 152 #include <gnuradio/math.h> 153-#include <boost/math/common_factor.hpp> 154 #include <stdexcept> 155 156 namespace gr { 157@@ -97,7 +97,7 @@ symbol_sync_ff_impl::symbol_sync_ff_impl(enum ted_type detector_type, 158 throw std::runtime_error("unable to create interpolating_resampler_fff"); 159 160 // Block Internal Clocks 161- d_interps_per_symbol_n = boost::math::lcm(d_ted->inputs_per_symbol(), d_osps_n); 162+ d_interps_per_symbol_n = GR_LCM(d_ted->inputs_per_symbol(), d_osps_n); 163 d_interps_per_ted_input_n = d_interps_per_symbol_n / d_ted->inputs_per_symbol(); 164 d_interps_per_output_sample_n = d_interps_per_symbol_n / d_osps_n; 165 166