From 317e9c2234929bd8b1932bde22a6b5c3abf31834 Mon Sep 17 00:00:00 2001 From: Andrew Kane Date: Fri, 18 Oct 2024 13:26:08 -0700 Subject: [PATCH] Fix compilation on Ubuntu 20.04 --- .github/workflows/testing.yml | 3 +++ include/rice/rice.hpp | 28 +++++++++------------------- rice/detail/NativeRegistry.hpp | 4 +--- rice/detail/NativeRegistry.ipp | 24 ++++++++---------------- 4 files changed, 21 insertions(+), 38 deletions(-) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index b2ac0336..4854dd83 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -13,6 +13,9 @@ jobs: matrix: os: [ubuntu-latest, macos-latest, windows-latest] ruby: ['3.0', '3.1', '3.2', '3.3'] + include: + - os: ubuntu-20.04 + ruby: '3.1' runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v4 diff --git a/include/rice/rice.hpp b/include/rice/rice.hpp index 87bd59dd..c14e79be 100644 --- a/include/rice/rice.hpp +++ b/include/rice/rice.hpp @@ -1075,7 +1075,6 @@ namespace Rice::detail #include #include -#include namespace Rice::detail @@ -1094,8 +1093,7 @@ namespace Rice::detail Return_T lookup(VALUE klass, ID method_id); private: - size_t key(VALUE klass, ID method_id); - std::unordered_multimap> natives_ = {}; + std::unordered_multimap> natives_ = {}; }; } @@ -1111,14 +1109,6 @@ namespace Rice::detail namespace Rice::detail { - // Effective Java (2nd edition) - // https://stackoverflow.com/a/2634715 - inline size_t NativeRegistry::key(VALUE klass, ID id) - { - uint32_t prime = 53; - return (prime + klass) * prime + id; - } - inline void NativeRegistry::add(VALUE klass, ID method_id, std::any callable) { if (rb_type(klass) == T_ICLASS) @@ -1126,19 +1116,19 @@ namespace Rice::detail klass = detail::protect(rb_class_of, klass); } - auto range = this->natives_.equal_range(key(klass, method_id)); + auto range = this->natives_.equal_range(method_id); for (auto it = range.first; it != range.second; ++it) { - const auto [k, m, d] = it->second; + const auto [k, d] = it->second; - if (k == klass && m == method_id) + if (k == klass) { - std::get<2>(it->second) = callable; + std::get<1>(it->second) = callable; return; } } - this->natives_.emplace(std::make_pair(key(klass, method_id), std::make_tuple(klass, method_id, callable))); + this->natives_.emplace(std::make_pair(method_id, std::make_pair(klass, callable))); } template @@ -1162,12 +1152,12 @@ namespace Rice::detail klass = detail::protect(rb_class_of, klass); } - auto range = this->natives_.equal_range(key(klass, method_id)); + auto range = this->natives_.equal_range(method_id); for (auto it = range.first; it != range.second; ++it) { - const auto [k, m, d] = it->second; + const auto [k, d] = it->second; - if (k == klass && m == method_id) + if (k == klass) { auto* ptr = std::any_cast(&d); if (!ptr) diff --git a/rice/detail/NativeRegistry.hpp b/rice/detail/NativeRegistry.hpp index 3c7b9575..866a4bd9 100644 --- a/rice/detail/NativeRegistry.hpp +++ b/rice/detail/NativeRegistry.hpp @@ -3,7 +3,6 @@ #include #include -#include #include "ruby.hpp" @@ -23,8 +22,7 @@ namespace Rice::detail Return_T lookup(VALUE klass, ID method_id); private: - size_t key(VALUE klass, ID method_id); - std::unordered_multimap> natives_ = {}; + std::unordered_multimap> natives_ = {}; }; } #include "NativeRegistry.ipp" diff --git a/rice/detail/NativeRegistry.ipp b/rice/detail/NativeRegistry.ipp index 78ba58b8..19478d4f 100644 --- a/rice/detail/NativeRegistry.ipp +++ b/rice/detail/NativeRegistry.ipp @@ -10,14 +10,6 @@ namespace Rice::detail { - // Effective Java (2nd edition) - // https://stackoverflow.com/a/2634715 - inline size_t NativeRegistry::key(VALUE klass, ID id) - { - uint32_t prime = 53; - return (prime + klass) * prime + id; - } - inline void NativeRegistry::add(VALUE klass, ID method_id, std::any callable) { if (rb_type(klass) == T_ICLASS) @@ -25,19 +17,19 @@ namespace Rice::detail klass = detail::protect(rb_class_of, klass); } - auto range = this->natives_.equal_range(key(klass, method_id)); + auto range = this->natives_.equal_range(method_id); for (auto it = range.first; it != range.second; ++it) { - const auto [k, m, d] = it->second; + const auto [k, d] = it->second; - if (k == klass && m == method_id) + if (k == klass) { - std::get<2>(it->second) = callable; + std::get<1>(it->second) = callable; return; } } - this->natives_.emplace(std::make_pair(key(klass, method_id), std::make_tuple(klass, method_id, callable))); + this->natives_.emplace(std::make_pair(method_id, std::make_pair(klass, callable))); } template @@ -61,12 +53,12 @@ namespace Rice::detail klass = detail::protect(rb_class_of, klass); } - auto range = this->natives_.equal_range(key(klass, method_id)); + auto range = this->natives_.equal_range(method_id); for (auto it = range.first; it != range.second; ++it) { - const auto [k, m, d] = it->second; + const auto [k, d] = it->second; - if (k == klass && m == method_id) + if (k == klass) { auto* ptr = std::any_cast(&d); if (!ptr)