0005-boost-remove-deprecated-math-common_factor.hpp.patch 5.6 KB

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